File tree 6 files changed +117
-1
lines changed
6 files changed +117
-1
lines changed Original file line number Diff line number Diff line change
1
+ * .kpf
Original file line number Diff line number Diff line change 23
23
require 'git/status'
24
24
require 'git/author'
25
25
26
+ require 'git/stashes'
27
+ require 'git/stash'
28
+
26
29
require 'git/raw/repository'
27
30
28
31
Original file line number Diff line number Diff line change @@ -5,12 +5,15 @@ class Branch < Path
5
5
6
6
@base = nil
7
7
@gcommit = nil
8
+ @stashes = nil
8
9
9
10
def initialize ( base , name )
10
11
@remote = nil
11
12
@full = name
12
13
@base = base
13
14
15
+ @stashes = Git ::Stashes . new ( @base )
16
+
14
17
parts = name . split ( '/' )
15
18
if parts [ 1 ]
16
19
@remote = Git ::Remote . new ( @base , parts [ 0 ] )
@@ -25,6 +28,10 @@ def gcommit
25
28
@gcommit
26
29
end
27
30
31
+ def stashes
32
+ @stashes ||= Git ::Stashes . new ( @base )
33
+ end
34
+
28
35
def checkout
29
36
check_if_create
30
37
@base . checkout ( @full )
Original file line number Diff line number Diff line change @@ -401,8 +401,38 @@ def reset(commit, opts = {})
401
401
arr_opts << commit . to_s if commit
402
402
command ( 'reset' , arr_opts )
403
403
end
404
+
405
+ def stashes_all
406
+ arr = [ ]
407
+ filename = File . join ( @git_dir , 'logs/refs/stash' )
408
+ if File . exist? ( filename )
409
+ File . open ( filename ) . each_with_index { |line , i |
410
+ m = line . match ( /:(.*)$/ )
411
+ arr << [ i , m [ 1 ] . strip ]
412
+ }
413
+ end
414
+ arr
415
+ end
416
+
417
+ def stash_save ( message )
418
+ output = command ( 'stash save' , [ message ] )
419
+ return false unless output . match ( /HEAD is now at/ )
420
+ return true
421
+ end
404
422
405
-
423
+ def stash_apply ( id )
424
+ command ( 'stash apply' , [ id ] )
425
+ # Already uptodate! ---???? What then
426
+ end
427
+
428
+ def stash_clear
429
+ command ( 'stash clear' )
430
+ end
431
+
432
+ def stash_list
433
+ command ( 'stash list' )
434
+ end
435
+
406
436
def branch_new ( branch )
407
437
command ( 'branch' , branch )
408
438
end
Original file line number Diff line number Diff line change
1
+ module Git
2
+ class Stash
3
+ def initialize ( base , message , existing = false )
4
+ @base = base
5
+ @message = message
6
+ save if existing == false
7
+ end
8
+
9
+ def save
10
+ @saved = @base . lib . stash_save ( @message )
11
+ end
12
+
13
+ def saved?
14
+ @saved
15
+ end
16
+
17
+ def message
18
+ @message
19
+ end
20
+
21
+ def to_s
22
+ message
23
+ end
24
+
25
+ end
26
+ end
Original file line number Diff line number Diff line change
1
+ module Git
2
+
3
+ # object that holds all the available stashes
4
+ class Stashes
5
+ include Enumerable
6
+
7
+ @base = nil
8
+ @stashes = nil
9
+
10
+ def initialize ( base )
11
+ @stashes = [ ]
12
+
13
+ @base = base
14
+
15
+ @base . lib . stashes_all . each do |id , message |
16
+ @stashes . unshift ( Git ::Stash . new ( @base , message , true ) )
17
+ end
18
+ end
19
+
20
+ def save ( message )
21
+ s = Git ::Stash . new ( @base , message )
22
+ @stashes . unshift ( s ) if s . saved?
23
+ end
24
+
25
+ def apply ( index = 0 )
26
+ @base . lib . stash_apply ( index . to_i )
27
+ end
28
+
29
+ def clear
30
+ @base . lib . stash_clear
31
+ @stashes = [ ]
32
+ end
33
+
34
+ def size
35
+ @stashes . size
36
+ end
37
+
38
+ def each
39
+ @stashes . each do |s |
40
+ yield s
41
+ end
42
+ end
43
+
44
+ def []( symbol )
45
+ @stashes [ symbol . to_s ]
46
+ end
47
+
48
+ end
49
+ end
You can’t perform that action at this time.
0 commit comments