Skip to content

Commit

Permalink
Merge branch 'master' of github.com:defunkt/hub
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Jan 23, 2010
2 parents c12de8a + 8d87891 commit 8b1719f
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 2 deletions.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Install

`hub` is most easily installed as a standalone script:

curl -s http://defunkt.github.com/hub/standalone > ~/bin/hub && chmod 755 !#:4
curl -s http://defunkt.github.com/hub/standalone > ~/bin/hub &&
chmod 755 ~/bin/hub

Assuming `~/bin/` is in your `$PATH`, you're ready to roll:

Expand All @@ -56,6 +57,17 @@ Though not recommended, `hub` can also be installed as a RubyGem:

(Yes, the gem name is `git-hub`.)

(It's not recommended because of the RubyGems startup time. See [this
gist][speed] for information.)

### Standalone via RubyGems

Yes, the gem name is still `git-hub`:

$ gem install git-hub
$ hub hub standalone > ~/bin/hub && chmod 755 ~/bin/hub
$ gem uninstall git-hub

### Source

You can also install from source:
Expand Down Expand Up @@ -129,6 +141,20 @@ superpowers:
> git push staging bert_timeout
> git push qa bert_timeout

### git browse

$ git browse schacon/ticgit
> open http://github.com/schacon/ticgit

$ git browse -p schacon/ticgit
> open http://github.com/schacon/ticgit

$ git browse resque
> open http://github.com/YOUR_USER/resque

$ git browse -p resque
> open https://github.com:YOUR_USER/resque

### git help

$ git help
Expand Down Expand Up @@ -216,3 +242,4 @@ Chris Wanstrath :: chris@ozmm.org :: @defunkt

[0]: http://help.github.com/forking/
[1]: http://github.com/defunkt/hub/issues
[speed]: http://gist.github.com/284823
51 changes: 50 additions & 1 deletion lib/hub/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ module Commands
#
# $ hub clone -p kneath/hemingway
# > git clone git@github.com:kneath/hemingway.git
#
# $ hub clone tilt
# > git clone git://github.com/YOUR_LOGIN/tilt.
#
# $ hub clone -p github
# > git clone git@github.com:YOUR_LOGIN/hemingway.git
def clone(args)
ssh = args.delete('-p')

Expand All @@ -63,13 +69,16 @@ def clone(args)
next
end

if arg =~ %r{.+?://|.+?@} # Bail out early for URLs.
if arg =~ %r{.+?://|.+?@} || File.directory?(arg)
# Bail out early for URLs and local paths.
break
elsif arg.scan('/').size == 1 && !arg.include?(':')
# $ hub clone rtomayko/tilt
url = ssh ? PRIVATE : PUBLIC
args[args.index(arg)] = url % arg.split('/')
break
elsif arg !~ /:|\//
# $ hub clone tilt
url = ssh ? PRIVATE : PUBLIC
args[args.index(arg)] = url % [ github_user, arg ]
break
Expand Down Expand Up @@ -126,6 +135,46 @@ def push(args)
args.after after
end

# $ hub browse pjhyett/github-services
# > open http://github.com/pjhyett/github-services
#
# $ hub browse -p pjhyett/github-fi
# > open https://github.com/pjhyett/github-fi
#
# $ hub browse github-services
# > open http://github.com/YOUR_LOGIN/github-services
#
# $ hub browse -p github-fi
# > open https://github.com/YOUR_LOGIN/github-fi
def browse(args)
protocol = args.delete('-p') ? 'https' : 'http'

if args.last.include? '/'
# $ hub browse pjhyett/github-services
user, repo = args.last.split('/')
else
user = github_user
repo = args.last
end

browser = ENV['BROWSER'] || "open"
exec "#{browser} #{protocol}://github.com/#{user}/#{repo}"
end

# $ hub hub standalone
# Prints the "standalone" version of hub for an easy, memorable
# installation sequence:
#
# $ gem install git-hub
# $ hub standalone > ~/bin/standalone
# $ gem uninstall git-hub
def hub(args)
return help(args) unless args[1] == 'standalone'
require 'hub/standalone'
puts Hub::Standalone.build
exit
end

def alias(args)
shells = {
'sh' => 'alias git=hub',
Expand Down
19 changes: 19 additions & 0 deletions man/hub.1.ron
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ After configuring the alias, the following commands have superpowers:
Push <REF> to each of <REMOTE-1> through <REMOTE-N> by executing
multiple `git push` commands.
* `git browse` [`-p`] [<USER>`/`]<REPOSITORY>:
Open repository's GitHub page in the system's default web browser
using `open(1)` or the `BROWSER` env variable. Use `-p` to open a
page with https.
* `git help`:
Display enhanced git-help(1).
Expand Down Expand Up @@ -102,6 +107,20 @@ cloning:
> git push staging bert_timeout
> git push qa bert_timeout
### git browse
$ git browse schacon/ticgit
> open http://github.com/schacon/ticgit
$ git browse -p schacon/ticgit
> open http://github.com/schacon/ticgit
$ git browse resque
> open http://github.com/YOUR_USER/resque
$ git browse -p resque
> open https://github.com:YOUR_USER/resque
### git help
$ git help
Expand Down
35 changes: 35 additions & 0 deletions test/hub_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def test_normal_public_clone_with_path
assert_command input, command
end

def test_normal_clone_from_path
input = "clone ./test"
command = "git clone ./test"
assert_command input, command
end

def test_private_remote
input = "remote add -p rtomayko"
command = "git remote add rtomayko git@github.com:rtomayko/hub.git"
Expand Down Expand Up @@ -140,4 +146,33 @@ def groff?; false end
end
assert_equal "** Can't find groff(1)\n", help_manpage
end

def test_hub_standalone
help_standalone = hub("hub standalone")
assert_equal Hub::Standalone.build, help_standalone
end

def test_hub_open
input = "browse mojombo/bert"
command = "http://github.com/mojombo/bert\n"
assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
end

def test_hub_open_private
input = "browse -p bmizerany/sinatra"
command = "https://github.com/bmizerany/sinatra\n"
assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
end

def test_hub_open_self
input = "browse resque"
command = "http://github.com/tpw/resque\n"
assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
end

def test_hub_open_self_private
input = "browse -p github"
command = "https://github.com/tpw/github\n"
assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
end
end

0 comments on commit 8b1719f

Please sign in to comment.