git_curate 1.1.1 → 1.2.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: 0620507e22ffbb2e96ad04a04894299f7f6efcb55c38a8b1e7e7650de3f5576c
4
- data.tar.gz: 37e1ec6214029e452e9aa2c236b6cb5a002153ddb6931dc80b2f26bb0da0fd60
3
+ metadata.gz: 0f8a9157f39dcb50cf904d375b61d8ebf602611ce50cad41b0448db33d746de4
4
+ data.tar.gz: 7f8465222b4dfc420bd823ca97b936bfdb10c688cb20e030a60f56b94c527096
5
5
  SHA512:
6
- metadata.gz: 6b89724ae483edce819bc05f2fda7dd3be3f9325789001b15473cd0d61559cedc9f6a3a37e75c030422f86832db00fd9d3d821c4f3d9a35e987c53b0b50b5049
7
- data.tar.gz: 2889af0076307950a90925dc5aa95bd0ebd522ac475e7ece58bb88af4bd93f8e0fb678c30abf81ad81b20a8b3dd2e323f2ddba4083a7b4abbb3a8d5ff15054ce
6
+ metadata.gz: 9394485c4054ebfaff8fb98b1818efdae552fe3e9724b5f18dafc1064379915c6509031858e5e26cd2b7e2dbd48a9954b15f56dfa0b22334f891a0612368b6ee
7
+ data.tar.gz: af7835213e93526f5774f61287dbf6051dae5e50fa2f7bb1496683013ed4901dea8db358cdacb11a7e1fe672ca968c64959bd3223d5da6ec66c42d7f4535ad88
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  **/.*.swp
11
11
  coverage
12
+ play.rb
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.9
4
- - 2.5.8
5
- - 2.6.6
6
- - 2.7.1
3
+ - 2.4.10
4
+ - 2.5.9
5
+ - 2.6.7
6
+ - 2.7.3
7
+ - 3.0.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ### v1.2.0
4
+
5
+ * Fix issue #16: "undefined method 'upstream'" error on MacOS 15.7
6
+ * Use [rugged](https://github.com/libgit2/rugged) library to get various branch information,
7
+ decreasing reliance of parsing `git` CLI output, and increasing robustness of the application
8
+ across platforms.
9
+ * Dependency version upgrades
10
+
11
+ ### v1.1.2
12
+
13
+ * Dependency version upgrades
14
+ * Include Ruby v3 in automated tests
15
+
3
16
  ### v1.1.1
4
17
 
5
18
  * Dependency version upgrades
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2.0
data/git_curate.gemspec CHANGED
@@ -29,7 +29,8 @@ 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.6.1"
32
+ spec.add_runtime_dependency "rugged", "1.1.0"
33
+ spec.add_runtime_dependency "tabulo", "2.6.3"
33
34
  spec.add_runtime_dependency "tty-screen", "0.8.1"
34
35
 
35
36
  spec.add_development_dependency "bundler"
data/lib/git_curate.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "git_curate/app"
2
2
  require "git_curate/branch"
3
+ require "git_curate/commit"
3
4
  require "git_curate/cli_parser"
4
5
  require "git_curate/copyright"
5
6
  require "git_curate/exceptions"
@@ -1,6 +1,6 @@
1
- module GitCurate
1
+ require "rugged"
2
2
 
3
- UpstreamInfo = Struct.new(:upstream, :status)
3
+ module GitCurate
4
4
 
5
5
  class Branch
6
6
 
@@ -44,68 +44,63 @@ module GitCurate
44
44
  end
45
45
 
46
46
  def last_commit_date
47
- initialize_last_commit_data
48
- @last_commit_date
47
+ last_commit.date
49
48
  end
50
49
 
51
50
  def hash
52
- initialize_last_commit_data
53
- @hash
51
+ last_commit.hash
54
52
  end
55
53
 
56
54
  def last_author
57
- initialize_last_commit_data
58
- @last_author
55
+ last_commit.author
59
56
  end
60
57
 
61
58
  def last_subject
62
- initialize_last_commit_data
63
- @last_subject
59
+ last_commit.subject
64
60
  end
65
61
 
66
62
  # Returns the local branches
67
63
  def self.local
68
- merged_branch_raw_names = Util.command_to_a("git branch --merged").to_set
64
+ toplevel_dir = Util.command_output("git rev-parse --show-toplevel").strip
65
+ repo = Rugged::Repository.new(toplevel_dir)
69
66
 
70
- branch_info.map do |raw_name, info|
71
- new(raw_name, merged: merged_branch_raw_names.include?(raw_name), upstream_info: info)
72
- end
73
- end
67
+ rugged_branches = repo.branches
68
+ repo_head_target = repo.head.target
74
69
 
75
- private
76
-
77
- # Returns a Hash containing, as keys, the raw names of all local branches and, as values,
78
- # a brief description of each branch's status relative to its upstream branch (up to
79
- # date, or ahead/behind).
80
- def self.branch_info
81
- # Double quotes around the format string to ensure Windows compatibility.
82
- command = 'git for-each-ref --format="%(refname:short) .. %(upstream:short) .. %(upstream:track)" refs/heads'
83
- branches_with_remotes = Util.command_to_a(command).map do |line|
84
- parts = line.split("..", -1).map { |s| s.strip! ; s.empty? ? nil : s }
85
- [parts[0], UpstreamInfo.new(parts[1], parts[2])]
86
- end.to_h
87
-
88
- info = Util.command_to_a("git branch").map do |line|
70
+ Util.command_to_a("git branch").map do |line|
89
71
  raw_branch_name = line.strip
90
72
  proper_branch_name = raw_branch_name.gsub(CURRENT_BRANCH_REGEX, "")
91
- upstream_info = branches_with_remotes[proper_branch_name]
73
+ rugged_branch = rugged_branches[proper_branch_name]
74
+ upstream = rugged_branch.upstream
92
75
  upstream_data =
93
- if upstream_info.upstream
94
- status = upstream_info.status
95
- if status
96
- status.gsub(/^\[/, "").gsub(/\]$/, "").capitalize
76
+ if upstream
77
+ target_id = rugged_branch.target_id
78
+ ahead, behind = repo.ahead_behind(target_id, upstream.target_id)
79
+ parts = []
80
+ parts << "ahead #{ahead}" if ahead != 0
81
+ parts << "behind #{behind}" if behind != 0
82
+ if parts.any?
83
+ parts.join(", ").capitalize
97
84
  else
98
85
  "Up to date"
99
86
  end
100
87
  else
101
88
  "No upstream"
102
89
  end
103
- [raw_branch_name, upstream_data]
104
- end
105
90
 
106
- info.to_h
91
+ target = rugged_branch.resolve.target
92
+ merged = (repo.merge_base(repo_head_target, target) == target.oid)
93
+
94
+ new(
95
+ raw_branch_name,
96
+ merged: merged,
97
+ upstream_info: upstream_data,
98
+ )
99
+ end
107
100
  end
108
101
 
102
+ private
103
+
109
104
  def self.delete_multi(*branches)
110
105
  Util.command_output("git branch -D #{branches.map(&:proper_name).join(" ")} --")
111
106
  end
@@ -118,16 +113,13 @@ module GitCurate
118
113
  @upstream_info = upstream_info
119
114
  end
120
115
 
121
- # Returns an array with [date, author, subject], each as a string.
122
- def initialize_last_commit_data
123
- return if @last_commit_data
124
-
125
- # For Windows compatibility we need double quotes around the format string, as well as spaces
126
- # between the placeholders.
127
- command = %Q(git log -n1 --date=short --format=format:"%cd %n %h %n %an %n %s" #{proper_name} --)
128
- @last_commit_data = Util.command_to_a(command)
129
-
130
- @last_commit_date, @hash, @last_author, @last_subject = @last_commit_data
116
+ def last_commit
117
+ @last_commit ||= begin
118
+ # For Windows compatibility we need double quotes around the format string, as well as spaces
119
+ # between the placeholders.
120
+ command = %Q(git log -n1 --date=short --format=format:"%cd %n %h %n %an %n %s" #{proper_name} --)
121
+ Commit.new(*Util.command_to_a(command))
122
+ end
131
123
  end
132
124
 
133
125
  end
@@ -0,0 +1,5 @@
1
+ module GitCurate
2
+
3
+ Commit = Struct.new(:date, :hash, :author, :subject)
4
+
5
+ end
@@ -1,3 +1,3 @@
1
1
  module GitCurate
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.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: 1.1.1
4
+ version: 1.2.0
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-07-26 00:00:00.000000000 Z
11
+ date: 2021-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -24,20 +24,34 @@ 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.6.1
47
+ version: 2.6.3
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.6.1
54
+ version: 2.6.3
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: tty-screen
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -163,6 +177,7 @@ files:
163
177
  - lib/git_curate/app.rb
164
178
  - lib/git_curate/branch.rb
165
179
  - lib/git_curate/cli_parser.rb
180
+ - lib/git_curate/commit.rb
166
181
  - lib/git_curate/copyright.rb
167
182
  - lib/git_curate/exceptions.rb
168
183
  - lib/git_curate/runner.rb
@@ -174,7 +189,7 @@ licenses:
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
@@ -190,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
205
  version: '0'
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: []