提交 166aaccd 编写于 作者: M Mislav Marohnić

`git am` can now also apply patches from Gists

上级 5b60c3de
......@@ -217,10 +217,12 @@ module Hub
# > curl https://github.com/defunkt/hub/pull/55.patch -o /tmp/55.patch
# > git am /tmp/55.patch
def am(args)
if url = args.find { |a| a =~ %r{^https?://github\.com/} }
if url = args.find { |a| a =~ %r{^https?://(gist\.)?github\.com/} }
idx = args.index(url)
url += '.patch' unless File.extname(url) == '.patch'
patch_file = File.join(ENV['TMPDIR'], File.basename(url))
gist = $1 == 'gist.'
ext = gist ? '.txt' : '.patch'
url += ext unless File.extname(url) == ext
patch_file = File.join(ENV['TMPDIR'], "#{gist ? 'gist-' : ''}#{File.basename(url)}")
args.before 'curl', ['-#LA', "hub #{Hub::Version}", url, '-o', patch_file]
args[idx] = patch_file
end
......
......@@ -352,6 +352,16 @@ class HubTest < Test::Unit::TestCase
end
end
def test_am_gist
with_tmpdir('/tmp/') do
url = 'https://gist.github.com/8da7fb575debd88c54cf'
assert_commands "curl -#LA 'hub #{Hub::Version}' #{url}.txt -o /tmp/gist-8da7fb575debd88c54cf.txt",
"git am --signoff /tmp/gist-8da7fb575debd88c54cf.txt -p2",
"am --signoff #{url} -p2"
end
end
def test_init
assert_commands "git init", "git remote add origin git@github.com:tpw/hub.git", "init -g"
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册