yggdrasil 0.0.15 → 0.0.16

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.
@@ -75,24 +75,50 @@ class Yggdrasil
75
75
  protected
76
76
  include YggdrasilCommon
77
77
 
78
- def sync_mirror
78
+ def sync_mirror(target_paths)
79
+ target_relatives = Array.new
80
+ if target_paths.size == 0
81
+ target_relatives << @current_dir.sub(%r{^/*},'')
82
+ else
83
+ target_paths.each do |path|
84
+ if %r{^/} =~ path
85
+ target_relatives << path.sub(%r{^/*},'') # cut first '/'
86
+ else
87
+ target_relatives << @current_dir.sub(%r{^/*},'') + '/' + path
88
+ end
89
+ f = '/'+target_relatives[-1]
90
+ error "no such file of directory:#{f}" unless File.exist?(f)
91
+ end
92
+ end
93
+
79
94
  updates = Array.new
95
+ @target_file_num = 0
80
96
  FileUtils.cd @mirror_dir do
81
- cmd = "#@svn update --no-auth-cache --non-interactive"
82
- cmd += username_password_options_to_read_repo
83
- system3(cmd)
97
+ files = Array.new
84
98
  cmd = "#@svn ls #@repo -R --no-auth-cache --non-interactive"
85
99
  cmd += username_password_options_to_read_repo
86
100
  out = system3(cmd)
87
- files = out.split(/\n/)
88
- cmd = "#@svn status -q --no-auth-cache --non-interactive"
89
- cmd += username_password_options_to_read_repo
90
- out = system3(cmd)
91
- out.split(/\n/).each do |line|
92
- files << $1 if /^.*\s(\S+)\s*$/ =~ line
101
+ ls_files = out.split(/\n/)
102
+ target_relatives.each do |target_relative|
103
+ ls_files.each do |ls_file|
104
+ files << ls_file if ls_file.match("^#{target_relative}")
105
+ end
106
+ cmd = "#@svn update --no-auth-cache --non-interactive"
107
+ cmd += " -r #{@options[:revision]}" if @options.has_key?(:revision)
108
+ cmd += username_password_options_to_read_repo
109
+ cmd += ' '+target_relative
110
+ system3(cmd)
111
+ cmd = "#@svn status -q --no-auth-cache --non-interactive"
112
+ cmd += username_password_options_to_read_repo
113
+ cmd += ' '+target_relative
114
+ out = system3(cmd)
115
+ out.split(/\n/).each do |line|
116
+ files << $1 if /^.*\s(\S+)\s*$/ =~ line
117
+ end
93
118
  end
94
119
  files.sort!
95
120
  files.uniq!
121
+ @target_file_num = files.size
96
122
  files.each do |file|
97
123
  if !File.exist?("/#{file}")
98
124
  system3 "#@svn delete #{file} --force" +
@@ -116,58 +142,34 @@ class Yggdrasil
116
142
  end
117
143
  end
118
144
  end
119
- updates
145
+ updates.sort.uniq
120
146
  end
121
147
 
122
- def select_updates(updates, target_paths)
123
-
124
- target_relatives = Array.new
125
- if target_paths.size == 0
126
- target_relatives << @current_dir.sub(%r{^/*},'')
127
- else
128
- target_paths.each do |path|
129
- if %r{^/} =~ path
130
- target_relatives << path.sub(%r{^/*},'') # cut first '/'
131
- else
132
- target_relatives << @current_dir.sub(%r{^/*},'') + '/' + path
133
- end
134
- end
135
- end
136
-
137
- # search updated files in the specified dir
138
- cond = '^'+target_relatives.join('|^') # make reg exp
139
- matched_updates = Array.new
140
- updates.each do |update|
141
- matched_updates << update if update[1].match(cond)
142
- end
143
-
144
- # search parent updates of matched updates
145
- parents = Array.new
146
- updates.each do |update|
147
- matched_updates.each do |matched_update|
148
- parents << update if matched_update[1].match("^#{update[1]}/")
149
- end
150
- end
151
- matched_updates += parents
152
- matched_updates.sort.uniq
153
- end
154
-
155
- def confirm_updates(updates)
148
+ def confirm_updates(updates, yes_no=%w{Y n})
149
+ Signal.trap('INT') {
150
+ puts
151
+ exit 1
152
+ }
153
+ display_list = true
156
154
  until @options.has_key?(:non_interactive?)
157
155
  puts
158
- (0...updates.size).each do |i|
159
- puts "#{i}:#{updates[i][0]} #{updates[i][1]}"
156
+ if display_list
157
+ (0...updates.size).each do |i|
158
+ puts "#{i}:#{updates[i][0]} #{updates[i][1]}"
159
+ end
160
+ display_list = false
160
161
  end
161
- print 'OK? [Y|n|<num to diff>]:'
162
+ print "OK? [#{yes_no[0]}|#{yes_no[1]}|<num to diff>]: "
162
163
  res = $stdin.gets
163
164
  puts
164
165
  return nil unless res
165
166
  res.chomp!
166
- return nil if res == 'n'
167
- break if res == 'Y'
168
- next unless updates[res.to_i]
169
- if /^\d+$/ =~ res
167
+ break if res == yes_no[0]
168
+ return nil if res == yes_no[1]
169
+ if /^\d+$/ =~ res && updates[res.to_i]
170
170
  yield updates[res.to_i][1]
171
+ else
172
+ display_list = true
171
173
  end
172
174
  end
173
175
  # res == 'Y'
@@ -243,12 +245,15 @@ class Yggdrasil
243
245
  end
244
246
  end
245
247
 
246
- # add checker result
248
+ # add checker script and checker result
247
249
  result_files = Array.new
248
- Find.find(@checker_result_dir) {|f| result_files << f}
249
- stdout = $stdout
250
- $stdout = StringIO.new
251
- self.class.new.add result_files
252
- $stdout = stdout
250
+ Find.find(@checker_dir) {|f| result_files << f unless f == @checker_dir}
251
+ Find.find(@checker_result_dir) {|f| result_files << f unless f == @checker_result_dir}
252
+ if result_files.size != 0
253
+ stdout = $stdout
254
+ $stdout = StringIO.new
255
+ self.class.new.add result_files
256
+ $stdout = stdout
257
+ end
253
258
  end
254
259
  end
@@ -7,17 +7,18 @@ class Yggdrasil
7
7
  parse_options(args,
8
8
  {'--username'=>:username, '--password'=>:password,
9
9
  '--non-interactive'=>:non_interactive?})
10
+ error "invalid options: #{(@arg_options).join(', ')}" if @arg_options.size != 0
11
+
10
12
  @arg_paths << '/' if @arg_paths.size == 0
11
13
  get_user_pass_if_need_to_read_repo
12
14
 
13
15
  exec_checker
14
16
 
15
- updates = sync_mirror
16
- matched_updates = select_updates(updates, @arg_paths)
17
+ matched_updates = sync_mirror(@arg_paths)
17
18
 
18
19
  check_result = String.new
19
20
  if matched_updates.size != 0
20
- confirmed_updates = confirm_updates(matched_updates) do |relative_path|
21
+ confirmed_updates = confirm_updates(matched_updates, %w{A q}) do |relative_path|
21
22
  FileUtils.cd @mirror_dir do
22
23
  cmd = "#@svn diff --no-auth-cache --non-interactive #{relative_path}"
23
24
  cmd += username_password_options_to_read_repo
@@ -42,11 +43,17 @@ class Yggdrasil
42
43
  check_result << "\n\n"
43
44
 
44
45
  ############## add diff information to check_result
45
- cmd = "#@svn diff --no-auth-cache --non-interactive"
46
- cmd += username_password_options_to_read_repo
47
- cmd += " #{confirmed_updates.join(' ')}"
48
46
  FileUtils.cd @mirror_dir do
49
- check_result << system3(cmd)
47
+ result_array.each do |result_line|
48
+ if result_line =~ /\s(\S+)$/
49
+ result_path = $1
50
+ next if File.directory?(result_path)
51
+ cmd = "#@svn diff --no-auth-cache --non-interactive"
52
+ cmd += username_password_options_to_read_repo
53
+ cmd += ' '+result_path
54
+ check_result << system3(cmd) +"\n"
55
+ end
56
+ end
50
57
  end
51
58
  end
52
59
 
@@ -61,18 +68,15 @@ class Yggdrasil
61
68
  sock.puts check_result
62
69
  sock.close
63
70
  end
64
- if check_result == ''
65
- puts 'Yggdrasil check: OK.'
66
- else
67
- puts check_result
68
- puts "\nYggdrasil check: NG!!!"
69
- end
71
+ end
72
+
73
+ puts @target_file_num.to_s + ' files checked.'
74
+ return if @target_file_num == 0
75
+ if check_result == ''
76
+ puts 'Yggdrasil check: OK.'
70
77
  else
71
- if check_result == ''
72
- puts 'no files.'
73
- else
74
- puts check_result
75
- end
78
+ puts check_result
79
+ puts 'Yggdrasil check: NG!!!'
76
80
  end
77
81
  end
78
82
  end
@@ -10,8 +10,7 @@ class Yggdrasil
10
10
 
11
11
  exec_checker
12
12
 
13
- updates = sync_mirror
14
- matched_updates = select_updates(updates, @arg_paths)
13
+ matched_updates = sync_mirror(@arg_paths)
15
14
  if matched_updates.size == 0
16
15
  puts 'no files.'
17
16
  return
@@ -46,7 +45,7 @@ class Yggdrasil
46
45
 
47
46
  input_user_pass
48
47
  FileUtils.cd @mirror_dir do
49
- cmd = "#@svn commit -N -m '#{@options[:message]}'"\
48
+ cmd = "#@svn commit -m '#{@options[:message]}'"\
50
49
  ' --no-auth-cache --non-interactive'\
51
50
  " --username '#{@options[:username]}' --password '#{@options[:password]}'"\
52
51
  " #{confirmed_updates.join(' ')}"
@@ -4,12 +4,12 @@ class Yggdrasil
4
4
  def diff(args)
5
5
  parse_options(args,
6
6
  {'--username'=>:username, '--password'=>:password,
7
- '-r'=>:revision, '--revision'=>:revision})
7
+ '-r'=>:diff_rev, '--revision'=>:diff_rev})
8
8
  @arg_paths << '/' if @arg_paths.size == 0
9
9
 
10
10
  get_user_pass_if_need_to_read_repo
11
11
  exec_checker
12
- sync_mirror
12
+ sync_mirror(@arg_paths)
13
13
 
14
14
  paths = Array.new
15
15
  err_paths = Array.new
@@ -33,7 +33,7 @@ class Yggdrasil
33
33
  cmd_arg = "#@svn diff --no-auth-cache --non-interactive"
34
34
  cmd_arg += username_password_options_to_read_repo
35
35
  cmd_arg += ' ' + @arg_options.join(' ') if @arg_options.size != 0
36
- cmd_arg += " -r #{@options[:revision]}" if @options.has_key?(:revision)
36
+ cmd_arg += " -r #{@options[:diff_rev]}" if @options.has_key?(:diff_rev)
37
37
  cmd_arg += ' ' + paths.join(' ')
38
38
  FileUtils.cd @mirror_dir do
39
39
  puts system3(cmd_arg)
@@ -171,6 +171,7 @@ Valid options:
171
171
  --username ARG : specify a username ARG
172
172
  --password ARG : specify a password ARG
173
173
  --non-interactive : do no interactive prompting
174
+ -r [--revision] ARG : revision number
174
175
 
175
176
  EOS
176
177
 
@@ -29,9 +29,9 @@ class Yggdrasil
29
29
  `rm -rf #@config_file`
30
30
  break
31
31
  end
32
+ error "Already exist config file. use --force to ignore" if @options[:non_interactive?]
32
33
  puts "Already exist config file: #@config_file"
33
- exit 1 if @options[:non_interactive?]
34
- print "Overwrite? [Yn]:"
34
+ print 'Overwrite? [Yn]: '
35
35
  res = $stdin.gets
36
36
  puts
37
37
  return nil unless res
@@ -100,7 +100,7 @@ class Yggdrasil
100
100
  msg = "not exist directory(s) in repository: #{url_parts[url_parts_num...url_parts.size].join('/')}"
101
101
  error msg if @options[:non_interactive?]
102
102
  puts msg
103
- print 'make directory(s)? [Yn]:'
103
+ print 'make directory(s)? [Yn]: '
104
104
  input = $stdin.gets
105
105
  error 'can not gets $stdin' if input.nil?
106
106
  puts
@@ -146,18 +146,15 @@ class Yggdrasil
146
146
  cmd += " --username '#{@options[:ro_username]}' --password '#{@options[:ro_password]}'" unless anon_access
147
147
  system3 cmd
148
148
 
149
- # make checker dir and checker example
149
+ # make checker directory
150
150
  Dir.mkdir @checker_dir, 0755 unless File.exist?(@checker_dir)
151
- FileUtils.cd @checker_dir do
152
- `echo 'gem list' > gem_list`
153
- `chmod +x gem_list`
154
- end
155
151
  end
156
152
 
157
153
 
158
154
  def init_get_repo_interactive
155
+ error "need --repo or --server" if @options[:non_interactive?]
159
156
  loop do
160
- print 'Input svn repo URL:'
157
+ print 'Input svn repo URL: '
161
158
  input = $stdin.gets
162
159
  error 'can not input svn repo URL' unless input
163
160
  puts
@@ -4,12 +4,12 @@ class Yggdrasil
4
4
  def update(args)
5
5
  parse_options(args,
6
6
  {'--username'=>:username, '--password'=>:password,
7
+ '-r'=>:revision, '--revision'=>:revision,
7
8
  '--non-interactive'=>:non_interactive?})
8
9
  @arg_paths << '/' if @arg_paths.size == 0
9
10
  get_user_pass_if_need_to_read_repo
10
11
 
11
- updates = sync_mirror
12
- matched_updates = select_updates(updates, @arg_paths)
12
+ matched_updates = sync_mirror(@arg_paths)
13
13
  if matched_updates.size == 0
14
14
  puts 'no files.'
15
15
  return
@@ -1,5 +1,5 @@
1
1
  class Yggdrasil
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.16'
3
3
 
4
4
  def version
5
5
  puts <<"EOS"
@@ -66,7 +66,7 @@ module YggdrasilCommon
66
66
  def input_user_pass
67
67
  until @options.has_key?(:username) do
68
68
  error 'Can\'t get username or password' if @options.has_key?(:non_interactive?)
69
- print 'Input svn username:'
69
+ print 'Input svn username: '
70
70
  input = $stdin.gets
71
71
  error 'can not input username' unless input
72
72
  puts
@@ -76,7 +76,7 @@ module YggdrasilCommon
76
76
  end
77
77
  until @options.has_key?(:password) do
78
78
  error 'Can\'t get username or password' if @options.has_key?(:non_interactive?)
79
- print 'Input svn password:'
79
+ print 'Input svn password: '
80
80
  #input = `sh -c 'read -s hoge;echo $hoge'`
81
81
  system3 'stty -echo', false
82
82
  input = $stdin.gets
@@ -14,61 +14,61 @@ describe Yggdrasil, 'check' do
14
14
 
15
15
  it 'should display check result by "check"' do
16
16
  cmd = %w{check --username hoge --password foo}
17
- out = catch_out {Yggdrasil.command(cmd, "n\n")}
17
+ out = catch_out {Yggdrasil.command(cmd, "q\n")}
18
18
  out.should == <<"EOS"
19
19
 
20
20
  0:A tmp/yggdrasil-test/C
21
21
  1:D tmp/yggdrasil-test/A
22
22
  2:M tmp/yggdrasil-test/B
23
- OK? [Y|n|<num to diff>]:
23
+ OK? [A|q|<num to diff>]:#{' '}
24
24
  EOS
25
25
  end
26
26
 
27
27
  it 'should display check result by "c"' do
28
28
  cmd = %w{c --username hoge --password foo}
29
- out = catch_out {Yggdrasil.command(cmd, "n\n")}
29
+ out = catch_out {Yggdrasil.command(cmd, "q\n")}
30
30
  out.should == <<"EOS"
31
31
 
32
32
  0:A tmp/yggdrasil-test/C
33
33
  1:D tmp/yggdrasil-test/A
34
34
  2:M tmp/yggdrasil-test/B
35
- OK? [Y|n|<num to diff>]:
35
+ OK? [A|q|<num to diff>]:#{' '}
36
36
  EOS
37
37
  end
38
38
 
39
39
  it 'should display check result by "status"' do
40
40
  cmd = %w{status --username hoge --password foo}
41
- out = catch_out {Yggdrasil.command(cmd, "n\n")}
41
+ out = catch_out {Yggdrasil.command(cmd, "q\n")}
42
42
  out.should == <<"EOS"
43
43
 
44
44
  0:A tmp/yggdrasil-test/C
45
45
  1:D tmp/yggdrasil-test/A
46
46
  2:M tmp/yggdrasil-test/B
47
- OK? [Y|n|<num to diff>]:
47
+ OK? [A|q|<num to diff>]:#{' '}
48
48
  EOS
49
49
  end
50
50
 
51
51
  it 'should display check result by "stat"' do
52
52
  cmd = %w{stat --username hoge --password foo}
53
- out = catch_out {Yggdrasil.command(cmd, "n\n")}
53
+ out = catch_out {Yggdrasil.command(cmd, "q\n")}
54
54
  out.should == <<"EOS"
55
55
 
56
56
  0:A tmp/yggdrasil-test/C
57
57
  1:D tmp/yggdrasil-test/A
58
58
  2:M tmp/yggdrasil-test/B
59
- OK? [Y|n|<num to diff>]:
59
+ OK? [A|q|<num to diff>]:#{' '}
60
60
  EOS
61
61
  end
62
62
 
63
63
  it 'should display check result by "st"' do
64
64
  cmd = %w{st --username hoge --password foo}
65
- out = catch_out {Yggdrasil.command(cmd, "n\n")}
65
+ out = catch_out {Yggdrasil.command(cmd, "q\n")}
66
66
  out.should == <<"EOS"
67
67
 
68
68
  0:A tmp/yggdrasil-test/C
69
69
  1:D tmp/yggdrasil-test/A
70
70
  2:M tmp/yggdrasil-test/B
71
- OK? [Y|n|<num to diff>]:
71
+ OK? [A|q|<num to diff>]:#{' '}
72
72
  EOS
73
73
 
74
74
  `echo hoge > /tmp/yggdrasil-test/A`
@@ -78,6 +78,22 @@ EOS
78
78
  `rm -f /tmp/yggdrasil-test/C`
79
79
  end
80
80
 
81
+ it 'should fail by spell miss of path' do
82
+ cmd = %w{st --username hoge --password foo /hoge}
83
+ err = catch_err do
84
+ lambda{Yggdrasil.command(cmd)}.should raise_error(SystemExit)
85
+ end
86
+ err.should == "#{File.basename($0)} error: no such file of directory:/hoge\n\n"
87
+ end
88
+
89
+ it 'should fail by spell miss of option' do
90
+ cmd = %w{st --username hoge --password foo --hoge}
91
+ err = catch_err do
92
+ lambda{Yggdrasil.command(cmd)}.should raise_error(SystemExit)
93
+ end
94
+ err.should == "#{File.basename($0)} error: invalid options: --hoge\n\n"
95
+ end
96
+
81
97
  it 'should execute checker and svn add the result' do
82
98
  puts "\n---- should execute checker and svn add the result"
83
99
  `rm -f /tmp/yggdrasil-test/.yggdrasil/checker/gem_list`
@@ -88,8 +104,26 @@ EOS
88
104
  out = catch_out {Yggdrasil.command(cmd, "Y\n")}
89
105
  out.gsub! /[ ]+/, ' '
90
106
  out.should == <<"EOS"
107
+ 10 files checked.
108
+ A 0 tmp/yggdrasil-test/.yggdrasil
109
+ A 0 tmp/yggdrasil-test/.yggdrasil/checker
110
+ A 0 tmp/yggdrasil-test/.yggdrasil/checker/hoge
111
+ A 0 tmp/yggdrasil-test/.yggdrasil/checker_result
91
112
  A 0 tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
92
113
 
114
+ Index: tmp/yggdrasil-test/.yggdrasil/checker/hoge
115
+ ===================================================================
116
+ --- tmp/yggdrasil-test/.yggdrasil/checker/hoge (revision 0)
117
+ +++ tmp/yggdrasil-test/.yggdrasil/checker/hoge (revision 0)
118
+ @@ -0,0 +1 @@
119
+ +echo hoge
120
+
121
+ Property changes on: tmp/yggdrasil-test/.yggdrasil/checker/hoge
122
+ ___________________________________________________________________
123
+ Added: svn:executable
124
+ + *
125
+
126
+
93
127
  Index: tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
94
128
  ===================================================================
95
129
  --- tmp/yggdrasil-test/.yggdrasil/checker_result/hoge (revision 0)
@@ -107,8 +141,12 @@ EOS
107
141
  out = catch_out {Yggdrasil.command cmd}
108
142
 
109
143
  out.should == <<"EOS"
144
+ Adding tmp/yggdrasil-test/.yggdrasil
145
+ Adding tmp/yggdrasil-test/.yggdrasil/checker
146
+ Adding tmp/yggdrasil-test/.yggdrasil/checker/hoge
147
+ Adding tmp/yggdrasil-test/.yggdrasil/checker_result
110
148
  Adding tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
111
- Transmitting file data .
149
+ Transmitting file data ..
112
150
  Committed revision 4.
113
151
  EOS
114
152
  end
@@ -117,14 +155,24 @@ EOS
117
155
  puts "\n---- should delete result if checker deleted"
118
156
  `rm -f /tmp/yggdrasil-test/.yggdrasil/checker/hoge`
119
157
  cmd = %w{check --username hoge --password foo}
120
- out = catch_out {Yggdrasil.command(cmd, "Y\n")}
158
+ out = catch_out {Yggdrasil.command(cmd, "A\n")}
121
159
  out.gsub! /[ ]+/, ' '
122
160
  out.should == <<"EOS"
123
161
 
124
- 0:D tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
125
- OK? [Y|n|<num to diff>]:
162
+ 0:D tmp/yggdrasil-test/.yggdrasil/checker/hoge
163
+ 1:D tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
164
+ OK? [A|q|<num to diff>]:#{' '}
165
+ 9 files checked.
166
+ D 4 tmp/yggdrasil-test/.yggdrasil/checker/hoge
126
167
  D 4 tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
127
168
 
169
+ Index: tmp/yggdrasil-test/.yggdrasil/checker/hoge
170
+ ===================================================================
171
+ --- tmp/yggdrasil-test/.yggdrasil/checker/hoge (revision 4)
172
+ +++ tmp/yggdrasil-test/.yggdrasil/checker/hoge (working copy)
173
+ @@ -1 +0,0 @@
174
+ -echo hoge
175
+
128
176
  Index: tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
129
177
  ===================================================================
130
178
  --- tmp/yggdrasil-test/.yggdrasil/checker_result/hoge (revision 4)
@@ -142,6 +190,7 @@ EOS
142
190
  out = catch_out {Yggdrasil.command cmd}
143
191
 
144
192
  out.should == <<"EOS"
193
+ Deleting tmp/yggdrasil-test/.yggdrasil/checker/hoge
145
194
  Deleting tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
146
195
 
147
196
  Committed revision 5.
@@ -177,10 +226,10 @@ EOS
177
226
  Yggdrasil.command %w{init --debug --server localhost:4000} +
178
227
  %w{--username hoge --password foo},
179
228
  "Y\nhoge\nfoo\n"
180
- `rm -f /tmp/yggdrasil-test/.yggdrasil/checker/gem_list`
229
+
181
230
  Yggdrasil.command %w{check --non-interactive}
182
231
 
183
- sleep 1
232
+ sleep 2
184
233
  File.exist?('/tmp/yggdrasil-test/.yggdrasil/results').should be_true
185
234
  files = Dir.entries('/tmp/yggdrasil-test/.yggdrasil/results')
186
235
  result_files = files.select{|file| %r{^#{Socket.gethostname}} =~ file}
@@ -188,10 +237,6 @@ EOS
188
237
  out = `cat /tmp/yggdrasil-test/.yggdrasil/results/#{result_files[0]}`
189
238
  out.gsub! /[ ]+/, ' '
190
239
  out.should == <<"EOS"
191
- A 0 tmp
192
- A 0 tmp/yggdrasil-test
193
- A 0 tmp/yggdrasil-test/.yggdrasil
194
- A 0 tmp/yggdrasil-test/.yggdrasil/checker_result
195
240
 
196
241
  EOS
197
242
  end
@@ -205,8 +250,9 @@ EOS
205
250
  "Y\nHOGE\n"
206
251
 
207
252
  `echo foo >> /tmp/yggdrasil-test/A`
208
- Yggdrasil.command %w{check}, "Y\n"
253
+ Yggdrasil.command %w{check}, "A\n"
209
254
 
255
+ sleep 1
210
256
  files = Dir.entries('/tmp/yggdrasil-test/.yggdrasil/results')
211
257
  result_files = files.select{|file| %r{^#{Socket.gethostname}} =~ file}
212
258
  out = `cat /tmp/yggdrasil-test/.yggdrasil/results/#{result_files[0]}`
@@ -221,6 +267,7 @@ Index: tmp/yggdrasil-test/A
221
267
  @@ -1 +1,2 @@
222
268
  hoge
223
269
  +foo
270
+
224
271
  EOS
225
272
  end
226
273
 
@@ -232,11 +279,41 @@ EOS
232
279
 
233
280
  Yggdrasil.command %w{check --non-interactive}
234
281
 
282
+ sleep 1
235
283
  files = Dir.entries('/tmp/yggdrasil-test/.yggdrasil/results')
236
284
  result_files = files.select{|file| %r{^#{Socket.gethostname}} =~ file}
237
285
  `cat /tmp/yggdrasil-test/.yggdrasil/results/#{result_files[0]}`.should == "\n"
238
286
  end
239
287
 
288
+ it 'should recover delete flag' do
289
+ pending "under construction..."
290
+ puts "\n---- should recover delete flag"
291
+
292
+ `mkdir /tmp/yggdrasil-test/c`
293
+ `echo bar > /tmp/yggdrasil-test/c/C`
294
+
295
+ Yggdrasil.command %w{add /tmp/yggdrasil-test/c/C}
296
+ Yggdrasil.command %w{commit --username hoge --password foo} +
297
+ %w{-m BAR --non-interactive}
298
+
299
+ `mv /tmp/yggdrasil-test/c /tmp/yggdrasil-test/cc`
300
+ cmd = %w{c --username hoge --password foo}
301
+ out = catch_out {Yggdrasil.command(cmd, "q\n")}
302
+ out.should == <<"EOS"
303
+
304
+ 0:D tmp/yggdrasil-test/c
305
+ 1:D tmp/yggdrasil-test/c/C
306
+ OK? [A|q|<num to diff>]:#{' '}
307
+ EOS
308
+
309
+ `mv /tmp/yggdrasil-test/cc /tmp/yggdrasil-test/c`
310
+ cmd = %w{c --username hoge --password foo}
311
+ out = catch_out {Yggdrasil.command(cmd, "q\n")}
312
+ out.should == <<"EOS"
313
+
314
+ EOS
315
+ end
316
+
240
317
  after(:all) do
241
318
  sock = TCPSocket.open('localhost', 4000)
242
319
  sock.puts('quit')
@@ -105,7 +105,7 @@ describe Yggdrasil, 'commit' do
105
105
  puts "\n-- check file exists on repo"
106
106
  res = `svn ls file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/tmp/yggdrasil-test`
107
107
  puts res
108
- res.should == ".yggdrasil/\nA\nB\n"
108
+ res.should == "A\nB\n"
109
109
  end
110
110
 
111
111
  it 'should commit deleted file' do
@@ -120,7 +120,7 @@ describe Yggdrasil, 'commit' do
120
120
  puts "\n-- check committed delete file"
121
121
  res = `svn ls file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/tmp/yggdrasil-test`
122
122
  puts res
123
- res.should == ".yggdrasil/\nA\n"
123
+ res.should == "A\n"
124
124
  end
125
125
 
126
126
  it 'should commit all files at once' do
@@ -139,7 +139,20 @@ describe Yggdrasil, 'commit' do
139
139
  puts "\n-- check committed delete file"
140
140
  res = `svn ls file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/tmp/yggdrasil-test`
141
141
  puts res
142
- res.should == ".yggdrasil/\nA\nc/\n"
142
+ res.should == "A\nc/\n"
143
143
  end
144
144
 
145
+ it 'should commit deleted directory' do
146
+ puts '---- should commit deleted directory'
147
+ `rm -rf /tmp/yggdrasil-test/c`
148
+
149
+ Yggdrasil.command %w{commit -m delete --debug} +
150
+ %w{--username hoge --password foo},
151
+ "0\n1\nY\n"
152
+
153
+ puts "\n-- check committed delete file"
154
+ res = `svn ls file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/tmp/yggdrasil-test`
155
+ puts res
156
+ res.should == "A\n"
157
+ end
145
158
  end
@@ -232,6 +232,7 @@ Valid options:
232
232
  --username ARG : specify a username ARG
233
233
  --password ARG : specify a password ARG
234
234
  --non-interactive : do no interactive prompting
235
+ -r [--revision] ARG : revision number
235
236
 
236
237
  EOS
237
238
  end
@@ -247,6 +248,7 @@ Valid options:
247
248
  --username ARG : specify a username ARG
248
249
  --password ARG : specify a password ARG
249
250
  --non-interactive : do no interactive prompting
251
+ -r [--revision] ARG : revision number
250
252
 
251
253
  EOS
252
254
  end
@@ -15,6 +15,14 @@ describe Yggdrasil, 'init' do
15
15
  err.should == "#{File.basename($0)} error: Not enough arguments provided: --repo\n\n"
16
16
  end
17
17
 
18
+ it 'should error: "no --repo at --non-interactive"' do
19
+ puts '---- should error: "no --repo at --non-interactive"'
20
+ err = catch_err do
21
+ lambda{Yggdrasil.command(%w{init --non-interactive})}.should raise_error(SystemExit)
22
+ end
23
+ err.should == "#{File.basename($0)} error: need --repo or --server\n\n"
24
+ end
25
+
18
26
  it 'should error: can not access to SVN server' do
19
27
  puts '---- should error: can not access to SVN server'
20
28
  `rm -rf /tmp/yggdrasil-test/.yggdrasil`
@@ -115,25 +123,22 @@ EOS
115
123
  "Y\n"
116
124
  end
117
125
  out.should == <<"EOS"
118
- Input svn repo URL:
126
+ Input svn repo URL:#{' '}
119
127
  check SVN access...
120
- Input svn username:
121
- Input svn password:
128
+ Input svn username:#{' '}
129
+ Input svn password:#{' '}
122
130
  SVN access OK: svn://localhost/tmp/yggdrasil-test/svn-repo
123
131
  not exist directory(s) in repository: mng-repo/host-name
124
- make directory(s)? [Yn]:
132
+ make directory(s)? [Yn]:#{' '}
125
133
  add svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo
126
134
  add svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo/host-name
127
135
  EOS
128
136
  end
129
137
 
130
- it 'should make checker example at init' do
131
- puts "\n---- should make checker example at init"
138
+ it 'should make checker directory at init' do
139
+ puts "\n---- should make checker directory at init"
132
140
  dir = '/tmp/yggdrasil-test/.yggdrasil/checker'
133
141
  File.directory?(dir).should be_true
134
-
135
- example_checker = dir + '/gem_list'
136
- File.executable?(example_checker).should be_true
137
142
  end
138
143
 
139
144
  it 'should success init subcommand with server option' do
@@ -174,7 +179,7 @@ EOS
174
179
  end
175
180
  out.should == <<"EOS"
176
181
  Already exist config file: /tmp/yggdrasil-test/.yggdrasil/config
177
- Overwrite? [Yn]:
182
+ Overwrite? [Yn]:#{' '}
178
183
  EOS
179
184
  end
180
185
 
@@ -186,7 +191,7 @@ EOS
186
191
  end
187
192
  out.should == <<"EOS"
188
193
  Already exist config file: /tmp/yggdrasil-test/.yggdrasil/config
189
- Overwrite? [Yn]:
194
+ Overwrite? [Yn]:#{' '}
190
195
  check SVN access...
191
196
  SVN access OK: file:///tmp/yggdrasil-test/.yggdrasil/private_repo
192
197
  EOS
@@ -198,15 +203,14 @@ EOS
198
203
 
199
204
  it 'should error --non-interactive: already exist config file' do
200
205
  puts '---- should error --non-interactive: already exist config file'
201
- out = catch_out do
206
+ err = catch_err do
202
207
  cmd_args = %w{init --repo file:///tmp/yggdrasil-test/svn-repo}+
203
208
  %w{--username hoge --password foo} +
204
209
  %w{--non-interactive}
205
210
  lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
206
211
  end
207
- out.should == <<"EOS"
208
- Already exist config file: /tmp/yggdrasil-test/.yggdrasil/config
209
- EOS
212
+ err.should == "#{File.basename($0)} error: Already exist config file. use --force to ignore\n\n"
213
+
210
214
  config = `cat /tmp/yggdrasil-test/.yggdrasil/config | grep repo=`
211
215
  config.should == <<"EOS"
212
216
  repo=file:///tmp/yggdrasil-test/.yggdrasil/private_repo
@@ -22,7 +22,7 @@ describe Yggdrasil, 'list' do
22
22
  %w{--username hoge --password foo}
23
23
  end
24
24
  end
25
- out.should == ".yggdrasil/\nA\nB\n"
25
+ out.should == "A\nB\n"
26
26
  end
27
27
 
28
28
  it 'should show list (no path)' do
@@ -36,8 +36,6 @@ describe Yggdrasil, 'list' do
36
36
  out.should == <<"EOS"
37
37
  tmp/
38
38
  tmp/yggdrasil-test/
39
- tmp/yggdrasil-test/.yggdrasil/
40
- tmp/yggdrasil-test/.yggdrasil/checker_result/
41
39
  tmp/yggdrasil-test/A
42
40
  tmp/yggdrasil-test/B
43
41
  EOS
@@ -49,8 +47,6 @@ EOS
49
47
  %w{--username hoge --password foo})}
50
48
  out.should == <<"EOS"
51
49
  yggdrasil-test/
52
- yggdrasil-test/.yggdrasil/
53
- yggdrasil-test/.yggdrasil/checker_result/
54
50
  yggdrasil-test/A
55
51
  yggdrasil-test/B
56
52
  EOS
@@ -62,8 +58,6 @@ EOS
62
58
  %w{--username hoge --password foo})}
63
59
  out.should == <<"EOS"
64
60
  yggdrasil-test/
65
- yggdrasil-test/.yggdrasil/
66
- yggdrasil-test/.yggdrasil/checker_result/
67
61
  yggdrasil-test/A
68
62
  yggdrasil-test/B
69
63
  EOS
@@ -27,7 +27,7 @@ describe Yggdrasil, 'revert' do
27
27
  %w{--username hoge --password foo}
28
28
  end
29
29
  puts out
30
- out.should == "no files.\n"
30
+ out.should == "3 files checked.\nYggdrasil check: OK.\n"
31
31
  end
32
32
 
33
33
  it 'should revert modified file' do
@@ -45,7 +45,7 @@ describe Yggdrasil, 'revert' do
45
45
  %w{--username hoge --password foo}
46
46
  end
47
47
  puts out
48
- out.should == "no files.\n"
48
+ out.should == "3 files checked.\nYggdrasil check: OK.\n"
49
49
  end
50
50
 
51
51
  it 'should accept password interactive' do
@@ -61,7 +61,7 @@ describe Yggdrasil, 'revert' do
61
61
  %w{--username hoge --password foo}
62
62
  end
63
63
  puts out
64
- out.should == "no files.\n"
64
+ out.should == "3 files checked.\nYggdrasil check: OK.\n"
65
65
  end
66
66
 
67
67
  it 'should revert specified file only' do
@@ -81,6 +81,7 @@ describe Yggdrasil, 'revert' do
81
81
  puts out
82
82
  out.gsub!(%r{ +}, ' ')
83
83
  out.should == <<"EOS"
84
+ 3 files checked.
84
85
  M 3 tmp/yggdrasil-test/A
85
86
 
86
87
  Index: tmp/yggdrasil-test/A
@@ -91,6 +92,8 @@ Index: tmp/yggdrasil-test/A
91
92
  hoge
92
93
  hoge
93
94
  +A
95
+
96
+ Yggdrasil check: NG!!!
94
97
  EOS
95
98
  end
96
99
 
@@ -110,6 +113,7 @@ EOS
110
113
  puts out
111
114
  out.gsub!(%r{ +},' ')
112
115
  out.should == <<"EOS"
116
+ 3 files checked.
113
117
  D 3 tmp/yggdrasil-test/A
114
118
 
115
119
  Index: tmp/yggdrasil-test/A
@@ -119,6 +123,8 @@ Index: tmp/yggdrasil-test/A
119
123
  @@ -1,2 +0,0 @@
120
124
  -hoge
121
125
  -hoge
126
+
127
+ Yggdrasil check: NG!!!
122
128
  EOS
123
129
  end
124
130
 
@@ -141,6 +147,6 @@ EOS
141
147
  %w{--username hoge --password foo}
142
148
  end
143
149
  puts out
144
- out.should == "no files.\n"
150
+ out.should == "3 files checked.\nYggdrasil check: OK.\n"
145
151
  end
146
152
  end
@@ -77,6 +77,7 @@ Index: tmp/yggdrasil-test/A
77
77
  @@ -1 +1,2 @@
78
78
  hoge
79
79
  +foo
80
+
80
81
  EOS
81
82
  end
82
83
 
@@ -69,4 +69,20 @@ describe Yggdrasil, 'update' do
69
69
  `cat /tmp/yggdrasil-test/A`.should == "A:no path\n"
70
70
  `cat /tmp/yggdrasil-test/B`.should == "B:no path\n"
71
71
  end
72
+
73
+ it 'should success update with revision' do
74
+ puts '---- should success update with revision'
75
+ `echo A:hoge > /tmp/yggdrasil-test/A`
76
+ `echo B:hoge > /tmp/yggdrasil-test/B`
77
+ Yggdrasil.command %w{commit} +
78
+ %w{-m hoge} +
79
+ %w{--username hoge --password foo --non-interactive}
80
+
81
+ FileUtils.cd '/tmp' do
82
+ Yggdrasil.command %w{update} +
83
+ %w{-r 4 --username hoge --password foo --non-interactive}
84
+ end
85
+ `cat /tmp/yggdrasil-test/A`.should == "A:related/absolute path\n"
86
+ `cat /tmp/yggdrasil-test/B`.should == "B:related/absolute path\n"
87
+ end
72
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yggdrasil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-22 00:00:00.000000000 Z
12
+ date: 2013-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  segments:
118
118
  - 0
119
- hash: 4459761969192795769
119
+ hash: -1313669213311713118
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: 4459761969192795769
128
+ hash: -1313669213311713118
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 1.8.25