提交 8b1719f2 编写于 作者: C Chris Wanstrath

Merge branch 'master' of github.com:defunkt/hub

......@@ -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:
......@@ -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:
......@@ -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
......@@ -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
......@@ -52,6 +52,12 @@ module Hub
#
# $ 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')
......@@ -63,13 +69,16 @@ module Hub
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
......@@ -126,6 +135,46 @@ module Hub
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',
......
......@@ -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).
......@@ -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
......
......@@ -70,6 +70,12 @@ class HubTest < Test::Unit::TestCase
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"
......@@ -140,4 +146,33 @@ config
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册