2021-01-02 18:15:08 +08:00
|
|
|
""
|
|
|
|
" @section git-add, add
|
|
|
|
" @parentsection commands
|
|
|
|
" This commands is to add file contents to the index. For example, add current
|
|
|
|
" file to the index.
|
|
|
|
" >
|
|
|
|
" :Git add %
|
|
|
|
" <
|
|
|
|
|
2024-12-17 08:52:48 +08:00
|
|
|
if has('nvim-0.9.0')
|
|
|
|
function! git#add#complete(ArgLead, CmdLine, CursorPos) abort
|
|
|
|
return luaeval('require("git.command.add").complete(vim.api.nvim_eval("a:ArgLead"), vim.api.nvim_eval("a:CmdLine"), vim.api.nvim_eval("a:CursorPos"))')
|
|
|
|
endfunction
|
|
|
|
else
|
|
|
|
let s:JOB = SpaceVim#api#import('job')
|
|
|
|
let s:NOTI = SpaceVim#api#import('notify')
|
|
|
|
|
|
|
|
function! s:replace_argvs(argvs) abort
|
|
|
|
let argvs = []
|
|
|
|
for argv in a:argvs
|
|
|
|
if argv ==# '%'
|
|
|
|
call insert(argvs, expand('%'))
|
|
|
|
else
|
|
|
|
call insert(argvs, argv)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
return argvs
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! git#add#run(argvs) abort
|
|
|
|
let cmd = ['git', 'add'] + s:replace_argvs(a:argvs)
|
|
|
|
call git#logger#debug('git-add cmd:' . string(cmd))
|
|
|
|
call s:JOB.start(cmd,
|
|
|
|
\ {
|
2021-08-27 10:25:02 +08:00
|
|
|
\ 'on_exit' : function('s:on_exit'),
|
|
|
|
\ }
|
|
|
|
\ )
|
2021-01-02 18:15:08 +08:00
|
|
|
|
2024-12-17 08:52:48 +08:00
|
|
|
endfunction
|
2021-01-02 18:15:08 +08:00
|
|
|
|
2024-12-17 08:52:48 +08:00
|
|
|
function! s:on_exit(id, data, event) abort
|
|
|
|
call git#logger#debug('git-add exit data:' . string(a:data))
|
|
|
|
if a:data ==# 0
|
|
|
|
if exists(':GitGutter')
|
|
|
|
GitGutter
|
|
|
|
endif
|
|
|
|
call s:NOTI.notify('stage files done!')
|
|
|
|
else
|
|
|
|
call s:NOTI.notify('stage files failed!')
|
2021-01-02 18:15:08 +08:00
|
|
|
endif
|
2024-12-17 08:52:48 +08:00
|
|
|
endfunction
|
2021-01-02 18:15:08 +08:00
|
|
|
|
2024-12-17 08:52:48 +08:00
|
|
|
function! git#add#complete(ArgLead, CmdLine, CursorPos) abort
|
2021-01-02 18:15:08 +08:00
|
|
|
|
2024-12-17 08:52:48 +08:00
|
|
|
return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n")
|
2021-01-02 18:15:08 +08:00
|
|
|
|
2024-12-17 08:52:48 +08:00
|
|
|
endfunction
|
|
|
|
endif
|