mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 11:30:06 +08:00
feat(git): complete checkout command
This commit is contained in:
parent
a50c6bf250
commit
0801126d19
@ -1,47 +1,69 @@
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:NOTI = SpaceVim#api#import('notify')
|
||||
"=============================================================================
|
||||
" checkout.vim --- checkout command
|
||||
" Copyright (c) 2016 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
function! git#checkout#run(args)
|
||||
""
|
||||
" @section git-checkout, checkout
|
||||
" @parentsection commands
|
||||
" This comamnd is to switch branches or restore working tree files.
|
||||
" >
|
||||
" :Git checkout -b new_branch_name
|
||||
" <
|
||||
|
||||
if has('nvim-0.9.0')
|
||||
function! git#checkout#complete(ArgLead, CmdLine, CursorPos) abort
|
||||
return luaeval('require("git.command.checkout").complete(vim.api.nvim_eval("a:ArgLead"), vim.api.nvim_eval("a:CmdLine"), vim.api.nvim_eval("a:CursorPos"))')
|
||||
endfunction
|
||||
else
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:NOTI = SpaceVim#api#import('notify')
|
||||
|
||||
function! git#checkout#run(args)
|
||||
|
||||
let cmd = ['git', 'checkout'] + a:args
|
||||
call git#logger#debug('git-checkout cmd:' . string(cmd))
|
||||
call s:JOB.start(cmd,
|
||||
\ {
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
\ )
|
||||
\ {
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
\ )
|
||||
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
function! s:on_exit(id, data, event) abort
|
||||
function! s:on_exit(id, data, event) abort
|
||||
call git#logger#debug('git-checkout exit data:' . string(a:data))
|
||||
if a:data ==# 0
|
||||
silent! checktime
|
||||
call s:NOTI.notify('checkout done.')
|
||||
call git#branch#detect()
|
||||
silent! checktime
|
||||
call s:NOTI.notify('checkout done.')
|
||||
call git#branch#detect()
|
||||
else
|
||||
call s:NOTI.notify('checkout failed.', 'WarningMsg')
|
||||
call s:NOTI.notify('checkout failed.', 'WarningMsg')
|
||||
endif
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
function! s:options() abort
|
||||
function! s:options() abort
|
||||
return join([
|
||||
\ '-m',
|
||||
\ '-b',
|
||||
\ ], "\n")
|
||||
endfunction
|
||||
\ '-m',
|
||||
\ '-b',
|
||||
\ ], "\n")
|
||||
endfunction
|
||||
|
||||
function! git#checkout#complete(ArgLead, CmdLine, CursorPos)
|
||||
function! git#checkout#complete(ArgLead, CmdLine, CursorPos)
|
||||
if a:ArgLead =~# '^-'
|
||||
return s:options()
|
||||
return s:options()
|
||||
endif
|
||||
let branchs = systemlist('git branch')
|
||||
if v:shell_error
|
||||
return ''
|
||||
return ''
|
||||
else
|
||||
let branchs = join(map(filter(branchs, 'v:val !~ "^*"'), 'trim(v:val)'), "\n")
|
||||
return branchs
|
||||
let branchs = join(map(filter(branchs, 'v:val !~ "^*"'), 'trim(v:val)'), "\n")
|
||||
return branchs
|
||||
endif
|
||||
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
@ -3,18 +3,19 @@ Wang Shidong & Mattes Groeger *git*
|
||||
|
||||
==============================================================================
|
||||
CONTENTS *git-contents*
|
||||
1. Introduction..................................................|git-intro|
|
||||
2. Commands...................................................|git-commands|
|
||||
1. git-add.....................................................|git-add|
|
||||
2. git-branch...............................................|git-branch|
|
||||
3. git-cherry-pick.....................................|git-cherry-pick|
|
||||
4. git-clean.................................................|git-clean|
|
||||
5. git-mv.......................................................|git-mv|
|
||||
6. git-reflog...............................................|git-reflog|
|
||||
7. git-rm.......................................................|git-rm|
|
||||
8. git-stash.................................................|git-stash|
|
||||
9. git-tag.....................................................|git-tag|
|
||||
3. Functions.................................................|git-functions|
|
||||
1. Introduction................................................... |git-intro|
|
||||
2. Commands.................................................... |git-commands|
|
||||
1. git-add...................................................... |git-add|
|
||||
2. git-branch................................................ |git-branch|
|
||||
3. git-checkout............................................ |git-checkout|
|
||||
4. git-cherry-pick...................................... |git-cherry-pick|
|
||||
5. git-clean.................................................. |git-clean|
|
||||
6. git-mv........................................................ |git-mv|
|
||||
7. git-reflog................................................ |git-reflog|
|
||||
8. git-rm........................................................ |git-rm|
|
||||
9. git-stash.................................................. |git-stash|
|
||||
10. git-tag..................................................... |git-tag|
|
||||
3. Functions.................................................. |git-functions|
|
||||
|
||||
==============================================================================
|
||||
INTRODUCTION *git-intro*
|
||||
@ -45,6 +46,14 @@ This commands is to open branch manager.
|
||||
:Git branch
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
GIT-CHECKOUT *git-checkout*
|
||||
|
||||
This comamnd is to switch branches or restore working tree files.
|
||||
>
|
||||
:Git checkout -b new_branch_name
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
GIT-CHERRY-PICK *git-cherry-pick*
|
||||
|
||||
|
@ -27,4 +27,22 @@ function M.run(argv)
|
||||
job.start(cmd, { on_exit = on_exit })
|
||||
end
|
||||
|
||||
function M.complete(arglead, cmdline, cursorpos)
|
||||
if vim.startswith(arglead, '-') then
|
||||
return table.concat({ '-b', '-m' }, '\n')
|
||||
end
|
||||
local branchs = vim.fn.systemlist('git branch')
|
||||
return table.concat(
|
||||
vim.tbl_map(
|
||||
function(t)
|
||||
return vim.fn.trim(t)
|
||||
end,
|
||||
vim.tbl_filter(function(t)
|
||||
return not vim.startswith(t, '*')
|
||||
end, branchs)
|
||||
),
|
||||
'\n'
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
|
Loading…
Reference in New Issue
Block a user