Skip to content
Browse files

Merge pull request #74 from ndbroadbent/parse_local_revisions

Fix for expanding Git revisions when passed from the command line.
  • Loading branch information...
2 parents 53af42b + b3ec819 commit 7ec98d08115d73b29870227a7c5061fdd8e99b47 @leehambley leehambley committed Sep 20, 2011
Showing with 19 additions and 2 deletions.
  1. +7 −0 lib/capistrano/recipes/deploy/scm/git.rb
  2. +12 −2 test/deploy/scm/git_test.rb
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,14 +61,23 @@ 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"
end
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
+

0 comments on commit 7ec98d0

Please sign in to comment.
Something went wrong with that request. Please try again.