From e4ad58d0c748f35c6a829fbb6718736724a0eb49 Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Thu, 2 Jun 2011 13:41:11 -0700 Subject: [PATCH] teach `hub apply` about GitHub URLs, same as `hub am` --- lib/hub/commands.rb | 5 +++++ test/hub_test.rb | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 59773f77..50045ca4 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -254,6 +254,11 @@ module Hub end end + # $ hub apply https://github.com/defunkt/hub/pull/55 + # > curl https://github.com/defunkt/hub/pull/55.patch -o /tmp/55.patch + # > git apply /tmp/55.patch + alias_method :apply, :am + # $ hub init -g # > git init # > git remote add origin git@github.com:USER/REPO.git diff --git a/test/hub_test.rb b/test/hub_test.rb index 0e847d1a..2892c621 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -387,6 +387,41 @@ class HubTest < Test::Unit::TestCase end end + def test_apply_untouched + assert_forwarded "apply some.patch" + end + + def test_apply_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 apply /tmp/55.patch -p2", + "apply https://github.com/defunkt/hub/pull/55 -p2" + + cmd = Hub("apply https://github.com/defunkt/hub/pull/55/files").command + assert_includes '/pull/55.patch', cmd + end + end + + def test_apply_commit_url + with_tmpdir('/tmp/') do + url = 'https://github.com/davidbalbert/hub/commit/fdb9921' + + assert_commands "curl -#LA 'hub #{Hub::Version}' #{url}.patch -o /tmp/fdb9921.patch", + "git apply /tmp/fdb9921.patch -p2", + "apply #{url} -p2" + end + end + + def test_apply_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 apply /tmp/gist-8da7fb575debd88c54cf.txt -p2", + "apply #{url} -p2" + end + end + def test_init assert_commands "git init", "git remote add origin git@github.com:tpw/hub.git", "init -g" end -- GitLab