Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for expanding git revisions when passed from the command line #74

Merged
merged 2 commits into from

3 participants

@ndbroadbent

Capistrano didn't expand shortened revisions when they were passed on the command line, i.e. when rolling back code with cap deploy -s revision=d7e99f.
You needed to pass the whole 40 char revision since git ls-remote can't help with expanding a historical revision.
query_revision() now tries searching the local repository if a remote SHA cannot be obtained.
(git ls-remote is still tried first though, and still gets the latest master or HEAD from the remote server)

(tests included.)

ndbroadbent added some commits
@ndbroadbent ndbroadbent Capistrano cannot expand shortened revisions when they are passed on …
…the command line, i.e. when rolling back code with "cap deploy -s revision=d7e99f". You previously needed to pass the whole 40 char revision since "git ls-remote" can't help with expanding the revision from the remote server. query_revision() now tries searching the local repository first. This also speeds up a deployment since it can take a while to poll the remote server.
02de6c3
@ndbroadbent ndbroadbent Poll remote server first, then fall back to local repository to try a…
…nd expand a partial SHA
b3ec819
@leehambley
Owner
@ndbroadbent
@leehambley leehambley merged commit 7ec98d0 into capistrano:master
@nilbus

Thanks for this change! We were having trouble trying to deploy from a dev machine inside a VPN that didn't have access to our git repo (even though the deploy target did). This should take care of that for us. :-)

No worries, I'm glad you found it useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 5, 2011
  1. @ndbroadbent

    Capistrano cannot expand shortened revisions when they are passed on …

    ndbroadbent authored
    …the command line, i.e. when rolling back code with "cap deploy -s revision=d7e99f". You previously needed to pass the whole 40 char revision since "git ls-remote" can't help with expanding the revision from the remote server. query_revision() now tries searching the local repository first. This also speeds up a deployment since it can take a while to poll the remote server.
  2. @ndbroadbent
This page is out of date. Refresh to see the latest.
View
7 lib/capistrano/recipes/deploy/scm/git.rb
@@ -232,6 +232,12 @@ def query_revision(revision)
break
end
end
+ return newrev if newrev =~ /^[0-9a-f]{40}$/
+
+ # If sha is not found on remote, try expanding from local repository
+ command = scm('rev-parse --revs-only', revision)
+ newrev = yield(command).to_s.strip
+
raise "Unable to resolve revision for '#{revision}' on repository '#{repository}'." unless newrev =~ /^[0-9a-f]{40}$/
return newrev
end
@@ -280,3 +286,4 @@ def verbose
end
end
end
+
View
14 test/deploy/scm/git_test.rb
@@ -15,7 +15,7 @@ def @config.exists?(name); key?(name); end
def test_head
assert_equal "HEAD", @source.head
-
+
# With :branch
@config[:branch] = "master"
assert_equal "master", @source.head
@@ -61,7 +61,7 @@ def test_log
assert_equal "git log master..branch", @source.log('master', 'branch')
end
- def test_query_revision
+ def test_query_revision_from_remote
revision = @source.query_revision('HEAD') do |o|
assert_equal "git ls-remote . HEAD", o
"d11006102c07c94e5d54dd0ee63dca825c93ed61\tHEAD"
@@ -69,6 +69,15 @@ def test_query_revision
assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
end
+ def test_query_revision_falls_back_to_local
+ revision = @source.query_revision('d11006') do |o|
+ return nil if o == "git ls-remote . d11006"
+ assert_equal "git rev-parse --revs-only d11006", o
+ "d11006102c07c94e5d54dd0ee63dca825c93ed61"
+ end
+ assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
+ end
+
def test_query_revision_has_whitespace
revision = @source.query_revision('HEAD') do |o|
assert_equal "git ls-remote . HEAD", o
@@ -182,3 +191,4 @@ def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
assert_equal "/foo/bar/git", @source.command
end
end
+
Something went wrong with that request. Please try again.