Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

read remotes URLs with `remote -v` instead of git-config

When reading config, "insteadOf" substitution rules aren't applied.
Using `git remote -v` is better because it reports the URLs that would
actually be used by git.

This reverts the feature that supports detecting the GitHub URL among
multiple others made for #59. If you have multiple URLs configured for
the same remote, put the GitHub one first and you'll be fine.

Fixes #241
  • Loading branch information...
commit 595b53c3ce9e09af5210a4a5bfe721dd5358c4ed 1 parent 7ab0d27
@mislav mislav authored
View
36 features/pull_request.feature
@@ -0,0 +1,36 @@
+Feature: hub pull-request
+ Background:
+ Given I am in "dotfiles" git repo
+ And I am "mislav" on github.com with OAuth token "OTOKEN"
+
+ Scenario: Non-GitHub repo
+ Given the "origin" remote has url "mygh:Manganeez/repo.git"
+ When I run `hub pull-request`
+ Then the stderr should contain "Aborted: the origin remote doesn't point to a GitHub repository.\n"
+ And the exit status should be 1
+
+ Scenario: Create pull request respecting "insteadOf" configuration
+ Given the "origin" remote has url "mygh:Manganeez/repo.git"
+ When I successfully run `git config url."git@github.com:".insteadOf mygh:`
+ Given the GitHub API server:
+ """
+ post('/repos/Manganeez/repo/pulls') {
+ { :base => 'master',
+ :head => 'mislav:master',
+ :title => 'hereyougo'
+ }.each do |param, value|
+ if params[param] != value
+ halt 422, json(
+ :message => "expected %s to be %s; got %s" % [
+ param.inspect,
+ value.inspect,
+ params[param].inspect
+ ]
+ )
+ end
+ end
+ json :html_url => "https://github.com/Manganeez/repo/pull/12"
+ }
+ """
+ When I successfully run `hub pull-request hereyougo`
+ Then the output should contain exactly "https://github.com/Manganeez/repo/pull/12\n"
View
22 lib/hub/context.rb
@@ -331,7 +331,7 @@ def ==(other)
end
def project
- urls.each { |url|
+ urls.each_value { |url|
if valid = GithubProject.from_url(url, local_repo)
return valid
end
@@ -340,15 +340,21 @@ def project
end
def urls
- @urls ||= local_repo.git_config("remote.#{name}.url", :all).to_s.split("\n").map { |uri|
- begin
- if uri =~ %r{^[\w-]+://} then uri_parse(uri)
- elsif uri =~ %r{^([^/]+?):} then uri_parse("ssh://#{$1}/#{$'}") # scp-like syntax
+ return @urls if defined? @urls
+ @urls = {}
+ local_repo.git_command('remote -v').to_s.split("\n").map do |line|
+ next if line !~ /^(.+?)\t(.+) \((.+)\)$/
+ remote, uri, type = $1, $2, $3
+ next if remote != self.name
+ if uri =~ %r{^[\w-]+://} or uri =~ %r{^([^/]+?):}
+ uri = "ssh://#{$1}/#{$'}" if $1
+ begin
+ @urls[type] = uri_parse(uri)
+ rescue URI::InvalidURIError
end
- rescue URI::InvalidURIError
- nil
end
- }.compact
+ end
+ @urls
end
def uri_parse uri
View
10 test/hub_test.rb
@@ -74,8 +74,7 @@ def setup
@git_reader.stub! \
'remote' => "mislav\norigin",
'symbolic-ref -q HEAD' => 'refs/heads/master',
- 'config --get-all remote.origin.url' => 'git://github.com/defunkt/hub.git',
- 'config --get-all remote.mislav.url' => 'git://github.com/mislav/hub.git',
+ 'remote -v' => "origin\tgit://github.com/defunkt/hub.git (fetch)\nmislav\tgit://github.com/mislav/hub.git (fetch)",
'rev-parse --symbolic-full-name master@{upstream}' => 'refs/remotes/origin/master',
'config --get --bool hub.http-clone' => 'false',
'config --get hub.protocol' => nil,
@@ -641,11 +640,6 @@ def test_not_choking_on_ruby_methods
assert_forwarded 'name'
end
- def test_multiple_remote_urls
- stub_repo_url("git://example.com/other.git\ngit://github.com/my/repo.git")
- assert_command "browse", "open https://github.com/my/repo"
- end
-
def test_global_flags_preserved
cmd = '--no-pager --bare -c core.awesome=true -c name=value --git-dir=/srv/www perform'
assert_command cmd, 'git --bare -c core.awesome=true -c name=value --git-dir=/srv/www --no-pager perform'
@@ -655,7 +649,7 @@ def test_global_flags_preserved
private
def stub_repo_url(value, remote_name = 'origin')
- stub_config_value "remote.#{remote_name}.url", value, '--get-all'
+ stub_command_output 'remote -v', "#{remote_name}\t#{value} (fetch)"
end
def stub_branch(value)
Please sign in to comment.
Something went wrong with that request. Please try again.