1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 16:00:07 +08:00
SpaceVim/bundle/git.vim/autoload/git/fetch.vim

72 lines
1.7 KiB
VimL
Raw Normal View History

2024-12-17 19:13:47 +08:00
"=============================================================================
" fetch.vim --- Git fetch command
" Copyright 2021 Eric Wong
" Author: Eric Wong < wsdjeg@outlook.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
2021-01-02 18:15:08 +08:00
2024-12-17 19:13:47 +08:00
if has('nvim-0.9.0')
function! git#fetch#complete(ArgLead, CmdLine, CursorPos) abort
return luaeval('require("git.command.fetch").complete(vim.api.nvim_eval("a:ArgLead"), vim.api.nvim_eval("a:CmdLine"), vim.api.nvim_eval("a:CursorPos"))')
endfunction
else
""
" @section git-fetch, fetch
" @parentsection commands
" This commands is to fetch remote repo.
" >
" :Git fetch --all
" <
let s:JOB = SpaceVim#api#import('job')
function! git#fetch#run(args)
2021-01-02 18:15:08 +08:00
let cmd = ['git', 'fetch'] + a:args
call git#logger#debug('git-fetch cmd:' . string(cmd))
2021-01-02 18:15:08 +08:00
call s:JOB.start(cmd,
2024-12-17 19:13:47 +08:00
\ {
\ 'on_exit' : function('s:on_exit'),
\ }
\ )
2021-01-02 18:15:08 +08:00
2024-12-17 19:13:47 +08:00
endfunction
2021-01-02 18:15:08 +08:00
2024-12-17 19:13:47 +08:00
function! s:on_exit(id, data, event) abort
call git#logger#debug('git-fetch exit data:' . string(a:data))
2021-01-02 18:15:08 +08:00
if a:data ==# 0
2024-12-17 19:13:47 +08:00
echo 'fetch done!'
2021-01-02 18:15:08 +08:00
else
2024-12-17 19:13:47 +08:00
echo 'fetch failed!'
2021-01-02 18:15:08 +08:00
endif
2024-12-17 19:13:47 +08:00
endfunction
2021-01-02 18:15:08 +08:00
2024-12-17 19:13:47 +08:00
function! git#fetch#complete(ArgLead, CmdLine, CursorPos)
2021-01-02 18:15:08 +08:00
if a:ArgLead =~# '^-'
2024-12-17 19:13:47 +08:00
return s:options()
2021-01-02 18:15:08 +08:00
endif
let str = a:CmdLine[:a:CursorPos-1]
if str =~# '^Git\s\+fetch\s\+[^ ]*$'
2024-12-17 19:13:47 +08:00
return join(s:remotes(), "\n")
2021-01-02 18:15:08 +08:00
else
2024-12-17 19:13:47 +08:00
return ''
2021-01-02 18:15:08 +08:00
endif
2024-12-17 19:13:47 +08:00
endfunction
2021-01-02 18:15:08 +08:00
2024-12-17 19:13:47 +08:00
function! s:remotes() abort
2021-01-02 18:15:08 +08:00
return map(systemlist('git remote'), 'trim(v:val)')
2024-12-17 19:13:47 +08:00
endfunction
2021-01-02 18:15:08 +08:00
2024-12-17 19:13:47 +08:00
function! s:options() abort
2021-01-02 18:15:08 +08:00
return join([
2024-12-17 19:13:47 +08:00
\ '--all',
\ '--multiple',
\ ], "\n")
endfunction
endif