From 2155debcb9d096828e8faafa34b405af083471db Mon Sep 17 00:00:00 2001 From: Joshua Roesslein Date: Sun, 11 Apr 2010 17:30:08 -0400 Subject: [PATCH] Add "compare" command. This command allows you to view a compare view in the browser from a START to an END commit. Example: hub compare AWESOME_PATCH...MASTER --- README.md | 14 ++++++++++++++ lib/hub/commands.rb | 30 ++++++++++++++++++++++++++++++ man/hub.1.ron | 20 ++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/README.md b/README.md index 1a7ad54a4..fcc159f37 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,20 @@ login" below for details. $ git browse -p resque > open https://github.com:YOUR_USER/resque +### git compare + + $ git compare refactor + > open http://github.com/CURRENT_REPO/compare/refactor + + $ git compare 1.0...1.1 + > open http://github.com/CURRENT_REPO/compare/1.0...1.1 + + $ git compare -u fix + > (http://github.com/CURRENT_REPO/compare/fix) + + $ git compare myfork patch + > open http://github.com/myfork/compare/patch + ### git help $ git help diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 0bd924970..13748f2b5 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -232,6 +232,36 @@ def browse(args) args.push "#{protocol}://github.com/#{user}/#{repo}" end + # $ hub compare 1.0...fix + # > open http://github.com/CURRENT_REPO/compare/1.0...fix + # $ hub compare refactor + # > open http://github.com/CURRENT_REPO/comapre/refactor + # $ hub compare myfork feature + # > open http://github.com/myfork/REPO/compare/feature + # $ hub compare -u 1.0...2.0 + # (Prints the URL for the compare view) + def compare(args) + args.shift + urlOnly = args.delete('-u') ? true : false + range = args.pop + user = args.pop || OWNER + + if range and !OWNER.empty? + url = "http://github.com/#{user}/#{REPO}/compare/#{range}" + else + warn "Usage: hub compare [...]" + exit(1) + end + + if urlOnly + puts url + exit + else + args.executable = ENV['BROWSER'] || 'open' + args.push url + end + end + # $ hub hub standalone # Prints the "standalone" version of hub for an easy, memorable # installation sequence: diff --git a/man/hub.1.ron b/man/hub.1.ron index 227928c98..021d3f624 100644 --- a/man/hub.1.ron +++ b/man/hub.1.ron @@ -58,6 +58,12 @@ alias command displays information on configuring your environment: page with https. If the repository isn't specified, `browse` opens the page of the repository found in the current directory. + * `git compare` [`-u`] [] [...]: + Open a Github compare view page in the system's default web browser. + to are branch names, tag names, or commit SHA1s specifying + the range of history to compare. If is omitted, + the repository's default branch is assumed. + * `git submodule add` [`-p`] [/] : Submodule repository "git://github.com//.git" into as with git-submodule(1). When / is omitted, assumes @@ -151,6 +157,20 @@ cloning: $ git browse -p resque > open https://github.com:YOUR_USER/resque +### git compare + + $ git compare refactor + > open http://github.com/CURRENT_REPO/compare/refactor + + $ git compare 1.0...1.1 + > open http://github.com/CURRENT_REPO/compare/1.0...1.1 + + $ git compare -u fix + > (http://github.com/CURRENT_REPO/compare/fix) + + $ git compare myfork patch + > open http://github.com/myfork/compare/patch + ### git help $ git help