diff --git a/bundle/git.vim/autoload/git/fetch.vim b/bundle/git.vim/autoload/git/fetch.vim index 72de2c97c..b94d3f441 100644 --- a/bundle/git.vim/autoload/git/fetch.vim +++ b/bundle/git.vim/autoload/git/fetch.vim @@ -1,47 +1,71 @@ -let s:JOB = SpaceVim#api#import('job') +"============================================================================= +" fetch.vim --- Git fetch command +" Copyright 2021 Eric Wong +" Author: Eric Wong < wsdjeg@outlook.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= -function! git#fetch#run(args) + +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) let cmd = ['git', 'fetch'] + a:args call git#logger#debug('git-fetch cmd:' . string(cmd)) call s:JOB.start(cmd, - \ { - \ 'on_exit' : function('s:on_exit'), - \ } - \ ) + \ { + \ 'on_exit' : function('s:on_exit'), + \ } + \ ) -endfunction + endfunction -function! s:on_exit(id, data, event) abort + function! s:on_exit(id, data, event) abort call git#logger#debug('git-fetch exit data:' . string(a:data)) if a:data ==# 0 - echo 'fetch done!' + echo 'fetch done!' else - echo 'fetch failed!' + echo 'fetch failed!' endif -endfunction + endfunction -function! git#fetch#complete(ArgLead, CmdLine, CursorPos) + function! git#fetch#complete(ArgLead, CmdLine, CursorPos) if a:ArgLead =~# '^-' - return s:options() + return s:options() endif let str = a:CmdLine[:a:CursorPos-1] if str =~# '^Git\s\+fetch\s\+[^ ]*$' - return join(s:remotes(), "\n") + return join(s:remotes(), "\n") else - return '' + return '' endif -endfunction + endfunction -function! s:remotes() abort + function! s:remotes() abort return map(systemlist('git remote'), 'trim(v:val)') -endfunction + endfunction -function! s:options() abort + function! s:options() abort return join([ - \ '--all', - \ '--multiple', - \ ], "\n") -endfunction + \ '--all', + \ '--multiple', + \ ], "\n") + endfunction +endif diff --git a/bundle/git.vim/doc/git.txt b/bundle/git.vim/doc/git.txt index 195928cb9..a456bd624 100644 --- a/bundle/git.vim/doc/git.txt +++ b/bundle/git.vim/doc/git.txt @@ -10,11 +10,12 @@ CONTENTS *git-contents* 3. git-checkout............................................ |git-checkout| 4. git-cherry-pick...................................... |git-cherry-pick| 5. git-clean.................................................. |git-clean| - 6. git-mv........................................................ |git-mv| - 7. git-reflog................................................ |git-reflog| - 8. git-rm........................................................ |git-rm| - 9. git-stash.................................................. |git-stash| - 10. git-tag..................................................... |git-tag| + 6. git-fetch.................................................. |git-fetch| + 7. git-mv........................................................ |git-mv| + 8. git-reflog................................................ |git-reflog| + 9. git-rm........................................................ |git-rm| + 10. git-stash................................................. |git-stash| + 11. git-tag..................................................... |git-tag| 3. Functions.................................................. |git-functions| ============================================================================== @@ -70,6 +71,14 @@ This commands is to run `git clean`. :Git clean -f < +============================================================================== +GIT-FETCH *git-fetch* + +This commands is to fetch remote repo. +> + :Git fetch --all +< + ============================================================================== GIT-MV *git-mv* diff --git a/bundle/git.vim/lua/git/command/fetch.lua b/bundle/git.vim/lua/git/command/fetch.lua index 9653f8028..b20a2192c 100644 --- a/bundle/git.vim/lua/git/command/fetch.lua +++ b/bundle/git.vim/lua/git/command/fetch.lua @@ -1,12 +1,12 @@ --============================================================================= --- fetch.lua --- :Git fetch --- Copyright (c) 2016-2022 Wang Shidong & Contributors --- Author: Wang Shidong < wsdjeg@outlook.com > +-- fetch.lua --- Git fetch +-- Copyright 2023 Eric Wong +-- Author: Eric Wong < wsdjeg@outlook.com > -- URL: https://spacevim.org -- License: GPLv3 --============================================================================= -local m = {} +local M = {} local job = require('spacevim.api.job') local nt = require('spacevim.api.notify') @@ -28,7 +28,7 @@ local function on_std(id, data) end end -function m.run(argv) +function M.run(argv) local cmd = { 'git', 'fetch' } for _, v in ipairs(argv) do table.insert(cmd, v) @@ -38,8 +38,27 @@ function m.run(argv) job.start(cmd, { on_exit = on_exit, on_stdout = on_std, - on_stderr = on_std + on_stderr = on_std, }) end -return m +local function get_remotes() + return vim.tbl_map(function(t) + return vim.fn.trim(t) + end, vim.fn.systemlist('git remote')) +end + +function M.complete(ArgLead, CmdLine, CursorPos) + if vim.startswith(ArgLead, '-') then + return table.concat({ '--all', '--multiple' }, '\n') + end + + local str = string.sub(CmdLine, 1, CursorPos) + if vim.regex([[^Git\s\+fetch\s\+[^ ]*$]]):match_str(str) then + return table.concat(get_remotes(), '\n') + else + return '' + end +end + +return M