1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-14 05:37:57 +08:00

feat(rebase): complete after :Git rebase

This commit is contained in:
Eric Wong 2025-02-03 14:01:06 +08:00
parent 3829f764fa
commit 21315be59f
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
3 changed files with 108 additions and 98 deletions

View File

@ -119,6 +119,8 @@ function! git#complete(ArgLead, CmdLine, CursorPos) abort
return git#reflog#complete(a:ArgLead, a:CmdLine, a:CursorPos) return git#reflog#complete(a:ArgLead, a:CmdLine, a:CursorPos)
elseif str =~# '^Git\s\+clean\s\+.*$' elseif str =~# '^Git\s\+clean\s\+.*$'
return git#clean#complete(a:ArgLead, a:CmdLine, a:CursorPos) return git#clean#complete(a:ArgLead, a:CmdLine, a:CursorPos)
elseif str =~# '^Git\s\+rebase\s\+.*$'
return git#rebase#complete(a:ArgLead, a:CmdLine, a:CursorPos)
else else
return '' return ''
endif endif

View File

@ -1,7 +1,12 @@
let s:JOB = SpaceVim#api#import('job') if has('nvim-0.9.0')
let s:BUFFER = SpaceVim#api#import('vim#buffer') function! git#rebase#complete(ArgLead, CmdLine, CursorPos) abort
" @todo rewrite Git rebase in lua return luaeval('require("git.command.rebase").complete(vim.api.nvim_eval("a:ArgLead"), vim.api.nvim_eval("a:CmdLine"), vim.api.nvim_eval("a:CursorPos"))')
function! git#rebase#run(...) abort endfunction
else
let s:JOB = SpaceVim#api#import('job')
let s:BUFFER = SpaceVim#api#import('vim#buffer')
" @todo rewrite Git rebase in lua
function! git#rebase#run(...) abort
let s:bufnr = s:openRebaseCommitBuffer() let s:bufnr = s:openRebaseCommitBuffer()
let s:lines = [] let s:lines = []
if !empty(a:1) if !empty(a:1)
@ -22,27 +27,27 @@ function! git#rebase#run(...) abort
\ 'on_exit' : function('s:on_exit'), \ 'on_exit' : function('s:on_exit'),
\ } \ }
\ ) \ )
endfunction endfunction
function! s:on_stdout(id, data, event) abort function! s:on_stdout(id, data, event) abort
for data in a:data for data in a:data
call git#logger#debug('git-rebase stdout:' . data) call git#logger#debug('git-rebase stdout:' . data)
endfor endfor
let s:lines += a:data let s:lines += a:data
endfunction endfunction
function! s:on_stderr(id, data, event) abort function! s:on_stderr(id, data, event) abort
for data in a:data for data in a:data
call git#logger#debug('git-rebase stderr:' . data) call git#logger#debug('git-rebase stderr:' . data)
endfor endfor
" stderr should not be added to commit buffer " stderr should not be added to commit buffer
" let s:lines += a:data " let s:lines += a:data
endfunction endfunction
function! s:on_exit(id, data, event) abort function! s:on_exit(id, data, event) abort
call git#logger#debug('git-rebase exit data:' . string(a:data)) call git#logger#debug('git-rebase exit data:' . string(a:data))
call s:BUFFER.buf_set_lines(s:bufnr, 0 , -1, 0, s:lines) call s:BUFFER.buf_set_lines(s:bufnr, 0 , -1, 0, s:lines)
endfunction endfunction
function! s:openRebaseCommitBuffer() abort function! s:openRebaseCommitBuffer() abort
10split git://rebase 10split git://rebase
normal! "_dd normal! "_dd
setlocal nobuflisted setlocal nobuflisted
@ -62,25 +67,25 @@ function! s:openRebaseCommitBuffer() abort
autocmd WinEnter <buffer> let b:git_rebase_quitpre = 0 autocmd WinEnter <buffer> let b:git_rebase_quitpre = 0
augroup END augroup END
return bufnr('%') return bufnr('%')
endfunction endfunction
" NOTE: " NOTE:
" :w -- BufWriteCmd " :w -- BufWriteCmd
" <C-w>p -- WinLeave " <C-w>p -- WinLeave
" :wq -- QuitPre -> BufWriteCmd -> WinLeave " :wq -- QuitPre -> BufWriteCmd -> WinLeave
" when run `:wq` the commit window will not be closed " when run `:wq` the commit window will not be closed
" :q -- QuitPre -> WinLeave " :q -- QuitPre -> WinLeave
function! s:BufWriteCmd() abort function! s:BufWriteCmd() abort
let commit_file = '.git\COMMIT_EDITMSG' let commit_file = '.git\COMMIT_EDITMSG'
call writefile(getline(1, '$'), commit_file) call writefile(getline(1, '$'), commit_file)
setlocal nomodified setlocal nomodified
endfunction endfunction
function! s:QuitPre() abort function! s:QuitPre() abort
let b:git_rebase_quitpre = 1 let b:git_rebase_quitpre = 1
endfunction endfunction
function! s:WinLeave() abort function! s:WinLeave() abort
if b:git_rebase_quitpre == 1 if b:git_rebase_quitpre == 1
let cmd = ['git', 'rebase', '--continue'] let cmd = ['git', 'rebase', '--continue']
call git#logger#debug('git-rebase cmd:' . string(cmd)) call git#logger#debug('git-rebase cmd:' . string(cmd))
@ -91,14 +96,14 @@ function! s:WinLeave() abort
\ ) \ )
" line start with # should be ignored " line start with # should be ignored
endif endif
endfunction endfunction
function! s:on_rebase_continue(id, data, event) abort function! s:on_rebase_continue(id, data, event) abort
call git#logger#debug('git-rebase exit data:' . string(a:data)) call git#logger#debug('git-rebase exit data:' . string(a:data))
if a:data ==# 0 if a:data ==# 0
echo 'done!' echo 'done!'
else else
echo 'failed!' echo 'failed!'
endif endif
endfunction endfunction
endif

View File

@ -135,5 +135,8 @@ function m.run(argv)
on_stderr = on_std, on_stderr = on_std,
}) })
end end
function m.complete(ArgLead, CmdLine, CursorPos)
return table.concat({'-i', '--abort'}, '\n')
end
return m return m