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.
- checksums.yaml +4 -4
- data/lib/git-dd.rb +41 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 195328aea93732112ec5983e715276cbeb0935c6
|
4
|
+
data.tar.gz: 2966d39bef25e8662fc79b558655c3a526c9f35d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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 !=
|
27
|
+
return if branch_names.size != branches_vv.size
|
25
28
|
|
26
|
-
|
27
|
-
branch_names.each_with_index { |b, i|
|
29
|
+
branches_for_select = {}
|
30
|
+
branch_names.each_with_index { |b, i| branches_for_select[b] = branches_vv[i] }
|
28
31
|
|
29
|
-
if
|
32
|
+
if branches_for_select.size == 1
|
30
33
|
return print(ONLY_ONE_BRANCH)
|
31
34
|
end
|
32
35
|
|
33
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2017-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-prompt
|