spacevim/bundle/gina.vim/autoload/gina/action/branch.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

176 lines
5.4 KiB
VimL

function! gina#action#branch#define(binder) abort
call a:binder.define('branch:refresh', function('s:on_refresh'), {
\ 'description': 'Refresh remote branches',
\ 'mapping_mode': 'n',
\ 'requirements': [],
\ 'options': {},
\ 'use_marks': 0,
\ 'clear_marks': 0,
\})
call a:binder.define('branch:new', function('s:on_new'), {
\ 'description': 'Create a new branch',
\ 'mapping_mode': 'n',
\ 'requirements': ['branch', 'remote'],
\ 'options': {},
\})
call a:binder.define('branch:move', function('s:on_move'), {
\ 'description': 'Rename a branch',
\ 'mapping_mode': 'nv',
\ 'requirements': ['branch', 'remote'],
\ 'options': {},
\})
call a:binder.define('branch:move:force', function('s:on_move'), {
\ 'hidden': 1,
\ 'description': 'Rename a branch',
\ 'mapping_mode': 'nv',
\ 'requirements': ['branch', 'remote'],
\ 'options': { 'force': 1 },
\})
call a:binder.define('branch:delete', function('s:on_delete'), {
\ 'description': 'Delete a branch',
\ 'mapping_mode': 'nv',
\ 'requirements': ['branch', 'remote'],
\ 'options': {},
\})
call a:binder.define('branch:delete:force', function('s:on_delete'), {
\ 'hidden': 1,
\ 'description': 'Delete a branch',
\ 'mapping_mode': 'nv',
\ 'requirements': ['branch', 'remote'],
\ 'options': { 'force': 1 },
\})
call a:binder.define('branch:set-upstream-to', function('s:on_set_upstream_to'), {
\ 'description': 'Set an upstream of a branch',
\ 'mapping_mode': 'nv',
\ 'requirements': ['branch', 'remote'],
\ 'options': {},
\})
call a:binder.define('branch:unset-upstream', function('s:on_unset_upstream'), {
\ 'description': 'Unset an upstream of a branch',
\ 'mapping_mode': 'nv',
\ 'requirements': ['branch', 'remote'],
\ 'options': {},
\})
endfunction
" Private --------------------------------------------------------------------
function! s:on_refresh(candidates, options) abort
let options = extend({}, a:options)
execute printf(
\ '%s Gina remote update --prune',
\ options.mods,
\)
endfunction
function! s:on_new(candidates, options) abort
if empty(a:candidates)
return
endif
let options = extend({}, a:options)
for candidate in a:candidates
let name = gina#core#console#ask_or_cancel(
\ 'Name: ', '',
\)
let from = gina#core#console#ask_or_cancel(
\ 'From: ', candidate.rev,
\ function('gina#complete#commit#branch')
\)
execute printf(
\ '%s Gina checkout -b %s %s',
\ options.mods,
\ gina#util#shellescape(name),
\ gina#util#shellescape(from),
\)
endfor
endfunction
function! s:on_move(candidates, options) abort
let candidates = filter(copy(a:candidates), 'empty(v:val.remote)')
if empty(candidates)
return
endif
let options = extend({
\ 'force': 0,
\}, a:options)
for candidate in candidates
let name = gina#core#console#ask_or_cancel(
\ 'Rename: ',
\ candidate.branch,
\)
execute printf(
\ '%s Gina branch --move %s %s %s',
\ options.mods,
\ options.force ? '--force' : '',
\ gina#util#shellescape(candidate.branch),
\ gina#util#shellescape(name),
\)
endfor
endfunction
function! s:on_delete(candidates, options) abort
if empty(a:candidates)
return
endif
let options = extend({
\ 'force': 0,
\}, a:options)
for candidate in a:candidates
let is_remote = !empty(candidate.remote)
if is_remote
execute printf(
\ '%s Gina push --delete %s %s %s',
\ options.mods,
\ options.force ? '--force' : '',
\ gina#util#shellescape(candidate.remote),
\ gina#util#shellescape(candidate.branch),
\)
else
execute printf(
\ '%s Gina branch --delete %s %s',
\ options.mods,
\ options.force ? '--force' : '',
\ gina#util#shellescape(candidate.branch),
\)
endif
endfor
endfunction
function! s:on_set_upstream_to(candidates, options) abort
let candidates = filter(copy(a:candidates), 'empty(v:val.remote)')
if empty(candidates)
return
endif
let options = extend({}, a:options)
for candidate in candidates
let upstream = gina#core#console#ask_or_cancel(
\ 'Upstream: ', candidate.branch,
\ function('gina#complete#commit#remote_branch'),
\)
let upstream = substitute(
\ upstream, printf('^%s/', candidate.remote), '', ''
\)
execute printf(
\ '%s Gina branch --set-upstream-to=%s %s',
\ options.mods,
\ gina#util#shellescape(upstream),
\ gina#util#shellescape(candidate.branch),
\)
endfor
endfunction
function! s:on_unset_upstream(candidates, options) abort
let candidates = filter(copy(a:candidates), 'empty(v:val.remote)')
if empty(candidates)
return
endif
let options = extend({}, a:options)
for candidate in candidates
execute printf(
\ '%s Gina branch --unset-upstream %s',
\ options.mods,
\ gina#util#shellescape(candidate.branch),
\)
endfor
endfunction