Permalink
Browse files

Add stash source and kind

But some erro occured. why..
  • Loading branch information...
1 parent f149b08 commit a6016e8c44d7307797c82a12ffbc7a54c1a74095 @kmnk committed Aug 22, 2012
View
9 autoload/giti/stash.vim
@@ -16,7 +16,7 @@ endfunction"}}}
function! giti#stash#built_list()"{{{
return map(split(giti#system(
-\ printf('stash list --date=relative --pretty=format:"%s"',
+\ printf('stash list --pretty=format:"%s"',
\ s:pretty_format)
\ ), '\n'), '
\ s:build_data(v:val)
@@ -25,7 +25,12 @@ endfunction"}}}
function! giti#stash#show(param)"{{{
let stash = has_key(a:param, 'stash') ? a:param.stash : ''
- return giti#system('stash show ' . stash)
+ let patch = has_key(a:param, 'patch') ? a:param.patch : ''
+ return giti#system(printf(
+\ 'stash show %s %s',
+\ patch ? '-p' : '',
+\ stash,
+\ ))
endfunction"}}}
function! giti#stash#drop(param)"{{{
View
130 autoload/unite/kinds/giti/stash.vim
@@ -0,0 +1,130 @@
+" File: stash.vim
+" Author: kmnk <kmnknmk+vim@gmail.com>
+" Version: 0.1.0
+" License:
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#kinds#giti#stash#define()"{{{
+ return s:kind
+endfunction"}}}
+
+let s:kind = {
+\ 'name' : 'giti/stash',
+\ 'default_action' : 'show',
+\ 'action_table' : {},
+\ 'alias_table' : {},
+\}
+
+let s:kind.action_table.view = {
+\ 'description' : 'view information of this stash',
+\ 'is_selectable' : 0,
+\ 'is_quit' : 0,
+\ 'is_invalidate_cache' : 0,
+\ 'is_listed' : 1,
+\}
+function! s:kind.action_table.view.func(candidate)"{{{
+ let data = a:candidate.action__data
+ echo 'Hash: ' . data.hash
+ echo 'Stash: ' . data.stash
+ echo printf('Author: %s <%s> - %s',
+\ data.author.name, data.author.mail, data.author.date)
+ echo printf('Committer: %s <%s> - %s',
+\ data.committer.name, data.committer.mail, data.committer.date)
+ echo 'Comment: ' . data.comment
+endfunction"}}}
+
+let s:kind.action_table.show = {
+\ 'description' : 'show stash',
+\ 'is_selectable' : 0,
+\ 'is_quit' : 0,
+\ 'is_invalidate_cache' : 0,
+\ 'is_listed' : 1,
+\}
+function! s:kind.action_table.show.func(candidate)"{{{
+ let data = a:candidate.action__data
+ echo giti#stash#show({'stash' : data.hash})
+endfunction"}}}
+
+let s:kind.action_table.patch = {
+\ 'description' : 'show stash patch',
+\ 'is_selectable' : 0,
+\ 'is_quit' : 1,
+\ 'is_invalidate_cache' : 0,
+\ 'is_listed' : 1,
+\}
+function! s:kind.action_table.patch.func(candidate)"{{{
+ let data = a:candidate.action__data
+ let patch = giti#stash#show({'stash' : data.hash, 'patch' : 1})
+
+ if !strlen(patch)
+ echo 'no patch'
+ return
+ endif
+
+ call giti#new_buffer({
+\ 'method' : giti#edit_command(),
+\ 'string' : patch,
+\ 'filetype' : 'diff',
+\ 'buftype' : 'nofile',
+\ })
+endfunction"}}}
+let s:kind.alias_table.diff = 'patch'
+let s:kind.alias_table.di = 'patch'
+
+let s:kind.action_table.drop = {
+\ 'description' : 'drop this stash',
+\ 'is_selectable' : 0,
+\ 'is_quit' : 1,
+\ 'is_invalidate_cache' : 0,
+\ 'is_listed' : 1,
+\}
+function! s:kind.action_table.drop.func(candidate)"{{{
+ let data = a:candidate.action__data
+ echo giti#stash#drop({'stash' : data.hash})
+endfunction"}}}
+
+let s:kind.action_table.pop = {
+\ 'description' : 'pop this stash (apply and drop)',
+\ 'is_selectable' : 0,
+\ 'is_quit' : 1,
+\ 'is_invalidate_cache' : 0,
+\ 'is_listed' : 1,
+\}
+function! s:kind.action_table.pop.func(candidate)"{{{
+ let data = a:candidate.action__data
+ echo giti#stash#pop({'stash' : data.hash})
+endfunction"}}}
+
+let s:kind.action_table.apply = {
+\ 'description' : 'apply this stash',
+\ 'is_selectable' : 0,
+\ 'is_quit' : 1,
+\ 'is_invalidate_cache' : 0,
+\ 'is_listed' : 1,
+\}
+function! s:kind.action_table.apply.func(candidate)"{{{
+ let data = a:candidate.action__data
+ echo giti#stash#apply({'stash' : data.hash})
+endfunction"}}}
+
+let s:kind.action_table.branch = {
+\ 'description' : 'make new branch with this stash',
+\ 'is_selectable' : 0,
+\ 'is_quit' : 1,
+\ 'is_invalidate_cache' : 0,
+\ 'is_listed' : 1,
+\}
+function! s:kind.action_table.branch.func(candidate)"{{{
+ let data = a:candidate.action__data
+ let branchname = input('branch name: ')
+ echo giti#stash#branch({'stash' : data.hash, 'branchname' : branchname})
+endfunction"}}}
+
+" local functions {{{
+" }}}
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+" __END__
View
49 autoload/unite/sources/giti/stash.vim
@@ -0,0 +1,49 @@
+" File: stash.vim
+" Author: kmnk <kmnknmk+vim@gmail.com>
+" Version: 0.1.0
+" License:
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#sources#giti#stash#define()"{{{
+ return s:source
+endfunction"}}}
+
+let s:source = {
+\ 'name' : 'giti/stash',
+\ 'description' : 'manage stash',
+\}
+
+function! s:source.gather_candidates(args, context)"{{{
+ call unite#print_message('[giti/stash]')
+ return map(giti#stash#built_list(), '{
+\ "word" : s:build_word(v:val),
+\ "source" : s:source.name,
+\ "kind" : s:source.name,
+\ "action__data" : v:val,
+\ }')
+endfunction"}}}
+
+" local functions {{{
+let s:word_format = '%s - %s, %s : %s'
+function! s:build_word(val)"{{{
+ return printf(s:word_format,
+\ a:val.hash[0:6],
+\ a:val.author.name,
+\ a:val.author.date,
+\ a:val.comment
+\ )
+endfunction"}}}
+function! s:build_title()"{{{
+ return printf(s:word_format,
+\ 'hash',
+\ 'author',
+\ 'relative date',
+\ 'comment')
+endfunction"}}}
+" }}}
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+" __END__
View
25 test/autoload/giti/test_stash.vim
@@ -32,17 +32,34 @@ function! s:tc.test_built_list()"{{{
\ 'comment' : 'eeee',
\ }])
call self.assert_match(
-\ 'stash list --date=relative --pretty=format:".\+"',
+\ 'stash list --pretty=format:".\+"',
\ b:system_called_with
\ )
call self.assert_throw('E118', 'call giti#stash#built_list("")')
endfunction"}}}
function! s:tc.test_show()"{{{
- call self.assert_equal(giti#stash#show({'stash' : 'hoge'}), 'mocked_system')
- call self.assert_equal('stash show hoge', b:system_called_with)
+ call self.assert_equal(
+\ giti#stash#show({'stash' : 'hoge', 'patch' : 1}),
+\ 'mocked_system'
+\ )
+ call self.assert_equal('stash show -p hoge', b:system_called_with)
+
+ call self.assert_equal(
+\ giti#stash#show({'patch' : 1}),
+\ 'mocked_system'
+\ )
+ call self.assert_equal('stash show -p ', b:system_called_with)
+
+ call self.assert_equal(
+\ giti#stash#show({'stash' : 'hoge'}),
+\ 'mocked_system'
+\ )
+ call self.assert_equal('stash show hoge', b:system_called_with)
+
call self.assert_equal(giti#stash#show({}), 'mocked_system')
- call self.assert_equal('stash show ', b:system_called_with)
+ call self.assert_equal('stash show ', b:system_called_with)
+
call self.assert_throw('E118', 'call giti#stash#show("", "")')
call self.assert_throw('E119', 'call giti#stash#show()')
endfunction"}}}

0 comments on commit a6016e8

Please sign in to comment.