1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:00: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 = {
'" Git remote manager quickhelp',
'" ============================',
'" <CR>: checkout branch',
'" <CR>: 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:
-- d89ff7896994692e7bcc6a53095c7ec2e2d780aa<Tab>refs/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', '<Enter>', '', {
callback = checkout_branch,
callback = view_git_log,
})
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'o', '', {
callback = toggle_remote_branch,

View File

@ -37,7 +37,7 @@ lang: zh
- [x] 使用 lua 重写 pastebin 插件
- [x] 使得 `:A` 命令支持 toml 配置文件
- [x] 增加 git 远程仓库管理插件
- [ ] 使用 `<cr>` 快捷键展示 git log
- [x] 使用 `<cr>` 快捷键展示 git log
- [ ] 缓存远程仓库以及分支名称等信息
- [ ] 基于项目路径存储信息
- [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] make `:A` command support toml configuration file
- [x] add git remote manager
- [ ] make `<cr>` show git log
- [x] make `<cr>` show git log
- [ ] cache remote and branch info
- [ ] cache info based on project root
- [x] implement `ctags#update` in lua