mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 23:00:04 +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
|
||||
|
||||
let cmd = ['git', 'push']
|
||||
if len(a:1) > 0
|
||||
let cmd += a:1
|
||||
endif
|
||||
call s:JOB.start(cmd,
|
||||
\ {
|
||||
\ 'on_stdout' : function('s:on_stdout'),
|
||||
\ 'on_stderr' : function('s:on_stderr'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
\ )
|
||||
let cmd = ['git', 'push']
|
||||
if len(a:1) > 0
|
||||
let cmd += a:1
|
||||
endif
|
||||
call s:JOB.start(cmd, {
|
||||
\ 'on_stdout' : function('s:on_stdout'),
|
||||
\ 'on_stderr' : function('s:on_stderr'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
\ )
|
||||
|
||||
endfunction
|
||||
|
||||
function! s:on_exit(...) abort
|
||||
let data = get(a:000, 2)
|
||||
if data != 0
|
||||
call s:NOTI.notify('Git push failed!', 'WarningMsg')
|
||||
else
|
||||
call s:NOTI.notify('Git push done!')
|
||||
endif
|
||||
let data = get(a:000, 2)
|
||||
if data != 0
|
||||
for line in s:std_data.stderr
|
||||
call s:NOTI.notify(line, 'WarningMsg')
|
||||
endfor
|
||||
else
|
||||
for line in s:std_data.stderr
|
||||
call s:NOTI.notify(line)
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:on_stdout(id, data, event) abort
|
||||
for line in filter(a:data, '!empty(v:val)')
|
||||
call s:NOTI.notify(line, 'Normal')
|
||||
endfor
|
||||
for line in filter(a:data, '!empty(v:val)')
|
||||
call s:NOTI.notify(line, 'Normal')
|
||||
endfor
|
||||
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
|
||||
for line in filter(a:data, '!empty(v:val)')
|
||||
call s:NOTI.notify(line, 'WarningMsg')
|
||||
endfor
|
||||
call extend(s:std_data.stderr, a:data)
|
||||
endfunction
|
||||
|
||||
function! s:options() abort
|
||||
return [
|
||||
\ '-u',
|
||||
\ ]
|
||||
return [
|
||||
\ '-u',
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
function! git#push#complete(ArgLead, CmdLine, CursorPos) abort
|
||||
let str = a:CmdLine[:a:CursorPos-1]
|
||||
if str =~# '^Git\s\+push\s\+-$'
|
||||
return join(s:options(), "\n")
|
||||
elseif str =~# '^Git\s\+push\s\+[^ ]*$' || str =~# '^Git\s\+push\s\+-u\s\+[^ ]*$'
|
||||
return join(s:remotes(), "\n")
|
||||
else
|
||||
let remote = matchstr(str, '\(Git\s\+push\s\+\)\@<=[^ ]*')
|
||||
return s:remote_branch(remote)
|
||||
endif
|
||||
let str = a:CmdLine[:a:CursorPos-1]
|
||||
if str =~# '^Git\s\+push\s\+-$'
|
||||
return join(s:options(), "\n")
|
||||
elseif str =~# '^Git\s\+push\s\+[^ ]*$' || str =~# '^Git\s\+push\s\+-u\s\+[^ ]*$'
|
||||
return join(s:remotes(), "\n")
|
||||
else
|
||||
let remote = matchstr(str, '\(Git\s\+push\s\+\)\@<=[^ ]*')
|
||||
return s:remote_branch(remote)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:remotes() abort
|
||||
return map(systemlist('git remote'), 'trim(v:val)')
|
||||
return map(systemlist('git remote'), 'trim(v:val)')
|
||||
endfunction
|
||||
|
||||
function! s:remote_branch(remote) abort
|
||||
let branchs = systemlist('git branch -a')
|
||||
if v:shell_error
|
||||
return ''
|
||||
else
|
||||
let branchs = join(map(filter(branchs, 'v:val =~ "\s*remotes/" . a:remote . "/[^ ]*$"'), 'trim(v:val)[len(a:remote) + 9:]'), "\n")
|
||||
return branchs
|
||||
endif
|
||||
let branchs = systemlist('git branch -a')
|
||||
if v:shell_error
|
||||
return ''
|
||||
else
|
||||
let branchs = join(map(filter(branchs, 'v:val =~ "\s*remotes/" . a:remote . "/[^ ]*$"'), 'trim(v:val)[len(a:remote) + 9:]'), "\n")
|
||||
return branchs
|
||||
endif
|
||||
endfunction
|
||||
|
Loading…
Reference in New Issue
Block a user