git-whence 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1b7eea59985e627d3b8ea1d736ed08b366ce2f4
4
+ data.tar.gz: ea63dbc55464e70ba50375ea89200e7bbb2c5d37
5
+ SHA512:
6
+ metadata.gz: 0904f748ef078e0c8cf4e0e78f562a4d39b516b959abf7c4da3f95eaeb3f55d97055cd550a3036b37c195ed80c51ed1a6512efcabc5a2f351483ff09eb4c70f5
7
+ data.tar.gz: c960879a1edcfcaca0f11e80ea8e8644ef21ec7dcdc55db8e5560d158f8e326e43d0728322434ace15dc063058e50d6f750c25830f7c7dd720a771a1aa766364
checksums.yaml.gz.sig ADDED
Binary file
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2013 Michael Grosser <michael@grosser.it>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/git-whence ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << File.expand_path("../../lib", __FILE__)
3
+ require "rubygems" if RUBY_VERSION < "1.9"
4
+ require "git/whence"
5
+ exit Git::Whence::CLI.run(ARGV)
@@ -0,0 +1,5 @@
1
+ module Git
2
+ module Whence
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/git/whence.rb ADDED
@@ -0,0 +1,91 @@
1
+ require "git/whence/version"
2
+ require "optparse"
3
+
4
+ module Git::Whence
5
+ module CLI
6
+ class << self
7
+ def run(argv)
8
+ options = parse_options(argv)
9
+ commit = argv[0]
10
+ unless system("git rev-parse --git-dir 1>&2>/dev/null")
11
+ puts "Not in a git directory"
12
+ return 1
13
+ end
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}"}
20
+ else
21
+ puts merge
22
+ end
23
+ 0
24
+ else
25
+ $stderr.puts "Unable to find commit"
26
+ 1
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def origin
33
+ remotes = sh("git remote -v").split("\n")
34
+ remotes.detect { |l| l.start_with?("origin\t") }.split(" ")[1]
35
+ end
36
+
37
+ def find_merge(commit)
38
+ find_merge_simple(commit, "HEAD") ||
39
+ find_merge_simple(commit, "master") ||
40
+ find_merge_fuzzy(commit, "master")
41
+ end
42
+
43
+ def find_merge_fuzzy(commit, branch)
44
+ if similar = find_similar(commit, branch)
45
+ find_merge_simple(similar, branch)
46
+ end
47
+ end
48
+
49
+ def find_similar(commit, branch)
50
+ month = 30 * 24 * 60 * 60
51
+ time, search = sh("git show -s --format='%ct %an %s' #{commit}").strip.split(" ", 2)
52
+ time = time.to_i
53
+ same = sh("git log #{branch} --pretty=format:'%h %an %s' --before #{time + month} --after #{time - month}")
54
+ found = same.split("\n").map { |x| x.split(" ", 2) }.detect { |commit, message| message == search }
55
+ found && found.first
56
+ end
57
+
58
+ def find_merge_simple(commit, branch)
59
+ result = sh "git log #{commit}..#{branch} --ancestry-path --merges --oneline 2>/dev/null | tail -n 1"
60
+ result unless result.strip.empty?
61
+ end
62
+
63
+ def sh(command)
64
+ result = `#{command}`
65
+ raise unless $?.success?
66
+ result
67
+ end
68
+
69
+ def parse_options(argv)
70
+ options = {}
71
+ OptionParser.new do |opts|
72
+ opts.banner = <<-BANNER.gsub(/^ {10}/, "")
73
+ Find the merge and pull request a commit came from, also finding straight cherry-picks.
74
+
75
+ Usage:
76
+ git-whence <sha>
77
+
78
+ Options:
79
+ BANNER
80
+ opts.on("-o", "--open", "Open PR in github") { options[:open] = true }
81
+ opts.on("-h", "--help", "Show this.") { puts opts; exit }
82
+ opts.on("-v", "--version", "Show Version"){ puts Git::Whence::VERSION; exit}
83
+ end.parse!(argv)
84
+
85
+ raise "just 1 commit plz" if argv.size != 1
86
+
87
+ options
88
+ end
89
+ end
90
+ end
91
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-whence
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
14
+ YWVsMRcwFQYKCZImiZPyLGQBGRYHZ3Jvc3NlcjESMBAGCgmSJomT8ixkARkWAml0
15
+ MB4XDTE0MDIwNDIwMjk0MVoXDTE1MDIwNDIwMjk0MVowPzEQMA4GA1UEAwwHbWlj
16
+ aGFlbDEXMBUGCgmSJomT8ixkARkWB2dyb3NzZXIxEjAQBgoJkiaJk/IsZAEZFgJp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35
+ description:
36
+ email: michael@grosser.it
37
+ executables:
38
+ - git-whence
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - MIT-LICENSE
43
+ - bin/git-whence
44
+ - lib/git/whence.rb
45
+ - lib/git/whence/version.rb
46
+ homepage: https://github.com/grosser/git-whence
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.2.2
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Find the merge and pull request a commit came from + find cherry-picks
70
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ `7�*� jJ#�&�,!��((�_ K ��CN�e
2
+ �Bvh0;�9LtK�ւ�{�Y^��W\G���(�h��4���I~?Cvfcg�Vd��)2���C��+.�Svu����g�1˸