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
This commit is contained in:
Mislav Marohnić 2012-10-10 13:59:45 +02:00
Родитель 7ab0d27ffa
Коммит 595b53c3ce
3 изменённых файлов: 52 добавлений и 16 удалений

Просмотреть файл

@ -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"

Просмотреть файл

@ -331,7 +331,7 @@ module Hub
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 @@ module Hub
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

Просмотреть файл

@ -74,8 +74,7 @@ class HubTest < Test::Unit::TestCase
@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 @@ class HubTest < Test::Unit::TestCase
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 @@ class HubTest < Test::Unit::TestCase
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)