提交 595b53c3 编写于 作者: M Mislav Marohnić

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
上级 7ab0d27f
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 ...@@ -331,7 +331,7 @@ module Hub
end end
def project def project
urls.each { |url| urls.each_value { |url|
if valid = GithubProject.from_url(url, local_repo) if valid = GithubProject.from_url(url, local_repo)
return valid return valid
end end
...@@ -340,15 +340,21 @@ module Hub ...@@ -340,15 +340,21 @@ module Hub
end end
def urls def urls
@urls ||= local_repo.git_config("remote.#{name}.url", :all).to_s.split("\n").map { |uri| return @urls if defined? @urls
begin @urls = {}
if uri =~ %r{^[\w-]+://} then uri_parse(uri) local_repo.git_command('remote -v').to_s.split("\n").map do |line|
elsif uri =~ %r{^([^/]+?):} then uri_parse("ssh://#{$1}/#{$'}") # scp-like syntax 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 end
rescue URI::InvalidURIError
nil
end end
}.compact end
@urls
end end
def uri_parse uri def uri_parse uri
......
...@@ -74,8 +74,7 @@ class HubTest < Test::Unit::TestCase ...@@ -74,8 +74,7 @@ class HubTest < Test::Unit::TestCase
@git_reader.stub! \ @git_reader.stub! \
'remote' => "mislav\norigin", 'remote' => "mislav\norigin",
'symbolic-ref -q HEAD' => 'refs/heads/master', 'symbolic-ref -q HEAD' => 'refs/heads/master',
'config --get-all remote.origin.url' => 'git://github.com/defunkt/hub.git', 'remote -v' => "origin\tgit://github.com/defunkt/hub.git (fetch)\nmislav\tgit://github.com/mislav/hub.git (fetch)",
'config --get-all remote.mislav.url' => 'git://github.com/mislav/hub.git',
'rev-parse --symbolic-full-name master@{upstream}' => 'refs/remotes/origin/master', 'rev-parse --symbolic-full-name master@{upstream}' => 'refs/remotes/origin/master',
'config --get --bool hub.http-clone' => 'false', 'config --get --bool hub.http-clone' => 'false',
'config --get hub.protocol' => nil, 'config --get hub.protocol' => nil,
...@@ -641,11 +640,6 @@ class HubTest < Test::Unit::TestCase ...@@ -641,11 +640,6 @@ class HubTest < Test::Unit::TestCase
assert_forwarded 'name' assert_forwarded 'name'
end 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 def test_global_flags_preserved
cmd = '--no-pager --bare -c core.awesome=true -c name=value --git-dir=/srv/www perform' 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' 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 ...@@ -655,7 +649,7 @@ class HubTest < Test::Unit::TestCase
private private
def stub_repo_url(value, remote_name = 'origin') 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 end
def stub_branch(value) def stub_branch(value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册