Skip to content
Browse files

Implement showing changed files from giti/log

  • Loading branch information...
1 parent 5c99f35 commit c2c214a25b5a05e868091455b3ef5539dc635784 @kmnk committed Mar 19, 2013
View
31 autoload/unite/kinds/giti/log.vim
@@ -159,6 +159,37 @@ function! s:kind.action_table.yank_hash.func(candidate)"{{{
let @" = a:candidate.action__data.hash
endfunction"}}}
+let s:kind.action_table.changed_files = {
+\ 'description' : 'show changed files',
+\ 'is_selectable' : 1,
+\ 'is_quit' : 1,
+\ 'is_invalidate_cache' : 0,
+\ 'is_listed' : 1,
+\}
+function! s:kind.action_table.changed_files.func(candidates)"{{{
+ if s:is_graph_only_line(a:candidates[0])
+\ || len(a:candidates) > 1 && s:is_graph_only_line(a:candidates[1])
+ call giti#print('graph only line')
+ return
+ endif
+
+ let from = ''
+ let to = ''
+ if len(a:candidates) == 1
+ let to = a:candidates[0].action__data.hash
+ let from = a:candidates[0].action__data.parent_hash
+ elseif len(a:candidates) == 2
+ let to = a:candidates[0].action__data.hash
+ let from = a:candidates[1].action__data.hash
+ else
+ call unite#print_error('too many commits selected')
+ endif
+
+ let context = unite#get_context()
+ let context.input = ''
+ return unite#start([['giti/diff_tree/changed_files', from, to]], context)
+endfunction"}}}
+
" }}}
" local functions {{{
View
37 autoload/unite/sources/giti/diff_tree.vim
@@ -0,0 +1,37 @@
+" File: diff_tree.vim
+" Author: kmnk <kmnknmk+vim@gmail.com>
+" Version: 0.1.0
+" Copyright: Copyright (C) 2013- diff_tree
+" License: MIT Licence {{{
+" Permission is hereby granted, free of charge, to any person obtaining
+" a copy of this software and associated documentation files (the
+" "Software"), to deal in the Software without restriction, including
+" without limitation the rights to use, copy, modify, merge, publish,
+" distribute, sublicense, and/or sell copies of the Software, and to
+" permit persons to whom the Software is furnished to do so, subject to
+" the following conditions:
+" The above copyright notice and this permission notice shall be
+" included in all copies or substantial portions of the Software.
+"
+" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+" }}}
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#sources#giti#diff_tree#define()"{{{
+ return [unite#sources#giti#diff_tree#changed_files#define()]
+endfunction"}}}
+
+" local functions {{{
+" }}}
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+" __END__
View
61 autoload/unite/sources/giti/diff_tree/changed_files.vim
@@ -0,0 +1,61 @@
+" File: changed_files.vim
+" Author: kmnk <kmnknmk+vim@gmail.com>
+" Version: 0.1.0
+" Copyright: Copyright (C) 2013- changed_files
+" License: MIT Licence {{{
+" Permission is hereby granted, free of charge, to any person obtaining
+" a copy of this software and associated documentation files (the
+" "Software"), to deal in the Software without restriction, including
+" without limitation the rights to use, copy, modify, merge, publish,
+" distribute, sublicense, and/or sell copies of the Software, and to
+" permit persons to whom the Software is furnished to do so, subject to
+" the following conditions:
+" The above copyright notice and this permission notice shall be
+" included in all copies or substantial portions of the Software.
+"
+" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+" }}}
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#sources#giti#diff_tree#changed_files#define()"{{{
+ return s:source
+endfunction"}}}
+
+let s:source = {
+\ 'name' : 'giti/diff_tree/changed_files',
+\ 'description' : 'show changed files of specified commits',
+\}
+
+function! s:source.gather_candidates(args, context)"{{{
+ call unite#print_message('[giti/diff_tree/changed_files]')
+ let from = ''
+ let to = ''
+ if len(a:args) == 1
+ let from = a:args[0]
+ let to = a:args[0]
+ elseif len(a:args) == 2
+ let from = a:args[0]
+ let to = a:args[1]
+ endif
+ return map(giti#diff_tree#changed_files({'from' : from, 'to' : to}), '{
+\ "word" : v:val,
+\ "source" : s:source.name,
+\ "kind" : "file",
+\ "action__path" : v:val,
+\ }')
+endfunction"}}}
+
+" local functions {{{
+" }}}
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+" __END__
View
41 test/autoload/unite/kinds/giti/test_log.vim
@@ -232,6 +232,47 @@ function! s:tc.test_action_yank_hash()"{{{
call self.assert_equal(candidate.action__data.hash, @")
endfunction"}}}
+function! s:tc.setup_kind_action_changed_files()"{{{
+ function! giti#diff_tree#changed_files(param)"{{{
+ let b:changed_files_called_with = a:param
+ return 'mocked giti#diff_tree#changed_files'
+ endfunction"}}}
+endfunction"}}}
+function! s:tc.teardown_kind_action_changed_files()"{{{
+ let paths = split(globpath(&rtp, 'autoload/giti/diff_tree.vim'), '\n')
+ execute 'source ' . paths[0]
+endfunction"}}}
+function! s:tc.test_kind_action_changed_files()"{{{
+ let kind = self.get('s:kind')
+ let changed_files = kind.action_table.changed_files
+ call self.assert_equal(type({}), type(changed_files))
+ call self.assert_equal(type(''), type(changed_files.description))
+ call self.assert_equal(changed_files.is_selectable, 1)
+ call self.assert_equal(changed_files.is_quit, 1)
+ call self.assert_equal(changed_files.is_invalidate_cache, 0)
+ call self.assert_equal(type(function('tr')), type(changed_files.func))
+
+ let candidates = map(range(2), '
+\ {
+\ "action__data" : {
+\ "hash" : "hoge" . v:val,
+\ "parent_hash" : "fuga" . v:val,
+\ },
+\ }
+\ ')
+ call self.assert_equal(changed_files.func([candidates[0]]), 'mocked unite#start')
+ call self.assert_equal(b:unite_start_called_with,
+\ [[['giti/diff_tree/changed_files',
+\ candidates[0].action__data.parent_hash,
+\ candidates[0].action__data.hash]], {'input' : ''}])
+
+ call self.assert_equal(changed_files.func(candidates), 'mocked unite#start')
+ call self.assert_equal(b:unite_start_called_with,
+\ [[['giti/diff_tree/changed_files',
+\ candidates[1].action__data.hash,
+\ candidates[0].action__data.hash]], {'input' : ''}])
+endfunction"}}}
+
function! s:tc.test_kind_alias_table_has()"{{{
let kind = self.get('s:kind')
let table = kind.alias_table

0 comments on commit c2c214a

Please sign in to comment.
Something went wrong with that request. Please try again.