1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 05:30:05 +08:00
SpaceVim/bundle/git.vim/lua/git/init.lua
2024-03-24 00:32:32 +08:00

79 lines
1.2 KiB
Lua

local M = {}
local log = require('git.log')
local argv_parser = require('spacevim.api.vim.argv')
local cmds = {
'add',
'blame',
'branch',
'checkout',
'config',
'cherry-pick',
'clean',
'commit',
'diff',
'fetch',
'log',
'merge',
'mv',
'pull',
'push',
'remote',
'reset',
'rm',
'reflog',
'shortlog',
'status',
'grep',
'rebase',
'stash',
'tag',
}
local supported_commands = {}
local function update_cmd()
for _, v in ipairs(cmds) do
supported_commands[v] = true
end
end
update_cmd()
function M.run(cmdline)
-- log.debug('cmdlien:' .. cmdline)
local argv = argv_parser.parser(cmdline)
-- log.debug('argvs:' .. vim.inspect(argv))
local command = table.remove(argv, 1)
if not supported_commands[command] then
vim.api.nvim_echo(
{ { ':Git ' .. command .. ' is not supported', 'WarningMsg' } },
false,
{}
)
return
end
local ok, cmd = pcall(require, 'git.command.' .. command)
if ok then
if type(cmd.run) == 'function' then
cmd.run(argv)
else
vim.api.nvim_echo(
{ { 'git.command.' .. command .. '.run is not function', 'WarningMsg' } },
false,
{}
)
end
else
error(cmd)
end
end
return M