From 487f4fa543067d6b561f1f2272323e83d11931d8 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Wed, 4 Aug 2021 12:13:28 +0800 Subject: [PATCH] Add Git mv command (#4350) --- bundle/git.vim/autoload/git.vim | 6 +++- bundle/git.vim/autoload/git/mv.vim | 46 ++++++++++++++++++++++++++++++ bundle/git.vim/doc/git.txt | 14 +++++++-- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 bundle/git.vim/autoload/git/mv.vim diff --git a/bundle/git.vim/autoload/git.vim b/bundle/git.vim/autoload/git.vim index e11b90738..493f89e22 100644 --- a/bundle/git.vim/autoload/git.vim +++ b/bundle/git.vim/autoload/git.vim @@ -31,6 +31,8 @@ function! git#run(...) abort call git#diff#run(a:000[1:]) elseif cmd ==# 'rm' call git#rm#run(a:000[1:]) + elseif cmd ==# 'mv' + call git#mv#run(a:000[1:]) elseif cmd ==# 'log' call git#log#run(a:000[1:]) elseif cmd ==# 'reflog' @@ -74,13 +76,15 @@ function! git#complete(ArgLead, CmdLine, CursorPos) abort return join(['add', 'push', 'status', 'commit', 'diff', \ 'merge', 'rebase', 'branch', 'checkout', \ 'fetch', 'reset', 'log', 'config', 'reflog', - \ 'blame', 'pull', 'stash', 'cherry-pick', 'rm' + \ 'blame', 'pull', 'stash', 'cherry-pick', 'rm', 'mv' \ ], \ "\n") elseif str =~# '^Git\s\+add\s\+.*$' return git#add#complete(a:ArgLead, a:CmdLine, a:CursorPos) elseif str =~# '^Git\s\+rm\s\+.*$' return git#rm#complete(a:ArgLead, a:CmdLine, a:CursorPos) + elseif str =~# '^Git\s\+mv\s\+.*$' + return git#mv#complete(a:ArgLead, a:CmdLine, a:CursorPos) elseif str =~# '^Git\s\+push\s\+.*$' return git#push#complete(a:ArgLead, a:CmdLine, a:CursorPos) elseif str =~# '^Git\s\+diff\s\+.*$' diff --git a/bundle/git.vim/autoload/git/mv.vim b/bundle/git.vim/autoload/git/mv.vim new file mode 100644 index 000000000..dd7c826bb --- /dev/null +++ b/bundle/git.vim/autoload/git/mv.vim @@ -0,0 +1,46 @@ +"" +" @section git-mv, mv +" @parentsection commands +" This commands is to run `git mv` command asynchronously. +" It is to move file to the index. For example, rename current file. +" > +" :Git mv % new_file.txt +" < + +let s:JOB = SpaceVim#api#import('job') + +function! git#mv#run(args) abort + + let args = a:args + if index(a:args, '%') !=# -1 + let index = index(a:args, '%') + let args[index] = expand('%') + endif + let cmd = ['git', 'mv'] + args + call git#logger#info('git-mv cmd:' . string(cmd)) + call s:JOB.start(cmd, + \ { + \ 'on_exit' : function('s:on_exit'), + \ } + \ ) + +endfunction + +function! s:on_exit(id, data, event) abort + call git#logger#info('git-mv exit data:' . string(a:data)) + if a:data ==# 0 + if exists(':GitGutter') + GitGutter + endif + echo 'done!' + else + echo 'failed!' + endif +endfunction + +function! git#rm#complete(ArgLead, CmdLine, CursorPos) abort + + return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n") + +endfunction + diff --git a/bundle/git.vim/doc/git.txt b/bundle/git.vim/doc/git.txt index 5c20268bb..2660872e4 100644 --- a/bundle/git.vim/doc/git.txt +++ b/bundle/git.vim/doc/git.txt @@ -7,8 +7,9 @@ CONTENTS *git-contents* 2. Commands...................................................|git-commands| 1. git-add.....................................................|git-add| 2. git-cherry-pick.....................................|git-cherry-pick| - 3. git-rm.......................................................|git-rm| - 4. git-stash.................................................|git-stash| + 3. git-mv.......................................................|git-mv| + 4. git-rm.......................................................|git-rm| + 5. git-stash.................................................|git-stash| ============================================================================== INTRODUCTION *git-intro* @@ -39,6 +40,15 @@ This command is to cherry pick commit from other branch. :Git cherry-pick < +============================================================================== +GIT-MV *git-mv* + +This commands is to run `git mv` command asynchronously. It is to move file to +the index. For example, rename current file. +> + :Git mv % new_file.txt +< + ============================================================================== GIT-RM *git-rm*