git-dd 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/git-dd +21 -1
- data/lib/git-dd.rb +72 -50
- data/lib/git-dd/const.rb +5 -0
- data/lib/git-dd/version.rb +3 -0
- metadata +24 -9
- data/lib/const.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5115a3ac2184af4b5c7b5da6918b945649bc968c
|
4
|
+
data.tar.gz: d38a39047fbd1d13eda7692e420b6a760201f137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3043e7132eb2d38aec46a3fede7905365ec33b45e81bc79ced688061ea8a3bf2f285fbeb0a121bd32abedb7dd88d8b5623255e7d6df051bfa6a7bfff7c41edb
|
7
|
+
data.tar.gz: 6966dd36a6793924dbd97ec28c052f20f3a35aa8c0747c1656ebb8bca706987e7941bb80e3f7f50aff7676dafabc513f03ff53fb3f1742fc31eb96aebbfac695
|
data/bin/git-dd
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'git-dd'
|
4
|
+
require 'git-dd/version'
|
5
|
+
require 'slop'
|
4
6
|
|
5
|
-
|
7
|
+
opts = Slop::Options.new
|
8
|
+
opts.banner = "usage: git dd [options] ..."
|
9
|
+
opts.null '[no options]', 'select branches to delete'
|
10
|
+
opts.bool '-m', '--merged', 'delete branches have been merged into current branch'
|
11
|
+
opts.bool '-v', '--version', 'print the version'
|
12
|
+
opts.bool '-h', '--help', 'print help'
|
13
|
+
|
14
|
+
parser = Slop::Parser.new(opts)
|
15
|
+
result = parser.parse(ARGV).to_hash
|
16
|
+
|
17
|
+
if result[:version]
|
18
|
+
puts GitDD::VERSION
|
19
|
+
elsif result[:merged]
|
20
|
+
GitDD.new.delete_merged_branches
|
21
|
+
elsif result[:help]
|
22
|
+
puts opts
|
23
|
+
else
|
24
|
+
GitDD.new.select_branches_to_delete
|
25
|
+
end
|
data/lib/git-dd.rb
CHANGED
@@ -2,76 +2,57 @@
|
|
2
2
|
|
3
3
|
require 'tty-prompt'
|
4
4
|
require 'rainbow/ext/string'
|
5
|
-
|
5
|
+
require_relative './git-dd/const.rb'
|
6
6
|
|
7
7
|
class GitDD
|
8
8
|
attr_accessor :prompt
|
9
9
|
MERGED = "merged"
|
10
10
|
UNMERGE = "unmerge"
|
11
|
+
DETACHED = "* (HEAD detached at"
|
11
12
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
13
|
+
def initialize(test_prompt = nil)
|
14
|
+
if test_prompt
|
15
|
+
@prompt = test_prompt
|
16
|
+
else
|
17
|
+
@prompt = TTY::Prompt.new(interrupt: :exit)
|
18
|
+
end
|
15
19
|
|
16
|
-
|
20
|
+
@prompt.on(:keypress) { |event| exit 1 if event.value == 'q' }
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
str = `git branch -vv`
|
21
|
-
str.split("\n")
|
22
|
-
rescue
|
23
|
-
str = `git branch`
|
24
|
-
str.split("\n")
|
25
|
-
end
|
23
|
+
def delete_merged_branches()
|
24
|
+
return print(NO_MERGED_BRANCH) if merged_branches.size == 0
|
26
25
|
|
27
|
-
|
26
|
+
puts "Branches have been merged into: #{current_branch.color(:green)}"
|
28
27
|
|
29
|
-
branches_for_select
|
30
|
-
branch_names.each_with_index { |b, i| branches_for_select[b] = branches_vv[i] }
|
28
|
+
merged_branches.each { |b| puts " "*4 + branches_for_select[b] }
|
31
29
|
|
32
|
-
|
33
|
-
return print(ONLY_ONE_BRANCH)
|
34
|
-
end
|
30
|
+
ensure_delete = !prompt.no?('Are you sure?')
|
35
31
|
|
36
|
-
|
32
|
+
merged_branches.each { |b| delete(b) } if ensure_delete
|
37
33
|
|
38
|
-
|
34
|
+
return merged_branches
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
prompt = TTY::Prompt.new(interrupt: :exit)
|
44
|
-
end
|
45
|
-
prompt.on(:keypress) { |event| return if event.value == 'q' }
|
37
|
+
def select_branches_to_delete()
|
38
|
+
return if branches.size != branches_vv.size
|
39
|
+
return print(ONLY_ONE_BRANCH) if branches_for_select.size == 0
|
46
40
|
|
47
|
-
|
48
|
-
branches_for_select[k] =
|
49
|
-
if merged?(k)
|
50
|
-
MERGED.color(:green) + " " + v
|
51
|
-
else
|
52
|
-
UNMERGE.color(:red) + v
|
53
|
-
end
|
54
|
-
end
|
41
|
+
puts "Current branch is: #{current_branch.color(:green)}"
|
55
42
|
|
56
|
-
|
43
|
+
prompt_options = { per_page: 20, help: '', echo: false }
|
44
|
+
prompt_help = "Choose branches to delete:"
|
45
|
+
branches_to_delete = @prompt.multi_select(prompt_help, prompt_options) do |menu|
|
57
46
|
branches_for_select.each { |k, v| menu.choice(v, k) }
|
58
47
|
end
|
59
48
|
|
60
|
-
if branches_to_delete.size == 0
|
61
|
-
return print(NO_BRANCH_SELECTED)
|
62
|
-
end
|
49
|
+
return print(NO_BRANCH_SELECTED) if branches_to_delete.size == 0
|
63
50
|
|
64
|
-
branches_to_delete.each
|
65
|
-
puts " "*4 + branches_for_select[b]
|
66
|
-
end
|
51
|
+
branches_to_delete.each { |b| puts " "*4 + branches_for_select[b] }
|
67
52
|
|
68
53
|
ensure_delete = !prompt.no?('Are you sure?')
|
69
54
|
|
70
|
-
if ensure_delete
|
71
|
-
branches_to_delete.each do |b|
|
72
|
-
puts `git branch -D #{b}`.chomp.color(:yellow)
|
73
|
-
end
|
74
|
-
end
|
55
|
+
branches_to_delete.each { |b| delete(b) } if ensure_delete
|
75
56
|
|
76
57
|
return branches_to_delete
|
77
58
|
end
|
@@ -86,7 +67,7 @@ class GitDD
|
|
86
67
|
@current_branch ||= `git rev-parse --abbrev-ref HEAD`.chomp
|
87
68
|
end
|
88
69
|
|
89
|
-
def
|
70
|
+
def merged_branches
|
90
71
|
return @merged_branches if @merged_branches
|
91
72
|
|
92
73
|
@merged_branches = `git branch --merged`
|
@@ -95,12 +76,53 @@ class GitDD
|
|
95
76
|
@merged_branches = @merged_branches.select { |b| b != current_branch_with_mark }
|
96
77
|
end
|
97
78
|
|
98
|
-
def
|
99
|
-
|
79
|
+
def branches
|
80
|
+
return @branches if @branches
|
81
|
+
|
82
|
+
@branches = `git branch`
|
83
|
+
@branches = @branches.split("\n")
|
84
|
+
end
|
85
|
+
|
86
|
+
def branches_vv
|
87
|
+
@branches_vv ||=
|
88
|
+
begin
|
89
|
+
str = `git branch -vv`
|
90
|
+
str.split("\n")
|
91
|
+
rescue
|
92
|
+
str = `git branch`
|
93
|
+
str.split("\n")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def branches_for_select
|
98
|
+
return @branches_for_select if @branches_for_select
|
99
|
+
|
100
|
+
@branches_for_select = {}
|
101
|
+
branches.each_with_index { |b, i| @branches_for_select[b] = branches_vv[i] }
|
102
|
+
|
103
|
+
@branches_for_select = @branches_for_select.select \
|
104
|
+
{ |k, v| k != current_branch_with_mark && !k.include?(DETACHED) }
|
105
|
+
|
106
|
+
@branches_for_select.each do |k, v|
|
107
|
+
@branches_for_select[k] =
|
108
|
+
if merged?(k)
|
109
|
+
MERGED.color(:green) + " " + v
|
110
|
+
else
|
111
|
+
UNMERGE.color(:red) + v
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def merged?(branch)
|
117
|
+
merged_branches.include? branch
|
100
118
|
end
|
101
119
|
|
102
120
|
def print(return_message)
|
103
121
|
puts return_message
|
104
122
|
return_message
|
105
123
|
end
|
124
|
+
|
125
|
+
def delete(branch)
|
126
|
+
puts `git branch -D #{branch}`.chomp.color(:yellow)
|
127
|
+
end
|
106
128
|
end
|
data/lib/git-dd/const.rb
ADDED
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.4.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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-prompt
|
@@ -28,16 +28,30 @@ dependencies:
|
|
28
28
|
name: rainbow
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: slop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.5'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,14 +70,14 @@ dependencies:
|
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
description:
|
@@ -74,8 +88,9 @@ extensions: []
|
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
90
|
- bin/git-dd
|
77
|
-
- lib/const.rb
|
78
91
|
- lib/git-dd.rb
|
92
|
+
- lib/git-dd/const.rb
|
93
|
+
- lib/git-dd/version.rb
|
79
94
|
homepage: https://github.com/Sanster/git-dd
|
80
95
|
licenses:
|
81
96
|
- MIT
|
data/lib/const.rb
DELETED