提交 a0ba3f39 编写于 作者: C Chris Wanstrath

init -g fails if no github user set

上级 eac7f7e5
......@@ -36,6 +36,7 @@ module Hub
PUBLIC = 'git://github.com/%s/%s.git'
USER = `git config --global github.user`.chomp
REPO = `basename $(pwd)`.chomp
LGHCONF = "http://github.com/guides/local-github-config"
# $ hub clone rtomayko/tilt
# > git clone git://github.com/rtomayko/tilt.
......@@ -75,6 +76,12 @@ module Hub
# > git remote add origin git@github.com:USER/REPO.git
def init(args)
if args.delete('-g')
# Can't do anything if we don't have a USER set.
if USER.empty?
abort "** No GitHub user set. See #{LGHCONF}"
end
url = PRIVATE % [ USER, REPO ]
args.after "git remote add origin #{url}"
end
......
......@@ -27,9 +27,18 @@ class HubTest < Test::Unit::TestCase
end
def test_init
Hub::Commands::USER.replace("tpw")
h = Hub("init -g")
assert_equal "git init", h.command
assert_equal "git remote add origin git@github.com:defunkt/hub.git", h.after
assert_equal "git remote add origin git@github.com:tpw/hub.git", h.after
end
def test_init_no_login
out = hub("init -g") do
Hub::Commands::USER.replace("")
end
assert_equal "** No GitHub user set. See http://github.com/guides/local-github-config\n", out
end
def test_version
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册