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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 104be2a4415dd003c7c407d28ffcabb1eda79e0f8276e7be30aa5387592fe0ef
4
- data.tar.gz: 2636466a92daeda271e41ebd4b10003f10703f792f1b41c0f5757089ed7aa932
3
+ metadata.gz: 7f019dd79a60464f73b25ee00bcd5f0a5bb07f696fb873ce288d05b3aeacdcb4
4
+ data.tar.gz: b29735e0e19a7f3c1110d19bca33811dce1875f9b097d12fb64010a312d680dc
5
5
  SHA512:
6
- metadata.gz: 4cf19b5538b1a996c29e260e7d576e9f12dade39bc506c008946aaec2ef4f2042fe2b4f85b7c66fe1c87c9db5d1c69815ded3e38496226bfc5f6354ef62ae07b
7
- data.tar.gz: 0521c60590d20e6fd36aecc5b8759a38c7d30077043e1b64d33cab6d8d200fb179af6091a52c24be8a63352af82128bbef0d7a317ff5b96ad9e74a1f579280aa
6
+ metadata.gz: 335169413223db9f953f974533e3255dc51b5a42abd970dcbbcc37d743bb0302053204f51cfed51ee1859c4f8bdd7f1e975937f3c4d9abef35ad72bf01fd92e8
7
+ data.tar.gz: b9a30efa63839e7bd84354dce75b8604b9af34ad6ab04c2b57363ce14dea9e42093080ff8cacf8701a6babd30ac5f2e76a225c14ce5303acd45dfba54ea74376
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /_yardoc/
4
+ /Gemfile.lock
4
5
  /coverage/
5
6
  /doc/
6
7
  /pkg/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.10
5
+ - 2.2.10
6
+ - 2.3.8
7
+ - 2.4.6
8
+ - 2.5.5
9
+ - 2.6.3
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/demo2.gif" width="1000" alt="Demo" />
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
- [GV img]: https://img.shields.io/gem/v/git_curate.svg?style=plastic
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.6.4
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
@@ -2,4 +2,5 @@ require "git_curate/branch"
2
2
  require "git_curate/cli_parser"
3
3
  require "git_curate/copyright"
4
4
  require "git_curate/runner"
5
+ require "git_curate/util"
5
6
  require "git_curate/version"
@@ -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.gsub(/^\*\s+/, '')
21
+ @proper_name ||= @raw_name.lstrip.sub(CURRENT_BRANCH_REGEX, '')
16
22
  end
17
23
 
18
24
  def current?
19
- @current ||= (/^\*\s+/ =~ @raw_name)
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
- Open3.capture2("git log -n1 --format=format:%an #{proper_name}").first
37
+ Util.command_output("git log -n1 --format=format:%an #{proper_name}")
32
38
  end
33
39
 
34
40
  def last_commit_date
35
- Open3.capture2("git log -n1 --date=short --format=format:%cd #{proper_name}").first
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
- Open3.capture2("git log -n1 --format=format:%s #{proper_name}").first
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
@@ -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 = command_to_a("git branch").map { |b| Branch.new(b) }
20
+ branches = Branch.local
26
21
  branches.reject!(&:current?) if interactive?
27
- merged_branches = command_to_a("git branch --merged").to_set
28
- upstream_branches = get_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| merged_branches.include?(b.proper_name) ? "Merged" : "Not merged" }
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/n/done/abort/help] "
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
- if interactive?
55
- case HighLine.ask("#{row}#{prompt}")
56
- when "y"
57
- branches_to_delete << row.source.proper_name
58
- when "n", ""
59
- ; # do nothing
60
- when "done"
61
- puts table.horizontal_rule
62
- finalize(branches_to_delete)
63
- exit
64
- when "abort"
65
- puts table.horizontal_rule
66
- puts "#{$/}Aborting. No branches deleted."
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 row
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) if interactive?
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
@@ -1,3 +1,3 @@
1
1
  module GitCurate
2
- VERSION = "0.6.4"
2
+ VERSION = "0.7.0"
3
3
  end
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.6.4
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-07-26 00:00:00.000000000 Z
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/demo2.gif
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