mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-13 22:47:59 +08:00
feat(rebase): complete after :Git rebase
This commit is contained in:
parent
3829f764fa
commit
21315be59f
@ -119,6 +119,8 @@ function! git#complete(ArgLead, CmdLine, CursorPos) abort
|
||||
return git#reflog#complete(a:ArgLead, a:CmdLine, a:CursorPos)
|
||||
elseif str =~# '^Git\s\+clean\s\+.*$'
|
||||
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
|
||||
return ''
|
||||
endif
|
||||
|
@ -1,104 +1,109 @@
|
||||
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:lines = []
|
||||
if !empty(a:1)
|
||||
let cmd = ['git', '--no-pager', '-c',
|
||||
\ 'core.editor=cat', '-c',
|
||||
\ 'color.status=always',
|
||||
\ '-C',
|
||||
\ expand(getcwd(), ':p'),
|
||||
\ 'rebase'] + a:1
|
||||
else
|
||||
finish
|
||||
endif
|
||||
call git#logger#debug('git-rebase cmd:' . string(cmd))
|
||||
call s:JOB.start(cmd,
|
||||
\ {
|
||||
\ 'on_stderr' : function('s:on_stderr'),
|
||||
\ 'on_stdout' : function('s:on_stdout'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
\ )
|
||||
endfunction
|
||||
|
||||
function! s:on_stdout(id, data, event) abort
|
||||
for data in a:data
|
||||
call git#logger#debug('git-rebase stdout:' . data)
|
||||
endfor
|
||||
let s:lines += a:data
|
||||
endfunction
|
||||
function! s:on_stderr(id, data, event) abort
|
||||
for data in a:data
|
||||
call git#logger#debug('git-rebase stderr:' . data)
|
||||
endfor
|
||||
" stderr should not be added to commit buffer
|
||||
" let s:lines += a:data
|
||||
endfunction
|
||||
function! s:on_exit(id, data, event) abort
|
||||
call git#logger#debug('git-rebase exit data:' . string(a:data))
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, 0 , -1, 0, s:lines)
|
||||
endfunction
|
||||
|
||||
function! s:openRebaseCommitBuffer() abort
|
||||
10split git://rebase
|
||||
normal! "_dd
|
||||
setlocal nobuflisted
|
||||
setlocal buftype=acwrite
|
||||
setlocal bufhidden=wipe
|
||||
setlocal noswapfile
|
||||
setlocal modifiable
|
||||
setf git-rebase
|
||||
nnoremap <buffer><silent> q :bd!<CR>
|
||||
let b:git_rebase_quitpre = 0
|
||||
|
||||
augroup git_commit_buffer
|
||||
autocmd! * <buffer>
|
||||
autocmd BufWriteCmd <buffer> call s:BufWriteCmd()
|
||||
autocmd QuitPre <buffer> call s:QuitPre()
|
||||
autocmd WinLeave <buffer> call s:WinLeave()
|
||||
autocmd WinEnter <buffer> let b:git_rebase_quitpre = 0
|
||||
augroup END
|
||||
return bufnr('%')
|
||||
endfunction
|
||||
|
||||
" NOTE:
|
||||
" :w -- BufWriteCmd
|
||||
" <C-w>p -- WinLeave
|
||||
" :wq -- QuitPre -> BufWriteCmd -> WinLeave
|
||||
" when run `:wq` the commit window will not be closed
|
||||
" :q -- QuitPre -> WinLeave
|
||||
function! s:BufWriteCmd() abort
|
||||
let commit_file = '.git\COMMIT_EDITMSG'
|
||||
call writefile(getline(1, '$'), commit_file)
|
||||
setlocal nomodified
|
||||
endfunction
|
||||
|
||||
function! s:QuitPre() abort
|
||||
let b:git_rebase_quitpre = 1
|
||||
endfunction
|
||||
|
||||
function! s:WinLeave() abort
|
||||
if b:git_rebase_quitpre == 1
|
||||
let cmd = ['git', 'rebase', '--continue']
|
||||
if has('nvim-0.9.0')
|
||||
function! git#rebase#complete(ArgLead, CmdLine, CursorPos) abort
|
||||
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"))')
|
||||
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:lines = []
|
||||
if !empty(a:1)
|
||||
let cmd = ['git', '--no-pager', '-c',
|
||||
\ 'core.editor=cat', '-c',
|
||||
\ 'color.status=always',
|
||||
\ '-C',
|
||||
\ expand(getcwd(), ':p'),
|
||||
\ 'rebase'] + a:1
|
||||
else
|
||||
finish
|
||||
endif
|
||||
call git#logger#debug('git-rebase cmd:' . string(cmd))
|
||||
let id = s:JOB.start(cmd,
|
||||
call s:JOB.start(cmd,
|
||||
\ {
|
||||
\ 'on_exit' : function('s:on_rebase_continue'),
|
||||
\ 'on_stderr' : function('s:on_stderr'),
|
||||
\ 'on_stdout' : function('s:on_stdout'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
\ )
|
||||
" line start with # should be ignored
|
||||
endif
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
function! s:on_rebase_continue(id, data, event) abort
|
||||
call git#logger#debug('git-rebase exit data:' . string(a:data))
|
||||
if a:data ==# 0
|
||||
echo 'done!'
|
||||
else
|
||||
echo 'failed!'
|
||||
endif
|
||||
endfunction
|
||||
function! s:on_stdout(id, data, event) abort
|
||||
for data in a:data
|
||||
call git#logger#debug('git-rebase stdout:' . data)
|
||||
endfor
|
||||
let s:lines += a:data
|
||||
endfunction
|
||||
function! s:on_stderr(id, data, event) abort
|
||||
for data in a:data
|
||||
call git#logger#debug('git-rebase stderr:' . data)
|
||||
endfor
|
||||
" stderr should not be added to commit buffer
|
||||
" let s:lines += a:data
|
||||
endfunction
|
||||
function! s:on_exit(id, data, event) abort
|
||||
call git#logger#debug('git-rebase exit data:' . string(a:data))
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, 0 , -1, 0, s:lines)
|
||||
endfunction
|
||||
|
||||
function! s:openRebaseCommitBuffer() abort
|
||||
10split git://rebase
|
||||
normal! "_dd
|
||||
setlocal nobuflisted
|
||||
setlocal buftype=acwrite
|
||||
setlocal bufhidden=wipe
|
||||
setlocal noswapfile
|
||||
setlocal modifiable
|
||||
setf git-rebase
|
||||
nnoremap <buffer><silent> q :bd!<CR>
|
||||
let b:git_rebase_quitpre = 0
|
||||
|
||||
augroup git_commit_buffer
|
||||
autocmd! * <buffer>
|
||||
autocmd BufWriteCmd <buffer> call s:BufWriteCmd()
|
||||
autocmd QuitPre <buffer> call s:QuitPre()
|
||||
autocmd WinLeave <buffer> call s:WinLeave()
|
||||
autocmd WinEnter <buffer> let b:git_rebase_quitpre = 0
|
||||
augroup END
|
||||
return bufnr('%')
|
||||
endfunction
|
||||
|
||||
" NOTE:
|
||||
" :w -- BufWriteCmd
|
||||
" <C-w>p -- WinLeave
|
||||
" :wq -- QuitPre -> BufWriteCmd -> WinLeave
|
||||
" when run `:wq` the commit window will not be closed
|
||||
" :q -- QuitPre -> WinLeave
|
||||
function! s:BufWriteCmd() abort
|
||||
let commit_file = '.git\COMMIT_EDITMSG'
|
||||
call writefile(getline(1, '$'), commit_file)
|
||||
setlocal nomodified
|
||||
endfunction
|
||||
|
||||
function! s:QuitPre() abort
|
||||
let b:git_rebase_quitpre = 1
|
||||
endfunction
|
||||
|
||||
function! s:WinLeave() abort
|
||||
if b:git_rebase_quitpre == 1
|
||||
let cmd = ['git', 'rebase', '--continue']
|
||||
call git#logger#debug('git-rebase cmd:' . string(cmd))
|
||||
let id = s:JOB.start(cmd,
|
||||
\ {
|
||||
\ 'on_exit' : function('s:on_rebase_continue'),
|
||||
\ }
|
||||
\ )
|
||||
" line start with # should be ignored
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:on_rebase_continue(id, data, event) abort
|
||||
call git#logger#debug('git-rebase exit data:' . string(a:data))
|
||||
if a:data ==# 0
|
||||
echo 'done!'
|
||||
else
|
||||
echo 'failed!'
|
||||
endif
|
||||
endfunction
|
||||
endif
|
||||
|
@ -135,5 +135,8 @@ function m.run(argv)
|
||||
on_stderr = on_std,
|
||||
})
|
||||
end
|
||||
function m.complete(ArgLead, CmdLine, CursorPos)
|
||||
return table.concat({'-i', '--abort'}, '\n')
|
||||
end
|
||||
|
||||
return m
|
||||
|
Loading…
Reference in New Issue
Block a user