git_curate 1.1.2 → 1.2.0.beta
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -0
- data/VERSION +1 -1
- data/lib/git_curate/branch.rb +28 -28
- data/lib/git_curate/version.rb +1 -1
- data/play.rb +31 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4460f5b9f1e2e1dc37bc0afbab3b0d67ab3a1a767d66c2e41c49a31de9ae8ceb
|
4
|
+
data.tar.gz: 64d28c60264cde31f088074f7d431ae8019f97fa0117b940c05cc9d40d855187
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ffe2949a193e80a8fda6c480464eb73ac4f859309f2deb1f48c818f916566eac2a3b5f4fd6e97b031df6b673f79fc59df03262d44d934c754d3f1b45efa9d15
|
7
|
+
data.tar.gz: 3941f4ed634a97b83db6d13d91288e37271e61d8a1f9c73c2e88e492b9805c417f261c0bb9af49a9a8c6f7dd25759bb287f3adee5c907287041e65b87e84fb20
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0.beta
|
data/lib/git_curate/branch.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
78
|
+
rugged_branch = rugged_branches[proper_branch_name]
|
79
|
+
upstream = rugged_branch.upstream
|
92
80
|
upstream_data =
|
93
|
-
if
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
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
|
data/lib/git_curate/version.rb
CHANGED
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.
|
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-
|
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:
|
191
|
+
version: 1.3.1
|
191
192
|
requirements: []
|
192
193
|
rubygems_version: 3.1.2
|
193
194
|
signing_key:
|