Skip to content
Browse files

update git query_revision strategy

  • Loading branch information...
1 parent 96cb5ab commit dd7a4928af356902975aed0382f4e652d20ff48f grantr committed with jamis
Showing with 13 additions and 4 deletions.
  1. +2 −0 CHANGELOG.rdoc
  2. +10 −3 lib/capistrano/recipes/deploy/scm/git.rb
  3. +1 −1 test/deploy/scm/git_test.rb
View
2 CHANGELOG.rdoc
@@ -1,5 +1,7 @@
== (unreleased)
+* Make sure git query-revision matches on exact branch name [grant@nightriot.com]
+
* Use -T <arg> to filter listed tasks by namespace [Mathias Meyer]
* Expose the #scm method on SCM::Base for building custom scm commands [Mathias Meyer]
View
13 lib/capistrano/recipes/deploy/scm/git.rb
@@ -210,10 +210,17 @@ def log(from, to=nil)
def query_revision(revision)
raise ArgumentError, "Deploying remote branches has been deprecated. Specify the remote branch as a local branch for the git repository you're deploying from (ie: '#{revision.gsub('origin/', '')}' rather than '#{revision}')." if revision =~ /^origin\//
return revision if revision =~ /^[0-9a-f]{40}$/
- command = scm('ls-remote', repository, revision)
+ command = scm('ls-remote -h -t', repository, revision)
result = yield(command)
- revdata = result.split("\t")
- newrev = revdata[0]
+ revdata = result.split(/[\t\n]/)
+ newrev = nil
+ revdata.each_slice(2) do |refs|
+ rev, ref = *refs
+ if ref.sub(/refs\/.*?\//, '') == revision
+ newrev = rev
+ break
+ end
+ end
raise "Unable to resolve revision for '#{revision}' on repository '#{repository}'." unless newrev =~ /^[0-9a-f]{40}$/
return newrev
end
View
2 test/deploy/scm/git_test.rb
@@ -59,7 +59,7 @@ def test_log
def test_query_revision
revision = @source.query_revision('HEAD') do |o|
- assert_equal "git ls-remote . HEAD", o
+ assert_equal "git ls-remote -h -t . HEAD", o
"d11006102c07c94e5d54dd0ee63dca825c93ed61\tHEAD"
end
assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision

0 comments on commit dd7a492

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