git-whence 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/git/whence/version.rb +1 -1
- data/lib/git/whence.rb +23 -4
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d905ac8083db64392216de76354c9f4fdf082ec37654e6d17a5355c2d616091e
|
4
|
+
data.tar.gz: 80bcec14ef080aecc1b8ad0db28ba44d9eb273ce890cbd75e7bc76d21fac17f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d3626ddbb2c37530b32f152809ac02675f816df2457e1c339af15da06a0c87a75a1d67b7f2ca6820769eb55c286cee7385881ae92182b06772fe1f0aba8325e
|
7
|
+
data.tar.gz: a35ab59affb9244aed513371ad3ebdc2b0c9b29c060dd945b1d801a7578b18d19f8d4d0c89957e670587f60a6118d2074ad62d374097fd5c87cc5818226d03ee
|
data/lib/git/whence/version.rb
CHANGED
data/lib/git/whence.rb
CHANGED
@@ -4,6 +4,7 @@ require "optparse"
|
|
4
4
|
module Git::Whence
|
5
5
|
module CLI
|
6
6
|
SQUASH_REGEX = /\(#(\d+)\)$/
|
7
|
+
DEFAULT_BRANCHES = ["main", "master"]
|
7
8
|
|
8
9
|
class << self
|
9
10
|
def run(argv)
|
@@ -66,8 +67,8 @@ module Git::Whence
|
|
66
67
|
def find_merge(commit)
|
67
68
|
merge_commit, merge = (
|
68
69
|
find_merge_simple(commit, "HEAD") ||
|
69
|
-
find_merge_simple(commit,
|
70
|
-
find_merge_fuzzy(commit,
|
70
|
+
find_merge_simple(commit, default_branch) ||
|
71
|
+
find_merge_fuzzy(commit, default_branch)
|
71
72
|
)
|
72
73
|
|
73
74
|
if merge && merge_include_commit?(merge, merge_commit)
|
@@ -83,11 +84,29 @@ module Git::Whence
|
|
83
84
|
end
|
84
85
|
|
85
86
|
def find_merge_fuzzy(commit, branch)
|
86
|
-
if similar = find_similar(commit, branch)
|
87
|
+
if (similar = find_similar(commit, branch))
|
87
88
|
find_merge_simple(similar, branch)
|
88
89
|
end
|
89
90
|
end
|
90
91
|
|
92
|
+
def default_branch
|
93
|
+
@default_branch ||= remote_default_branch || local_default_branch
|
94
|
+
end
|
95
|
+
|
96
|
+
def remote_default_branch
|
97
|
+
remotes = sh("git remote").split("\n")
|
98
|
+
return nil if remotes.empty?
|
99
|
+
preferred = (remotes.include?("origin") ? "origin" : remotes.first)
|
100
|
+
folder = ".git/refs/remotes/#{preferred}"
|
101
|
+
(Dir["#{folder}/*"].map { |f| f.sub("#{folder}/", "") } & DEFAULT_BRANCHES).sort.first
|
102
|
+
end
|
103
|
+
|
104
|
+
# guess default branch by last changed commonly used default branch or current branch
|
105
|
+
def local_default_branch
|
106
|
+
branches = sh("git branch --sort=-committerdate").split("\n").map { |br| br.split(" ").last }
|
107
|
+
(branches & DEFAULT_BRANCHES).first || sh("git symbolic-ref HEAD").strip.sub("refs/heads/", "")
|
108
|
+
end
|
109
|
+
|
91
110
|
def find_squash_merge(commit)
|
92
111
|
commit if sh("git show -s --format='%s' #{commit}") =~ SQUASH_REGEX
|
93
112
|
end
|
@@ -98,7 +117,7 @@ module Git::Whence
|
|
98
117
|
time = time.to_i
|
99
118
|
same = sh("git log #{branch} --pretty=format:'%H %an %s' --before #{time + month} --after #{time - month}")
|
100
119
|
found = same.split("\n").map { |x| x.split(" ", 2) }.detect { |_, message| message == search }
|
101
|
-
found
|
120
|
+
found&.first
|
102
121
|
end
|
103
122
|
|
104
123
|
def find_merge_simple(commit, branch)
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-whence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email: michael@grosser.it
|
15
15
|
executables:
|
16
16
|
- git-whence
|
@@ -25,7 +25,7 @@ homepage: https://github.com/grosser/git-whence
|
|
25
25
|
licenses:
|
26
26
|
- MIT
|
27
27
|
metadata: {}
|
28
|
-
post_install_message:
|
28
|
+
post_install_message:
|
29
29
|
rdoc_options: []
|
30
30
|
require_paths:
|
31
31
|
- lib
|
@@ -33,15 +33,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
33
|
requirements:
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '2.3'
|
37
37
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
|
-
rubygems_version: 3.
|
44
|
-
signing_key:
|
43
|
+
rubygems_version: 3.4.10
|
44
|
+
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: Find the merge and pull request a commit came from + find cherry-picks
|
47
47
|
test_files: []
|