Permalink
Browse files

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

  • Loading branch information...
1 parent b6b51db commit d0a8e5ff0ead3ea5de09e8d95b7a62d83c5f53f2 @mislav mislav committed Jan 28, 2012
Showing with 5 additions and 3 deletions.
  1. +4 −2 lib/hub/commands.rb
  2. +1 −1 test/hub_test.rb
View
6 lib/hub/commands.rb
@@ -368,10 +368,12 @@ def am(args)
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
View
2 test/hub_test.rb
@@ -461,7 +461,7 @@ def test_am_pull_request
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

0 comments on commit d0a8e5f

Please sign in to comment.