Permalink
Browse files

fix enterprise pull request when no upstream branch

Closes #123
  • Loading branch information...
1 parent fd71d60 commit a579aef12883d63321035e4419413a69df17d6ea @mislav mislav committed Dec 25, 2011
Showing with 24 additions and 4 deletions.
  1. +1 −0 HISTORY.md
  2. +4 −2 lib/hub/commands.rb
  3. +19 −2 test/hub_test.rb
View
1 HISTORY.md
@@ -1,5 +1,6 @@
## master
+* fix `pull-request` on GH Enterprise project branch without upstream
* ensure Content-Length for POST requests
* handle pull requests from private repos
* support branches with slashes in their name
View
6 lib/hub/commands.rb
@@ -116,8 +116,10 @@ def pull_request(args)
end
options[:head] ||= (tracked_branch || current_branch).short_name
- if head_project.owner != github_user and !tracked_branch and !explicit_owner
- head_project = github_project(head_project.name, github_user)
+ # when no tracking, assume remote branch is published under active user's fork
+ user = github_user(true, head_project.host)
+ if head_project.owner != user and !tracked_branch and !explicit_owner
+ head_project = head_project.owned_by(user)
end
remote_branch = "#{head_project.remote}/#{options[:head]}"
View
21 test/hub_test.rb
@@ -839,6 +839,23 @@ def test_pullrequest_from_tracking_branch
assert_output expected, "pull-request hereyougo -f"
end
+ def test_pullrequest_enterprise_no_tracking
+ stub_hub_host('git.my.org')
+ stub_repo_url('git@git.my.org:defunkt/hub.git')
+ stub_github_user('myfiname', 'git.my.org')
+ stub_github_token('789xyz', 'git.my.org')
+ stub_branch('refs/heads/feature')
+ stub_tracking_nothing('feature')
+ stub_command_output "rev-list --cherry origin/feature...", nil
+
+ stub_request(:post, "https://#{auth('myfiname', '789xyz')}git.my.org/api/v2/json/pulls/defunkt/hub").
+ with(:body => { 'pull' => {'base' => "master", 'head' => "myfiname:feature", 'title' => "hereyougo"} }).
+ to_return(:body => mock_pullreq_response(1, 'defunkt/hub', 'git.my.org'))
+
+ expected = "https://git.my.org/defunkt/hub/pull/1\n"
+ assert_output expected, "pull-request hereyougo -f"
+ end
+
def test_pullrequest_explicit_head
stub_request(:post, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub").
with(:body => { 'pull' => {'base' => "master", 'head' => "tpw:yay-feature", 'title' => "hereyougo"} }).
@@ -1344,8 +1361,8 @@ def auth(user = git_config('github.user'), password = git_config('github.token')
"#{user}%2Ftoken:#{password}@"
end
- def mock_pullreq_response(id, name_with_owner = 'defunkt/hub')
- %({"pull": { "html_url": "https://github.com/#{name_with_owner}/pull/#{id}" }})
+ def mock_pullreq_response(id, name_with_owner = 'defunkt/hub', host = 'github.com')
+ %({"pull": { "html_url": "https://#{host}/#{name_with_owner}/pull/#{id}" }})
end
def mock_pull_response(label, priv = false)

0 comments on commit a579aef

Please sign in to comment.