yggdrasil 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +49 -8
- data/Rakefile +8 -0
- data/bin/yggdrasil +3 -1
- data/lib/yggdrasil/add.rb +25 -0
- data/lib/yggdrasil/cleanup.rb +19 -0
- data/lib/yggdrasil/commit.rb +34 -0
- data/lib/yggdrasil/diff.rb +29 -0
- data/lib/yggdrasil/help.rb +190 -0
- data/lib/yggdrasil/init.rb +83 -0
- data/lib/yggdrasil/list.rb +34 -0
- data/lib/yggdrasil/log.rb +34 -0
- data/lib/yggdrasil/revert.rb +47 -0
- data/lib/yggdrasil/status.rb +30 -0
- data/lib/yggdrasil/update.rb +62 -0
- data/lib/yggdrasil/version.rb +13 -2
- data/lib/yggdrasil.rb +242 -2
- data/spec/add_spec.rb +25 -0
- data/spec/cleanup_spec.rb +23 -0
- data/spec/commit_spec.rb +129 -0
- data/spec/diff_spec.rb +104 -0
- data/spec/help_spec.rb +269 -0
- data/spec/init_spec.rb +80 -0
- data/spec/list_spec.rb +45 -0
- data/spec/log_spec.rb +114 -0
- data/spec/revert_spec.rb +127 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/status_spec.rb +59 -0
- data/spec/update_spec.rb +72 -0
- data/spec/version_spec.rb +24 -0
- data/yggdrasil.gemspec +8 -5
- metadata +82 -7
data/spec/help_spec.rb
ADDED
@@ -0,0 +1,269 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Yggdrasil, "help" do
|
4
|
+
puts '-------- help'
|
5
|
+
|
6
|
+
show_subcommands = <<"EOS"
|
7
|
+
usage: #{File.basename($0)} <subcommand> [options] [args]
|
8
|
+
Yggdrasil version #{Yggdrasil::VERSION}
|
9
|
+
Type '#{File.basename($0)} help <subcommand>' for help on a specific subcommand.
|
10
|
+
|
11
|
+
Available subcommands:
|
12
|
+
add
|
13
|
+
cleanup
|
14
|
+
commit (ci)
|
15
|
+
diff (di)
|
16
|
+
help (?, h)
|
17
|
+
init
|
18
|
+
list (ls)
|
19
|
+
log
|
20
|
+
status (stat, st)
|
21
|
+
revert
|
22
|
+
update
|
23
|
+
version
|
24
|
+
|
25
|
+
Yggdrasil is a configuration management tool by Subversion.
|
26
|
+
You should type 'yggdrasil init' at first.
|
27
|
+
|
28
|
+
EOS
|
29
|
+
|
30
|
+
it 'should show subcommands on no subcommands' do
|
31
|
+
puts '---- should show subcommands on no subcommands'
|
32
|
+
out = catch_stdout{Yggdrasil.command []}
|
33
|
+
out.should == show_subcommands
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should show subcommands on "help"' do
|
37
|
+
puts '---- should show subcommands on "help"'
|
38
|
+
out = catch_stdout{Yggdrasil.command %w{help}}
|
39
|
+
out.should == show_subcommands
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should show subcommands on "h"' do
|
43
|
+
puts '---- should show subcommands on "h"'
|
44
|
+
out = catch_stdout{Yggdrasil.command %w{h}}
|
45
|
+
out.should == show_subcommands
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should show subcommands on "?"' do
|
49
|
+
puts '---- should show subcommands on "?"'
|
50
|
+
out = catch_stdout{Yggdrasil.command %w{?}}
|
51
|
+
out.should == show_subcommands
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should be unknown subcommand on "hoge"' do
|
55
|
+
puts '---- should be unknown subcommand on "hoge"'
|
56
|
+
out = catch_stdout do
|
57
|
+
lambda{Yggdrasil.command(%w{hoge})}.should raise_error(SystemExit)
|
58
|
+
end
|
59
|
+
out.should == "#{File.basename($0)} error: Unknown subcommand: 'hoge'\n\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
help_help = <<"EOS"
|
63
|
+
help (?,h): Describe the usage of this program or its subcommands.
|
64
|
+
usage: #{File.basename($0)} help [SUBCOMMAND]
|
65
|
+
|
66
|
+
EOS
|
67
|
+
|
68
|
+
it 'should show help_help' do
|
69
|
+
puts '---- should show help_help'
|
70
|
+
out = catch_stdout{Yggdrasil.command %w{help help}}
|
71
|
+
out.should == help_help
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should error too many arguments' do
|
75
|
+
puts '---- should error too many arguments'
|
76
|
+
out = catch_stdout do
|
77
|
+
lambda{Yggdrasil.command(%w{help help help})}.should raise_error(SystemExit)
|
78
|
+
end
|
79
|
+
out.should == "#{File.basename($0)} error: too many arguments.\n\n"
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should show help of version' do
|
83
|
+
puts '---- should show help of version'
|
84
|
+
out = catch_stdout{Yggdrasil.command %w{help version}}
|
85
|
+
out.should == <<"EOS"
|
86
|
+
version: See the program version
|
87
|
+
usage: #{File.basename($0)} version
|
88
|
+
|
89
|
+
EOS
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should show help of init' do
|
93
|
+
puts '---- should show help of init'
|
94
|
+
out = catch_stdout{Yggdrasil.command %w{help init}}
|
95
|
+
out.should == <<"EOS"
|
96
|
+
init: Check environment and initialize configuration.
|
97
|
+
usage: #{File.basename($0)} init [OPTIONS...]
|
98
|
+
|
99
|
+
Valid options:
|
100
|
+
--repo ARG : specify svn repository
|
101
|
+
--username ARG : specify a username ARG
|
102
|
+
--password ARG : specify a password ARG
|
103
|
+
|
104
|
+
EOS
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should show help of add' do
|
108
|
+
puts '---- should show help of add'
|
109
|
+
out = catch_stdout{Yggdrasil.command %w{help add}}
|
110
|
+
out.should == <<"EOS"
|
111
|
+
add: Add files to management list (add to subversion)
|
112
|
+
usage #{File.basename($0)} add [FILES...]
|
113
|
+
|
114
|
+
EOS
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should show help of commit' do
|
118
|
+
puts '---- should show help of commit'
|
119
|
+
out = catch_stdout{Yggdrasil.command %w{help commit}}
|
120
|
+
out.should == <<"EOS"
|
121
|
+
commit (ci): Send changes from your local file to the repository.
|
122
|
+
usage: #{File.basename($0)} commit [OPTIONS...] [FILES...]
|
123
|
+
|
124
|
+
Valid options:
|
125
|
+
--username ARG : specify a username ARG
|
126
|
+
--password ARG : specify a password ARG
|
127
|
+
-m [--message] ARG : specify log message ARG
|
128
|
+
--non-interactive : do no interactive prompting
|
129
|
+
|
130
|
+
EOS
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should show help of cleanup' do
|
134
|
+
puts '---- should show help of cleanup'
|
135
|
+
out = catch_stdout{Yggdrasil.command %w{help cleanup}}
|
136
|
+
out.should == <<"EOS"
|
137
|
+
cleanup: clean up the working copy
|
138
|
+
usage: #{File.basename($0)} cleanup [OPTIONS...]
|
139
|
+
|
140
|
+
Valid options:
|
141
|
+
--username ARG : specify a username ARG
|
142
|
+
--password ARG : specify a password ARG
|
143
|
+
|
144
|
+
EOS
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should show help of diff' do
|
148
|
+
puts '---- should show help of diff'
|
149
|
+
out = catch_stdout{Yggdrasil.command %w{help diff}}
|
150
|
+
out.should == <<"EOS"
|
151
|
+
diff (di): Display the differences between two revisions or paths.
|
152
|
+
usage: #{File.basename($0)} diff [OPTIONS...] [PATH...]
|
153
|
+
|
154
|
+
Valid options:
|
155
|
+
--username ARG : specify a username ARG
|
156
|
+
--password ARG : specify a password ARG
|
157
|
+
-r [--revision] ARG : ARG (some commands also take ARG1:ARG2 range)
|
158
|
+
A revision argument can be one of:
|
159
|
+
NUMBER revision number
|
160
|
+
'{' DATE '}' revision at start of the date
|
161
|
+
'HEAD' latest in repository
|
162
|
+
'BASE' base rev of item's working copy
|
163
|
+
'COMMITTED' last commit at or before BASE
|
164
|
+
'PREV' revision just before COMMITTED
|
165
|
+
|
166
|
+
EOS
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should show help of list' do
|
170
|
+
puts '---- should show help of list'
|
171
|
+
out = catch_stdout{Yggdrasil.command %w{help list}}
|
172
|
+
out.should == <<"EOS"
|
173
|
+
list (ls): List directory entries in the repository.
|
174
|
+
usage: #{File.basename($0)} list [OPTIONS...] [PATH...]
|
175
|
+
|
176
|
+
Valid options:
|
177
|
+
--username ARG : specify a username ARG
|
178
|
+
--password ARG : specify a password ARG
|
179
|
+
-r [--revision] ARG : ARG (some commands also take ARG1:ARG2 range)
|
180
|
+
A revision argument can be one of:
|
181
|
+
NUMBER revision number
|
182
|
+
'{' DATE '}' revision at start of the date
|
183
|
+
'HEAD' latest in repository
|
184
|
+
'BASE' base rev of item's working copy
|
185
|
+
'COMMITTED' last commit at or before BASE
|
186
|
+
'PREV' revision just before COMMITTED
|
187
|
+
-R [--recursive] : descend recursively, same as --depth=infinity
|
188
|
+
--depth ARG : limit operation by depth ARG ('empty', 'files',
|
189
|
+
'immediates', or 'infinity')
|
190
|
+
|
191
|
+
EOS
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should show help of log' do
|
195
|
+
puts '---- should show help of log'
|
196
|
+
out = catch_stdout{Yggdrasil.command %w{help log}}
|
197
|
+
out.should == <<"EOS"
|
198
|
+
log: Show the log messages for a set of revision(s) and/or file(s).
|
199
|
+
usage: #{File.basename($0)} log [OPTIONS...] [PATH]
|
200
|
+
|
201
|
+
Valid options:
|
202
|
+
--username ARG : specify a username ARG
|
203
|
+
--password ARG : specify a password ARG
|
204
|
+
-r [--revision] ARG : ARG (some commands also take ARG1:ARG2 range)
|
205
|
+
A revision argument can be one of:
|
206
|
+
NUMBER revision number
|
207
|
+
'{' DATE '}' revision at start of the date
|
208
|
+
'HEAD' latest in repository
|
209
|
+
'BASE' base rev of item's working copy
|
210
|
+
'COMMITTED' last commit at or before BASE
|
211
|
+
'PREV' revision just before COMMITTED
|
212
|
+
|
213
|
+
EOS
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'should show help of status' do
|
217
|
+
puts '---- should show help of status'
|
218
|
+
out = catch_stdout{Yggdrasil.command %w{help status}}
|
219
|
+
out.should == <<"EOS"
|
220
|
+
status (stat, st): Print the status of managed files and directories.
|
221
|
+
usage: #{File.basename($0)} status [OPTIONS...] [PATH...]
|
222
|
+
|
223
|
+
Valid options:
|
224
|
+
--username ARG : specify a username ARG
|
225
|
+
--password ARG : specify a password ARG
|
226
|
+
--depth ARG : limit operation by depth ARG ('empty', 'files',
|
227
|
+
'immediates', or 'infinity')
|
228
|
+
|
229
|
+
EOS
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should show help of update' do
|
233
|
+
puts '---- should show help of update'
|
234
|
+
out = catch_stdout{Yggdrasil.command %w{help update}}
|
235
|
+
out.should == <<"EOS"
|
236
|
+
update (up): Bring changes from the repository into the local files.
|
237
|
+
usage: #{File.basename($0)} update [PATH...]
|
238
|
+
|
239
|
+
Valid options:
|
240
|
+
--username ARG : specify a username ARG
|
241
|
+
--password ARG : specify a password ARG
|
242
|
+
-r [--revision] ARG : ARG (some commands also take ARG1:ARG2 range)
|
243
|
+
A revision argument can be one of:
|
244
|
+
NUMBER revision number
|
245
|
+
'{' DATE '}' revision at start of the date
|
246
|
+
'HEAD' latest in repository
|
247
|
+
'BASE' base rev of item's working copy
|
248
|
+
'COMMITTED' last commit at or before BASE
|
249
|
+
'PREV' revision just before COMMITTED
|
250
|
+
--non-interactive : do no interactive prompting
|
251
|
+
|
252
|
+
EOS
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'should show help of revert' do
|
256
|
+
puts '---- should show help of revert'
|
257
|
+
out = catch_stdout{Yggdrasil.command %w{help revert}}
|
258
|
+
out.should == <<"EOS"
|
259
|
+
revert: Restore pristine working copy file (undo most local edits).
|
260
|
+
usage: #{File.basename($0)} revert [PATH...]
|
261
|
+
|
262
|
+
Valid options:
|
263
|
+
--username ARG : specify a username ARG
|
264
|
+
--password ARG : specify a password ARG
|
265
|
+
--non-interactive : do no interactive prompting
|
266
|
+
|
267
|
+
EOS
|
268
|
+
end
|
269
|
+
end
|
data/spec/init_spec.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Yggdrasil, "init" do
|
4
|
+
it '-------- init' do
|
5
|
+
puts '-------- init'
|
6
|
+
prepare_environment
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should error: "Not enough arguments provided"' do
|
10
|
+
puts '---- should error: "Not enough arguments provided"'
|
11
|
+
out = catch_stdout do
|
12
|
+
lambda{Yggdrasil.command(%w{init --repo})}.should raise_error(SystemExit)
|
13
|
+
end
|
14
|
+
out.should == "#{File.basename($0)} error: Not enough arguments provided: --repo\n\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should error: can not access to SVN server' do
|
18
|
+
puts '---- should error: can not access to SVN server'
|
19
|
+
`rm -rf /tmp/yggdrasil-test/.yggdrasil`
|
20
|
+
out = catch_stdout do
|
21
|
+
cmd_args = %w{init --repo file:///tmp/yggdrasil-test/hoge --username hoge --password foo}
|
22
|
+
lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
|
23
|
+
end
|
24
|
+
out.should == "SVN access test...\nSVN error: can not access to 'file:///tmp/yggdrasil-test/hoge'.\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should error: no valid repository' do
|
28
|
+
puts '---- should error: no valid repository'
|
29
|
+
`rm -rf /tmp/yggdrasil-test/.yggdrasil`
|
30
|
+
`rm -rf /tmp/yggdrasil-test/svn-repo`
|
31
|
+
|
32
|
+
catch_stdout do # > /dev/null
|
33
|
+
cmd_args = %w{init --repo file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/ --username hoge --password foo}
|
34
|
+
lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should success: create config file' do
|
39
|
+
puts '---- should success: create config file'
|
40
|
+
`rm -rf /tmp/yggdrasil-test/.yggdrasil`
|
41
|
+
`rm -rf /tmp/yggdrasil-test/svn-repo`
|
42
|
+
`svnadmin create /tmp/yggdrasil-test/svn-repo`
|
43
|
+
|
44
|
+
out = catch_stdout do
|
45
|
+
Yggdrasil.command %w{init} +
|
46
|
+
%w{--repo file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/} +
|
47
|
+
%w{--username hoge --password foo}
|
48
|
+
end
|
49
|
+
out.should == "SVN access test...\nSVN mkdir: OK.\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should success: create config file (interactive)' do
|
53
|
+
puts '---- should success: create config file (interactive)'
|
54
|
+
`pkill svnserve`
|
55
|
+
`rm -rf /tmp/yggdrasil-test/.yggdrasil`
|
56
|
+
`rm -rf /tmp/yggdrasil-test/svn-repo`
|
57
|
+
`svnadmin create /tmp/yggdrasil-test/svn-repo`
|
58
|
+
Yggdrasil.system3 'cat > /tmp/yggdrasil-test/svn-repo/conf/passwd', true, "[users]\nhoge = foo"
|
59
|
+
Yggdrasil.system3 'cat > /tmp/yggdrasil-test/svn-repo/conf/svnserve.conf', true, <<"EOS"
|
60
|
+
[general]
|
61
|
+
anon-access = none
|
62
|
+
auth-access = write
|
63
|
+
password-db = passwd
|
64
|
+
EOS
|
65
|
+
`svnserve -d`
|
66
|
+
|
67
|
+
out = catch_stdout do
|
68
|
+
Yggdrasil.command %w{init},
|
69
|
+
"svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo/host-name/\n"\
|
70
|
+
"hoge\n"\
|
71
|
+
"foo\n"
|
72
|
+
end
|
73
|
+
out.should == \
|
74
|
+
"Input svn repo URL: "\
|
75
|
+
"Input svn username: "\
|
76
|
+
"Input svn password: "\
|
77
|
+
"SVN access test...\n"\
|
78
|
+
"SVN mkdir: OK.\n"
|
79
|
+
end
|
80
|
+
end
|
data/spec/list_spec.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Yggdrasil, "list" do
|
4
|
+
it '-------- list' do
|
5
|
+
puts '-------- list'
|
6
|
+
prepare_environment
|
7
|
+
init_yggdrasil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should show list (absolute path)' do
|
11
|
+
puts '---- should show list (absolute path)'
|
12
|
+
out = catch_stdout{Yggdrasil.command(%w{list /tmp} +
|
13
|
+
%w{--username hoge --password foo})}
|
14
|
+
out.should == "yggdrasil-test/\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should show list (relative path)' do
|
18
|
+
puts '---- should show list (relative path)'
|
19
|
+
out = catch_stdout do
|
20
|
+
FileUtils.cd "/tmp" do
|
21
|
+
Yggdrasil.command %w{list yggdrasil-test}+
|
22
|
+
%w{--username hoge --password foo}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
out.should == "A\nB\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should show list (no path)' do
|
29
|
+
puts '---- should show list (no path)'
|
30
|
+
out = catch_stdout do
|
31
|
+
FileUtils.cd "/tmp/yggdrasil-test" do
|
32
|
+
Yggdrasil.command %w{list} +
|
33
|
+
%w{--username hoge --password foo}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
out.should == "A\nB\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should show list (with options)' do
|
40
|
+
puts '---- should show list (with options)'
|
41
|
+
out = catch_stdout{Yggdrasil.command(%w{list --revision 2 --recursive --depth infinity /tmp} +
|
42
|
+
%w{--username hoge --password foo})}
|
43
|
+
out.should == "yggdrasil-test/\nyggdrasil-test/A\nyggdrasil-test/B\n"
|
44
|
+
end
|
45
|
+
end
|
data/spec/log_spec.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Yggdrasil, "log" do
|
4
|
+
it '-------- log' do
|
5
|
+
puts '-------- log'
|
6
|
+
prepare_environment
|
7
|
+
init_yggdrasil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should show log (absolute path)' do
|
11
|
+
puts '---- should show log (absolute path)'
|
12
|
+
out = catch_stdout{Yggdrasil.command(%w{log /tmp} +
|
13
|
+
%w{--username hoge --password foo})}
|
14
|
+
out.gsub!(%r{20..-..-.. .*20..\)}, '')
|
15
|
+
out.should == <<"EOS"
|
16
|
+
------------------------------------------------------------------------
|
17
|
+
r3 | hoge | | 1 line
|
18
|
+
Changed paths:
|
19
|
+
M /mng-repo/host-name/tmp/yggdrasil-test/A
|
20
|
+
M /mng-repo/host-name/tmp/yggdrasil-test/B
|
21
|
+
|
22
|
+
modify
|
23
|
+
------------------------------------------------------------------------
|
24
|
+
r2 | hoge | | 1 line
|
25
|
+
Changed paths:
|
26
|
+
A /mng-repo/host-name/tmp
|
27
|
+
A /mng-repo/host-name/tmp/yggdrasil-test
|
28
|
+
A /mng-repo/host-name/tmp/yggdrasil-test/A
|
29
|
+
A /mng-repo/host-name/tmp/yggdrasil-test/B
|
30
|
+
|
31
|
+
add files
|
32
|
+
------------------------------------------------------------------------
|
33
|
+
EOS
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should show log (relative path)' do
|
37
|
+
puts '---- should show log (relative path)'
|
38
|
+
out = catch_stdout do
|
39
|
+
FileUtils.cd "/tmp" do
|
40
|
+
Yggdrasil.command %w{log yggdrasil-test}+
|
41
|
+
%w{--username hoge --password foo}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
out.gsub!(%r{20..-..-.. .*20..\)}, '')
|
45
|
+
out.should == <<"EOS"
|
46
|
+
------------------------------------------------------------------------
|
47
|
+
r3 | hoge | | 1 line
|
48
|
+
Changed paths:
|
49
|
+
M /mng-repo/host-name/tmp/yggdrasil-test/A
|
50
|
+
M /mng-repo/host-name/tmp/yggdrasil-test/B
|
51
|
+
|
52
|
+
modify
|
53
|
+
------------------------------------------------------------------------
|
54
|
+
r2 | hoge | | 1 line
|
55
|
+
Changed paths:
|
56
|
+
A /mng-repo/host-name/tmp
|
57
|
+
A /mng-repo/host-name/tmp/yggdrasil-test
|
58
|
+
A /mng-repo/host-name/tmp/yggdrasil-test/A
|
59
|
+
A /mng-repo/host-name/tmp/yggdrasil-test/B
|
60
|
+
|
61
|
+
add files
|
62
|
+
------------------------------------------------------------------------
|
63
|
+
EOS
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should show log (no path)' do
|
67
|
+
puts '---- should show log (no path)'
|
68
|
+
out = catch_stdout do
|
69
|
+
FileUtils.cd "/tmp/yggdrasil-test" do
|
70
|
+
Yggdrasil.command %w{log} +
|
71
|
+
%w{--username hoge --password foo}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
out.gsub!(%r{20..-..-.. .*20..\)}, '')
|
75
|
+
out.should == <<"EOS"
|
76
|
+
------------------------------------------------------------------------
|
77
|
+
r3 | hoge | | 1 line
|
78
|
+
Changed paths:
|
79
|
+
M /mng-repo/host-name/tmp/yggdrasil-test/A
|
80
|
+
M /mng-repo/host-name/tmp/yggdrasil-test/B
|
81
|
+
|
82
|
+
modify
|
83
|
+
------------------------------------------------------------------------
|
84
|
+
r2 | hoge | | 1 line
|
85
|
+
Changed paths:
|
86
|
+
A /mng-repo/host-name/tmp
|
87
|
+
A /mng-repo/host-name/tmp/yggdrasil-test
|
88
|
+
A /mng-repo/host-name/tmp/yggdrasil-test/A
|
89
|
+
A /mng-repo/host-name/tmp/yggdrasil-test/B
|
90
|
+
|
91
|
+
add files
|
92
|
+
------------------------------------------------------------------------
|
93
|
+
EOS
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should show log (with options)' do
|
97
|
+
puts '---- should show log (with options)'
|
98
|
+
out = catch_stdout{Yggdrasil.command(%w{log --revision 2 /tmp} +
|
99
|
+
%w{--username hoge --password foo})}
|
100
|
+
out.sub!(%r{20..-..-.. .*20..\)}, '')
|
101
|
+
out.should == <<"EOS"
|
102
|
+
------------------------------------------------------------------------
|
103
|
+
r2 | hoge | | 1 line
|
104
|
+
Changed paths:
|
105
|
+
A /mng-repo/host-name/tmp
|
106
|
+
A /mng-repo/host-name/tmp/yggdrasil-test
|
107
|
+
A /mng-repo/host-name/tmp/yggdrasil-test/A
|
108
|
+
A /mng-repo/host-name/tmp/yggdrasil-test/B
|
109
|
+
|
110
|
+
add files
|
111
|
+
------------------------------------------------------------------------
|
112
|
+
EOS
|
113
|
+
end
|
114
|
+
end
|
data/spec/revert_spec.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Yggdrasil, "revert" do
|
4
|
+
it '-------- revert' do
|
5
|
+
puts '-------- revert'
|
6
|
+
prepare_environment
|
7
|
+
init_yggdrasil
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
it 'should revert added files' do
|
12
|
+
puts '---- should commit added files'
|
13
|
+
`echo hoge > /tmp/yggdrasil-test/AA`
|
14
|
+
`echo foo > /tmp/yggdrasil-test/BB`
|
15
|
+
FileUtils.cd "/tmp/yggdrasil-test" do
|
16
|
+
puts '-- add'
|
17
|
+
Yggdrasil.command %w{add AA /tmp/yggdrasil-test/BB}
|
18
|
+
|
19
|
+
puts "-- revert"
|
20
|
+
Yggdrasil.command %w{revert --username hoge --password foo},
|
21
|
+
"0\nY\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "\n-- check revert file (add)"
|
25
|
+
out = catch_stdout do
|
26
|
+
Yggdrasil.command %w{status /tmp/yggdrasil-test} +
|
27
|
+
%w{--username hoge --password foo}
|
28
|
+
end
|
29
|
+
puts out
|
30
|
+
out.should == ""
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should revert modified file' do
|
34
|
+
puts "---- should revert modified file"
|
35
|
+
puts "-- modify"
|
36
|
+
`echo hoge >> /tmp/yggdrasil-test/A`
|
37
|
+
|
38
|
+
puts "-- revert"
|
39
|
+
Yggdrasil.command %w{revert / --username hoge --password foo},
|
40
|
+
"0\nY\n"
|
41
|
+
|
42
|
+
puts "\n-- check revert file (modify)"
|
43
|
+
out = catch_stdout do
|
44
|
+
Yggdrasil.command %w{status /tmp/yggdrasil-test} +
|
45
|
+
%w{--username hoge --password foo}
|
46
|
+
end
|
47
|
+
puts out
|
48
|
+
out.should == ""
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should accept password interactive' do
|
52
|
+
puts "---- should accept password interactive"
|
53
|
+
`echo A >> /tmp/yggdrasil-test/A`
|
54
|
+
|
55
|
+
Yggdrasil.command %w{revert /tmp/yggdrasil-test/A --username hoge},
|
56
|
+
"foo\nY\n" # interactive input: password, Y/n
|
57
|
+
|
58
|
+
puts "\n-- check revert file"
|
59
|
+
out = catch_stdout do
|
60
|
+
Yggdrasil.command %w{status /tmp/yggdrasil-test} +
|
61
|
+
%w{--username hoge --password foo}
|
62
|
+
end
|
63
|
+
puts out
|
64
|
+
out.should == ""
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should revert specified file only' do
|
68
|
+
puts "---- should revert specified file only"
|
69
|
+
`echo A >> /tmp/yggdrasil-test/A`
|
70
|
+
`echo B >> /tmp/yggdrasil-test/B`
|
71
|
+
|
72
|
+
Yggdrasil.command %w{revert /tmp/yggdrasil-test/B} +
|
73
|
+
%w{--username hoge --password foo},
|
74
|
+
"0\nY\n"
|
75
|
+
|
76
|
+
puts "\n-- check revert file"
|
77
|
+
out = catch_stdout do
|
78
|
+
Yggdrasil.command %w{status /tmp/yggdrasil-test} +
|
79
|
+
%w{--username hoge --password foo}
|
80
|
+
end
|
81
|
+
puts out
|
82
|
+
out.should == <<"EOS"
|
83
|
+
M 3 tmp/yggdrasil-test/A
|
84
|
+
EOS
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should not revert deleted file' do
|
88
|
+
puts "---- should not revert deleted file"
|
89
|
+
`rm -f /tmp/yggdrasil-test/A`
|
90
|
+
|
91
|
+
Yggdrasil.command %w{revert /} +
|
92
|
+
%w{--username hoge --password foo},
|
93
|
+
"0\nn\n"
|
94
|
+
|
95
|
+
puts "\n-- check status"
|
96
|
+
out = catch_stdout do
|
97
|
+
Yggdrasil.command %w{status /tmp/yggdrasil-test} +
|
98
|
+
%w{--username hoge --password foo}
|
99
|
+
end
|
100
|
+
puts out
|
101
|
+
out.should == <<"EOS"
|
102
|
+
D 3 tmp/yggdrasil-test/A
|
103
|
+
EOS
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should revert all files at once' do
|
107
|
+
puts "---- should revert all files at once"
|
108
|
+
|
109
|
+
`echo HOGE >> /tmp/yggdrasil-test/A`
|
110
|
+
`rm -f /tmp/yggdrasil-test/B`
|
111
|
+
`mkdir /tmp/yggdrasil-test/c`
|
112
|
+
`echo bar > /tmp/yggdrasil-test/c/C`
|
113
|
+
Yggdrasil.command %w{add /tmp/yggdrasil-test/c/C}
|
114
|
+
|
115
|
+
Yggdrasil.command %w{revert /} +
|
116
|
+
%w{--username hoge --password foo},
|
117
|
+
"0\nY\n"
|
118
|
+
|
119
|
+
puts "\n-- check status"
|
120
|
+
out = catch_stdout do
|
121
|
+
Yggdrasil.command %w{status /tmp/yggdrasil-test} +
|
122
|
+
%w{--username hoge --password foo}
|
123
|
+
end
|
124
|
+
puts out
|
125
|
+
out.should == ""
|
126
|
+
end
|
127
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/yggdrasil'
|
2
|
+
|
3
|
+
def prepare_environment
|
4
|
+
puts "---- prepare environment"
|
5
|
+
|
6
|
+
`pkill svnserve`
|
7
|
+
`rm -rf /tmp/yggdrasil-test`
|
8
|
+
Dir.mkdir('/tmp/yggdrasil-test', 0755)
|
9
|
+
ENV['HOME']='/tmp/yggdrasil-test'
|
10
|
+
|
11
|
+
puts '-- create repo'
|
12
|
+
`svnadmin create /tmp/yggdrasil-test/svn-repo`
|
13
|
+
|
14
|
+
puts '-- launch svnserve'
|
15
|
+
Yggdrasil.system3 'cat > /tmp/yggdrasil-test/svn-repo/conf/passwd', true, "[users]\nhoge = foo"
|
16
|
+
Yggdrasil.system3 'cat > /tmp/yggdrasil-test/svn-repo/conf/svnserve.conf', true, <<"EOS"
|
17
|
+
[general]
|
18
|
+
anon-access = none
|
19
|
+
auth-access = write
|
20
|
+
password-db = passwd
|
21
|
+
EOS
|
22
|
+
`svnserve -d`
|
23
|
+
end
|
24
|
+
|
25
|
+
def init_yggdrasil
|
26
|
+
puts '---- init yggdrasil and some commits'
|
27
|
+
puts '-- init'
|
28
|
+
Yggdrasil.command %w{init} +
|
29
|
+
%w{--repo svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo/host-name/} +
|
30
|
+
%w{--username hoge --password foo}
|
31
|
+
puts '-- add'
|
32
|
+
`echo hoge > /tmp/yggdrasil-test/A`
|
33
|
+
`echo foo > /tmp/yggdrasil-test/B`
|
34
|
+
Yggdrasil.command %w{add} +
|
35
|
+
%w{/tmp/yggdrasil-test/A /tmp/yggdrasil-test/B}
|
36
|
+
puts '-- commit'
|
37
|
+
Yggdrasil.command %w{commit / --non-interactive -m add\ files} +
|
38
|
+
%w{--username hoge --password foo}
|
39
|
+
puts '-- modify'
|
40
|
+
`echo hoge >> /tmp/yggdrasil-test/A`
|
41
|
+
`echo foo >> /tmp/yggdrasil-test/B`
|
42
|
+
puts '-- commit'
|
43
|
+
Yggdrasil.command %w{commit / --non-interactive -m modify} +
|
44
|
+
%w{--username hoge --password foo}
|
45
|
+
end
|
46
|
+
|
47
|
+
def catch_stdout
|
48
|
+
exit 1 unless block_given?
|
49
|
+
tmp_out = $stdout
|
50
|
+
$stdout = StringIO.new
|
51
|
+
yield
|
52
|
+
$stdout,tmp_out = tmp_out, $stdout
|
53
|
+
tmp_out.string
|
54
|
+
end
|