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

74 lines
1.7 KiB
VimL
Raw Normal View History

2021-01-02 18:15:08 +08:00
let s:JOB = SpaceVim#api#import('job')
let s:STR = SpaceVim#api#import('data#string')
2021-01-23 22:16:59 +08:00
function! git#branch#run(args) abort
if len(a:args) == 0
call git#branch#manager#open()
return
else
let cmd = ['git', 'branch'] + a:args
endif
call git#logger#info('git-branch cmd:' . string(cmd))
call s:JOB.start(cmd,
\ {
\ 'on_stderr' : function('s:on_stderr'),
\ 'on_stdout' : function('s:on_stdout'),
\ 'on_exit' : function('s:on_exit'),
\ }
\ )
2021-01-02 18:15:08 +08:00
endfunction
function! s:on_stdout(id, data, event) abort
2021-01-23 22:16:59 +08:00
for line in filter(a:data, '!empty(v:val)')
exe 'Echo ' . line
endfor
2021-01-02 18:15:08 +08:00
endfunction
function! s:on_stderr(id, data, event) abort
2021-01-23 22:16:59 +08:00
for line in filter(a:data, '!empty(v:val)')
exe 'Echoerr ' . line
endfor
2021-01-02 18:15:08 +08:00
endfunction
function! s:on_exit(id, data, event) abort
2021-01-23 22:16:59 +08:00
call git#logger#info('git-branch exit data:' . string(a:data))
if a:data ==# 0
call git#branch#manager#update()
echo 'done!'
else
echo 'failed!'
endif
2021-01-02 18:15:08 +08:00
endfunction
2021-01-23 22:16:59 +08:00
function! git#branch#complete(ArgLead, CmdLine, CursorPos) abort
2021-01-02 18:15:08 +08:00
2021-01-23 22:16:59 +08:00
return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n")
2021-01-02 18:15:08 +08:00
endfunction
let s:branch = ''
function! s:update_branch_name() abort
2021-01-23 22:16:59 +08:00
let cmd = 'git rev-parse --abbrev-ref HEAD'
call s:JOB.start(cmd,
\ {
\ 'on_stdout' : function('s:on_stdout_show_branch'),
\ }
\ )
2021-01-02 18:15:08 +08:00
endfunction
function! s:on_stdout_show_branch(id, data, event) abort
2021-01-23 22:16:59 +08:00
let b = s:STR.trim(join(a:data, ''))
if !empty(b)
let s:branch = b
endif
2021-01-02 18:15:08 +08:00
endfunction
2021-01-23 22:16:59 +08:00
function! git#branch#current() abort
if empty(s:branch)
call s:update_branch_name()
endif
return s:branch
2021-01-02 18:15:08 +08:00
endfunction
2021-01-23 22:16:59 +08:00
function! git#branch#detect() abort
call s:update_branch_name()
2021-01-02 18:15:08 +08:00
endfunction