fix `am` command when given URLs that include the fragment

This commit is contained in:
Mislav Marohnić 2012-01-28 19:58:52 +01:00
Родитель b6b51db5e6
Коммит d0a8e5ff0e
2 изменённых файлов: 5 добавлений и 3 удалений

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

@ -368,10 +368,12 @@ module Hub
if url = args.find { |a| a =~ %r{^https?://(gist\.)?github\.com/} }
idx = args.index(url)
gist = $1 == 'gist.'
# strip the fragment part of the url
url.sub!(/#.+/, '')
# strip extra path from "pull/42/files", "pull/42/commits"
url = url.sub(%r{(/pull/\d+)/\w*$}, '\1') unless gist
url.sub!(%r{(/pull/\d+)/\w*$}, '\1') unless gist
ext = gist ? '.txt' : '.patch'
url += ext unless File.extname(url) == ext
url << ext unless File.extname(url) == ext
patch_file = File.join(ENV['TMPDIR'] || '/tmp', "#{gist ? 'gist-' : ''}#{File.basename(url)}")
args.before 'curl', ['-#LA', "hub #{Hub::Version}", url, '-o', patch_file]
args[idx] = patch_file

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

@ -461,7 +461,7 @@ class HubTest < Test::Unit::TestCase
with_tmpdir('/tmp/') do
assert_commands "curl -#LA 'hub #{Hub::Version}' https://github.com/defunkt/hub/pull/55.patch -o /tmp/55.patch",
"git am --signoff /tmp/55.patch -p2",
"am --signoff https://github.com/defunkt/hub/pull/55 -p2"
"am --signoff https://github.com/defunkt/hub/pull/55#comment_123 -p2"
cmd = Hub("am https://github.com/defunkt/hub/pull/55/files").command
assert_includes '/pull/55.patch', cmd