git_curate 1.1.2 → 1.2.0.beta

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: 17d14ef21b3dceacc1b65f9d2ce51238b1f2841f1a0815afdc302ca97875c109
4
- data.tar.gz: 246e45f78b57dd14cef91610ef09e3944f82b8559184248327a99759fd99b1bd
3
+ metadata.gz: 4460f5b9f1e2e1dc37bc0afbab3b0d67ab3a1a767d66c2e41c49a31de9ae8ceb
4
+ data.tar.gz: 64d28c60264cde31f088074f7d431ae8019f97fa0117b940c05cc9d40d855187
5
5
  SHA512:
6
- metadata.gz: 5bd2a261e13944e2ef578ffd97e33719c9a191c11d8b7de5885ab75c980255df6fc52321863052b6c6d3c3a56e8690e77794ee56af914e3391da03d1e7312ce3
7
- data.tar.gz: 0a79e2356319b7b31a454416bdc366b7924b85966c534bb6e122824279a4a459dc65daa6369780bd53342d53c28c2caacc06b9ebb92edbe0c78593f09ba2f450
6
+ metadata.gz: 6ffe2949a193e80a8fda6c480464eb73ac4f859309f2deb1f48c818f916566eac2a3b5f4fd6e97b031df6b673f79fc59df03262d44d934c754d3f1b45efa9d15
7
+ data.tar.gz: 3941f4ed634a97b83db6d13d91288e37271e61d8a1f9c73c2e88e492b9805c417f261c0bb9af49a9a8c6f7dd25759bb287f3adee5c907287041e65b87e84fb20
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ### v1.2.0.beta
4
+
5
+ * Fix for issue #16: "undefined method upstream" error on MacOS 15.7
6
+ * Add rugged library
7
+
3
8
  ### v1.1.2
4
9
 
5
10
  * Dependency version upgrades
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in git_curate.gemspec
6
6
  gemspec
7
+
8
+ gem "rugged", "~> 1.1"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.2.0.beta
@@ -1,9 +1,13 @@
1
+ require "rugged"
2
+
1
3
  module GitCurate
2
4
 
3
5
  UpstreamInfo = Struct.new(:upstream, :status)
4
6
 
5
7
  class Branch
6
8
 
9
+ @@repo = Rugged::Repository.new(".")
10
+
7
11
  # Regex for determining whether a "raw" branch name is the name of the current branch
8
12
  # on this or another worktree.
9
13
  CURRENT_BRANCH_REGEX = /^[+*]\s+/
@@ -65,47 +69,43 @@ module GitCurate
65
69
 
66
70
  # Returns the local branches
67
71
  def self.local
68
- merged_branch_raw_names = Util.command_to_a("git branch --merged").to_set
69
-
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
74
-
75
- private
72
+ rugged_branches = @@repo.branches
73
+ repo_head_target = @@repo.head.target
76
74
 
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|
75
+ Util.command_to_a("git branch").map do |line|
89
76
  raw_branch_name = line.strip
90
77
  proper_branch_name = raw_branch_name.gsub(CURRENT_BRANCH_REGEX, "")
91
- upstream_info = branches_with_remotes[proper_branch_name]
78
+ rugged_branch = rugged_branches[proper_branch_name]
79
+ upstream = rugged_branch.upstream
92
80
  upstream_data =
93
- if upstream_info.upstream
94
- status = upstream_info.status
95
- if status
96
- status.gsub(/^\[/, "").gsub(/\]$/, "").capitalize
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
97
89
  else
98
90
  "Up to date"
99
91
  end
100
92
  else
101
93
  "No upstream"
102
94
  end
103
- [raw_branch_name, upstream_data]
104
- end
105
95
 
106
- 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
107
105
  end
108
106
 
107
+ private
108
+
109
109
  def self.delete_multi(*branches)
110
110
  Util.command_output("git branch -D #{branches.map(&:proper_name).join(" ")} --")
111
111
  end
@@ -1,3 +1,3 @@
1
1
  module GitCurate
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0.beta"
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.1.2
4
+ version: 1.2.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Harvey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-09 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
@@ -168,6 +168,7 @@ files:
168
168
  - lib/git_curate/runner.rb
169
169
  - lib/git_curate/util.rb
170
170
  - lib/git_curate/version.rb
171
+ - play.rb
171
172
  homepage: https://github.com/matt-harvey/git_curate
172
173
  licenses:
173
174
  - MIT
@@ -185,9 +186,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
186
  version: 2.4.9
186
187
  required_rubygems_version: !ruby/object:Gem::Requirement
187
188
  requirements:
188
- - - ">="
189
+ - - ">"
189
190
  - !ruby/object:Gem::Version
190
- version: '0'
191
+ version: 1.3.1
191
192
  requirements: []
192
193
  rubygems_version: 3.1.2
193
194
  signing_key: