Skip to content
This repository
Browse code

Add stash source and kind

But some erro occured. why..
  • Loading branch information...
commit a6016e8c44d7307797c82a12ffbc7a54c1a74095 1 parent f149b08
MORIGAKI Junichi authored August 22, 2012
9  autoload/giti/stash.vim
@@ -16,7 +16,7 @@ endfunction"}}}
16 16
 
17 17
 function! giti#stash#built_list()"{{{
18 18
   return map(split(giti#system(
19  
-\   printf('stash list --date=relative --pretty=format:"%s"',
  19
+\   printf('stash list --pretty=format:"%s"',
20 20
 \          s:pretty_format)
21 21
 \ ), '\n'), '
22 22
 \   s:build_data(v:val)
@@ -25,7 +25,12 @@ endfunction"}}}
25 25
 
26 26
 function! giti#stash#show(param)"{{{
27 27
   let stash = has_key(a:param, 'stash') ? a:param.stash : ''
28  
-  return giti#system('stash show ' . stash)
  28
+  let patch = has_key(a:param, 'patch') ? a:param.patch : ''
  29
+  return giti#system(printf(
  30
+\   'stash show %s %s',
  31
+\   patch ? '-p' : '',
  32
+\   stash,
  33
+\ ))
29 34
 endfunction"}}}
30 35
 
31 36
 function! giti#stash#drop(param)"{{{
130  autoload/unite/kinds/giti/stash.vim
... ...
@@ -0,0 +1,130 @@
  1
+" File:    stash.vim
  2
+" Author:  kmnk <kmnknmk+vim@gmail.com>
  3
+" Version: 0.1.0
  4
+" License: 
  5
+
  6
+let s:save_cpo = &cpo
  7
+set cpo&vim
  8
+
  9
+function! unite#kinds#giti#stash#define()"{{{
  10
+  return s:kind
  11
+endfunction"}}}
  12
+
  13
+let s:kind = {
  14
+\ 'name' : 'giti/stash',
  15
+\ 'default_action' : 'show',
  16
+\ 'action_table' : {},
  17
+\ 'alias_table' : {},
  18
+\}
  19
+
  20
+let s:kind.action_table.view = {
  21
+\ 'description' : 'view information of this stash',
  22
+\ 'is_selectable' : 0,
  23
+\ 'is_quit' : 0,
  24
+\ 'is_invalidate_cache' : 0,
  25
+\ 'is_listed' : 1,
  26
+\}
  27
+function! s:kind.action_table.view.func(candidate)"{{{
  28
+  let data = a:candidate.action__data
  29
+  echo        'Hash:       ' . data.hash
  30
+  echo        'Stash:      ' . data.stash
  31
+  echo printf('Author:     %s <%s> - %s',
  32
+\       data.author.name, data.author.mail, data.author.date)
  33
+  echo printf('Committer:  %s <%s> - %s',
  34
+\       data.committer.name, data.committer.mail, data.committer.date)
  35
+  echo        'Comment:    ' . data.comment
  36
+endfunction"}}}
  37
+
  38
+let s:kind.action_table.show = {
  39
+\ 'description' : 'show stash',
  40
+\ 'is_selectable' : 0,
  41
+\ 'is_quit' : 0,
  42
+\ 'is_invalidate_cache' : 0,
  43
+\ 'is_listed' : 1,
  44
+\}
  45
+function! s:kind.action_table.show.func(candidate)"{{{
  46
+  let data = a:candidate.action__data
  47
+  echo giti#stash#show({'stash' : data.hash})
  48
+endfunction"}}}
  49
+
  50
+let s:kind.action_table.patch = {
  51
+\ 'description' : 'show stash patch',
  52
+\ 'is_selectable' : 0,
  53
+\ 'is_quit' : 1,
  54
+\ 'is_invalidate_cache' : 0,
  55
+\ 'is_listed' : 1,
  56
+\}
  57
+function! s:kind.action_table.patch.func(candidate)"{{{
  58
+  let data = a:candidate.action__data
  59
+  let patch = giti#stash#show({'stash' : data.hash, 'patch' : 1})
  60
+
  61
+  if !strlen(patch)
  62
+    echo 'no patch'
  63
+    return
  64
+  endif
  65
+
  66
+  call giti#new_buffer({
  67
+\   'method'   : giti#edit_command(),
  68
+\   'string'   : patch,
  69
+\   'filetype' : 'diff',
  70
+\   'buftype'  : 'nofile',
  71
+\ })
  72
+endfunction"}}}
  73
+let s:kind.alias_table.diff = 'patch'
  74
+let s:kind.alias_table.di = 'patch'
  75
+
  76
+let s:kind.action_table.drop = {
  77
+\ 'description' : 'drop this stash',
  78
+\ 'is_selectable' : 0,
  79
+\ 'is_quit' : 1,
  80
+\ 'is_invalidate_cache' : 0,
  81
+\ 'is_listed' : 1,
  82
+\}
  83
+function! s:kind.action_table.drop.func(candidate)"{{{
  84
+  let data = a:candidate.action__data
  85
+  echo giti#stash#drop({'stash' : data.hash})
  86
+endfunction"}}}
  87
+
  88
+let s:kind.action_table.pop = {
  89
+\ 'description' : 'pop this stash (apply and drop)',
  90
+\ 'is_selectable' : 0,
  91
+\ 'is_quit' : 1,
  92
+\ 'is_invalidate_cache' : 0,
  93
+\ 'is_listed' : 1,
  94
+\}
  95
+function! s:kind.action_table.pop.func(candidate)"{{{
  96
+  let data = a:candidate.action__data
  97
+  echo giti#stash#pop({'stash' : data.hash})
  98
+endfunction"}}}
  99
+
  100
+let s:kind.action_table.apply = {
  101
+\ 'description' : 'apply this stash',
  102
+\ 'is_selectable' : 0,
  103
+\ 'is_quit' : 1,
  104
+\ 'is_invalidate_cache' : 0,
  105
+\ 'is_listed' : 1,
  106
+\}
  107
+function! s:kind.action_table.apply.func(candidate)"{{{
  108
+  let data = a:candidate.action__data
  109
+  echo giti#stash#apply({'stash' : data.hash})
  110
+endfunction"}}}
  111
+
  112
+let s:kind.action_table.branch = {
  113
+\ 'description' : 'make new branch with this stash',
  114
+\ 'is_selectable' : 0,
  115
+\ 'is_quit' : 1,
  116
+\ 'is_invalidate_cache' : 0,
  117
+\ 'is_listed' : 1,
  118
+\}
  119
+function! s:kind.action_table.branch.func(candidate)"{{{
  120
+  let data = a:candidate.action__data
  121
+  let branchname = input('branch name: ')
  122
+  echo giti#stash#branch({'stash' : data.hash, 'branchname' : branchname})
  123
+endfunction"}}}
  124
+
  125
+" local functions {{{
  126
+" }}}
  127
+
  128
+let &cpo = s:save_cpo
  129
+unlet s:save_cpo
  130
+" __END__
49  autoload/unite/sources/giti/stash.vim
... ...
@@ -0,0 +1,49 @@
  1
+" File:    stash.vim
  2
+" Author:  kmnk <kmnknmk+vim@gmail.com>
  3
+" Version: 0.1.0
  4
+" License: 
  5
+
  6
+let s:save_cpo = &cpo
  7
+set cpo&vim
  8
+
  9
+function! unite#sources#giti#stash#define()"{{{
  10
+  return s:source
  11
+endfunction"}}}
  12
+
  13
+let s:source = {
  14
+\ 'name' : 'giti/stash',
  15
+\ 'description' : 'manage stash',
  16
+\}
  17
+
  18
+function! s:source.gather_candidates(args, context)"{{{
  19
+  call unite#print_message('[giti/stash]')
  20
+  return map(giti#stash#built_list(), '{
  21
+\   "word"   : s:build_word(v:val),
  22
+\   "source" : s:source.name,
  23
+\   "kind"   : s:source.name,
  24
+\   "action__data" : v:val,
  25
+\ }')
  26
+endfunction"}}}
  27
+
  28
+" local functions {{{
  29
+let s:word_format = '%s - %s, %s : %s'
  30
+function! s:build_word(val)"{{{
  31
+  return printf(s:word_format,
  32
+\   a:val.hash[0:6],
  33
+\   a:val.author.name,
  34
+\   a:val.author.date,
  35
+\   a:val.comment
  36
+\ )
  37
+endfunction"}}}
  38
+function! s:build_title()"{{{
  39
+  return printf(s:word_format,
  40
+\   'hash',
  41
+\   'author',
  42
+\   'relative date',
  43
+\   'comment')
  44
+endfunction"}}}
  45
+" }}}
  46
+
  47
+let &cpo = s:save_cpo
  48
+unlet s:save_cpo
  49
+" __END__
25  test/autoload/giti/test_stash.vim
@@ -32,17 +32,34 @@ function! s:tc.test_built_list()"{{{
32 32
 \   'comment'   : 'eeee',
33 33
 \ }])
34 34
   call self.assert_match(
35  
-\   'stash list --date=relative --pretty=format:".\+"',
  35
+\   'stash list --pretty=format:".\+"',
36 36
 \   b:system_called_with
37 37
 \ )
38 38
   call self.assert_throw('E118', 'call giti#stash#built_list("")')
39 39
 endfunction"}}}
40 40
 
41 41
 function! s:tc.test_show()"{{{
42  
-  call self.assert_equal(giti#stash#show({'stash' : 'hoge'}), 'mocked_system')
43  
-  call self.assert_equal('stash show hoge', b:system_called_with)
  42
+  call self.assert_equal(
  43
+\   giti#stash#show({'stash' : 'hoge', 'patch' : 1}),
  44
+\   'mocked_system'
  45
+\ )
  46
+  call self.assert_equal('stash show -p hoge', b:system_called_with)
  47
+
  48
+  call self.assert_equal(
  49
+\   giti#stash#show({'patch' : 1}),
  50
+\   'mocked_system'
  51
+\ )
  52
+  call self.assert_equal('stash show -p ', b:system_called_with)
  53
+
  54
+  call self.assert_equal(
  55
+\   giti#stash#show({'stash' : 'hoge'}),
  56
+\   'mocked_system'
  57
+\ )
  58
+  call self.assert_equal('stash show  hoge', b:system_called_with)
  59
+
44 60
   call self.assert_equal(giti#stash#show({}), 'mocked_system')
45  
-  call self.assert_equal('stash show ', b:system_called_with)
  61
+  call self.assert_equal('stash show  ', b:system_called_with)
  62
+
46 63
   call self.assert_throw('E118', 'call giti#stash#show("", "")')
47 64
   call self.assert_throw('E119', 'call giti#stash#show()')
48 65
 endfunction"}}}

0 notes on commit a6016e8

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