1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-04 00:50:04 +08:00
SpaceVim/bundle/git.vim/autoload/git/add.vim

52 lines
1.1 KiB
VimL
Raw Normal View History

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 %
" <
let s:JOB = SpaceVim#api#import('job')
2021-08-27 10:25:02 +08:00
function! s:replace_argvs(argvs) abort
let argvs = []
for argv in a:argvs
if argv ==# '%'
call insert(argvs, expand('%'))
2021-01-02 18:15:08 +08:00
else
2021-08-27 10:25:02 +08:00
call insert(argvs, argv)
2021-01-02 18:15:08 +08:00
endif
2021-08-27 10:25:02 +08:00
endfor
return argvs
endfunction
function! git#add#run(argvs) abort
let cmd = ['git', 'add'] + s:replace_argvs(a:argvs)
call git#logger#info('git-add cmd:' . string(cmd))
call s:JOB.start(cmd,
\ {
\ 'on_exit' : function('s:on_exit'),
\ }
\ )
2021-01-02 18:15:08 +08:00
endfunction
function! s:on_exit(id, data, event) abort
2021-08-27 10:25:02 +08:00
call git#logger#info('git-add exit data:' . string(a:data))
if a:data ==# 0
if exists(':GitGutter')
GitGutter
2021-01-02 18:15:08 +08:00
endif
2021-08-27 10:25:02 +08:00
echo 'done!'
else
echo 'failed!'
endif
2021-01-02 18:15:08 +08:00
endfunction
2021-08-27 10:25:02 +08:00
function! git#add#complete(ArgLead, CmdLine, CursorPos) abort
2021-01-02 18:15:08 +08:00
2021-08-27 10:25:02 +08:00
return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n")
2021-01-02 18:15:08 +08:00
endfunction