git_curate 0.6.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +7 -0
- data/README.md +10 -3
- data/VERSION +1 -1
- data/assets/demo.gif +0 -0
- data/git_curate.gemspec +2 -0
- data/lib/git_curate.rb +1 -0
- data/lib/git_curate/branch.rb +51 -7
- data/lib/git_curate/runner.rb +30 -66
- data/lib/git_curate/util.rb +20 -0
- data/lib/git_curate/version.rb +1 -1
- metadata +34 -4
- data/Gemfile.lock +0 -47
- data/assets/demo2.gif +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f019dd79a60464f73b25ee00bcd5f0a5bb07f696fb873ce288d05b3aeacdcb4
|
4
|
+
data.tar.gz: b29735e0e19a7f3c1110d19bca33811dce1875f9b097d12fb64010a312d680dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 335169413223db9f953f974533e3255dc51b5a42abd970dcbbcc37d743bb0302053204f51cfed51ee1859c4f8bdd7f1e975937f3c4d9abef35ad72bf01fd92e8
|
7
|
+
data.tar.gz: b9a30efa63839e7bd84354dce75b8604b9af34ad6ab04c2b57363ce14dea9e42093080ff8cacf8701a6babd30ac5f2e76a225c14ce5303acd45dfba54ea74376
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### v0.7.0
|
4
|
+
|
5
|
+
* Show "no" option as capital "N", to hint that it's the default
|
6
|
+
* Get user input case-insensitively
|
7
|
+
* More unit tests
|
8
|
+
* Build status and coverage badges added to README
|
9
|
+
|
3
10
|
### v0.6.4
|
4
11
|
|
5
12
|
* Fix breakage on Ruby <= 2.3 due to unsupported Regex #match? method.
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# git curate
|
2
2
|
|
3
3
|
[![Gem Version][GV img]][Gem Version]
|
4
|
+
[![Build Status][BS img]][Build Status]
|
5
|
+
[![Coverage Status][CS img]][Coverage Status]
|
4
6
|
|
5
|
-
<img src="https://raw.githubusercontent.com/matt-harvey/git_curate/master/assets/
|
7
|
+
<img src="https://raw.githubusercontent.com/matt-harvey/git_curate/master/assets/demo.gif" width="1000" alt="Demo" />
|
6
8
|
|
7
9
|
## Motivation
|
8
10
|
|
@@ -68,7 +70,7 @@ Bug reports and pull requests are welcome on [GitHub](https://github.com/matt-ha
|
|
68
70
|
To start working on `git_curate`, `git clone` and `cd` into your fork of the repo, then run `bin/setup` to
|
69
71
|
install dependencies.
|
70
72
|
|
71
|
-
To run the test suite, run `rake spec`. For a list of other Rake tasks, run `rake -T`.
|
73
|
+
To run the test suite, run `bundle exec rake spec`. For a list of other Rake tasks, run `bundle exec rake -T`.
|
72
74
|
|
73
75
|
## License
|
74
76
|
|
@@ -76,4 +78,9 @@ The gem is available as open source under the terms of the [MIT
|
|
76
78
|
License](http://opensource.org/licenses/MIT).
|
77
79
|
|
78
80
|
[Gem Version]: https://rubygems.org/gems/git_curate
|
79
|
-
[
|
81
|
+
[Build Status]: https://travis-ci.org/matt-harvey/git_curate
|
82
|
+
[Coverage Status]: https://coveralls.io/github/matt-harvey/git_curate
|
83
|
+
|
84
|
+
[GV img]: https://img.shields.io/gem/v/git_curate.svg
|
85
|
+
[BS img]: https://img.shields.io/travis/matt-harvey/git_curate.svg
|
86
|
+
[CS img]: https://img.shields.io/coveralls/matt-harvey/git_curate.svg
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/assets/demo.gif
ADDED
Binary file
|
data/git_curate.gemspec
CHANGED
@@ -33,7 +33,9 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_runtime_dependency "tty-screen", "0.7.0"
|
34
34
|
|
35
35
|
spec.add_development_dependency "bundler"
|
36
|
+
spec.add_development_dependency "coveralls"
|
36
37
|
spec.add_development_dependency "rake", "~> 12.3"
|
37
38
|
spec.add_development_dependency "rake-version", "~> 1.0"
|
38
39
|
spec.add_development_dependency "rspec", "~> 3.0"
|
40
|
+
spec.add_development_dependency "simplecov"
|
39
41
|
end
|
data/lib/git_curate.rb
CHANGED
data/lib/git_curate/branch.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
require "open3"
|
2
|
-
|
3
1
|
module GitCurate
|
4
2
|
|
5
3
|
class Branch
|
6
4
|
|
5
|
+
# Regex for determining whether a "raw" branch name is the name of the current branch
|
6
|
+
CURRENT_BRANCH_REGEX = /^\*\s+/
|
7
|
+
|
8
|
+
# Regexes for unpacking the output of `git branch -vv`
|
9
|
+
BRANCH_NAME_REGEX = /\s+/
|
10
|
+
LEADING_STAR_REGEX = /^\* /
|
11
|
+
REMOTE_INFO_REGEX = /^[^\s]+\s+[^\s]+\s+\[(.+?)\]/
|
12
|
+
|
7
13
|
attr_reader :raw_name
|
8
14
|
|
9
15
|
# raw_name should start in "* " if the current branch, but should otherwise have not whitespace.
|
@@ -12,11 +18,11 @@ module GitCurate
|
|
12
18
|
end
|
13
19
|
|
14
20
|
def proper_name
|
15
|
-
@proper_name ||= @raw_name.lstrip.
|
21
|
+
@proper_name ||= @raw_name.lstrip.sub(CURRENT_BRANCH_REGEX, '')
|
16
22
|
end
|
17
23
|
|
18
24
|
def current?
|
19
|
-
@current ||= (
|
25
|
+
@current ||= (@raw_name =~ CURRENT_BRANCH_REGEX)
|
20
26
|
end
|
21
27
|
|
22
28
|
def displayable_name(pad:)
|
@@ -28,15 +34,53 @@ module GitCurate
|
|
28
34
|
end
|
29
35
|
|
30
36
|
def last_author
|
31
|
-
|
37
|
+
Util.command_output("git log -n1 --format=format:%an #{proper_name}")
|
32
38
|
end
|
33
39
|
|
34
40
|
def last_commit_date
|
35
|
-
|
41
|
+
Util.command_output("git log -n1 --date=short --format=format:%cd #{proper_name}")
|
36
42
|
end
|
37
43
|
|
38
44
|
def last_subject
|
39
|
-
|
45
|
+
Util.command_output("git log -n1 --format=format:%s #{proper_name}")
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the local branches
|
49
|
+
def self.local
|
50
|
+
command_to_branches("git branch")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns local branches that are merged into current HEAD
|
54
|
+
def self.local_merged
|
55
|
+
command_to_branches("git branch --merged")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns a Hash containing, as keys, the proper names of all local branches that have upstream branches,
|
59
|
+
# and, as values, a brief description of each branch's status relative to its upstream
|
60
|
+
# branch (up to date, or ahead/behind)
|
61
|
+
def self.upstream_info
|
62
|
+
Util.command_to_a("git branch -vv").map do |line|
|
63
|
+
line.gsub!(LEADING_STAR_REGEX, "")
|
64
|
+
branch_name = line.split(BRANCH_NAME_REGEX)[0]
|
65
|
+
remote_info = line[REMOTE_INFO_REGEX, 1]
|
66
|
+
if remote_info.nil?
|
67
|
+
nil
|
68
|
+
else
|
69
|
+
comparison_raw = remote_info.split(":")
|
70
|
+
comparison = if comparison_raw.length < 2
|
71
|
+
"Up to date"
|
72
|
+
else
|
73
|
+
comparison_raw[1].strip.capitalize
|
74
|
+
end
|
75
|
+
[branch_name, comparison]
|
76
|
+
end
|
77
|
+
end.compact.to_h
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def self.command_to_branches(command)
|
83
|
+
Util.command_to_a(command).map { |raw_branch_name| self.new(raw_branch_name) }
|
40
84
|
end
|
41
85
|
|
42
86
|
end
|
data/lib/git_curate/runner.rb
CHANGED
@@ -5,11 +5,6 @@ require "tty-screen"
|
|
5
5
|
|
6
6
|
module GitCurate
|
7
7
|
|
8
|
-
# Regexes for unpacking the output of `git branch -vv`
|
9
|
-
BRANCH_NAME_REGEX = /\s+/
|
10
|
-
LEADING_STAR_REGEX = /^\* /
|
11
|
-
REMOTE_INFO_REGEX = /^[^\s]+\s+[^\s]+\s+\[(.+?)\]/
|
12
|
-
|
13
8
|
class Runner
|
14
9
|
|
15
10
|
def initialize(opts)
|
@@ -22,10 +17,10 @@ module GitCurate
|
|
22
17
|
exit
|
23
18
|
end
|
24
19
|
|
25
|
-
branches =
|
20
|
+
branches = Branch.local
|
26
21
|
branches.reject!(&:current?) if interactive?
|
27
|
-
|
28
|
-
upstream_branches =
|
22
|
+
merged_branch_names = Branch.local_merged.map(&:proper_name).to_set
|
23
|
+
upstream_branches = Branch.upstream_info
|
29
24
|
|
30
25
|
table = Tabulo::Table.new(branches, vertical_rule_character: " ", intersection_character: " ",
|
31
26
|
horizontal_rule_character: "-", column_padding: 0, align_header: :left) do |t|
|
@@ -34,50 +29,47 @@ module GitCurate
|
|
34
29
|
t.add_column("Last commit", &:last_commit_date)
|
35
30
|
t.add_column("Last author", &:last_author)
|
36
31
|
t.add_column("Last subject", &:last_subject)
|
37
|
-
t.add_column("Merged#{$/}into HEAD?") { |b|
|
32
|
+
t.add_column("Merged#{$/}into HEAD?") { |b| merged_branch_names.include?(b.proper_name) ? "Merged" : "Not merged" }
|
38
33
|
t.add_column("Status vs#{$/}upstream") { |b| upstream_branches.fetch(b.proper_name, "No upstream") }
|
39
34
|
end
|
40
35
|
|
41
|
-
prompt = " Delete? [y/
|
36
|
+
prompt = " Delete? [y/N/done/abort/help] "
|
42
37
|
longest_response = "abort"
|
43
|
-
prompt_and_response_width =
|
44
|
-
if interactive?
|
45
|
-
prompt.length + longest_response.length + 1
|
46
|
-
else
|
47
|
-
0
|
48
|
-
end
|
38
|
+
prompt_and_response_width = (interactive? ? (prompt.length + longest_response.length + 1) : 0)
|
49
39
|
table.pack(max_table_width: TTY::Screen.width - prompt_and_response_width)
|
50
40
|
|
51
41
|
branches_to_delete = []
|
52
42
|
|
43
|
+
if !interactive?
|
44
|
+
puts table
|
45
|
+
puts table.horizontal_rule
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
53
49
|
table.each_with_index do |row, index|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
exit
|
68
|
-
else
|
69
|
-
puts table.horizontal_rule
|
70
|
-
print_help
|
71
|
-
puts table.horizontal_rule unless index == 0
|
72
|
-
redo
|
73
|
-
end
|
50
|
+
case HighLine.ask("#{row}#{prompt}").downcase
|
51
|
+
when "y"
|
52
|
+
branches_to_delete << row.source.proper_name
|
53
|
+
when "n", ""
|
54
|
+
; # do nothing
|
55
|
+
when "done"
|
56
|
+
puts table.horizontal_rule
|
57
|
+
finalize(branches_to_delete)
|
58
|
+
exit
|
59
|
+
when "abort"
|
60
|
+
puts table.horizontal_rule
|
61
|
+
puts "#{$/}Aborting. No branches deleted."
|
62
|
+
exit
|
74
63
|
else
|
75
|
-
puts
|
64
|
+
puts table.horizontal_rule
|
65
|
+
print_help
|
66
|
+
puts table.horizontal_rule unless index == 0
|
67
|
+
redo
|
76
68
|
end
|
77
69
|
end
|
78
70
|
puts table.horizontal_rule
|
79
71
|
|
80
|
-
finalize(branches_to_delete)
|
72
|
+
finalize(branches_to_delete)
|
81
73
|
end
|
82
74
|
|
83
75
|
private
|
@@ -86,28 +78,6 @@ module GitCurate
|
|
86
78
|
!@opts[:list]
|
87
79
|
end
|
88
80
|
|
89
|
-
# Returns a Hash containing, as keys, all local branches that have upstream branches,
|
90
|
-
# and, as values, a brief description of each branch's status relative to its upstream
|
91
|
-
# branch (up to date, or ahead/behind)
|
92
|
-
def get_upstream_branches
|
93
|
-
command_to_a("git branch -vv").map do |line|
|
94
|
-
line.gsub!(LEADING_STAR_REGEX, "")
|
95
|
-
branch_name = line.split(BRANCH_NAME_REGEX)[0]
|
96
|
-
remote_info = line[REMOTE_INFO_REGEX, 1]
|
97
|
-
if remote_info.nil?
|
98
|
-
nil
|
99
|
-
else
|
100
|
-
comparison_raw = remote_info.split(":")
|
101
|
-
comparison = if comparison_raw.length < 2
|
102
|
-
"Up to date"
|
103
|
-
else
|
104
|
-
comparison_raw[1].strip.capitalize
|
105
|
-
end
|
106
|
-
[branch_name, comparison]
|
107
|
-
end
|
108
|
-
end.compact.to_h
|
109
|
-
end
|
110
|
-
|
111
81
|
def finalize(branches_to_delete)
|
112
82
|
if branches_to_delete.size != 0
|
113
83
|
puts
|
@@ -130,12 +100,6 @@ module GitCurate
|
|
130
100
|
EOL
|
131
101
|
end
|
132
102
|
|
133
|
-
# Runs the passed string command as a system command, gathers any lines of output, stripped of
|
134
|
-
# leading and trailing whitespace, and returns them as an array.
|
135
|
-
def command_to_a(command)
|
136
|
-
`#{command}`.split($/).map(&:strip)
|
137
|
-
end
|
138
|
-
|
139
103
|
end
|
140
104
|
|
141
105
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "open3"
|
2
|
+
|
3
|
+
module GitCurate
|
4
|
+
|
5
|
+
module Util
|
6
|
+
|
7
|
+
# Runs the passed string as a system command, gathers any lines of output, stripped of
|
8
|
+
# leading and trailing whitespace, and returns them as an array.
|
9
|
+
def self.command_to_a(command)
|
10
|
+
command_output(command).split($/).map(&:strip)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Runs the passed string as a system command and returns its output.
|
14
|
+
def self.command_output(command)
|
15
|
+
Open3.capture2(command).first
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/git_curate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_curate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Harvey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,20 @@ dependencies:
|
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '3.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description: Step through local git branches from the command line, keeping or deleting
|
112
140
|
each.
|
113
141
|
email:
|
@@ -118,14 +146,15 @@ extensions: []
|
|
118
146
|
extra_rdoc_files: []
|
119
147
|
files:
|
120
148
|
- ".gitignore"
|
149
|
+
- ".rspec"
|
150
|
+
- ".travis.yml"
|
121
151
|
- CHANGELOG.md
|
122
152
|
- Gemfile
|
123
|
-
- Gemfile.lock
|
124
153
|
- LICENSE.txt
|
125
154
|
- README.md
|
126
155
|
- Rakefile
|
127
156
|
- VERSION
|
128
|
-
- assets/
|
157
|
+
- assets/demo.gif
|
129
158
|
- bin/setup
|
130
159
|
- exe/git-curate
|
131
160
|
- git_curate.gemspec
|
@@ -134,6 +163,7 @@ files:
|
|
134
163
|
- lib/git_curate/cli_parser.rb
|
135
164
|
- lib/git_curate/copyright.rb
|
136
165
|
- lib/git_curate/runner.rb
|
166
|
+
- lib/git_curate/util.rb
|
137
167
|
- lib/git_curate/version.rb
|
138
168
|
homepage: https://github.com/matt-harvey/git_curate
|
139
169
|
licenses:
|
data/Gemfile.lock
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
git_curate (0.6.4)
|
5
|
-
highline (= 2.0.2)
|
6
|
-
tabulo (= 1.5.1)
|
7
|
-
tty-screen (= 0.7.0)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
diff-lcs (1.3)
|
13
|
-
highline (2.0.2)
|
14
|
-
rake (12.3.2)
|
15
|
-
rake-version (1.0.1)
|
16
|
-
rake (> 11.1)
|
17
|
-
rspec (3.8.0)
|
18
|
-
rspec-core (~> 3.8.0)
|
19
|
-
rspec-expectations (~> 3.8.0)
|
20
|
-
rspec-mocks (~> 3.8.0)
|
21
|
-
rspec-core (3.8.2)
|
22
|
-
rspec-support (~> 3.8.0)
|
23
|
-
rspec-expectations (3.8.4)
|
24
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.8.0)
|
26
|
-
rspec-mocks (3.8.1)
|
27
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.8.0)
|
29
|
-
rspec-support (3.8.2)
|
30
|
-
tabulo (1.5.1)
|
31
|
-
tty-screen (= 0.7.0)
|
32
|
-
unicode-display_width (= 1.6.0)
|
33
|
-
tty-screen (0.7.0)
|
34
|
-
unicode-display_width (1.6.0)
|
35
|
-
|
36
|
-
PLATFORMS
|
37
|
-
ruby
|
38
|
-
|
39
|
-
DEPENDENCIES
|
40
|
-
bundler
|
41
|
-
git_curate!
|
42
|
-
rake (~> 12.3)
|
43
|
-
rake-version (~> 1.0)
|
44
|
-
rspec (~> 3.0)
|
45
|
-
|
46
|
-
BUNDLED WITH
|
47
|
-
2.0.1
|
data/assets/demo2.gif
DELETED
Binary file
|