From 7ce5d8b0b9bdb3e976219e3643ef11eb6e589641 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Wed, 9 Aug 2023 00:03:38 +0800 Subject: [PATCH] feat(git): add `:Git rm` command --- bundle/git.vim/lua/git/command/mv.lua | 80 +++++++++++++-------------- bundle/git.vim/lua/git/command/rm.lua | 50 +++++++++++++++++ 2 files changed, 90 insertions(+), 40 deletions(-) create mode 100644 bundle/git.vim/lua/git/command/rm.lua diff --git a/bundle/git.vim/lua/git/command/mv.lua b/bundle/git.vim/lua/git/command/mv.lua index 321c34dc6..0ab95ba84 100644 --- a/bundle/git.vim/lua/git/command/mv.lua +++ b/bundle/git.vim/lua/git/command/mv.lua @@ -1,40 +1,40 @@ -local m = {} - -local job = require('spacevim.api.job') -local nt = require('spacevim.api.notify') -local log = require('git.log') -local stddata = {} - -local function on_exit(id, code, single) - log.debug('git-mv exit code:' .. code .. ' single:' .. single) - if code == 0 and single == 0 then - nt.notify('git mv successfully') - else - nt.notify(table.concat(stddata, '\n'), 'warningmsg') - end -end - -local function on_std(id, data) - for _, v in ipairs(data) do - table.insert(stddata, v) - end -end - -function m.run(argv) - local cmd = { 'git', 'mv' } - if vim.fn.index(argv, '%') ~= -1 then - argv[vim.fn.index(argv, '%') + 1] = vim.fn.expand('%') - end - for _, v in ipairs(argv) do - table.insert(cmd, v) - end - log.debug('git-mv cmd:' .. vim.inspect(cmd)) - stddata = {} - job.start(cmd, { - on_exit = on_exit, - on_stdout = on_std, - on_stderr = on_std - }) -end - -return m +local m = {} + +local job = require('spacevim.api.job') +local nt = require('spacevim.api.notify') +local log = require('git.log') +local stddata = {} + +local function on_exit(id, code, single) + log.debug('git-mv exit code:' .. code .. ' single:' .. single) + if code == 0 and single == 0 then + nt.notify('git mv successfully') + else + nt.notify(table.concat(stddata, '\n'), 'warningmsg') + end +end + +local function on_std(id, data) + for _, v in ipairs(data) do + table.insert(stddata, v) + end +end + +function m.run(argv) + local cmd = { 'git', 'mv' } + if vim.fn.index(argv, '%') ~= -1 then + argv[vim.fn.index(argv, '%') + 1] = vim.fn.expand('%') + end + for _, v in ipairs(argv) do + table.insert(cmd, v) + end + log.debug('git-mv cmd:' .. vim.inspect(cmd)) + stddata = {} + job.start(cmd, { + on_exit = on_exit, + on_stdout = on_std, + on_stderr = on_std + }) +end + +return m diff --git a/bundle/git.vim/lua/git/command/rm.lua b/bundle/git.vim/lua/git/command/rm.lua new file mode 100644 index 000000000..a02fa9915 --- /dev/null +++ b/bundle/git.vim/lua/git/command/rm.lua @@ -0,0 +1,50 @@ +--============================================================================= +-- rm.lua --- Git rm command +-- Copyright (c) 2016-2022 Wang Shidong & Contributors +-- Author: Wang Shidong < wsdjeg@outlook.com > +-- URL: https://spacevim.org +-- License: GPLv3 +--============================================================================= + +local m = {} + +local job = require('spacevim.api.job') +local nt = require('spacevim.api.notify') +local log = require('git.log') +local stddata = {} + +local function on_exit(id, code, single) + log.debug('git-rm exit code:' .. code .. ' single:' .. single) + if code == 0 and single == 0 then + if vim.fn.exists(':GitGutter') == 2 then + vim.cmd('GitGutter') + end + nt.notify('git rm done!') + else + nt.notify(table.concat(stddata, '\n'), 'warningmsg') + end +end + +local function on_std(id, data) + for _, v in ipairs(data) do + table.insert(stddata, v) + end +end + +function m.run(argv) + local cmd = { 'git', 'rm' } + if #argv == 1 and argv[1] == '%' then + table.insert(cmd, vim.fn.expand('%')) + else + for _, v in ipairs(argv) do table.insert(cmd, v) end + end + log.debug('git-rm cmd:' .. vim.inspect(cmd)) + stddata = {} + job.start(cmd, { + on_exit = on_exit, + on_stdout = on_std, + on_stderr = on_std + }) +end + +return m