mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 00:00:04 +08:00
feat(git): rewrite :Git reflog
in lua
This commit is contained in:
parent
dc65e2b3bf
commit
1c3e61b5c5
@ -1,6 +1,22 @@
|
||||
"=============================================================================
|
||||
" reflog.vim --- git-reflog
|
||||
" Copyright (c) 2016-2019 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
" @todo rewrite Git reflog in lua
|
||||
|
||||
""
|
||||
" @section git-reflog, reflog
|
||||
" @parentsection commands
|
||||
" This commands is to view git reflog.
|
||||
" >
|
||||
" :Git reflog
|
||||
" <
|
||||
|
||||
function! git#reflog#run(args)
|
||||
let cmd = ['git', 'reflog'] + a:args
|
||||
let s:bufnr = s:openRefLogBuffer()
|
||||
|
@ -10,8 +10,9 @@ CONTENTS *git-contents*
|
||||
3. git-cherry-pick.....................................|git-cherry-pick|
|
||||
4. git-clean.................................................|git-clean|
|
||||
5. git-mv.......................................................|git-mv|
|
||||
6. git-rm.......................................................|git-rm|
|
||||
7. git-stash.................................................|git-stash|
|
||||
6. git-reflog...............................................|git-reflog|
|
||||
7. git-rm.......................................................|git-rm|
|
||||
8. git-stash.................................................|git-stash|
|
||||
3. Functions.................................................|git-functions|
|
||||
|
||||
==============================================================================
|
||||
@ -68,6 +69,14 @@ the index. For example, rename current file.
|
||||
:Git mv % new_file.txt
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
GIT-REFLOG *git-reflog*
|
||||
|
||||
This commands is to view git reflog.
|
||||
>
|
||||
:Git reflog
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
GIT-RM *git-rm*
|
||||
|
||||
|
98
bundle/git.vim/lua/git/command/reflog.lua
Normal file
98
bundle/git.vim/lua/git/command/reflog.lua
Normal file
@ -0,0 +1,98 @@
|
||||
--=============================================================================
|
||||
-- reflog.lua --- git-reflog
|
||||
-- Copyright (c) 2016-2022 Wang Shidong & Contributors
|
||||
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
-- URL: https://spacevim.org
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
|
||||
local M = {}
|
||||
|
||||
local reflog_stdout = {}
|
||||
local reflog_stderr = {}
|
||||
local jobid = -1
|
||||
local reflog_bufid = -1
|
||||
|
||||
local job = require('spacevim.api.job')
|
||||
local nt = require('spacevim.api.notify')
|
||||
|
||||
local log = require('git.log')
|
||||
|
||||
local function on_stdout(id, data)
|
||||
if id ~= jobid then
|
||||
return
|
||||
end
|
||||
|
||||
for _, v in ipairs(data) do
|
||||
table.insert(reflog_stdout, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_stderr(id, data)
|
||||
if id ~= jobid then
|
||||
return
|
||||
end
|
||||
|
||||
for _, v in ipairs(data) do
|
||||
table.insert(reflog_stderr, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function open_reflog_buffer()
|
||||
local previous_buf = vim.api.nvim_get_current_buf()
|
||||
vim.cmd('edit git://reflog')
|
||||
vim.cmd([[
|
||||
normal! "_dd
|
||||
setl nobuflisted
|
||||
setl nomodifiable
|
||||
setl nonumber norelativenumber
|
||||
setl buftype=nofile
|
||||
setl bufhidden=wipe
|
||||
setf git-reflog
|
||||
]])
|
||||
vim.api.nvim_buf_set_keymap(vim.api.nvim_get_current_buf(), 'n', 'q', '', {
|
||||
callback = function ()
|
||||
if vim.api.nvim_buf_is_valid(previous_buf) then
|
||||
vim.api.nvim_set_current_buf(previous_buf)
|
||||
else
|
||||
vim.cmd('bd')
|
||||
end
|
||||
end,
|
||||
})
|
||||
return vim.api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
local function on_exit(id, code, signal)
|
||||
log.debug(string.format('git-reflog exit code %d, signal %d', code, signal))
|
||||
|
||||
if code == 0 and signal == 0 then
|
||||
reflog_bufid = open_reflog_buffer()
|
||||
|
||||
vim.api.nvim_buf_set_option(reflog_bufid, 'modifiable', true)
|
||||
vim.api.nvim_buf_set_lines(reflog_bufid, 0, -1, false, reflog_stdout)
|
||||
vim.api.nvim_buf_set_option(reflog_bufid, 'modifiable', false)
|
||||
else
|
||||
nt.notify(string.format('failed to run git reflog, exit code: %d', code), 'WaringMsg')
|
||||
end
|
||||
|
||||
jobid = -1
|
||||
end
|
||||
|
||||
function M.run(argv)
|
||||
local cmd = { 'git', 'reflog' }
|
||||
|
||||
for _, v in ipairs(argv) do
|
||||
table.insert(cmd, v)
|
||||
end
|
||||
|
||||
log.debug('git-reflog cmd:' .. vim.inspect(cmd))
|
||||
reflog_stdout = {}
|
||||
reflog_stderr = {}
|
||||
jobid = job.start(cmd, {
|
||||
on_stderr = on_stderr,
|
||||
on_stdout = on_stdout,
|
||||
on_exit = on_exit,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
@ -21,6 +21,7 @@ local cmds = {
|
||||
'remote',
|
||||
'reset',
|
||||
'rm',
|
||||
'reflog',
|
||||
'shortlog',
|
||||
'status',
|
||||
'tag',
|
||||
|
@ -37,7 +37,7 @@ If you have any suggestions , please checkout feedback section on [community](..
|
||||
- [x] `:Git pull`
|
||||
- [x] `:Git push`
|
||||
- [ ] `:Git rebase`
|
||||
- [ ] `:Git reflog`
|
||||
- [x] `:Git reflog`
|
||||
- [x] `:Git remote`
|
||||
- [x] `:Git reset`
|
||||
- [x] `:Git rm`
|
||||
|
Loading…
Reference in New Issue
Block a user