spacevim/bundle/git.vim/autoload/git/branch/manager.vim
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

116 lines
3.3 KiB
VimL

"=============================================================================
" manager.vim --- Git branch manager
" Copyright (c) 2016-2023 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg@outlook.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
scriptencoding utf-8
let s:JOB = SpaceVim#api#import('job')
let s:BUFFER = SpaceVim#api#import('vim#buffer')
let s:branch_manager_bufnr = 0
function! git#branch#manager#open() abort
if s:branch_manager_bufnr != 0 && bufexists(s:branch_manager_bufnr)
exe 'bd ' . s:branch_manager_bufnr
endif
topleft vsplit __git_branch_manager__
let s:winid = win_getid(winnr('#'))
let lines = &columns * 30 / 100
exe 'vertical resize ' . lines
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber winfixheight nomodifiable
set filetype=SpaceVimGitBranchManager
let s:branch_manager_bufnr = bufnr('%')
call s:update()
augroup git_branch_manager
autocmd! * <buffer>
autocmd WinEnter <buffer> call s:WinEnter()
augroup END
nnoremap <buffer><silent> <Enter> :call <SID>checkout_branch()<cr>
nnoremap <buffer><silent> dd :call <SID>delete_branch()<cr>
endfunction
function! s:WinEnter() abort
let s:winid = win_getid(winnr('#'))
endfunction
function! s:checkout_branch() abort
let line = getline('.')
if line =~# '^\s\+\S\+'
let branch = split(line)[0]
exe 'Git checkout ' . branch
endif
endfunction
function! git#branch#manager#update() abort
call s:update()
endfunction
function! s:delete_branch() abort
let line = getline('.')
if line =~# '^\s\+\S\+'
let branch = split(line)[0]
exe 'Git branch -d ' . branch
endif
endfunction
function! s:update() abort
let s:branchs = []
let cmd = ['git', 'branch', '--all']
call git#logger#debug('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'),
\ }
\ )
endfunction
function! s:update_buffer_context() abort
let lines = []
call add(lines, 'local')
let remote = ''
for branch in s:branchs
if branch.remote != remote
call add(lines, 'r:' . branch.remote)
let remote = branch.remote
endif
call add(lines, ' ' . branch.name)
endfor
call s:BUFFER.buf_set_lines(s:branch_manager_bufnr, 0 , -1, 0, lines)
endfunction
function! s:on_stdout(id, data, event) abort
for line in filter(a:data, '!empty(v:val)')
call SpaceVim#logger#info('>>' . line)
if stridx(line, 'remotes/') == -1
let branch = {
\ 'name': trim(line),
\ 'remote': '',
\ 'islocal': 1,
\ }
else
let branch = {
\ 'name': line[stridx(line, '/', 10) + 1 :],
\ 'remote': split(line, '/')[1],
\ 'islocal': 0,
\ }
endif
call add(s:branchs, branch)
endfor
endfunction
function! s:on_stderr(id, data, event) abort
for line in filter(a:data, '!empty(v:val)')
exe 'Echoerr ' . line
endfor
endfunction
function! s:on_exit(id, data, event) abort
call git#logger#debug('git-branch exit data:' . string(a:data))
if a:data ==# 0
call s:update_buffer_context()
endif
endfunction