From 697fec62ea7ebe59528f2efd8f4419ca7140e553 Mon Sep 17 00:00:00 2001
From: Wang Shidong <wsdjeg@outlook.com>
Date: Sun, 1 Aug 2021 13:30:23 +0800
Subject: [PATCH] Add `Git rm` command (#4347)

---
 .gitignore                         |  1 +
 bundle/README.md                   | 21 ++++++--------
 bundle/git.vim/autoload/git.vim    |  6 +++-
 bundle/git.vim/autoload/git/rm.vim | 44 ++++++++++++++++++++++++++++++
 bundle/git.vim/doc/git.txt         | 12 +++++++-
 5 files changed, 70 insertions(+), 14 deletions(-)
 create mode 100644 bundle/git.vim/autoload/git/rm.vim

diff --git a/.gitignore b/.gitignore
index a611ec1df..e45029aa4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,3 +39,4 @@ jdt.ls-java-project/
 # generated by rustfmt.vim
 # https://github.com/rust-lang/rust.vim/blob/master/autoload/rustfmt.vim#L110
 view/
+.vim-bookmarks
diff --git a/bundle/README.md b/bundle/README.md
index 621f0fc31..cc648d1d6 100644
--- a/bundle/README.md
+++ b/bundle/README.md
@@ -1,16 +1,13 @@
-## Forked repos
+## Bundle plugins
+
+In `bundle/` directory, there are two kinds of plugins: forked plugins without changes and forked plugins which have been changed.
+
+### Changed plugin:
+
+- `vim-bookmarks`: based on [`MattesGroeger/vim-bookmarks@3adeae1`](https://github.com/MattesGroeger/vim-bookmarks/commit/3adeae10639edcba29ea80dafa1c58cf545cb80e)
+
+### No changed plugins
 
 - [defx.nvim](https://github.com/Shougo/defx.nvim/tree/df5e6ea6734dc002919ea41786668069fa0b497d)
 - [dein.vim](https://github.com/Shougo/dein.vim/tree/772ae08cef5e712b2b31b4aaee908fc853accd94)
 - [neoformat](https://github.com/sbdchd/neoformat/tree/1a49552cdaddeaaa766a6f0016effe530634b39f)
-
-
-### checkers layer
-
-- neomake
-- vim-snippets
-- neco-syntax
-- context_filetype.vim
-- neoinclude.vim
-- neosnippet-snippets
-- neopairs.vim
diff --git a/bundle/git.vim/autoload/git.vim b/bundle/git.vim/autoload/git.vim
index b71792622..e11b90738 100644
--- a/bundle/git.vim/autoload/git.vim
+++ b/bundle/git.vim/autoload/git.vim
@@ -29,6 +29,8 @@ function! git#run(...) abort
         call git#config#run(a:000[1:])
     elseif cmd ==# 'diff'
         call git#diff#run(a:000[1:])
+    elseif cmd ==# 'rm'
+        call git#rm#run(a:000[1:])
     elseif cmd ==# 'log'
         call git#log#run(a:000[1:])
     elseif cmd ==# 'reflog'
@@ -72,11 +74,13 @@ 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',
+                    \ 'blame', 'pull', 'stash', 'cherry-pick', 'rm'
                     \ ],
                     \ "\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\+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/rm.vim b/bundle/git.vim/autoload/git/rm.vim
new file mode 100644
index 000000000..18827ced6
--- /dev/null
+++ b/bundle/git.vim/autoload/git/rm.vim
@@ -0,0 +1,44 @@
+""
+" @section git-rm, rm
+" @parentsection commands
+" This commands is to rm file contents to the index. For example, rm current
+" file to the index.
+" >
+"   :Git rm %
+" <
+
+let s:JOB = SpaceVim#api#import('job')
+
+function! git#rm#run(files) abort
+
+    if len(a:files) == 1 && a:files[0] ==# '%'
+        let cmd = ['git', 'rm', expand('%')] 
+    else
+        let cmd = ['git', 'rm'] + a:files
+    endif
+    call git#logger#info('git-rm 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-rm 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 14f41ec0d..5c20268bb 100644
--- a/bundle/git.vim/doc/git.txt
+++ b/bundle/git.vim/doc/git.txt
@@ -7,7 +7,8 @@ CONTENTS                                                        *git-contents*
   2. Commands...................................................|git-commands|
       1. git-add.....................................................|git-add|
       2. git-cherry-pick.....................................|git-cherry-pick|
-      3. git-stash.................................................|git-stash|
+      3. git-rm.......................................................|git-rm|
+      4. git-stash.................................................|git-stash|
 
 ==============================================================================
 INTRODUCTION                                                       *git-intro*
@@ -38,6 +39,15 @@ This command is to cherry pick commit from other branch.
   :Git cherry-pick <HashA> <HashB>
 <
 
+==============================================================================
+GIT-RM                                                                *git-rm*
+
+This commands is to rm file contents to the index. For example, rm current
+file to the index.
+>
+  :Git rm %
+<
+
 ==============================================================================
 GIT-STASH                                                          *git-stash*