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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86c5c32d0a3880b82437ad8aa22e6342f972ac313e05645c3b1d1def149351d2
4
- data.tar.gz: 8c3f10c1fa4728c7136ea165dbd7afd3fc785e8663716163a5ba4c8c6905c31d
3
+ metadata.gz: 4e0dc2d94365f5f12a1edd47599205648467c18e110807e14a69ff08696e9093
4
+ data.tar.gz: 69bef635b1d5aae9064a03fff30ca6c81adbc3b0520d75287e96c46bf81f94b1
5
5
  SHA512:
6
- metadata.gz: 5ed0fe98091032d3cf9cbd4e444d663a3ae8fa15730273e506d8e5f133df93a532f13b4328e0bf339b7a086fabf88c32bf1fd3bc490f3e5d1c7f437408a1280d
7
- data.tar.gz: 04fb50b7df2fcd455ed99985bde668bd4b15b5d547c98c5d4913c139cab32fed9e44e389f59eb0f04937278706641614282984217aaca1ac721324548cde6778
6
+ metadata.gz: 457a389f43af2378997956bb2b54aa373449b02338feab8bd067248d39cfbff3ffd57c816cd9628b4d0746084d1b9cf469e5dfcf166722fc245701507f485b67
7
+ data.tar.gz: d16c4cf11e11f9c16dd68d253f23bd4cfda983c564125fd4ff18f5298cce4e23e2c38007f5065de6b849ca85f26cdb57165edee17732b3ec41167823c6701de5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.5.0
4
+
5
+ * Add `-l` option to output branch information non-interactively
6
+ * Add help output (`-h` option)
7
+
3
8
  ### v0.4.3
4
9
 
5
10
  * Upgrade dependency versions
data/Gemfile.lock CHANGED
@@ -21,10 +21,10 @@ PLATFORMS
21
21
  ruby
22
22
 
23
23
  DEPENDENCIES
24
- bundler (~> 1.16)
24
+ bundler
25
25
  git_curate!
26
26
  rake (~> 12.3)
27
27
  rake-version (~> 1.0)
28
28
 
29
29
  BUNDLED WITH
30
- 1.16.6
30
+ 2.0.1
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.4.3
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
- runner = GitCurate::Runner.new
6
- runner.run
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", "~> 1.16"
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
@@ -0,0 +1,3 @@
1
+ module GitCurate
2
+ COPYRIGHT = "(c) 2019 Matthew Harvey"
3
+ end
@@ -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 { |b| current_branch?(b) }
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 = prompt.length + longest_response.length + 1
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
- case HighLine.ask("#{row}#{prompt}")
59
- when "y"
60
- branches_to_delete << row.to_h[:branch]
61
- when "n"
62
- ; # do nothing
63
- when "done"
64
- puts table.horizontal_rule
65
- finalize(branches_to_delete)
66
- exit
67
- when "abort"
68
- puts table.horizontal_rule
69
- puts "\nAborting. No branches deleted."
70
- exit
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 table.horizontal_rule
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 current_branch?(branch)
86
- branch =~ /^\s*\*/
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,
@@ -1,3 +1,3 @@
1
1
  module GitCurate
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/git_curate.rb CHANGED
@@ -1,2 +1,4 @@
1
+ require "git_curate/cli_parser"
2
+ require "git_curate/copyright"
1
3
  require "git_curate/runner"
2
4
  require "git_curate/version"
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.3
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: '1.16'
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: '1.16'
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