1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 12:50:04 +08:00

feat(git): make <Cr> show git log in remote manager

This commit is contained in:
Eric Wong 2024-02-23 13:21:12 +08:00
parent 7bad66fad6
commit 42ed861445
3 changed files with 17 additions and 8 deletions

View File

@ -28,13 +28,12 @@ local fetch_remote_name = ''
local help_info = { local help_info = {
'" Git remote manager quickhelp', '" Git remote manager quickhelp',
'" ============================', '" ============================',
'" <CR>: checkout branch', '" <CR>: view git log',
'" f: fetch remote under cursor', '" f: fetch remote under cursor',
'" o: toggle display of branchs', '" o: toggle display of branchs',
} }
local bufnr = -1 local bufnr = -1
local winid = -1
local bufname = '' local bufname = ''
@ -122,8 +121,6 @@ end
local function enter_win() end local function enter_win() end
local function checkout_branch() end
local function get_cursor_info() local function get_cursor_info()
local l = vim.fn.getline('.') local l = vim.fn.getline('.')
local c = {} local c = {}
@ -131,6 +128,11 @@ local function get_cursor_info()
c.remote = string.sub(l, 7) c.remote = string.sub(l, 7)
elseif vim.startswith(l, '') then elseif vim.startswith(l, '') then
c.remote = string.sub(l, 7) 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 end
if c.remote then if c.remote then
@ -140,6 +142,14 @@ local function get_cursor_info()
return c return c
end 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) local function update_branch_stdout(id, data)
-- stdout example: -- stdout example:
-- d89ff7896994692e7bcc6a53095c7ec2e2d780aa<Tab>refs/heads/dein-lua-job -- d89ff7896994692e7bcc6a53095c7ec2e2d780aa<Tab>refs/heads/dein-lua-job
@ -266,7 +276,6 @@ function M.open()
}) })
end end
vim.api.nvim_command('topleft vsplit __git_remote_manager__') vim.api.nvim_command('topleft vsplit __git_remote_manager__')
winid = vim.api.nvim_get_current_win()
local lines = vim.o.columns * 20 / 100 local lines = vim.o.columns * 20 / 100
vim.api.nvim_command('vertical resize ' .. tostring(lines)) vim.api.nvim_command('vertical resize ' .. tostring(lines))
vim.api.nvim_command( vim.api.nvim_command(
@ -284,7 +293,7 @@ function M.open()
callback = enter_win, callback = enter_win,
}) })
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Enter>', '', { vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Enter>', '', {
callback = checkout_branch, callback = view_git_log,
}) })
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'o', '', { vim.api.nvim_buf_set_keymap(bufnr, 'n', 'o', '', {
callback = toggle_remote_branch, callback = toggle_remote_branch,

View File

@ -37,7 +37,7 @@ lang: zh
- [x] 使用 lua 重写 pastebin 插件 - [x] 使用 lua 重写 pastebin 插件
- [x] 使得 `:A` 命令支持 toml 配置文件 - [x] 使得 `:A` 命令支持 toml 配置文件
- [x] 增加 git 远程仓库管理插件 - [x] 增加 git 远程仓库管理插件
- [ ] 使用 `<cr>` 快捷键展示 git log - [x] 使用 `<cr>` 快捷键展示 git log
- [ ] 缓存远程仓库以及分支名称等信息 - [ ] 缓存远程仓库以及分支名称等信息
- [ ] 基于项目路径存储信息 - [ ] 基于项目路径存储信息
- [x] 使用 lua 实现 `ctags#update` 函数 - [x] 使用 lua 实现 `ctags#update` 函数

View File

@ -36,7 +36,7 @@ The roadmap defines the project direction and priorities.
- [x] implement pastebin plugin with lua - [x] implement pastebin plugin with lua
- [x] make `:A` command support toml configuration file - [x] make `:A` command support toml configuration file
- [x] add git remote manager - [x] add git remote manager
- [ ] make `<cr>` show git log - [x] make `<cr>` show git log
- [ ] cache remote and branch info - [ ] cache remote and branch info
- [ ] cache info based on project root - [ ] cache info based on project root
- [x] implement `ctags#update` in lua - [x] implement `ctags#update` in lua