git-whence 0.2.1 → 0.3.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: 3ff4eae5cbbb56bd17fdd8baa9a653bb45b68f70b1214358d6b595d1c5b8b829
4
- data.tar.gz: de12ddbebc457c3e72c324b17242787c96c5c4243868042d3ba199706d4f19e1
3
+ metadata.gz: 8469e43011173ed18cdd8b1d51709b6436286037806fb88e923901ff2c6a7123
4
+ data.tar.gz: c5e5821f09e4019e5aa23c66a2b4c76160c5219e69cb3fb506119348caaaaf48
5
5
  SHA512:
6
- metadata.gz: 5a3193767c1a1cb822946ae91b9e4956294349669f32664364f62ea99806ad0af882e3313998bb2f8c3c5505c4a2daced0087af63858e0162fdca48a2a88902f
7
- data.tar.gz: 7c6c048d81234fdeae88b330d768d6485bb5a5dd18a3c3f923d49aa2ba99a5196a22a268203d76be7ffe4882fb08d1f14b54f43b579e9a301868bcab55ce9680
6
+ metadata.gz: 3b184b3804d3f0adc3c8c909dc62bd5a77d3d9565b25dd65bb397f3333ab4fec834e767caa0e3389c5c500a9f9bd7fe4872808d25db1efe833ae4ee06b0e5cd5
7
+ data.tar.gz: 73e1238e7a961cdad0e4558d5d2fd8579d5e54f0dc2c2b044b5d1db4b3e3a73493e7bfbd3afa27013b6ba3f77a0453fff1bf02b6c706a5629783c5a801940e73
@@ -3,6 +3,8 @@ require "optparse"
3
3
 
4
4
  module Git::Whence
5
5
  module CLI
6
+ SQUASH_REGEX = /\(#(\d+)\)$/
7
+
6
8
  class << self
7
9
  def run(argv)
8
10
  options = parse_options(argv)
@@ -19,8 +21,7 @@ module Git::Whence
19
21
  show_commit(commit, options)
20
22
  1
21
23
  else
22
- merge = find_merge(commit)
23
- if merge
24
+ if merge = find_merge(commit)
24
25
  show_commit(merge, options)
25
26
  0
26
27
  else
@@ -44,7 +45,7 @@ module Git::Whence
44
45
  def show_commit(merge, options)
45
46
  info = sh("git show -s --oneline #{merge}").strip
46
47
  if options[:open]
47
- if pr = info[/Merge pull request #(\d+) from /, 1]
48
+ if pr = info[/Merge pull request #(\d+) from /, 1] || info[SQUASH_REGEX, 1]
48
49
  exec "open", "https://github.com/#{origin}/pull/#{pr}"
49
50
  else
50
51
  warn "Unable to find PR number in #{info}"
@@ -57,19 +58,23 @@ module Git::Whence
57
58
 
58
59
  # https://github.com/foo/bar or git@github.com:foo/bar.git -> foo/bar
59
60
  def origin
60
- repo = sh("git remote get-url origin").strip
61
+ repo = sh("git remote get-url origin").strip # TODO: read file instead
61
62
  repo.sub!(/\.git$/, "")
62
63
  repo.split(/[:\/]/).last(2).join("/")
63
64
  end
64
65
 
65
66
  def find_merge(commit)
66
- commit, merge = (
67
+ merge_commit, merge = (
67
68
  find_merge_simple(commit, "HEAD") ||
68
69
  find_merge_simple(commit, "master") ||
69
70
  find_merge_fuzzy(commit, "master")
70
71
  )
71
72
 
72
- merge if merge && merge_include_commit?(merge, commit)
73
+ if merge && merge_include_commit?(merge, merge_commit)
74
+ merge
75
+ else
76
+ find_squash_merge(commit) # not very exact, so do this last ... ideally ask github api
77
+ end
73
78
  end
74
79
 
75
80
  def merge_include_commit?(merge, commit)
@@ -83,6 +88,10 @@ module Git::Whence
83
88
  end
84
89
  end
85
90
 
91
+ def find_squash_merge(commit)
92
+ commit if sh("git show -s --format='%s' #{commit}") =~ SQUASH_REGEX
93
+ end
94
+
86
95
  def find_similar(commit, branch)
87
96
  month = 30 * 24 * 60 * 60
88
97
  time, search = sh("git show -s --format='%ct %an %s' #{commit}").strip.split(" ", 2)
@@ -93,8 +102,8 @@ module Git::Whence
93
102
  end
94
103
 
95
104
  def find_merge_simple(commit, branch)
96
- result = sh "git log #{commit}..#{branch} --ancestry-path --merges --pretty='%H' 2>/dev/null | tail -n 1"
97
- [commit, result.strip] unless result.strip.empty?
105
+ result = sh("git log #{commit}..#{branch} --ancestry-path --merges --pretty='%H' 2>/dev/null | tail -n 1").chomp
106
+ [commit, result] unless result.empty?
98
107
  end
99
108
 
100
109
  def sh(command)
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Whence
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-whence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-22 00:00:00.000000000 Z
11
+ date: 2019-06-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it
@@ -40,8 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  requirements: []
43
- rubyforge_project:
44
- rubygems_version: 2.7.6
43
+ rubygems_version: 3.0.3
45
44
  signing_key:
46
45
  specification_version: 4
47
46
  summary: Find the merge and pull request a commit came from + find cherry-picks