mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 00:00:04 +08:00
feat(git): complete checkout command
This commit is contained in:
parent
a50c6bf250
commit
0801126d19
@ -1,7 +1,28 @@
|
|||||||
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
|
let cmd = ['git', 'checkout'] + a:args
|
||||||
call git#logger#debug('git-checkout cmd:' . string(cmd))
|
call git#logger#debug('git-checkout cmd:' . string(cmd))
|
||||||
@ -11,9 +32,9 @@ function! git#checkout#run(args)
|
|||||||
\ }
|
\ }
|
||||||
\ )
|
\ )
|
||||||
|
|
||||||
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))
|
call git#logger#debug('git-checkout exit data:' . string(a:data))
|
||||||
if a:data ==# 0
|
if a:data ==# 0
|
||||||
silent! checktime
|
silent! checktime
|
||||||
@ -22,16 +43,16 @@ function! s:on_exit(id, data, event) abort
|
|||||||
else
|
else
|
||||||
call s:NOTI.notify('checkout failed.', 'WarningMsg')
|
call s:NOTI.notify('checkout failed.', 'WarningMsg')
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:options() abort
|
function! s:options() abort
|
||||||
return join([
|
return join([
|
||||||
\ '-m',
|
\ '-m',
|
||||||
\ '-b',
|
\ '-b',
|
||||||
\ ], "\n")
|
\ ], "\n")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! git#checkout#complete(ArgLead, CmdLine, CursorPos)
|
function! git#checkout#complete(ArgLead, CmdLine, CursorPos)
|
||||||
if a:ArgLead =~# '^-'
|
if a:ArgLead =~# '^-'
|
||||||
return s:options()
|
return s:options()
|
||||||
endif
|
endif
|
||||||
@ -43,5 +64,6 @@ function! git#checkout#complete(ArgLead, CmdLine, CursorPos)
|
|||||||
return branchs
|
return branchs
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
endif
|
||||||
|
@ -3,18 +3,19 @@ Wang Shidong & Mattes Groeger *git*
|
|||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
CONTENTS *git-contents*
|
CONTENTS *git-contents*
|
||||||
1. Introduction..................................................|git-intro|
|
1. Introduction................................................... |git-intro|
|
||||||
2. Commands...................................................|git-commands|
|
2. Commands.................................................... |git-commands|
|
||||||
1. git-add.....................................................|git-add|
|
1. git-add...................................................... |git-add|
|
||||||
2. git-branch...............................................|git-branch|
|
2. git-branch................................................ |git-branch|
|
||||||
3. git-cherry-pick.....................................|git-cherry-pick|
|
3. git-checkout............................................ |git-checkout|
|
||||||
4. git-clean.................................................|git-clean|
|
4. git-cherry-pick...................................... |git-cherry-pick|
|
||||||
5. git-mv.......................................................|git-mv|
|
5. git-clean.................................................. |git-clean|
|
||||||
6. git-reflog...............................................|git-reflog|
|
6. git-mv........................................................ |git-mv|
|
||||||
7. git-rm.......................................................|git-rm|
|
7. git-reflog................................................ |git-reflog|
|
||||||
8. git-stash.................................................|git-stash|
|
8. git-rm........................................................ |git-rm|
|
||||||
9. git-tag.....................................................|git-tag|
|
9. git-stash.................................................. |git-stash|
|
||||||
3. Functions.................................................|git-functions|
|
10. git-tag..................................................... |git-tag|
|
||||||
|
3. Functions.................................................. |git-functions|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
INTRODUCTION *git-intro*
|
INTRODUCTION *git-intro*
|
||||||
@ -45,6 +46,14 @@ This commands is to open branch manager.
|
|||||||
:Git branch
|
: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*
|
GIT-CHERRY-PICK *git-cherry-pick*
|
||||||
|
|
||||||
|
@ -27,4 +27,22 @@ function M.run(argv)
|
|||||||
job.start(cmd, { on_exit = on_exit })
|
job.start(cmd, { on_exit = on_exit })
|
||||||
end
|
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
|
return M
|
||||||
|
Loading…
Reference in New Issue
Block a user