diff --git a/bundle/git.vim/autoload/git/commit.vim b/bundle/git.vim/autoload/git/commit.vim index 501ba803a..16f6d17ce 100644 --- a/bundle/git.vim/autoload/git/commit.vim +++ b/bundle/git.vim/autoload/git/commit.vim @@ -3,6 +3,10 @@ let s:BUFFER = SpaceVim#api#import('vim#buffer') let s:commit_bufnr = -1 +" Init +let s:commit_context = [] +let s:commit_jobid = -1 + function! git#commit#run(...) abort if index(a:1, '-m') ==# -1 if bufexists(s:commit_bufnr) && index(tabpagebuflist(), s:commit_bufnr) !=# -1 @@ -14,7 +18,7 @@ function! git#commit#run(...) abort else let s:commit_bufnr = -1 endif - let s:lines = [] + let s:commit_context = [] if empty(a:1) let cmd = ['git', '--no-pager', '-c', \ 'core.editor=cat', '-c', @@ -37,7 +41,7 @@ function! git#commit#run(...) abort \ expand(getcwd(), ':p'), \ 'commit',] + a:1 endif - call s:JOB.start(cmd, + let s:commit_jobid = s:JOB.start(cmd, \ { \ 'on_stderr' : function('s:on_stderr'), \ 'on_stdout' : function('s:on_stdout'), @@ -47,19 +51,31 @@ function! git#commit#run(...) abort endfunction function! s:on_stdout(id, data, event) abort + if a:id !=# s:commit_jobid + " ignore previous git commit job + return + endif for data in a:data call git#logger#info('git-commit stdout:' . data) endfor - let s:lines += a:data + let s:commit_context += a:data endfunction function! s:on_stderr(id, data, event) abort + if a:id !=# s:commit_jobid + " ignore previous git commit job + return + endif for data in a:data call git#logger#info('git-commit stderr:' . data) endfor " stderr should not be added to commit buffer - " let s:lines += a:data + " let s:commit_context += a:data endfunction function! s:on_exit(id, data, event) abort + if a:id !=# s:commit_jobid + " ignore previous git commit job + return + endif call git#logger#info('git-exit exit data:' . string(a:data)) if s:commit_bufnr == -1 if a:data ==# 0 @@ -68,7 +84,7 @@ function! s:on_exit(id, data, event) abort echo 'commit failed!' endif else - call s:BUFFER.buf_set_lines(s:commit_bufnr, 0 , -1, 0, s:lines) + call s:BUFFER.buf_set_lines(s:commit_bufnr, 0 , -1, 0, s:commit_context) endif endfunction @@ -101,8 +117,7 @@ endfunction " when run `:wq` the commit window will not be closed " :q -- QuitPre -> WinLeave function! s:BufWriteCmd() abort - let commit_file = '.git\COMMIT_EDITMSG' - call writefile(getline(1, '$'), commit_file) + let s:commit_context = getline(1, '$') setlocal nomodified endfunction @@ -119,7 +134,7 @@ function! s:WinLeave() abort \ } \ ) " line start with # should be ignored - call s:JOB.send(id, filter(readfile('.git\COMMIT_EDITMSG'), 'v:val !~# "^\s*#"')) + call s:JOB.send(id, filter(s:commit_context, 'v:val !~# "^\s*#"')) call s:JOB.chanclose(id, 'stdin') endif endfunction