提交 7e804aae 编写于 作者: M Mislav Marohnić

improve `checkout` command

Now forwards flags to internal `checkout` command, resets the existing
local branch by default.

Closes #132
上级 d0a8e5ff
......@@ -201,7 +201,7 @@ superpowers:
# $ git checkout https://github.com/defunkt/hub/pull/73
# > git remote add -f -t feature git://github:com/mislav/hub.git
# > git checkout -b mislav-feature mislav/feature
# > git checkout --track -B mislav-feature mislav/feature
# $ git checkout https://github.com/defunkt/hub/pull/73 custom-branch-name
......
......@@ -303,17 +303,20 @@ module Hub
# $ git checkout https://github.com/defunkt/hub/pull/73
# > git remote add -f -t feature git://github:com/mislav/hub.git
# > git checkout -b mislav-feature mislav/feature
# > git checkout --track -B mislav-feature mislav/feature
def checkout(args)
if (2..3) === args.length and url = resolve_github_url(args[1]) and url.project_path =~ /^pull\/(\d+)/
_, url_arg, new_branch_name = args.words
if url = resolve_github_url(url_arg) and url.project_path =~ /^pull\/(\d+)/
pull_id = $1
load_net_http
response = http_request(url.project.api_pullrequest_url(pull_id, 'json'))
pull_data = JSON.parse(response.body)['pull']
args.delete new_branch_name
user, branch = pull_data['head']['label'].split(':', 2)
new_branch_name = args[2] || "#{user}-#{branch}"
abort "Error: #{user}'s fork is not available anymore" unless pull_data['head']['repository']
new_branch_name ||= "#{user}-#{branch}"
if remotes.include? user
args.before ['remote', 'set-branches', '--add', user, branch]
......@@ -323,7 +326,9 @@ module Hub
:https => https_protocol?)
args.before ['remote', 'add', '-f', '-t', branch, user, url]
end
args[1..-1] = ['-b', new_branch_name, "#{user}/#{branch}"]
idx = args.index url_arg
args.delete_at idx
args.insert idx, '--track', '-B', new_branch_name, "#{user}/#{branch}"
end
end
......
......@@ -947,8 +947,8 @@ class HubTest < Test::Unit::TestCase
to_return(:body => mock_pull_response('blueyed:feature'))
assert_commands 'git remote add -f -t feature blueyed git://github.com/blueyed/hub.git',
'git checkout -b blueyed-feature blueyed/feature',
"checkout https://github.com/defunkt/hub/pull/73/files"
'git checkout -f --track -B blueyed-feature blueyed/feature -q',
"checkout -f https://github.com/defunkt/hub/pull/73/files -q"
end
def test_checkout_private_pullrequest
......@@ -956,7 +956,7 @@ class HubTest < Test::Unit::TestCase
to_return(:body => mock_pull_response('blueyed:feature', :private))
assert_commands 'git remote add -f -t feature blueyed git@github.com:blueyed/hub.git',
'git checkout -b blueyed-feature blueyed/feature',
'git checkout --track -B blueyed-feature blueyed/feature',
"checkout https://github.com/defunkt/hub/pull/73/files"
end
......@@ -965,7 +965,7 @@ class HubTest < Test::Unit::TestCase
to_return(:body => mock_pull_response('blueyed:feature'))
assert_commands 'git remote add -f -t feature blueyed git://github.com/blueyed/hub.git',
'git checkout -b review blueyed/feature',
'git checkout --track -B review blueyed/feature',
"checkout https://github.com/defunkt/hub/pull/73/files review"
end
......@@ -977,7 +977,7 @@ class HubTest < Test::Unit::TestCase
assert_commands 'git remote set-branches --add blueyed feature',
'git fetch blueyed +refs/heads/feature:refs/remotes/blueyed/feature',
'git checkout -b blueyed-feature blueyed/feature',
'git checkout --track -B blueyed-feature blueyed/feature',
"checkout https://github.com/defunkt/hub/pull/73/files"
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册