Created
July 5, 2011 15:36
-
-
Save ssoroka/1065081 to your computer and use it in GitHub Desktop.
github git-compare; opens commits in github's compare feature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # ONE-LINE INSTALL INSTRUCTIONS: | |
| # wget --no-check-certificate https://raw.github.com/gist/1065081/git-compare; chmod u+x git-compare; mv git-compare `which git-status | ruby -e "puts STDIN.read.split(/\//)[0..-2].join('/')"`/ | |
| $remote = 'origin' | |
| def usage | |
| puts %( | |
| opens commits in github's compare feature. Commits must be pushed (remote "origin" is default) | |
| git-compare [options] from_sha to_sha | |
| If to_sha is left off, head will be assumed. | |
| Options | |
| -r[remote_name] | use a remote repo other than origin | |
| Examples: | |
| $ git compare head^^ | |
| $ git compare 15f3da3..master | |
| $ git compare -rmainline 15f3da3 master | |
| ) | |
| end | |
| def remote_details | |
| `git remote show -n #{$remote}` | |
| end | |
| def sha_lookup(reference) | |
| `git log #{reference} -1 --format="%h"`.chomp | |
| end | |
| def branches | |
| `git branch | cut -c3-`.chomp.split(/\n/) | |
| end | |
| args = ARGV | |
| if args.size == 0 | |
| usage | |
| exit | |
| end | |
| # support switching remote | |
| if args.first =~ /^\-r(.*)/ | |
| $remote = $1 | |
| args.shift | |
| end | |
| # support "from_sha..to_sha" | |
| if args.size == 1 | |
| args = args[0].split(/\.{2,3}/) | |
| end | |
| # support "git-compare from_sha", assume "git-compare from_sha..head" | |
| if args.size == 1 | |
| args.push('head') | |
| end | |
| # support vague commit names | |
| args.map!{|arg| sha_lookup(arg) } | |
| remote_details =~ /Push URL: git@github\.com\:(.+)\/(.+)\.git/ | |
| user, repo = $1, $2 | |
| system %(open https://github.com/#{user}/#{repo}/compare/#{args.first}...#{args.last}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment