From 42ed861445fe2eed7cf8915d269c780709e7677e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 23 Feb 2024 13:21:12 +0800 Subject: [PATCH] feat(git): make `` show git log in remote manager --- bundle/git.vim/lua/git/ui/remote.lua | 21 +++++++++++++++------ docs/cn/roadmap.md | 2 +- docs/roadmap.md | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/bundle/git.vim/lua/git/ui/remote.lua b/bundle/git.vim/lua/git/ui/remote.lua index 009cfd63b..5661e9b85 100644 --- a/bundle/git.vim/lua/git/ui/remote.lua +++ b/bundle/git.vim/lua/git/ui/remote.lua @@ -28,13 +28,12 @@ local fetch_remote_name = '' local help_info = { '" Git remote manager quickhelp', '" ============================', - '" : checkout branch', + '" : view git log', '" f: fetch remote under cursor', '" o: toggle display of branchs', } local bufnr = -1 -local winid = -1 local bufname = '' @@ -122,8 +121,6 @@ end local function enter_win() end -local function checkout_branch() end - local function get_cursor_info() local l = vim.fn.getline('.') local c = {} @@ -131,6 +128,11 @@ local function get_cursor_info() c.remote = string.sub(l, 7) elseif vim.startswith(l, ' ▷ ') then c.remote = string.sub(l, 7) + elseif vim.startswith(l, '  ') then + local remote_line = vim.fn.search('^ ▼ ', 'bnW') + if remote_line > 0 then + c.branch = string.gsub(string.sub(vim.fn.getline('.'), 7), updating_extra_text, '') .. string.sub(l, 12) + end end if c.remote then @@ -140,6 +142,14 @@ local function get_cursor_info() return c end +local function view_git_log() + local cursor_info = get_cursor_info() + if cursor_info.branch then + log.debug('run command:' .. 'Git log ' .. cursor_info.branch) + vim.api.nvim_command('Git log ' .. cursor_info.branch) + end +end + local function update_branch_stdout(id, data) -- stdout example: -- d89ff7896994692e7bcc6a53095c7ec2e2d780aarefs/heads/dein-lua-job @@ -266,7 +276,6 @@ function M.open() }) end vim.api.nvim_command('topleft vsplit __git_remote_manager__') - winid = vim.api.nvim_get_current_win() local lines = vim.o.columns * 20 / 100 vim.api.nvim_command('vertical resize ' .. tostring(lines)) vim.api.nvim_command( @@ -284,7 +293,7 @@ function M.open() callback = enter_win, }) vim.api.nvim_buf_set_keymap(bufnr, 'n', '', '', { - callback = checkout_branch, + callback = view_git_log, }) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'o', '', { callback = toggle_remote_branch, diff --git a/docs/cn/roadmap.md b/docs/cn/roadmap.md index be10e3b9d..8596f595b 100644 --- a/docs/cn/roadmap.md +++ b/docs/cn/roadmap.md @@ -37,7 +37,7 @@ lang: zh - [x] 使用 lua 重写 pastebin 插件 - [x] 使得 `:A` 命令支持 toml 配置文件 - [x] 增加 git 远程仓库管理插件 - - [ ] 使用 `` 快捷键展示 git log + - [x] 使用 `` 快捷键展示 git log - [ ] 缓存远程仓库以及分支名称等信息 - [ ] 基于项目路径存储信息 - [x] 使用 lua 实现 `ctags#update` 函数 diff --git a/docs/roadmap.md b/docs/roadmap.md index ccb5b79c3..a8a1f83c1 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -36,7 +36,7 @@ The roadmap defines the project direction and priorities. - [x] implement pastebin plugin with lua - [x] make `:A` command support toml configuration file - [x] add git remote manager - - [ ] make `` show git log + - [x] make `` show git log - [ ] cache remote and branch info - [ ] cache info based on project root - [x] implement `ctags#update` in lua