Permalink
Browse files

Expose gita#command#rebase#execute

  • Loading branch information...
1 parent 555e81f commit f053c354e3b62bda58e82774994ba9bccac6e3e1 @lambdalisue committed May 23, 2016
Showing with 96 additions and 22 deletions.
  1. +9 −3 autoload/gita/command/rebase.vim
  2. +87 −19 test/gita/command/rebase.vimspec
@@ -183,20 +183,26 @@ function! s:args_from_options(git, options) abort
return filter(args, '!empty(v:val)')
endfunction
+function! gita#command#rebase#execute(git, options) abort
+ let args = s:args_from_options(a:git, a:options)
+ let result = gita#process#execute(a:git, args)
+ return result
+endfunction
+
function! gita#command#rebase#command(bang, range, args) abort
let parser = s:get_parser()
let options = parser.parse(a:bang, a:range, a:args)
if empty(options)
- return
+ return {}
endif
let options = extend(
\ copy(g:gita#command#rebase#default_options),
\ options
\)
let git = gita#core#get_or_fail()
- let args = s:args_from_options(git, options)
- call gita#process#execute(git, args)
+ let result = gita#command#rebase#execute(git, options)
call gita#trigger_modified()
+ return result
endfunction
function! gita#command#rebase#complete(arglead, cmdline, cursorpos) abort
@@ -4,17 +4,19 @@ Describe gita#command#rebase
let Path = V.import('System.Filepath')
let Guard = V.import('Vim.Guard')
let ScriptLocal = V.import('Vim.ScriptLocal')
- " the line below is required to load requirements before :redir
- silent Gita rebase
+ let ProcessMock = V.import('System.Process.Mock')
End
Before
let sf = ScriptLocal.sfuncs(
\ Path.realpath('autoload/gita/command/rebase.vim')
\)
- let guard = Guard.store(['g:gita#process#options'])
+ let guard = Guard.store([
+ \ 'g:gita#process#options',
+ \ 'g:gita#command#rebase#default_options',
+ \])
let g:gita#process#options = {
- \ 'clients': [deepcopy(V.import('System.Process.Mock'))],
+ \ 'clients': [deepcopy(ProcessMock)],
\}
End
@@ -102,26 +104,92 @@ Describe gita#command#rebase
End
End
+ Describe #execute({git}, {options})
+ let prefix = ['rebase', '--verbose']
+
+ It executes 'rebase --verbose' for options: {}
+ let git = gita#core#get()
+ let result = gita#command#rebase#execute(git, {})
+ Assert Equals(result.args[-2:], [
+ \ 'rebase', '--verbose',
+ \])
+ End
+
+ It executes 'rebase --verbose --stat' for options: {'abort': 1}
+ let git = gita#core#get()
+ let result = gita#command#rebase#execute(git, {
+ \ 'abort': 1,
+ \})
+ Assert Equals(result.args[-3:], [
+ \ 'rebase', '--verbose', '--abort',
+ \])
+ End
+
+ It executes 'rebase --verbose --abort --onto=A' for options: {'abort': 1, 'onto': 'A'}
+ let git = gita#core#get()
+ let result = gita#command#rebase#execute(git, {
+ \ 'abort': 1,
+ \ 'onto': 'A',
+ \})
+ Assert Equals(result.args[-4:], [
+ \ 'rebase', '--verbose', '--abort', '--onto=A',
+ \])
+ End
+
+ It executes 'rebase --verbose' for options: {'__unknown__': ['develop']}
+ let git = gita#core#get()
+ let result = gita#command#rebase#execute(git, {
+ \ '__unknown__': ['develop'],
+ \})
+ Assert Equals(result.args[-2:], [
+ \ 'rebase', '--verbose',
+ \])
+ End
+ End
+
Describe #command({bang}, {range}, {args})
- It executes 'git rebase --verbose' for 'Gita rebase'
- redir => content
- silent! verbose execute 'Gita rebase'
- redir END
- Assert Match(content, 'git .* rebase --verbose')
+ let prefix = ['rebase', '--verbose']
+
+ It shows a help and do nothing if -h/--help is specified
+ silent let result = gita#command#rebase#command('', [0, 0], ['-h'])
+ Assert Equals(result, {})
+
+ silent let result = gita#command#rebase#command('', [0, 0], ['--help'])
+ Assert Equals(result, {})
End
- It executes 'git rebase --verbose --stat' for 'Gita rebase --stat'
- redir => content
- silent! verbose execute 'Gita rebase --stat'
- redir END
- Assert Match(content, 'git .* rebase --verbose --stat')
+ It executes a command with default options
+ silent let result = gita#command#rebase#command('', [0, 0], [])
+ Assert Equals(result.args[-2:], prefix )
+
+ let g:gita#command#rebase#default_options = {
+ \ 'abort': 1,
+ \ 'onto': 'A',
+ \}
+ silent let result = gita#command#rebase#command('', [0, 0], [])
+ Assert Equals(result.args[-4:], [
+ \ 'rebase', '--verbose', '--abort', '--onto=A',
+ \])
End
- It executes 'git rebase --verbose --onto=develop' for 'Gita rebase --onto=develop'
- redir => content
- silent! verbose execute 'Gita rebase --onto=develop'
- redir END
- Assert Match(content, 'git .* rebase --verbose --onto=develop')
+ It triggers modified
+ augroup vim-gita-temporary
+ autocmd! *
+ autocmd User GitaStatusModifiedPre let g:GitaStatusModifiedPreCalled = 1
+ autocmd User GitaStatusModifiedPost let g:GitaStatusModifiedPostCalled = 1
+ augroup END
+
+ let g:GitaStatusModifiedPreCalled = 0
+ let g:GitaStatusModifiedPostCalled = 0
+ silent let result = gita#command#rebase#command('', [0, 0], [])
+ Assert True(g:GitaStatusModifiedPreCalled)
+ Assert True(g:GitaStatusModifiedPostCalled)
+
+ unlet g:GitaStatusModifiedPreCalled
+ unlet g:GitaStatusModifiedPostCalled
+ augroup vim-gita-temporary
+ autocmd! *
+ augroup END
End
End
End

0 comments on commit f053c35

Please sign in to comment.