mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 14:20:06 +08:00
perf(git): use normal highlight for non-errors
This commit is contained in:
parent
91fd3ad573
commit
f9c0889a3b
96
bundle/git.vim/autoload/git/push.vim
vendored
96
bundle/git.vim/autoload/git/push.vim
vendored
@ -10,70 +10,80 @@ let s:NOTI = SpaceVim#api#import('notify')
|
|||||||
|
|
||||||
function! git#push#run(...) abort
|
function! git#push#run(...) abort
|
||||||
|
|
||||||
let cmd = ['git', 'push']
|
let cmd = ['git', 'push']
|
||||||
if len(a:1) > 0
|
if len(a:1) > 0
|
||||||
let cmd += a:1
|
let cmd += a:1
|
||||||
endif
|
endif
|
||||||
call s:JOB.start(cmd,
|
call s:JOB.start(cmd, {
|
||||||
\ {
|
\ 'on_stdout' : function('s:on_stdout'),
|
||||||
\ 'on_stdout' : function('s:on_stdout'),
|
\ 'on_stderr' : function('s:on_stderr'),
|
||||||
\ 'on_stderr' : function('s:on_stderr'),
|
\ 'on_exit' : function('s:on_exit'),
|
||||||
\ 'on_exit' : function('s:on_exit'),
|
\ }
|
||||||
\ }
|
\ )
|
||||||
\ )
|
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_exit(...) abort
|
function! s:on_exit(...) abort
|
||||||
let data = get(a:000, 2)
|
let data = get(a:000, 2)
|
||||||
if data != 0
|
if data != 0
|
||||||
call s:NOTI.notify('Git push failed!', 'WarningMsg')
|
for line in s:std_data.stderr
|
||||||
else
|
call s:NOTI.notify(line, 'WarningMsg')
|
||||||
call s:NOTI.notify('Git push done!')
|
endfor
|
||||||
endif
|
else
|
||||||
|
for line in s:std_data.stderr
|
||||||
|
call s:NOTI.notify(line)
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! s:on_stdout(id, data, event) abort
|
function! s:on_stdout(id, data, event) abort
|
||||||
for line in filter(a:data, '!empty(v:val)')
|
for line in filter(a:data, '!empty(v:val)')
|
||||||
call s:NOTI.notify(line, 'Normal')
|
call s:NOTI.notify(line, 'Normal')
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
" https://stackoverflow.com/questions/57016157/how-to-stop-git-from-writing-non-errors-to-stderr
|
||||||
|
"
|
||||||
|
" why git push normal info to stderr
|
||||||
|
|
||||||
|
let s:std_data = {
|
||||||
|
\ 'stderr' : [],
|
||||||
|
\ 'stdout' : [],
|
||||||
|
\ }
|
||||||
function! s:on_stderr(id, data, event) abort
|
function! s:on_stderr(id, data, event) abort
|
||||||
for line in filter(a:data, '!empty(v:val)')
|
call extend(s:std_data.stderr, a:data)
|
||||||
call s:NOTI.notify(line, 'WarningMsg')
|
|
||||||
endfor
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:options() abort
|
function! s:options() abort
|
||||||
return [
|
return [
|
||||||
\ '-u',
|
\ '-u',
|
||||||
\ ]
|
\ ]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! git#push#complete(ArgLead, CmdLine, CursorPos) abort
|
function! git#push#complete(ArgLead, CmdLine, CursorPos) abort
|
||||||
let str = a:CmdLine[:a:CursorPos-1]
|
let str = a:CmdLine[:a:CursorPos-1]
|
||||||
if str =~# '^Git\s\+push\s\+-$'
|
if str =~# '^Git\s\+push\s\+-$'
|
||||||
return join(s:options(), "\n")
|
return join(s:options(), "\n")
|
||||||
elseif str =~# '^Git\s\+push\s\+[^ ]*$' || str =~# '^Git\s\+push\s\+-u\s\+[^ ]*$'
|
elseif str =~# '^Git\s\+push\s\+[^ ]*$' || str =~# '^Git\s\+push\s\+-u\s\+[^ ]*$'
|
||||||
return join(s:remotes(), "\n")
|
return join(s:remotes(), "\n")
|
||||||
else
|
else
|
||||||
let remote = matchstr(str, '\(Git\s\+push\s\+\)\@<=[^ ]*')
|
let remote = matchstr(str, '\(Git\s\+push\s\+\)\@<=[^ ]*')
|
||||||
return s:remote_branch(remote)
|
return s:remote_branch(remote)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:remotes() abort
|
function! s:remotes() abort
|
||||||
return map(systemlist('git remote'), 'trim(v:val)')
|
return map(systemlist('git remote'), 'trim(v:val)')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:remote_branch(remote) abort
|
function! s:remote_branch(remote) abort
|
||||||
let branchs = systemlist('git branch -a')
|
let branchs = systemlist('git branch -a')
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
return ''
|
return ''
|
||||||
else
|
else
|
||||||
let branchs = join(map(filter(branchs, 'v:val =~ "\s*remotes/" . a:remote . "/[^ ]*$"'), 'trim(v:val)[len(a:remote) + 9:]'), "\n")
|
let branchs = join(map(filter(branchs, 'v:val =~ "\s*remotes/" . a:remote . "/[^ ]*$"'), 'trim(v:val)[len(a:remote) + 9:]'), "\n")
|
||||||
return branchs
|
return branchs
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
Reference in New Issue
Block a user