git-whence 0.1.3 → 0.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
- SHA1:
3
- metadata.gz: 7086aa5c3bbc94e5f5a842c43e88669ded5738b5
4
- data.tar.gz: 0e22874dd8b2ec5d8e628ab18c72f453beb65044
2
+ SHA256:
3
+ metadata.gz: bbf02d5c73586be8d70edcabecd451091376a8f4db383766fb6ed64768d97bfc
4
+ data.tar.gz: 3c521c44e7fa1ece8af4b213940b1e61b96d7b4282cf90cbb94d9d54a5072a0c
5
5
  SHA512:
6
- metadata.gz: 2bcfce0b66afbac623de6721ab12b0025f1742bc0cafe6c23ce2cead5ef26ad6c912effdaff3d29ffd879bc63eba3321707b68ea9482dc5a22b2e82b30b03179
7
- data.tar.gz: bdd79fe9fe66d32b94bebfce7e792635c12ff12db101397065a08bba1578b4b7cb8e36f42b5246871575bde9b7959f319bfee873acc590ebccd827ab6b760fe4
6
+ metadata.gz: 6273c8f80e7fe4c56dd145294ac5eaa0dd950e9e530498414b1f0b87e54bcb1bd345e0fbef1aa1b2a816b608b14bc354e27dd868581920ee0e9e704f77533fbc
7
+ data.tar.gz: 5291c1401f7a04428a0cdda6d26824d7f4547eeea3bc9a4268e92fbdf1f5e723b16d309d4d064851affe708f36faa004a4fb78de07d6f34eb3d867d018f6af3a
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Whence
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/git/whence.rb CHANGED
@@ -8,24 +8,22 @@ module Git::Whence
8
8
  options = parse_options(argv)
9
9
  commit = argv[0]
10
10
  unless system("git rev-parse --git-dir 2>&1 >/dev/null")
11
- puts "Not in a git directory"
11
+ warn "Not in a git directory"
12
12
  return 1
13
13
  end
14
14
 
15
15
  commit = expand(commit)
16
16
 
17
17
  if is_merge?(commit)
18
- $stderr.puts "Commit is a merge"
18
+ warn "Commit is a merge"
19
19
  finished_with_commit(commit, options)
20
- 1
21
20
  else
22
21
  merge = find_merge(commit)
23
22
  if merge
24
23
  finished_with_commit(merge, options)
25
- 0
26
24
  else
27
- $stderr.puts "Unable to find merge"
28
- 1
25
+ warn "Unable to find merge"
26
+ options[:open] ? finished_with_commit(commit, options) : 1
29
27
  end
30
28
  end
31
29
  end
@@ -33,7 +31,7 @@ module Git::Whence
33
31
  private
34
32
 
35
33
  def expand(commit)
36
- sh("git show #{commit} -s --format='%H'").strip
34
+ sh("git rev-parse #{commit}").strip
37
35
  end
38
36
 
39
37
  def is_merge?(commit)
@@ -42,23 +40,32 @@ module Git::Whence
42
40
 
43
41
  def finished_with_commit(merge, options)
44
42
  info = sh("git show -s --oneline #{merge}").strip
45
- if options[:open] && (pr = info[/Merge pull request #(\d+) from /, 1]) && (url = origin)
46
- repo = url[%r{(\w+/[-\w\.]+)}i, 1].to_s.sub(/\.git$/, "")
47
- exec %Q{open "https://github.com/#{repo}/pull/#{pr}"}
43
+ if options[:open]
44
+ if pr = info[/Merge pull request #(\d+) from /, 1]
45
+ exec "open", "https://github.com/#{origin}/pull/#{pr}"
46
+ else
47
+ warn "Unable to find PR number in #{info}"
48
+ exec "open", "https://github.com/#{origin}/commit/#{merge}"
49
+ end
48
50
  else
49
51
  puts info
52
+ 0
50
53
  end
51
54
  end
52
55
 
56
+ # https://github.com/foo/bar or git@github.com:foo/bar.git -> foo/bar
53
57
  def origin
54
- remotes = sh("git remote -v").split("\n")
55
- remotes.detect { |l| l.start_with?("origin\t") }.split(" ")[1]
58
+ repo = sh("git remote get-url origin").strip
59
+ repo.sub!(/\.git$/, "")
60
+ repo.split(/[:\/]/).last(2).join("/")
56
61
  end
57
62
 
58
63
  def find_merge(commit)
59
- commit, merge = find_merge_simple(commit, "HEAD") ||
64
+ commit, merge = (
65
+ find_merge_simple(commit, "HEAD") ||
60
66
  find_merge_simple(commit, "master") ||
61
67
  find_merge_fuzzy(commit, "master")
68
+ )
62
69
 
63
70
  merge if merge && merge_include_commit?(merge, commit)
64
71
  end
@@ -79,18 +86,18 @@ module Git::Whence
79
86
  time, search = sh("git show -s --format='%ct %an %s' #{commit}").strip.split(" ", 2)
80
87
  time = time.to_i
81
88
  same = sh("git log #{branch} --pretty=format:'%H %an %s' --before #{time + month} --after #{time - month}")
82
- found = same.split("\n").map { |x| x.split(" ", 2) }.detect { |commit, message| message == search }
89
+ found = same.split("\n").map { |x| x.split(" ", 2) }.detect { |_, message| message == search }
83
90
  found && found.first
84
91
  end
85
92
 
86
93
  def find_merge_simple(commit, branch)
87
94
  result = sh "git log #{commit}..#{branch} --ancestry-path --merges --pretty='%H' 2>/dev/null | tail -n 1"
88
- [commit, result] unless result.strip.empty?
95
+ [commit, result.strip] unless result.strip.empty?
89
96
  end
90
97
 
91
98
  def sh(command)
92
99
  result = `#{command}`
93
- raise unless $?.success?
100
+ raise "Command failed\n#{command}\n#{result}" unless $?.success?
94
101
  result
95
102
  end
96
103
 
metadata CHANGED
@@ -1,36 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-whence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
14
- YWVsMRcwFQYKCZImiZPyLGQBGRYHZ3Jvc3NlcjESMBAGCgmSJomT8ixkARkWAml0
15
- MB4XDTE0MDIwNDIwMjk0MVoXDTE1MDIwNDIwMjk0MVowPzEQMA4GA1UEAwwHbWlj
16
- aGFlbDEXMBUGCgmSJomT8ixkARkWB2dyb3NzZXIxEjAQBgoJkiaJk/IsZAEZFgJp
17
- dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMorXo/hgbUq97+kII9H
18
- MsQcLdC/7wQ1ZP2OshVHPkeP0qH8MBHGg6eYisOX2ubNagF9YTCZWnhrdKrwpLOO
19
- cPLaZbjUjljJ3cQR3B8Yn1veV5IhG86QseTBjymzJWsLpqJ1UZGpfB9tXcsFtuxO
20
- 6vHvcIHdzvc/OUkICttLbH+1qb6rsHUceqh+JrH4GrsJ5H4hAfIdyS2XMK7YRKbh
21
- h+IBu6dFWJJByzFsYmV1PDXln3UBmgAt65cmCu4qPfThioCGDzbSJrGDGLmw/pFX
22
- FPpVCm1zgYSb1v6Qnf3cgXa2f2wYGm17+zAVyIDpwryFru9yF/jJxE38z/DRsd9R
23
- /88CAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFLIj
24
- Z1x7SnjGGHK+MiVZkFjjS/iMMB0GA1UdEQQWMBSBEm1pY2hhZWxAZ3Jvc3Nlci5p
25
- dDAdBgNVHRIEFjAUgRJtaWNoYWVsQGdyb3NzZXIuaXQwDQYJKoZIhvcNAQEFBQAD
26
- ggEBAExBcUWfGuamYn+IddOA0Ws8jUKwB14RXoZRDrTiTAlMm3Bkg2OKyxS3uJXa
27
- 6Z+LwFiZwVYk62yHXqNzEJycQk4SEmY+xDWLj0p7X6qEeU4QZKwR1TwJ5z3PTrZ6
28
- irJgM3q7NIBRvmTzRaAghWcQn+Eyr5YLOfMksjVBMUMnzh5/ZDgq53LphgJbGwvz
29
- ScJAgfNclLHnjk9q1mT1s0e1FPWbiAL3siBIR5HpH8qtSEiivTf2ntciebOqS93f
30
- F5etKHZg0j3eHO31/i2HnswY04lqGImUu6aM5EnijFTB7PPW2KwKKM4+kKDYFdlw
31
- /0WV1Ng2/Y6qsHwmqGg2VlYj2h4=
32
- -----END CERTIFICATE-----
33
- date: 2014-07-03 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2018-11-18 00:00:00.000000000 Z
34
12
  dependencies: []
35
13
  description:
36
14
  email: michael@grosser.it
@@ -63,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
41
  version: '0'
64
42
  requirements: []
65
43
  rubyforge_project:
66
- rubygems_version: 2.2.2
44
+ rubygems_version: 2.7.6
67
45
  signing_key:
68
46
  specification_version: 4
69
47
  summary: Find the merge and pull request a commit came from + find cherry-picks
checksums.yaml.gz.sig DELETED
Binary file
data.tar.gz.sig DELETED
@@ -1 +0,0 @@
1
- Ƃ����*�}���4E"�L3�i���͉�C����<��LE΃B*��S����J�ϓrT����J�7��~F-!�5�#��/m!��=��C��-��i���zX��2���g ����zѐ����ߑ1Y�1{�H��LŝԻZ���)`�q+u:�FQ}G�1z�d�v��E�:�v��%4o�����N�Ƒ��s�(��b%��/7�t���])Y
metadata.gz.sig DELETED
Binary file