1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 11:30:06 +08:00

feat(git): lua complete for git-fetch

This commit is contained in:
Eric Wong 2024-12-17 19:13:47 +08:00
parent 7959583115
commit eacd71c784
3 changed files with 87 additions and 35 deletions

View File

@ -1,3 +1,26 @@
"=============================================================================
" fetch.vim --- Git fetch command
" Copyright 2021 Eric Wong
" Author: Eric Wong < wsdjeg@outlook.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
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)
@ -45,3 +68,4 @@ function! s:options() abort
\ '--multiple',
\ ], "\n")
endfunction
endif

View File

@ -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*

View File

@ -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