From 6b7cf1094cc4a42f1d2c2ef49294431e509d880e Mon Sep 17 00:00:00 2001 From: ak47 Date: Wed, 24 Aug 2011 13:09:51 -0700 Subject: [PATCH 1/2] return p4_label if set --- lib/capistrano/recipes/deploy/scm/perforce.rb | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/capistrano/recipes/deploy/scm/perforce.rb b/lib/capistrano/recipes/deploy/scm/perforce.rb index 2e26d191..898e1513 100644 --- a/lib/capistrano/recipes/deploy/scm/perforce.rb +++ b/lib/capistrano/recipes/deploy/scm/perforce.rb @@ -1,9 +1,9 @@ require 'capistrano/recipes/deploy/scm/base' -# Notes: +# Notes: # no global verbose flag for scm_verbose # sync, checkout and export are just sync in p4 -# +# module Capistrano module Deploy module SCM @@ -27,7 +27,7 @@ module Capistrano def checkout(revision, destination) p4_sync(revision, destination, p4sync_flags) end - + # Returns the command that will sync the given revision to the given # destination directory. The perforce client has a fixed destination so # the files must be copied from there to their intended resting place. @@ -41,7 +41,7 @@ module Capistrano def export(revision, destination) p4_sync(revision, destination, p4sync_flags) end - + # Returns the command that will do an "p4 diff2" for the two revisions. def diff(from, to=head) scm authentication, :diff2, "-u -db", "//#{p4client}/...#{rev_no(from)}", "//#{p4client}/...#{rev_no(to)}" @@ -72,11 +72,11 @@ module Capistrano raise Capistrano::Error, "scm_password (or p4passwd) is incorrect or unset" when /Can.t create a new user.*/i raise Capistrano::Error, "scm_username (or p4user) is incorrect or unset" - when /Perforce client error\:/i + when /Perforce client error\:/i raise Capistrano::Error, "p4port is incorrect or unset" when /Client \'[\w\-\_\.]+\' unknown.*/i raise Capistrano::Error, "p4client is incorrect or unset" - end + end end private @@ -90,11 +90,11 @@ module Capistrano end # Returns the command that will sync the given revision to the given - # destination directory with specific options. The perforce client has - # a fixed destination so the files must be copied from there to their - # intended resting place. + # destination directory with specific options. The perforce client has + # a fixed destination so the files must be copied from there to their + # intended resting place. def p4_sync(revision, destination, options="") - scm authentication, :sync, options, "#{rev_no(revision)}", "&& cp -rf #{p4client_root} #{destination}" + scm authentication, :sync, options, "#{rev_no(revision)}", "&& cp -rf #{p4client_root} #{destination}" end def p4client @@ -108,7 +108,7 @@ module Capistrano def p4user variable(:p4user) || variable(:scm_username) end - + def p4passwd variable(:p4passwd) || variable(:scm_password) end @@ -120,16 +120,17 @@ module Capistrano def p4client_root variable(:p4client_root) || "`#{command} #{authentication} client -o | grep ^Root | cut -f2`" end - - def rev_no(revision) + + def rev_no(revision) + return "@#{variable(:p4_label)}" if variable(:p4_label) case revision.to_s when "head" "#head" - when /^\d+/ + when /^\d+/ "@#{revision}" else revision - end + end end end From cc0f601f86dd056aed18f6afa9369006c83beac6 Mon Sep 17 00:00:00 2001 From: ak47 Date: Thu, 25 Aug 2011 12:25:25 -0700 Subject: [PATCH 2/2] add some tests for the perforce.rb scm private method --- lib/capistrano/recipes/deploy/scm/perforce.rb | 10 +++++++- test/deploy/scm/perforce_test.rb | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/deploy/scm/perforce_test.rb diff --git a/lib/capistrano/recipes/deploy/scm/perforce.rb b/lib/capistrano/recipes/deploy/scm/perforce.rb index 898e1513..31c691c4 100644 --- a/lib/capistrano/recipes/deploy/scm/perforce.rb +++ b/lib/capistrano/recipes/deploy/scm/perforce.rb @@ -122,7 +122,15 @@ module Capistrano end def rev_no(revision) - return "@#{variable(:p4_label)}" if variable(:p4_label) + if variable(:p4_label) + p4_label = if variable(:p4_label) =~ /\A@/ + variable(:p4_label) + else + "@#{variable(:p4_label)}" + end + return p4_label + end + case revision.to_s when "head" "#head" diff --git a/test/deploy/scm/perforce_test.rb b/test/deploy/scm/perforce_test.rb new file mode 100644 index 00000000..2c796c85 --- /dev/null +++ b/test/deploy/scm/perforce_test.rb @@ -0,0 +1,23 @@ +require "utils" +require 'capistrano/recipes/deploy/scm/perforce' + +class DeploySCMPerforceTest < Test::Unit::TestCase + class TestSCM < Capistrano::Deploy::SCM::Perforce + default_command "perforce" + end + def setup + @config = { :repository => "." } + @source = TestSCM.new(@config) + end + + def test_p4_label + @config[:p4_label] = "some_p4_label" + assert_equal "@some_p4_label", @source.send(:rev_no, 'foo') + end + + def test_p4_label_with_symbol + @config[:p4_label] = "@some_p4_label" + assert_equal "@some_p4_label", @source.send(:rev_no, 'foo') + end + +end \ No newline at end of file