git-dd 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/git-dd.rb +41 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97dc4a649420571ccf91bc81296d361f7d5cf391
4
- data.tar.gz: aa5ab72e486ce86dc61918d3eb3971c0c910527c
3
+ metadata.gz: 195328aea93732112ec5983e715276cbeb0935c6
4
+ data.tar.gz: 2966d39bef25e8662fc79b558655c3a526c9f35d
5
5
  SHA512:
6
- metadata.gz: 9dd51a8d265e0649b8d01f5ce17ce0b88a69436dbfda4bb984a59266eb07f0c3e434d8ae07c9128d4e626aa22d581d61ae48e79eb8ccbcbada90f6418d8df69f
7
- data.tar.gz: b65485880763ff0e485e964a93c47ff307c6cddf6c7d36e9e8e12b789fb2c5c7b3bd8b396e7541ab4d0911e97950a795e0faddc66da23f130912e0b77ca9bfda
6
+ metadata.gz: 29f6c41b4eed286729fa726edfd4d15947132cee51caddfe8b5e02316f86805060f9096824ce895eb0ae4e9fd94303200d4456dcc9ad70bdc6fa5bc419cc1d9c
7
+ data.tar.gz: 780bf3989ebca32acdc24e43e9859099e31b5594192a7d4ff113c593fd74d7b9bbb2b365bdddfb0da9aa65fe3cc13e6633e122d8dacca4d0eac8cd13cc7a43a2
data/lib/git-dd.rb CHANGED
@@ -6,6 +6,8 @@ require 'const.rb'
6
6
 
7
7
  class GitDD
8
8
  attr_accessor :prompt
9
+ MERGED = "merged"
10
+ UNMERGE = "unmerge"
9
11
 
10
12
  def run(test_prompt = nil)
11
13
  branch_names = `git branch`
@@ -13,24 +15,25 @@ class GitDD
13
15
 
14
16
  branch_names = branch_names.split("\n")
15
17
 
16
- branches_with_more_info = `git branch -vv`
17
- begin
18
- branches_with_more_info = branches_with_more_info.split("\n")
19
- rescue
20
- branches_with_more_info = `git branch`
21
- branches_with_more_info = branches_with_more_info.split("\n")
22
- end
18
+ branches_vv =
19
+ begin
20
+ str = `git branch -vv`
21
+ str.split("\n")
22
+ rescue
23
+ str = `git branch`
24
+ str.split("\n")
25
+ end
23
26
 
24
- return if branch_names.size != branches_with_more_info.size
27
+ return if branch_names.size != branches_vv.size
25
28
 
26
- branches = {}
27
- branch_names.each_with_index { |b, i| branches[b] = branches_with_more_info[i] }
29
+ branches_for_select = {}
30
+ branch_names.each_with_index { |b, i| branches_for_select[b] = branches_vv[i] }
28
31
 
29
- if branches.size == 1
32
+ if branches_for_select.size == 1
30
33
  return print(ONLY_ONE_BRANCH)
31
34
  end
32
35
 
33
- branches = branches.select { |k, v| k != current_branch_with_mark && !k.include?("* (HEAD detached at") }
36
+ branches_for_select = branches_for_select.select { |k, v| k != current_branch_with_mark && !k.include?("* (HEAD detached at") }
34
37
 
35
38
  puts "Current branch is: #{current_branch.color(:green)}"
36
39
 
@@ -39,22 +42,28 @@ class GitDD
39
42
  else
40
43
  prompt = TTY::Prompt.new(interrupt: :exit)
41
44
  end
42
-
43
- prompt.on(:keypress) do |event|
44
- if event.value == 'q'
45
- return
46
- end
45
+ prompt.on(:keypress) { |event| return if event.value == 'q' }
46
+
47
+ branches_for_select.each do |k, v|
48
+ branches_for_select[k] =
49
+ if merged?(k)
50
+ MERGED.color(:green) + " " + v
51
+ else
52
+ UNMERGE.color(:red) + v
53
+ end
47
54
  end
48
55
 
49
56
  branches_to_delete = prompt.multi_select("Choose branches to delete:", per_page: 20, help: '',echo: false) do |menu|
50
- branches.each { |k, v| menu.choice v, k}
57
+ branches_for_select.each { |k, v| menu.choice(v, k) }
51
58
  end
52
59
 
53
60
  if branches_to_delete.size == 0
54
61
  return print(NO_BRANCH_SELECTED)
55
62
  end
56
63
 
57
- branches_to_delete.each { |b| puts b.color(:red) }
64
+ branches_to_delete.each do |b|
65
+ puts " "*4 + branches_for_select[b]
66
+ end
58
67
 
59
68
  ensure_delete = !prompt.no?('Are you sure?')
60
69
 
@@ -77,6 +86,19 @@ class GitDD
77
86
  @current_branch ||= `git rev-parse --abbrev-ref HEAD`.chomp
78
87
  end
79
88
 
89
+ def merged_branch_names
90
+ return @merged_branches if @merged_branches
91
+
92
+ @merged_branches = `git branch --merged`
93
+ @merged_branches = @merged_branches.split("\n")
94
+
95
+ @merged_branches = @merged_branches.select { |b| b != current_branch_with_mark }
96
+ end
97
+
98
+ def merged?(branch_name)
99
+ merged_branch_names.include? branch_name
100
+ end
101
+
80
102
  def print(return_message)
81
103
  puts return_message
82
104
  return_message
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-dd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weiqing Chu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-19 00:00:00.000000000 Z
11
+ date: 2017-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-prompt