git_curate 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +2 -2
- data/README.md +3 -0
- data/VERSION +1 -1
- data/exe/git-curate +13 -2
- data/git_curate.gemspec +1 -1
- data/lib/git_curate/cli_parser.rb +51 -0
- data/lib/git_curate/copyright.rb +3 -0
- data/lib/git_curate/runner.rb +64 -28
- data/lib/git_curate/version.rb +1 -1
- data/lib/git_curate.rb +2 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e0dc2d94365f5f12a1edd47599205648467c18e110807e14a69ff08696e9093
|
4
|
+
data.tar.gz: 69bef635b1d5aae9064a03fff30ca6c81adbc3b0520d75287e96c46bf81f94b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 457a389f43af2378997956bb2b54aa373449b02338feab8bd067248d39cfbff3ffd57c816cd9628b4d0746084d1b9cf469e5dfcf166722fc245701507f485b67
|
7
|
+
data.tar.gz: d16c4cf11e11f9c16dd68d253f23bd4cfda983c564125fd4ff18f5298cce4e23e2c38007f5065de6b849ca85f26cdb57165edee17732b3ec41167823c6701de5
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -49,6 +49,9 @@ delete each branch in what should be a fairly self-explanatory fashion. Note the
|
|
49
49
|
you are currently on will not be included in the list, as `git` does not allow you to delete
|
50
50
|
the branch you're on.
|
51
51
|
|
52
|
+
If you just want to view the information about your local branches without stepping through
|
53
|
+
them interactively, enter `git branch --list` or `git branch -l`.
|
54
|
+
|
52
55
|
(Note the space after `git`—we have effectively added a subcommand to `git` just by installing
|
53
56
|
a gem. When `git_curate` is installed, an executable is created called `git-curate`.
|
54
57
|
In general, for any executable of the form _git-xyz_ in your `PATH`, `git` will automatically
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/exe/git-curate
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "git_curate"
|
4
|
+
require "optparse"
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
def main
|
7
|
+
parser = GitCurate::CLIParser.new
|
8
|
+
parser.parse(ARGV)
|
9
|
+
runner = GitCurate::Runner.new(parser.parsed_options)
|
10
|
+
runner.run
|
11
|
+
rescue OptionParser::InvalidOption
|
12
|
+
puts "Unrecognized option"
|
13
|
+
puts 'For help, enter `git curate -h`'
|
14
|
+
exit(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
main
|
data/git_curate.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_runtime_dependency "tabulo", "1.3.0"
|
33
33
|
spec.add_runtime_dependency "tty-screen", "0.6.5"
|
34
34
|
|
35
|
-
spec.add_development_dependency "bundler"
|
35
|
+
spec.add_development_dependency "bundler"
|
36
36
|
spec.add_development_dependency "rake", "~> 12.3"
|
37
37
|
spec.add_development_dependency "rake-version", "~> 1.0"
|
38
38
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module GitCurate
|
4
|
+
|
5
|
+
class CLIParser
|
6
|
+
|
7
|
+
attr_reader :parsed_options
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@parsed_options = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(options)
|
14
|
+
opt_parser = OptionParser.new do |opts|
|
15
|
+
opts.banner = <<-EOF
|
16
|
+
Usage: git curate [options]
|
17
|
+
|
18
|
+
Interactively step through the local branches of the current git repository, showing various
|
19
|
+
information and asking whether to keep or delete each branch.
|
20
|
+
|
21
|
+
In the default (interactive) mode, the current branch is excluded, as it cannot be deleted.
|
22
|
+
|
23
|
+
Note git-curate does not perform a "git fetch"; if you want to be sure the output reflects the current
|
24
|
+
state of any remotes, run "git fetch" first.
|
25
|
+
|
26
|
+
Options:
|
27
|
+
EOF
|
28
|
+
|
29
|
+
opts.on(
|
30
|
+
"-l",
|
31
|
+
"--list",
|
32
|
+
"Show summary of local branches, including current branch, without stepping through interactively"
|
33
|
+
) do
|
34
|
+
self.parsed_options[:list] = true
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-h", "Print this help message") do
|
38
|
+
puts opts
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on("-v", "--version", "Print the currently installed version of this program") do
|
43
|
+
puts "git curate v#{GitCurate::VERSION} #{GitCurate::COPYRIGHT}"
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
opt_parser.parse!(options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/git_curate/runner.rb
CHANGED
@@ -9,81 +9,117 @@ module GitCurate
|
|
9
9
|
BRANCH_NAME_REGEX = /\s+/
|
10
10
|
REMOTE_INFO_REGEX = /^[^\s]+\s+[^\s]+\s+\[(.+?)\]/
|
11
11
|
|
12
|
+
Branch = Struct.new("Branch", :raw, :proper, :displayable)
|
13
|
+
|
12
14
|
class Runner
|
13
15
|
|
16
|
+
def initialize(opts)
|
17
|
+
@opts = opts
|
18
|
+
end
|
19
|
+
|
14
20
|
def run
|
15
21
|
if ARGV.length != 0
|
16
22
|
puts "This script does not accept any arguments."
|
17
23
|
exit
|
18
24
|
end
|
19
25
|
|
20
|
-
branches = command_to_a("git branch").reject { |
|
26
|
+
branches = command_to_a("git branch").reject { |raw_branch| excluded_branch?(raw_branch) }.map do |raw_branch|
|
27
|
+
Struct::Branch.new(raw_branch, proper_branch(raw_branch), displayable_branch(raw_branch))
|
28
|
+
end
|
29
|
+
|
21
30
|
merged_branches = command_to_a("git branch --merged").to_set
|
22
31
|
upstream_branches = get_upstream_branches
|
23
32
|
|
24
33
|
table = Tabulo::Table.new(branches, vertical_rule_character: " ", intersection_character: " ",
|
25
34
|
horizontal_rule_character: "-", column_padding: 0, align_header: :left) do |t|
|
26
35
|
|
27
|
-
t.add_column(:branch, header: "Branch") { |branch| branch }
|
36
|
+
t.add_column(:branch, header: "Branch") { |branch| branch.displayable }
|
28
37
|
|
29
38
|
t.add_column("Last commit") do |branch|
|
30
|
-
`git log -n1 --date=short --format='format:%cd' #{branch}`
|
39
|
+
`git log -n1 --date=short --format='format:%cd' #{branch.proper}`
|
31
40
|
end
|
32
41
|
|
33
42
|
t.add_column("Last author") do |branch|
|
34
|
-
`git log -n1 --format='format:%an' #{branch}`
|
43
|
+
`git log -n1 --format='format:%an' #{branch.proper}`
|
35
44
|
end
|
36
45
|
|
37
46
|
t.add_column("Last subject") do |branch|
|
38
|
-
`git log -n1 --format='format:%s' #{branch}`
|
47
|
+
`git log -n1 --format='format:%s' #{branch.proper}`
|
39
48
|
end
|
40
49
|
|
41
50
|
t.add_column("Merged\ninto HEAD?") do |branch|
|
42
|
-
merged_branches.include?(branch) ? "Merged" : "Not merged"
|
51
|
+
merged_branches.include?(branch.proper) ? "Merged" : "Not merged"
|
43
52
|
end
|
44
53
|
|
45
54
|
t.add_column("Status vs\nupstream") do |branch|
|
46
|
-
upstream_branches.fetch(branch, "No upstream")
|
55
|
+
upstream_branches.fetch(branch.proper, "No upstream")
|
47
56
|
end
|
48
57
|
end
|
49
58
|
|
50
59
|
prompt = " Delete? [y/n/done/abort/help] "
|
51
60
|
longest_response = "abort"
|
52
|
-
prompt_and_response_width =
|
61
|
+
prompt_and_response_width =
|
62
|
+
if interactive?
|
63
|
+
prompt.length + longest_response.length + 1
|
64
|
+
else
|
65
|
+
0
|
66
|
+
end
|
53
67
|
table.pack(max_table_width: TTY::Screen.width - prompt_and_response_width)
|
54
68
|
|
55
69
|
branches_to_delete = []
|
56
70
|
|
57
71
|
table.each_with_index do |row, index|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
72
|
+
if interactive?
|
73
|
+
case HighLine.ask("#{row}#{prompt}")
|
74
|
+
when "y"
|
75
|
+
branches_to_delete << proper_branch(row.to_h[:branch])
|
76
|
+
when "n"
|
77
|
+
; # do nothing
|
78
|
+
when "done"
|
79
|
+
puts table.horizontal_rule
|
80
|
+
finalize(branches_to_delete)
|
81
|
+
exit
|
82
|
+
when "abort"
|
83
|
+
puts table.horizontal_rule
|
84
|
+
puts "\nAborting. No branches deleted."
|
85
|
+
exit
|
86
|
+
else
|
87
|
+
puts table.horizontal_rule
|
88
|
+
print_help
|
89
|
+
puts table.horizontal_rule unless index == 0
|
90
|
+
redo
|
91
|
+
end
|
71
92
|
else
|
72
|
-
puts
|
73
|
-
print_help
|
74
|
-
puts table.horizontal_rule unless index == 0
|
75
|
-
redo
|
93
|
+
puts row
|
76
94
|
end
|
77
95
|
end
|
78
96
|
puts table.horizontal_rule
|
79
97
|
|
80
|
-
finalize(branches_to_delete)
|
98
|
+
finalize(branches_to_delete) if interactive?
|
81
99
|
end
|
82
100
|
|
83
101
|
private
|
84
102
|
|
85
|
-
def
|
86
|
-
|
103
|
+
def interactive?
|
104
|
+
!@opts[:list]
|
105
|
+
end
|
106
|
+
|
107
|
+
def proper_branch(raw_branch)
|
108
|
+
raw_branch.lstrip.gsub(/^\*\s*/, '')
|
109
|
+
end
|
110
|
+
|
111
|
+
def displayable_branch(raw_branch)
|
112
|
+
return raw_branch if interactive?
|
113
|
+
|
114
|
+
current_branch?(raw_branch) ? raw_branch : " " + raw_branch
|
115
|
+
end
|
116
|
+
|
117
|
+
def excluded_branch?(raw_branch)
|
118
|
+
interactive? && current_branch?(raw_branch)
|
119
|
+
end
|
120
|
+
|
121
|
+
def current_branch?(raw_branch)
|
122
|
+
raw_branch =~ /^\s*\*/
|
87
123
|
end
|
88
124
|
|
89
125
|
# Returns a Hash containing, as keys, all local branches that have upstream branches,
|
data/lib/git_curate/version.rb
CHANGED
data/lib/git_curate.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_curate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Harvey
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +116,8 @@ files:
|
|
116
116
|
- exe/git-curate
|
117
117
|
- git_curate.gemspec
|
118
118
|
- lib/git_curate.rb
|
119
|
+
- lib/git_curate/cli_parser.rb
|
120
|
+
- lib/git_curate/copyright.rb
|
119
121
|
- lib/git_curate/runner.rb
|
120
122
|
- lib/git_curate/version.rb
|
121
123
|
homepage: https://github.com/matt-harvey/git_curate
|