git_curate 1.0.2 → 1.2.0.beta2

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: 50f00058b5232e499100bf5a03447ed891a640c3efb8b9c1ce9adae50bf84b02
4
- data.tar.gz: bb443922c86047f3356e01eb160e83cbed0eb3ff8038826d03d2de3baef81f7b
3
+ metadata.gz: 0d25c82cca61f81731702b5ff45d30a44ed5778304c49a0a250171f268fd8ce9
4
+ data.tar.gz: b4ad3c50995bcee65fb57c6455b70b6960cf7ee5309265e70fd95f6a80c666ea
5
5
  SHA512:
6
- metadata.gz: 699f1b52fd674860eb71c8fc3c9eb4b43d8fbc884f5616d48781d965de50702ef910e6bea2d57b9bdd88a0f63c6aae976f497ab8de3a7a7819b1841edc0ef7a4
7
- data.tar.gz: 100ec40a8f8a23ebcef141c7ef7bd4df970719a7e0c9e76ebde4c8bf9d823a9c36a3010cc3732442e29bf2c714bb909eb9ff83f88ac5ba43063ebd0b8aa024fd
6
+ metadata.gz: 317df38e0f8d54f750544346570961ac09c4d5f03c5b1593c3423d53e461cb8c64b2d1e669453c3bf2f9ade9cd8a1c1336ba2aea4edc3a29b401912b8c374259
7
+ data.tar.gz: 6b6f5d5fee3bd0c6b96114afd5fda13ecd6cfc99d1ba5ebeff7fe16de44e5fe74239e530589adcec0423034d25a9918413af45b36771a758236693fb6a77737f
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
- - 2.4.9
3
+ - 2.4.10
5
4
  - 2.5.8
6
5
  - 2.6.6
7
- - 2.7.1
6
+ - 2.7.2
7
+ - 3.0.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # Changelog
2
2
 
3
+ ### v1.2.0.beta, v1.2.0.beta2
4
+
5
+ * Fix for issue #16: "undefined method upstream" error on MacOS 15.7
6
+ * Add rugged library
7
+
8
+ ### v1.1.2
9
+
10
+ * Dependency version upgrades
11
+ * Include Ruby v3 in automated tests
12
+
13
+ ### v1.1.1
14
+
15
+ * Dependency version upgrades
16
+
17
+ ### v1.1.0
18
+
19
+ #### Change that may be breaking for an obscure use case
20
+
21
+ * Output more helpful message in case there are no deletable branches when `git curate` run without `-l`/`--list` flag.
22
+
23
+ This will be a breaking change but only in the unlikely event that the output of `git curate` is being piped
24
+ through or processed by another program when run in _interactive_ (non-`--list`) mode.
25
+
26
+ _New behaviour when there are no deletable branches:_
27
+ Outputs `There are no local branches that can be deleted.`
28
+
29
+ _Old behaviour when there are no deletable branches:_
30
+ Outputs (irrelevantly and confusingly) the legend of interactive commands, followed by the message
31
+ `No branches deleted.`
32
+
33
+ ### v1.0.2
34
+
35
+ * Fix incorrect status-vs-upstream when commit subject begins with square-bracket-enclosed string.
36
+
3
37
  ### v1.0.1
4
38
 
5
39
  * Fix `fatal: bad revision '+'` error on encountering multiple worktrees.
data/README.md CHANGED
@@ -77,8 +77,7 @@ To run the test suite, run `bundle exec rake spec`. For a list of other Rake tas
77
77
 
78
78
  ## License
79
79
 
80
- The gem is available as open source under the terms of the [MIT
81
- License](http://opensource.org/licenses/MIT).
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
82
81
 
83
82
  [Gem Version]: https://rubygems.org/gems/git_curate
84
83
  [Build Status]: https://travis-ci.org/matt-harvey/git_curate
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.2.0.beta2
data/git_curate.gemspec CHANGED
@@ -29,8 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_runtime_dependency "highline", "2.0.3"
32
- spec.add_runtime_dependency "tabulo", "2.5.0"
33
- spec.add_runtime_dependency "tty-screen", "0.7.1"
32
+ spec.add_runtime_dependency "rugged", "1.1.0"
33
+ spec.add_runtime_dependency "tabulo", "2.6.2"
34
+ spec.add_runtime_dependency "tty-screen", "0.8.1"
34
35
 
35
36
  spec.add_development_dependency "bundler"
36
37
  spec.add_development_dependency "coveralls"
@@ -1,18 +1,19 @@
1
+ require "rugged"
2
+
1
3
  module GitCurate
2
4
 
5
+ UpstreamInfo = Struct.new(:upstream, :status)
6
+
3
7
  class Branch
4
8
 
9
+ @@repo = Rugged::Repository.new(".")
10
+
5
11
  # Regex for determining whether a "raw" branch name is the name of the current branch
6
12
  # on this or another worktree.
7
13
  CURRENT_BRANCH_REGEX = /^[+*]\s+/
8
14
 
9
- # Regexes for unpacking the output of `git branch -vv`
10
- BRANCH_NAME_REGEX = /\s+/
11
- LEADING_STAR_REGEX = /^\* /
12
- LEADING_PLUS_REGEX = /^\+ /
13
- REMOTE_INFO_REGEX = /^[^\s]+\s+[^\s]+\s+(\(.+\)\s+)?\[(?<remote_info>[^\]]+)\]/
14
-
15
- # Returns the branch name, with "* " prefixed if it's the current branch.
15
+ # Returns the branch name, with "* " prefixed if it's the current branch on the current
16
+ # worktree, or "+ " if it's the current branch on another worktree.
16
17
  attr_reader :raw_name
17
18
 
18
19
  # Returns a human-friendly string describing the status of the branch relative to the upstream branch
@@ -68,53 +69,43 @@ module GitCurate
68
69
 
69
70
  # Returns the local branches
70
71
  def self.local
71
- merged_branch_raw_names = Util.command_to_a("git branch --merged").to_set
72
-
73
- branch_info.map do |raw_name, info|
74
- new(raw_name, merged: merged_branch_raw_names.include?(raw_name), upstream_info: info)
75
- end
76
- end
77
-
78
- private
79
-
80
- # Returns a Hash containing, as keys, the raw names of all local branches and, as values,
81
- # a brief description of each branch's status relative to its upstream branch (up to
82
- # date, or ahead/behind).
83
- def self.branch_info
84
- command_0 = "git for-each-ref --format='%(refname:short) .. %(upstream:short)' refs/heads"
85
- command_1 = "git branch -vv"
86
-
87
- branches_with_remotes = Util.command_to_a(command_0).map do |line|
88
- parts = line.split(" .. ")
89
- [parts[0], parts[1] || nil]
90
- end.to_h
91
-
92
- info = Util.command_to_a(command_1).map do |line|
93
- line_is_current_branch = (line =~ CURRENT_BRANCH_REGEX)
94
- tidied_line = (line_is_current_branch ? line.gsub(CURRENT_BRANCH_REGEX, "") : line)
95
- proper_branch_name = tidied_line.split(BRANCH_NAME_REGEX)[0]
96
- raw_branch_name =
97
- if line =~ LEADING_STAR_REGEX
98
- "* #{proper_branch_name}"
99
- elsif line =~ LEADING_PLUS_REGEX
100
- "+ #{proper_branch_name}"
101
- else
102
- proper_branch_name
103
- end
104
- upstream_info =
105
- if branches_with_remotes[proper_branch_name]
106
- remote_info = tidied_line[REMOTE_INFO_REGEX, :remote_info]
107
- comparison_raw = remote_info.split(":")
108
- comparison_raw.length < 2 ? "Up to date" : comparison_raw[1].strip.capitalize
72
+ rugged_branches = @@repo.branches
73
+ repo_head_target = @@repo.head.target
74
+
75
+ Util.command_to_a("git branch").map do |line|
76
+ raw_branch_name = line.strip
77
+ proper_branch_name = raw_branch_name.gsub(CURRENT_BRANCH_REGEX, "")
78
+ rugged_branch = rugged_branches[proper_branch_name]
79
+ upstream = rugged_branch.upstream
80
+ upstream_data =
81
+ if upstream
82
+ target_id = rugged_branch.target_id
83
+ ahead, behind = @@repo.ahead_behind(target_id, upstream.target_id)
84
+ parts = []
85
+ parts << "ahead #{ahead}" if ahead != 0
86
+ parts << "behind #{behind}" if behind != 0
87
+ if parts.any?
88
+ parts.join(", ").capitalize
89
+ else
90
+ "Up to date"
91
+ end
109
92
  else
110
93
  "No upstream"
111
94
  end
112
- [raw_branch_name, upstream_info]
113
- end
114
95
 
115
- info.to_h
96
+ target = rugged_branch.resolve.target
97
+ merged = (@@repo.merge_base(repo_head_target, target) == target.oid)
98
+
99
+ new(
100
+ raw_branch_name,
101
+ merged: merged,
102
+ upstream_info: upstream_data,
103
+ )
104
+ end
116
105
  end
117
106
 
107
+ private
108
+
118
109
  def self.delete_multi(*branches)
119
110
  Util.command_output("git branch -D #{branches.map(&:proper_name).join(" ")} --")
120
111
  end
@@ -26,17 +26,11 @@ module GitCurate
26
26
  return EXIT_FAILURE
27
27
  end
28
28
 
29
- if interactive?
30
- puts
31
- print_help
32
- puts
33
- end
34
-
35
29
  branches = Branch.local
36
30
  branches.reject!(&:current?) if interactive?
37
31
 
38
32
  table = Tabulo::Table.new(branches, border: :reduced_ascii, column_padding: 0, align_header: :left) do |t|
39
- t.add_column(:branch, header: "Branch") { |b| b.displayable_name(pad: !interactive?) }
33
+ t.add_column("Branch") { |b| b.displayable_name(pad: !interactive?) }
40
34
  t.add_column("Last commit:#{$/}Date", &:last_commit_date)
41
35
  t.add_column("#{$/}Hash", &:hash)
42
36
  t.add_column("#{$/}Author", &:last_author)
@@ -57,6 +51,15 @@ module GitCurate
57
51
  return EXIT_SUCCESS
58
52
  end
59
53
 
54
+ if branches.empty?
55
+ puts "There are no local branches that can be deleted."
56
+ return EXIT_SUCCESS
57
+ end
58
+
59
+ puts
60
+ print_help
61
+ puts
62
+
60
63
  table.each_with_index do |row, index|
61
64
  case HighLine.ask("#{row} #{prompt}").downcase
62
65
  when "d"
@@ -1,3 +1,3 @@
1
1
  module GitCurate
2
- VERSION = "1.0.2"
2
+ VERSION = "1.2.0.beta2"
3
3
  end
data/play.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "rugged"
2
+
3
+ repo = Rugged::Repository.new(".")
4
+
5
+ current_branch_name = repo.head.name.sub(/^refs\/heads\//, '')
6
+
7
+ repo.branches.each_name(:local) do |branch_name|
8
+ branch_reference = repo.references["refs/heads/#{branch_name}"]
9
+ branch = repo.branches[branch_name]
10
+ is_current = current_branch_name == branch_name
11
+ target_id = branch.target_id
12
+ top_commit = branch_reference.log.first
13
+ commit = repo.lookup(target_id)
14
+
15
+ target = branch.resolve.target
16
+ merged = repo.merge_base(repo.head.target, target) == target.oid
17
+
18
+ puts "Branch: #{is_current ? '* ' + branch_name : branch_name}"
19
+ puts "date: #{commit.time}"
20
+ puts "hash: #{target_id}"
21
+ puts "author: #{top_commit[:committer][:name]}"
22
+ puts "subject: #{commit.message.split($/, -1)[0]}"
23
+ if branch.upstream
24
+ puts "upstream: #{branch.upstream.name}"
25
+ ahead, behind = repo.ahead_behind(target_id, branch.upstream.target_id)
26
+ puts "ahead: #{ahead}"
27
+ puts "behind: #{behind}"
28
+ end
29
+ puts "merged: #{merged ? 'Merged' : 'Not merged'}"
30
+ puts "*****************"
31
+ 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: 1.0.2
4
+ version: 1.2.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Harvey
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2021-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -24,34 +24,48 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rugged
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: tabulo
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - '='
32
46
  - !ruby/object:Gem::Version
33
- version: 2.5.0
47
+ version: 2.6.2
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - '='
39
53
  - !ruby/object:Gem::Version
40
- version: 2.5.0
54
+ version: 2.6.2
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: tty-screen
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - '='
46
60
  - !ruby/object:Gem::Version
47
- version: 0.7.1
61
+ version: 0.8.1
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - '='
53
67
  - !ruby/object:Gem::Version
54
- version: 0.7.1
68
+ version: 0.8.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -168,13 +182,14 @@ files:
168
182
  - lib/git_curate/runner.rb
169
183
  - lib/git_curate/util.rb
170
184
  - lib/git_curate/version.rb
185
+ - play.rb
171
186
  homepage: https://github.com/matt-harvey/git_curate
172
187
  licenses:
173
188
  - MIT
174
189
  metadata:
175
190
  source_code_uri: https://github.com/matt-harvey/git_curate
176
191
  changelog_uri: https://raw.githubusercontent.com/matt-harvey/git_curate/master/CHANGELOG.md
177
- post_install_message:
192
+ post_install_message:
178
193
  rdoc_options: []
179
194
  require_paths:
180
195
  - lib
@@ -185,12 +200,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
200
  version: 2.4.9
186
201
  required_rubygems_version: !ruby/object:Gem::Requirement
187
202
  requirements:
188
- - - ">="
203
+ - - ">"
189
204
  - !ruby/object:Gem::Version
190
- version: '0'
205
+ version: 1.3.1
191
206
  requirements: []
192
207
  rubygems_version: 3.1.2
193
- signing_key:
208
+ signing_key:
194
209
  specification_version: 4
195
210
  summary: Simple git branch curation tool
196
211
  test_files: []