capistrano 2.0.0 → 2.15.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG +755 -18
  5. data/Gemfile +13 -0
  6. data/README.md +94 -0
  7. data/Rakefile +11 -0
  8. data/bin/cap +0 -0
  9. data/bin/capify +37 -22
  10. data/capistrano.gemspec +40 -0
  11. data/lib/capistrano/callback.rb +5 -1
  12. data/lib/capistrano/cli/execute.rb +10 -7
  13. data/lib/capistrano/cli/help.rb +39 -16
  14. data/lib/capistrano/cli/help.txt +44 -16
  15. data/lib/capistrano/cli/options.rb +71 -11
  16. data/lib/capistrano/cli/ui.rb +13 -1
  17. data/lib/capistrano/cli.rb +5 -5
  18. data/lib/capistrano/command.rb +215 -58
  19. data/lib/capistrano/configuration/actions/file_transfer.rb +29 -14
  20. data/lib/capistrano/configuration/actions/inspect.rb +3 -3
  21. data/lib/capistrano/configuration/actions/invocation.rb +224 -22
  22. data/lib/capistrano/configuration/alias_task.rb +26 -0
  23. data/lib/capistrano/configuration/callbacks.rb +26 -27
  24. data/lib/capistrano/configuration/connections.rb +130 -52
  25. data/lib/capistrano/configuration/execution.rb +34 -18
  26. data/lib/capistrano/configuration/loading.rb +99 -6
  27. data/lib/capistrano/configuration/log_formatters.rb +75 -0
  28. data/lib/capistrano/configuration/namespaces.rb +45 -12
  29. data/lib/capistrano/configuration/roles.rb +34 -2
  30. data/lib/capistrano/configuration/servers.rb +51 -10
  31. data/lib/capistrano/configuration/variables.rb +3 -3
  32. data/lib/capistrano/configuration.rb +20 -4
  33. data/lib/capistrano/errors.rb +12 -8
  34. data/lib/capistrano/ext/multistage.rb +67 -0
  35. data/lib/capistrano/ext/string.rb +5 -0
  36. data/lib/capistrano/extensions.rb +1 -1
  37. data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
  38. data/lib/capistrano/logger.rb +112 -5
  39. data/lib/capistrano/processable.rb +55 -0
  40. data/lib/capistrano/recipes/compat.rb +2 -2
  41. data/lib/capistrano/recipes/deploy/assets.rb +202 -0
  42. data/lib/capistrano/recipes/deploy/dependencies.rb +2 -2
  43. data/lib/capistrano/recipes/deploy/local_dependency.rb +10 -2
  44. data/lib/capistrano/recipes/deploy/remote_dependency.rb +54 -2
  45. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  46. data/lib/capistrano/recipes/deploy/scm/base.rb +31 -11
  47. data/lib/capistrano/recipes/deploy/scm/bzr.rb +14 -14
  48. data/lib/capistrano/recipes/deploy/scm/cvs.rb +11 -9
  49. data/lib/capistrano/recipes/deploy/scm/darcs.rb +12 -1
  50. data/lib/capistrano/recipes/deploy/scm/git.rb +299 -0
  51. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +23 -15
  52. data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
  53. data/lib/capistrano/recipes/deploy/scm/perforce.rb +54 -28
  54. data/lib/capistrano/recipes/deploy/scm/subversion.rb +36 -18
  55. data/lib/capistrano/recipes/deploy/scm.rb +1 -1
  56. data/lib/capistrano/recipes/deploy/strategy/base.rb +32 -4
  57. data/lib/capistrano/recipes/deploy/strategy/copy.rb +238 -43
  58. data/lib/capistrano/recipes/deploy/strategy/remote.rb +1 -1
  59. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +11 -1
  60. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
  61. data/lib/capistrano/recipes/deploy/strategy.rb +4 -3
  62. data/lib/capistrano/recipes/deploy.rb +265 -123
  63. data/lib/capistrano/recipes/standard.rb +1 -1
  64. data/lib/capistrano/role.rb +102 -0
  65. data/lib/capistrano/server_definition.rb +6 -1
  66. data/lib/capistrano/shell.rb +30 -33
  67. data/lib/capistrano/ssh.rb +46 -60
  68. data/lib/capistrano/task_definition.rb +16 -8
  69. data/lib/capistrano/transfer.rb +218 -0
  70. data/lib/capistrano/version.rb +8 -17
  71. data/lib/capistrano.rb +4 -1
  72. data/test/cli/execute_test.rb +3 -3
  73. data/test/cli/help_test.rb +33 -7
  74. data/test/cli/options_test.rb +109 -6
  75. data/test/cli/ui_test.rb +2 -2
  76. data/test/cli_test.rb +3 -3
  77. data/test/command_test.rb +144 -124
  78. data/test/configuration/actions/file_transfer_test.rb +41 -20
  79. data/test/configuration/actions/inspect_test.rb +21 -7
  80. data/test/configuration/actions/invocation_test.rb +141 -30
  81. data/test/configuration/alias_task_test.rb +118 -0
  82. data/test/configuration/callbacks_test.rb +41 -46
  83. data/test/configuration/connections_test.rb +187 -36
  84. data/test/configuration/execution_test.rb +18 -2
  85. data/test/configuration/loading_test.rb +33 -4
  86. data/test/configuration/namespace_dsl_test.rb +54 -5
  87. data/test/configuration/roles_test.rb +114 -4
  88. data/test/configuration/servers_test.rb +97 -4
  89. data/test/configuration/variables_test.rb +12 -2
  90. data/test/configuration_test.rb +9 -13
  91. data/test/deploy/local_dependency_test.rb +76 -0
  92. data/test/deploy/remote_dependency_test.rb +146 -0
  93. data/test/deploy/scm/accurev_test.rb +23 -0
  94. data/test/deploy/scm/base_test.rb +1 -1
  95. data/test/deploy/scm/bzr_test.rb +51 -0
  96. data/test/deploy/scm/darcs_test.rb +37 -0
  97. data/test/deploy/scm/git_test.rb +274 -0
  98. data/test/deploy/scm/mercurial_test.rb +134 -0
  99. data/test/deploy/scm/none_test.rb +35 -0
  100. data/test/deploy/scm/perforce_test.rb +23 -0
  101. data/test/deploy/scm/subversion_test.rb +68 -0
  102. data/test/deploy/strategy/copy_test.rb +240 -26
  103. data/test/extensions_test.rb +2 -2
  104. data/test/logger_formatting_test.rb +149 -0
  105. data/test/logger_test.rb +13 -2
  106. data/test/recipes_test.rb +25 -0
  107. data/test/role_test.rb +11 -0
  108. data/test/server_definition_test.rb +15 -2
  109. data/test/shell_test.rb +33 -1
  110. data/test/ssh_test.rb +40 -24
  111. data/test/task_definition_test.rb +18 -2
  112. data/test/transfer_test.rb +168 -0
  113. data/test/utils.rb +28 -33
  114. data/test/version_test.rb +4 -17
  115. metadata +215 -100
  116. data/MIT-LICENSE +0 -20
  117. data/README +0 -43
  118. data/examples/sample.rb +0 -14
  119. data/lib/capistrano/gateway.rb +0 -131
  120. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
  121. data/lib/capistrano/recipes/upgrade.rb +0 -33
  122. data/lib/capistrano/upload.rb +0 -146
  123. data/test/gateway_test.rb +0 -167
  124. data/test/upload_test.rb +0 -131
@@ -0,0 +1,37 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/darcs'
3
+
4
+ class DeploySCMDarcsTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Darcs
6
+ default_command "darcs"
7
+ end
8
+ def setup
9
+ @config = { :repository => "." }
10
+ # def @config.exists?(name); key?(name); end
11
+
12
+ @source = TestSCM.new(@config)
13
+ end
14
+
15
+ # We should be able to pick a specific hash.
16
+ def test_checkout_hash
17
+ hsh = "*version_hash*"
18
+ assert_match(%r{--to-match=.hash #{Regexp.quote(hsh)}},
19
+ @source.checkout(hsh, "*foo_location*"),
20
+ "Specifying a revision hash got the --to-match option wrong.")
21
+ end
22
+
23
+ # Picking the head revision should leave out the hash, because head is the
24
+ # default and we don't have a HEAD pseudotag
25
+ def test_checkout_head
26
+ hsh = @source.head
27
+ assert_no_match(%r{--to-match}, @source.checkout(hsh, "*foo_location*"),
28
+ "Selecting the head revision incorrectly produced a --to-match option.")
29
+ end
30
+
31
+ # Leaving the revision as nil shouldn't break anything.
32
+ def test_checkout_nil
33
+ assert_no_match(%r{--to-match}, @source.checkout(nil, "*foo_location*"),
34
+ "Leaving the revision as nil incorrectly produced a --to-match option.")
35
+ end
36
+ end
37
+
@@ -0,0 +1,274 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/git'
3
+
4
+ class DeploySCMGitTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Git
6
+ default_command "git"
7
+ end
8
+
9
+ def setup
10
+ @config = { :repository => "." }
11
+ def @config.exists?(name); key?(name); end
12
+
13
+ @source = TestSCM.new(@config)
14
+ end
15
+
16
+ def test_head
17
+ assert_equal "HEAD", @source.head
18
+
19
+ # With :branch
20
+ @config[:branch] = "master"
21
+ assert_equal "master", @source.head
22
+ end
23
+
24
+ def test_origin
25
+ assert_equal "origin", @source.origin
26
+ @config[:remote] = "username"
27
+ assert_equal "username", @source.origin
28
+ end
29
+
30
+ def test_checkout
31
+ @config[:repository] = "git@somehost.com:project.git"
32
+ dest = "/var/www"
33
+ rev = 'c2d9e79'
34
+ assert_equal "git clone -q git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
35
+
36
+ # With :scm_command
37
+ git = "/opt/local/bin/git"
38
+ @config[:scm_command] = git
39
+ assert_equal "#{git} clone -q git@somehost.com:project.git /var/www && cd /var/www && #{git} checkout -q -b deploy #{rev}", @source.checkout(rev, dest).gsub(/\s+/, ' ')
40
+
41
+ # with submodules
42
+ @config[:git_enable_submodules] = true
43
+ assert_equal "#{git} clone -q git@somehost.com:project.git /var/www && cd /var/www && #{git} checkout -q -b deploy #{rev} && #{git} submodule -q init && #{git} submodule -q sync && export GIT_RECURSIVE=$([ ! \"`#{git} --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && #{git} submodule -q update --init $GIT_RECURSIVE", @source.checkout(rev, dest).gsub(/\s+/, ' ')
44
+ end
45
+
46
+ def test_checkout_branching
47
+ @config[:repository] = "git@somehost.com:project.git"
48
+ dest = "/var/www"
49
+ rev = 'c2d9e79'
50
+ assert_equal "git clone -q git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy c2d9e79", @source.checkout(rev, dest)
51
+
52
+ # with :branch
53
+ @config[:branch] = "master"
54
+ assert_equal "git clone -q -b master git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy c2d9e79", @source.checkout(rev, dest)
55
+
56
+ # with :branch with hash code
57
+ @config[:branch] = "c2d9e79"
58
+ assert_equal "git clone -q git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy c2d9e79", @source.checkout(rev, dest)
59
+ end
60
+
61
+ def test_checkout_submodules_without_recursive
62
+ @config[:repository] = "git@somehost.com:project.git"
63
+ dest = "/var/www"
64
+ rev = 'c2d9e79'
65
+ @config[:git_enable_submodules] = true
66
+ @config[:git_submodules_recursive] = false
67
+ assert_equal "git clone -q git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev} && git submodule -q init && git submodule -q sync && git submodule -q update --init", @source.checkout(rev, dest).gsub(/\s+/, ' ')
68
+ end
69
+
70
+ def test_checkout_with_verbose_should_not_use_q_switch
71
+ @config[:repository] = "git@somehost.com:project.git"
72
+ @config[:scm_verbose] = true
73
+ dest = "/var/www"
74
+ rev = 'c2d9e79'
75
+ assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest)
76
+ end
77
+
78
+ def test_checkout_with_verbose_off_should_use_q_switch
79
+ @config[:repository] = "git@somehost.com:project.git"
80
+ @config[:scm_verbose] = false
81
+ dest = "/var/www"
82
+ rev = 'c2d9e79'
83
+ assert_equal "git clone -q git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
84
+ end
85
+
86
+ def test_diff
87
+ assert_equal "git diff master", @source.diff('master')
88
+ assert_equal "git diff master..branch", @source.diff('master', 'branch')
89
+ end
90
+
91
+ def test_log
92
+ assert_equal "git log master..", @source.log('master')
93
+ assert_equal "git log master..branch", @source.log('master', 'branch')
94
+ end
95
+
96
+ def test_query_revision_from_remote
97
+ revision = @source.query_revision('HEAD') do |o|
98
+ assert_equal "git ls-remote . HEAD", o
99
+ "d11006102c07c94e5d54dd0ee63dca825c93ed61\tHEAD"
100
+ end
101
+ assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
102
+ end
103
+
104
+ def test_query_revision_falls_back_to_local
105
+ revision = @source.query_revision('d11006') do |o|
106
+ return nil if o == "git ls-remote . d11006"
107
+ assert_equal "git rev-parse --revs-only d11006", o
108
+ "d11006102c07c94e5d54dd0ee63dca825c93ed61"
109
+ end
110
+ assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
111
+ end
112
+
113
+ def test_query_revision_has_whitespace
114
+ revision = @source.query_revision('HEAD') do |o|
115
+ assert_equal "git ls-remote . HEAD", o
116
+ "d11006102c07c94e5d54dd0ee63dca825c93ed61\tHEAD\r"
117
+ end
118
+ assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
119
+ end
120
+
121
+ def test_query_revision_deprecation_error
122
+ assert_raise(ArgumentError) do
123
+ revision = @source.query_revision('origin/release') {}
124
+ end
125
+ end
126
+
127
+ def test_command_should_be_backwards_compatible
128
+ # 1.x version of this module used ":git", not ":scm_command"
129
+ @config[:git] = "/srv/bin/git"
130
+ assert_equal "/srv/bin/git", @source.command
131
+ end
132
+
133
+ def test_sync
134
+ dest = "/var/www"
135
+ rev = 'c2d9e79'
136
+ assert_equal "cd #{dest} && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard #{rev} && git clean -q -d -x -f", @source.sync(rev, dest)
137
+
138
+ # With :scm_command
139
+ git = "/opt/local/bin/git"
140
+ @config[:scm_command] = git
141
+ assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} fetch --tags -q origin && #{git} reset -q --hard #{rev} && #{git} clean -q -d -x -f", @source.sync(rev, dest)
142
+
143
+ # with submodules
144
+ @config[:git_enable_submodules] = true
145
+ assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} fetch --tags -q origin && #{git} reset -q --hard #{rev} && #{git} submodule -q init && #{git} submodule -q sync && export GIT_RECURSIVE=$([ ! \"`#{git} --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && #{git} submodule -q update --init $GIT_RECURSIVE && #{git} clean -q -d -x -f", @source.sync(rev, dest)
146
+ end
147
+
148
+ def test_sync_with_remote
149
+ dest = "/var/www"
150
+ rev = 'c2d9e79'
151
+ remote = "username"
152
+ repository = "git@somehost.com:project.git"
153
+
154
+ @config[:repository] = repository
155
+ @config[:remote] = remote
156
+
157
+ assert_equal "cd #{dest} && git config remote.#{remote}.url #{repository} && git config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/* && git fetch -q #{remote} && git fetch --tags -q username && git reset -q --hard #{rev} && git clean -q -d -x -f", @source.sync(rev, dest)
158
+ end
159
+
160
+ def test_shallow_clone
161
+ @config[:repository] = "git@somehost.com:project.git"
162
+ @config[:git_shallow_clone] = 1
163
+ @config[:branch] = nil
164
+ dest = "/var/www"
165
+ rev = 'c2d9e79'
166
+ assert_equal "git clone -q --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
167
+ end
168
+
169
+ def test_shallow_clone_with_branch
170
+ @config[:repository] = "git@somehost.com:project.git"
171
+ @config[:git_shallow_clone] = 1
172
+ @config[:branch] = 'foobar'
173
+ dest = "/var/www"
174
+ rev = 'c2d9e79'
175
+ assert_equal "git clone -q -b foobar --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
176
+ end
177
+
178
+ def test_remote_clone
179
+ @config[:repository] = "git@somehost.com:project.git"
180
+ @config[:remote] = "username"
181
+ dest = "/var/www"
182
+ rev = 'c2d9e79'
183
+ assert_equal "git clone -q -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
184
+ end
185
+
186
+ def test_remote_clone_with_submodules
187
+ @config[:repository] = "git@somehost.com:project.git"
188
+ @config[:remote] = "username"
189
+ @config[:git_enable_submodules] = true
190
+ dest = "/var/www"
191
+ rev = 'c2d9e79'
192
+ assert_equal "git clone -q -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev} && git submodule -q init && git submodule -q sync && export GIT_RECURSIVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && git submodule -q update --init $GIT_RECURSIVE", @source.checkout(rev, dest)
193
+ end
194
+
195
+ # Tests from base_test.rb, makin' sure we didn't break anything up there!
196
+ def test_command_should_default_to_default_command
197
+ assert_equal "git", @source.command
198
+ @source.local { assert_equal "git", @source.command }
199
+ end
200
+
201
+ def test_command_should_use_scm_command_if_available
202
+ @config[:scm_command] = "/opt/local/bin/git"
203
+ assert_equal "/opt/local/bin/git", @source.command
204
+ end
205
+
206
+ def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
207
+ @config[:scm_command] = "/opt/local/bin/git"
208
+ @source.local { assert_equal "/opt/local/bin/git", @source.command }
209
+ end
210
+
211
+ def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
212
+ @config[:scm_command] = "/opt/local/bin/git"
213
+ @config[:local_scm_command] = "/usr/local/bin/git"
214
+ assert_equal "/opt/local/bin/git", @source.command
215
+ @source.local { assert_equal "/usr/local/bin/git", @source.command }
216
+ end
217
+
218
+ def test_command_should_use_default_if_scm_command_is_default
219
+ @config[:scm_command] = :default
220
+ assert_equal "git", @source.command
221
+ end
222
+
223
+ def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
224
+ @config[:scm_command] = "/foo/bar/git"
225
+ @config[:local_scm_command] = :default
226
+ @source.local { assert_equal "git", @source.command }
227
+ end
228
+
229
+ def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
230
+ @config[:scm_command] = "/foo/bar/git"
231
+ @config[:local_scm_command] = :default
232
+ assert_equal "git", @source.local.command
233
+ assert_equal "/foo/bar/git", @source.command
234
+ end
235
+
236
+ def test_sends_password_if_set
237
+ require 'capistrano/logger'
238
+ text = "password:"
239
+ @config[:scm_password] = "opensesame"
240
+ assert_equal %("opensesame"\n), @source.handle_data(mock_state, :test_stream, text)
241
+ end
242
+
243
+ def test_prompt_password
244
+ require 'capistrano/logger'
245
+ require 'capistrano/cli'
246
+ Capistrano::CLI.stubs(:password_prompt).returns("opensesame")
247
+
248
+ text = 'password:'
249
+ assert_equal %("opensesame"\n), @source.handle_data(mock_state, :test_stream, text)
250
+ end
251
+
252
+ def test_sends_passphrase_if_set
253
+ require 'capistrano/logger'
254
+ text = "passphrase:"
255
+ @config[:scm_passphrase] = "opensesame"
256
+ assert_equal %("opensesame"\n), @source.handle_data(mock_state, :test_stream, text)
257
+ end
258
+
259
+ def test_prompt_passphrase
260
+ require 'capistrano/logger'
261
+ require 'capistrano/cli'
262
+ Capistrano::CLI.stubs(:password_prompt).returns("opensesame")
263
+
264
+ text = 'passphrase:'
265
+ assert_equal %("opensesame"\n), @source.handle_data(mock_state, :test_stream, text)
266
+ end
267
+
268
+ private
269
+
270
+ def mock_state
271
+ { :channel => { :host => "abc" } }
272
+ end
273
+ end
274
+
@@ -0,0 +1,134 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/mercurial'
3
+
4
+ class DeploySCMMercurialTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Mercurial
6
+ default_command "hg"
7
+ end
8
+
9
+ def setup
10
+ @config = { }
11
+ def @config.exists?(name); key?(name); end
12
+
13
+ @source = TestSCM.new(@config)
14
+ end
15
+
16
+ def test_head
17
+ assert_equal "tip", @source.head
18
+ end
19
+
20
+ def test_different_head
21
+ @config[:branch] = "staging"
22
+ assert_equal "staging", @source.head
23
+ end
24
+
25
+ def test_checkout
26
+ @config[:repository] = "http://example.com/project-hg"
27
+ dest = "/var/www"
28
+ assert_equal "hg clone --noupdate http://example.com/project-hg /var/www && hg update --repository /var/www --clean 8a8e00b8f11b", @source.checkout('8a8e00b8f11b', dest)
29
+ end
30
+
31
+ def test_diff
32
+ assert_equal "hg diff --rev tip", @source.diff('tip')
33
+ assert_equal "hg diff --rev 1 --rev 2", @source.diff('1', '2')
34
+ end
35
+
36
+ def test_log
37
+ assert_equal "hg log --rev 8a8e00b8f11b", @source.log('8a8e00b8f11b')
38
+ assert_equal "hg log --rev 0:3", @source.log('0', '3')
39
+ end
40
+
41
+ def test_query_revision
42
+ assert_equal "hg log -r 8a8e00b8f11b --template \"{node|short}\"", @source.query_revision('8a8e00b8f11b') { |o| o }
43
+ end
44
+
45
+ def test_username_should_be_backwards_compatible
46
+ # older versions of this module required :scm_user var instead
47
+ # of the currently preferred :scm_username
48
+ require 'capistrano/logger'
49
+ @config[:scm_user] = "fred"
50
+ text = "user:"
51
+ assert_equal %("fred"\n), @source.handle_data(mock_state, :test_stream, text)
52
+ # :scm_username takes priority
53
+ @config[:scm_username] = "wilma"
54
+ assert_equal %("wilma"\n), @source.handle_data(mock_state, :test_stream, text)
55
+ end
56
+
57
+ def test_sync
58
+ dest = "/var/www"
59
+ assert_equal "hg pull --repository /var/www && hg update --repository /var/www --clean 8a8e00b8f11b", @source.sync('8a8e00b8f11b', dest)
60
+
61
+ # With :scm_command
62
+ @config[:scm_command] = "/opt/local/bin/hg"
63
+ assert_equal "/opt/local/bin/hg pull --repository /var/www && /opt/local/bin/hg update --repository /var/www --clean 8a8e00b8f11b", @source.sync('8a8e00b8f11b', dest)
64
+ end
65
+
66
+ def test_export
67
+ dest = "/var/www"
68
+ assert_raise(NotImplementedError) { @source.export('8a8e00b8f11b', dest) }
69
+ end
70
+
71
+ def test_sends_password_if_set
72
+ require 'capistrano/logger'
73
+ text = "password:"
74
+ @config[:scm_password] = "opensesame"
75
+ assert_equal %("opensesame"\n), @source.handle_data(mock_state, :test_stream, text)
76
+ end
77
+
78
+ def test_prompts_for_password_if_preferred
79
+ require 'capistrano/logger'
80
+ require 'capistrano/cli'
81
+ Capistrano::CLI.stubs(:password_prompt).with("hg password: ").returns("opensesame")
82
+ @config[:scm_prefer_prompt] = true
83
+ text = "password:"
84
+ assert_equal %("opensesame"\n), @source.handle_data(mock_state, :test_stream, text)
85
+ end
86
+
87
+
88
+ # Tests from base_test.rb, makin' sure we didn't break anything up there!
89
+ def test_command_should_default_to_default_command
90
+ assert_equal "hg", @source.command
91
+ @source.local { assert_equal "hg", @source.command }
92
+ end
93
+
94
+ def test_command_should_use_scm_command_if_available
95
+ @config[:scm_command] = "/opt/local/bin/hg"
96
+ assert_equal "/opt/local/bin/hg", @source.command
97
+ end
98
+
99
+ def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
100
+ @config[:scm_command] = "/opt/local/bin/hg"
101
+ @source.local { assert_equal "/opt/local/bin/hg", @source.command }
102
+ end
103
+
104
+ def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
105
+ @config[:scm_command] = "/opt/local/bin/hg"
106
+ @config[:local_scm_command] = "/usr/local/bin/hg"
107
+ assert_equal "/opt/local/bin/hg", @source.command
108
+ @source.local { assert_equal "/usr/local/bin/hg", @source.command }
109
+ end
110
+
111
+ def test_command_should_use_default_if_scm_command_is_default
112
+ @config[:scm_command] = :default
113
+ assert_equal "hg", @source.command
114
+ end
115
+
116
+ def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
117
+ @config[:scm_command] = "/foo/bar/hg"
118
+ @config[:local_scm_command] = :default
119
+ @source.local { assert_equal "hg", @source.command }
120
+ end
121
+
122
+ def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
123
+ @config[:scm_command] = "/foo/bar/hg"
124
+ @config[:local_scm_command] = :default
125
+ assert_equal "hg", @source.local.command
126
+ assert_equal "/foo/bar/hg", @source.command
127
+ end
128
+
129
+ private
130
+
131
+ def mock_state
132
+ { :channel => { :host => "abc" } }
133
+ end
134
+ end
@@ -0,0 +1,35 @@
1
+ require 'utils'
2
+ require 'capistrano/recipes/deploy/scm/none'
3
+
4
+ class DeploySCMNoneTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::None
6
+ default_command 'none'
7
+ end
8
+
9
+ def setup
10
+ @config = {}
11
+ def @config.exists?(name); key?(name); end
12
+ @source = TestSCM.new(@config)
13
+ end
14
+
15
+ def test_the_truth
16
+ assert true
17
+ end
18
+
19
+ def test_checkout_on_linux
20
+ Capistrano::Deploy::LocalDependency.stubs(:on_windows?).returns(false)
21
+ @config[:repository] = '.'
22
+ rev = ''
23
+ dest = '/var/www'
24
+ assert_equal "cp -R . /var/www", @source.checkout(rev, dest)
25
+ end
26
+
27
+ def test_checkout_on_windows
28
+ Capistrano::Deploy::LocalDependency.stubs(:on_windows?).returns(true)
29
+ @config[:repository] = '.'
30
+ rev = ''
31
+ dest = 'c:/Documents and settings/admin/tmp'
32
+ assert_equal "xcopy . \"c:/Documents and settings/admin/tmp\" /S/I/Y/Q/E", @source.checkout(rev, dest)
33
+ end
34
+
35
+ end
@@ -0,0 +1,23 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/perforce'
3
+
4
+ class DeploySCMPerforceTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Perforce
6
+ default_command "perforce"
7
+ end
8
+ def setup
9
+ @config = { :repository => "." }
10
+ @source = TestSCM.new(@config)
11
+ end
12
+
13
+ def test_p4_label
14
+ @config[:p4_label] = "some_p4_label"
15
+ assert_equal "@some_p4_label", @source.send(:rev_no, 'foo')
16
+ end
17
+
18
+ def test_p4_label_with_symbol
19
+ @config[:p4_label] = "@some_p4_label"
20
+ assert_equal "@some_p4_label", @source.send(:rev_no, 'foo')
21
+ end
22
+
23
+ end
@@ -0,0 +1,68 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/subversion'
3
+
4
+ class DeploySCMSubversionTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Subversion
6
+ default_command "svn"
7
+ end
8
+
9
+ def setup
10
+ @config = { :repository => "." }
11
+ def @config.exists?(name); key?(name); end
12
+
13
+ @source = TestSCM.new(@config)
14
+ end
15
+
16
+ def test_query_revision
17
+ revision = @source.query_revision('HEAD') do |o|
18
+ assert_equal "svn info . -rHEAD", o
19
+ %Q{Path: rails_2_3
20
+ URL: svn+ssh://example.com/var/repos/project/branches/rails_2_3
21
+ Repository Root: svn+ssh://example.com/var/repos
22
+ Repository UUID: 2d86388d-c40f-0410-ad6a-a69da6a65d20
23
+ Revision: 2095
24
+ Node Kind: directory
25
+ Last Changed Author: sw
26
+ Last Changed Rev: 2064
27
+ Last Changed Date: 2009-03-11 11:04:25 -0700 (Wed, 11 Mar 2009)
28
+ }
29
+ end
30
+ assert_equal 2095, revision
31
+ end
32
+
33
+ def test_sync
34
+ @config[:repository] = "http://svn.github.com/capistrano/capistrano.git"
35
+ rev = '602'
36
+ dest = "/var/www"
37
+ assert_equal "svn switch -q -r602 http://svn.github.com/capistrano/capistrano.git /var/www", @source.sync(rev, dest)
38
+ end
39
+
40
+ def test_sends_password_if_set
41
+ require 'capistrano/logger'
42
+ text = "password:"
43
+ @config[:scm_password] = "opensesame"
44
+ assert_equal %("opensesame"\n), @source.handle_data(mock_state, :test_stream, text)
45
+ end
46
+
47
+ def test_prompt_password
48
+ require 'capistrano/logger'
49
+ require 'capistrano/cli'
50
+ Capistrano::CLI.stubs(:password_prompt).returns("opensesame")
51
+
52
+ text = 'password:'
53
+ assert_equal %("opensesame"\n), @source.handle_data(mock_state, :test_stream, text)
54
+ end
55
+
56
+ def test_sends_passphrase
57
+ require 'capistrano/logger'
58
+ text = 'passphrase:'
59
+ @config[:scm_passphrase] = "opensesame"
60
+ assert_equal %("opensesame"\n), @source.handle_data(mock_state, :test_stream, text)
61
+ end
62
+
63
+ private
64
+
65
+ def mock_state
66
+ { :channel => { :host => "abc" } }
67
+ end
68
+ end