git-whence 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: e1b7eea59985e627d3b8ea1d736ed08b366ce2f4
4
- data.tar.gz: ea63dbc55464e70ba50375ea89200e7bbb2c5d37
3
+ metadata.gz: 3d23b4ac84ee717b785cd7de075b1a2d035509e5
4
+ data.tar.gz: d7b37d818091f7abeaa0833f83d26a780c140b66
5
5
  SHA512:
6
- metadata.gz: 0904f748ef078e0c8cf4e0e78f562a4d39b516b959abf7c4da3f95eaeb3f55d97055cd550a3036b37c195ed80c51ed1a6512efcabc5a2f351483ff09eb4c70f5
7
- data.tar.gz: c960879a1edcfcaca0f11e80ea8e8644ef21ec7dcdc55db8e5560d158f8e326e43d0728322434ace15dc063058e50d6f750c25830f7c7dd720a771a1aa766364
6
+ metadata.gz: d357a86878294eaebddc58f3b21d7e53665260c744396325ee1ef056ce4b7b612c9a2bdd51d995fae61bb5fb620639f474b12e9b2c866ac300e9c5285b6d8c5a
7
+ data.tar.gz: c069e55bb44efa2c09aa52b48c9bcd74b2972421d6f477d709ab0ded902331b90db2ed97582b1d2473bd582ef6ddcb3d965870e7a89ce8dddb54bfcc8cc3e7c2
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/git/whence.rb CHANGED
@@ -7,28 +7,43 @@ module Git::Whence
7
7
  def run(argv)
8
8
  options = parse_options(argv)
9
9
  commit = argv[0]
10
- unless system("git rev-parse --git-dir 1>&2>/dev/null")
10
+ unless system("git rev-parse --git-dir 2>&1 >/dev/null")
11
11
  puts "Not in a git directory"
12
12
  return 1
13
13
  end
14
14
 
15
- merge = find_merge(commit)
16
- if merge
17
- if options[:open] && (pr = merge[/Merge pull request #(\d+) from /, 1]) && (url = origin)
18
- repo = url[%r{(\w+/[-\w\.]+)}i, 1].to_s.sub(/\.git$/, "")
19
- exec %Q{open "https://github.com/#{repo}/pull/#{pr}"}
15
+ if is_merge?(commit)
16
+ $stderr.puts "Commit is a merge"
17
+ finished_with_commit(commit, options)
18
+ 1
19
+ else
20
+ merge = find_merge(commit)
21
+ if merge
22
+ finished_with_commit(merge, options)
23
+ 0
20
24
  else
21
- puts merge
25
+ $stderr.puts "Unable to find merge"
26
+ 1
22
27
  end
23
- 0
24
- else
25
- $stderr.puts "Unable to find commit"
26
- 1
27
28
  end
28
29
  end
29
30
 
30
31
  private
31
32
 
33
+ def is_merge?(commit)
34
+ sh("git cat-file -p #{commit}").split("\n")[1..2].grep(/parent /).size > 1
35
+ end
36
+
37
+ def finished_with_commit(merge, options)
38
+ info = sh("git show -s --oneline #{merge}").strip
39
+ if options[:open] && (pr = info[/Merge pull request #(\d+) from /, 1]) && (url = origin)
40
+ repo = url[%r{(\w+/[-\w\.]+)}i, 1].to_s.sub(/\.git$/, "")
41
+ exec %Q{open "https://github.com/#{repo}/pull/#{pr}"}
42
+ else
43
+ puts info
44
+ end
45
+ end
46
+
32
47
  def origin
33
48
  remotes = sh("git remote -v").split("\n")
34
49
  remotes.detect { |l| l.start_with?("origin\t") }.split(" ")[1]
@@ -56,7 +71,7 @@ module Git::Whence
56
71
  end
57
72
 
58
73
  def find_merge_simple(commit, branch)
59
- result = sh "git log #{commit}..#{branch} --ancestry-path --merges --oneline 2>/dev/null | tail -n 1"
74
+ result = sh "git log #{commit}..#{branch} --ancestry-path --merges --pretty='%h' 2>/dev/null | tail -n 1"
60
75
  result unless result.strip.empty?
61
76
  end
62
77
 
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Whence
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-whence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -30,7 +30,7 @@ cert_chain:
30
30
  F5etKHZg0j3eHO31/i2HnswY04lqGImUu6aM5EnijFTB7PPW2KwKKM4+kKDYFdlw
31
31
  /0WV1Ng2/Y6qsHwmqGg2VlYj2h4=
32
32
  -----END CERTIFICATE-----
33
- date: 2014-05-03 00:00:00.000000000 Z
33
+ date: 2014-05-05 00:00:00.000000000 Z
34
34
  dependencies: []
35
35
  description:
36
36
  email: michael@grosser.it
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- `7�*� jJ#�&�,!��((�_ K ��CNe
2
- �Bvh0;�9LtK�ւ�{�Y^��W\G���(�h��4���I~?Cvfcg�Vd��)2���C��+.�Svu����g�1˸
1
+ V3�� QD�������9�'��=_nl���VD4��S9jr��Oh���\���������b}�� ���� x��)������� mR4��