From b9cc3e76e9443795092806bec2d71d73d45133f8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 27 Feb 2024 00:41:06 +0800 Subject: [PATCH] feat(git): add `:Git tag` command --- bundle/git.vim/autoload/git.vim | 2 +- bundle/git.vim/lua/git/command/tag.lua | 77 ++++++++++++++++++++++++++ bundle/git.vim/lua/git/init.lua | 1 + docs/cn/roadmap.md | 7 +++ docs/roadmap.md | 2 +- 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 bundle/git.vim/lua/git/command/tag.lua diff --git a/bundle/git.vim/autoload/git.vim b/bundle/git.vim/autoload/git.vim index 6cce2bd08..2a3e840f3 100644 --- a/bundle/git.vim/autoload/git.vim +++ b/bundle/git.vim/autoload/git.vim @@ -80,7 +80,7 @@ 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', 'mv', 'remote', 'clean', 'shortlog' + \ 'blame', 'pull', 'stash', 'cherry-pick', 'rm', 'mv', 'remote', 'clean', 'shortlog', 'tag' \ ], \ "\n") elseif str =~# '^Git\s\+add\s\+.*$' diff --git a/bundle/git.vim/lua/git/command/tag.lua b/bundle/git.vim/lua/git/command/tag.lua new file mode 100644 index 000000000..6a7c78104 --- /dev/null +++ b/bundle/git.vim/lua/git/command/tag.lua @@ -0,0 +1,77 @@ +local M = {} + +local job = require('spacevim.api.job') +local nt = require('spacevim.api.notify') +local log = require('git.log') + +local tag_jobid = -1 +local stderr_data = {} + +local function on_stdout(id, data) + if id ~= tag_jobid then + return + end + for _, line in pairs(data) do + nt.notify_max_width = vim.fn.max({ vim.fn.strwidth(line) + 5, nt.notify_max_width }) + nt.notify(line) + end +end + +local function on_stderr(id, data) + if id ~= tag_jobid then + return + end + for _, line in pairs(data) do + table.insert(stderr_data, line) + end +end + +local function on_exit(id, code, single) + log.debug('tag exit code:' .. code .. ' single:' .. single) + if id ~= tag_jobid then + return + end + if code == 0 and single == 0 then + for _, line in ipairs(stderr_data) do + nt.notify(line) + end + else + for _, line in ipairs(stderr_data) do + nt.notify(line, 'WarningMsg') + end + end + tag_jobid = -1 +end + +function M.run(argv) + if tag_jobid ~= -1 then + nt.notify('previous tag command is not finished') + end + + nt.notify_max_width = vim.fn.float2nr(vim.o.columns * 0.3) + + stderr_data = {} + + local cmd = { 'git', 'tag' } + + if argv then + for _, v in ipairs(argv) do + table.insert(cmd, v) + end + end + log.debug(vim.inspect(cmd)) + tag_jobid = job.start(cmd, { + on_stdout = on_stdout, + on_stderr = on_stderr, + on_exit = on_exit, + }) + + if tag_jobid == -1 then + nt.notify('`git` is not executable', 'WarningMsg') + end +end + +function M.complete(ArgLead, CmdLine, CursorPos) end + +return M + diff --git a/bundle/git.vim/lua/git/init.lua b/bundle/git.vim/lua/git/init.lua index ec2daf542..49e33cd7c 100644 --- a/bundle/git.vim/lua/git/init.lua +++ b/bundle/git.vim/lua/git/init.lua @@ -22,6 +22,7 @@ local cmds = { 'rm', 'shortlog', 'status', + 'tag', } local supported_commands = {} diff --git a/docs/cn/roadmap.md b/docs/cn/roadmap.md index 17dfbf053..0628adb5b 100644 --- a/docs/cn/roadmap.md +++ b/docs/cn/roadmap.md @@ -28,6 +28,7 @@ lang: zh - [x] `:Git blame` - [x] `:Git cherry-pick` - [x] `:Git shortlog` + - [x] `:Git tag` - [x] 日志系统整合至 SpaceVim 运行时日志 - [x] 使用 lua 重写 code runner - [x] 使用 lua 重写 task manager @@ -39,9 +40,15 @@ lang: zh - [x] 增加 git 远程仓库管理插件 - [x] 使用 `` 快捷键展示 git log - [x] 切换项目时,更新 remote 窗口信息 + - [x] 注册项目管理函数时,使用描述信息 - [ ] 缓存远程仓库以及分支名称等信息 - [ ] 基于项目路径存储信息 + - [x] 显示根目录地址 - [x] 使用 lua 实现 `ctags#update` 函数 + - [x] 项目管理插件注册函数增加描述支持 + - [x] 切换项目时,更新 todo 管理插件窗口内容 + - [x] 为主题 `one` 增加 treesitter 支持 + - [x] 最后一个窗口时,关闭 git log 页面 ## 已完成版本 diff --git a/docs/roadmap.md b/docs/roadmap.md index 7c6480223..7d50ca984 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -27,6 +27,7 @@ The roadmap defines the project direction and priorities. - [x] `:Git blame` - [x] `:Git cherry-pick` - [x] `:Git shortlog` + - [x] `:Git tag` - [x] plugin log manager derived from SPC runtime logger - [x] rewrite code runner with lua - [x] rewrite task manager with lua @@ -48,7 +49,6 @@ The roadmap defines the project direction and priorities. - [x] make `one` coloscheme support treesitter - [x] quit git log win when it is last win - ## Completed All completed releases can be viewed in [changelog](../development/#Changelog)