mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-12 09:35:40 +08:00
pref(git): use stdout/stdin instead of .git\COMMIT_EDITMSG
This commit is contained in:
parent
50c676e3a4
commit
86fd042764
@ -3,6 +3,10 @@ let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
|||||||
|
|
||||||
let s:commit_bufnr = -1
|
let s:commit_bufnr = -1
|
||||||
|
|
||||||
|
" Init
|
||||||
|
let s:commit_context = []
|
||||||
|
let s:commit_jobid = -1
|
||||||
|
|
||||||
function! git#commit#run(...) abort
|
function! git#commit#run(...) abort
|
||||||
if index(a:1, '-m') ==# -1
|
if index(a:1, '-m') ==# -1
|
||||||
if bufexists(s:commit_bufnr) && index(tabpagebuflist(), s:commit_bufnr) !=# -1
|
if bufexists(s:commit_bufnr) && index(tabpagebuflist(), s:commit_bufnr) !=# -1
|
||||||
@ -14,7 +18,7 @@ function! git#commit#run(...) abort
|
|||||||
else
|
else
|
||||||
let s:commit_bufnr = -1
|
let s:commit_bufnr = -1
|
||||||
endif
|
endif
|
||||||
let s:lines = []
|
let s:commit_context = []
|
||||||
if empty(a:1)
|
if empty(a:1)
|
||||||
let cmd = ['git', '--no-pager', '-c',
|
let cmd = ['git', '--no-pager', '-c',
|
||||||
\ 'core.editor=cat', '-c',
|
\ 'core.editor=cat', '-c',
|
||||||
@ -37,7 +41,7 @@ function! git#commit#run(...) abort
|
|||||||
\ expand(getcwd(), ':p'),
|
\ expand(getcwd(), ':p'),
|
||||||
\ 'commit',] + a:1
|
\ 'commit',] + a:1
|
||||||
endif
|
endif
|
||||||
call s:JOB.start(cmd,
|
let s:commit_jobid = s:JOB.start(cmd,
|
||||||
\ {
|
\ {
|
||||||
\ 'on_stderr' : function('s:on_stderr'),
|
\ 'on_stderr' : function('s:on_stderr'),
|
||||||
\ 'on_stdout' : function('s:on_stdout'),
|
\ 'on_stdout' : function('s:on_stdout'),
|
||||||
@ -47,19 +51,31 @@ function! git#commit#run(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_stdout(id, data, event) abort
|
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
|
for data in a:data
|
||||||
call git#logger#info('git-commit stdout:' . data)
|
call git#logger#info('git-commit stdout:' . data)
|
||||||
endfor
|
endfor
|
||||||
let s:lines += a:data
|
let s:commit_context += a:data
|
||||||
endfunction
|
endfunction
|
||||||
function! s:on_stderr(id, data, event) abort
|
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
|
for data in a:data
|
||||||
call git#logger#info('git-commit stderr:' . data)
|
call git#logger#info('git-commit stderr:' . data)
|
||||||
endfor
|
endfor
|
||||||
" stderr should not be added to commit buffer
|
" stderr should not be added to commit buffer
|
||||||
" let s:lines += a:data
|
" let s:commit_context += a:data
|
||||||
endfunction
|
endfunction
|
||||||
function! s:on_exit(id, data, event) abort
|
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))
|
call git#logger#info('git-exit exit data:' . string(a:data))
|
||||||
if s:commit_bufnr == -1
|
if s:commit_bufnr == -1
|
||||||
if a:data ==# 0
|
if a:data ==# 0
|
||||||
@ -68,7 +84,7 @@ function! s:on_exit(id, data, event) abort
|
|||||||
echo 'commit failed!'
|
echo 'commit failed!'
|
||||||
endif
|
endif
|
||||||
else
|
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
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -101,8 +117,7 @@ endfunction
|
|||||||
" when run `:wq` the commit window will not be closed
|
" when run `:wq` the commit window will not be closed
|
||||||
" :q -- QuitPre -> WinLeave
|
" :q -- QuitPre -> WinLeave
|
||||||
function! s:BufWriteCmd() abort
|
function! s:BufWriteCmd() abort
|
||||||
let commit_file = '.git\COMMIT_EDITMSG'
|
let s:commit_context = getline(1, '$')
|
||||||
call writefile(getline(1, '$'), commit_file)
|
|
||||||
setlocal nomodified
|
setlocal nomodified
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -119,7 +134,7 @@ function! s:WinLeave() abort
|
|||||||
\ }
|
\ }
|
||||||
\ )
|
\ )
|
||||||
" line start with # should be ignored
|
" 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')
|
call s:JOB.chanclose(id, 'stdin')
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user