yggdrasil 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,7 +14,7 @@ And you have to install subversion:
14
14
 
15
15
  Prepare subversion repository and initialize Yggdrasil:
16
16
 
17
- $ svnadmin create ~/svn-repo
17
+ (e.g.)$ svnadmin create ~/svn-repo
18
18
  $ yggdrasil init --repo file://$HOME/svn-repo
19
19
 
20
20
  You should use svn-server if you have.
@@ -23,7 +23,7 @@ Prepare subversion repository and initialize Yggdrasil:
23
23
 
24
24
  Add configuration files:
25
25
 
26
- $ yggdrasil add ~/.bashrc ..etc
26
+ $ yggdrasil add /etc/hosts /etc/fstab ..etc
27
27
 
28
28
  Check modify and/or delete:
29
29
 
data/lib/yggdrasil/add.rb CHANGED
@@ -10,15 +10,16 @@ class Yggdrasil
10
10
  next
11
11
  end
12
12
  mirror_path = @mirror_dir
13
- file_path.split('/')[1..-1].each do |part|
14
- mirror_path += '/'+part
13
+ file_path_parts = file_path.split('/')[1..-1]
14
+ file_path_parts.each do |part|
15
+ mirror_path += "/#{part}"
15
16
  next if File.exist?(mirror_path)
16
- if mirror_path == @mirror_dir+file_path
17
+ if part.equal?(file_path_parts[-1])
17
18
  FileUtils.copy file_path, mirror_path
18
19
  else
19
20
  Dir.mkdir mirror_path
20
21
  end
21
- puts system3("#@svn add --no-auth-cache --non-interactive #{mirror_path}")
22
+ puts system3("#@svn add #{mirror_path}")
22
23
  end
23
24
  end
24
25
  end
@@ -10,11 +10,11 @@ class Yggdrasil
10
10
 
11
11
  paths = Array.new
12
12
  if args.size == 0
13
- paths << @current_dir.sub(%r{^/}, '')
13
+ paths << @current_dir.sub(%r{^/*}, '')
14
14
  else
15
15
  args.each do |path|
16
16
  path = "#@current_dir/#{path}" unless %r{^/} =~ path
17
- paths << path.sub(%r{^/}, '')
17
+ paths << path.sub(%r{^/*}, '')
18
18
  end
19
19
  end
20
20
 
@@ -1,11 +1,11 @@
1
1
  class Yggdrasil
2
2
 
3
3
  # @param [Array] args
4
- def Yggdrasil.init(args)
5
- ENV['LANG'] = 'en_US.UTF-8'
4
+ def init(args)
6
5
 
7
6
  args, options = parse_options(args,
8
- {'--repo'=>:repo, '--username'=>:username, '--password'=>:password})
7
+ {'--username'=>:username, '--password'=>:password,
8
+ '--repo'=>:repo, '--parents'=>:parents?, '--debug'=>:debug?})
9
9
  if args.size != 0
10
10
  error "invalid arguments: #{args.join(',')}"
11
11
  end
@@ -20,9 +20,8 @@ class Yggdrasil
20
20
  end
21
21
  svn_version=$1
22
22
 
23
- config_dir = ENV["HOME"] + '/.yggdrasil'
24
- if File.exist?(config_dir)
25
- puts "#{CMD} error: already exist .yggdrasil directory: #{config_dir}"
23
+ if File.exist?(@config_file)
24
+ puts "#{CMD} error: already exist config file: #@config_file"
26
25
  exit 1
27
26
  end
28
27
 
@@ -42,43 +41,69 @@ class Yggdrasil
42
41
  options = input_user_pass(options)
43
42
 
44
43
  puts "SVN access test..."
44
+ url_parts = options[:repo].split('/')
45
+ url_parts_num = url_parts.size
45
46
  loop do
46
- ret = system3 "#{svn} ls --no-auth-cache --non-interactive"\
47
- " --username '#{options[:username]}' --password '#{options[:password]}'"\
48
- " #{options[:repo]}", false
49
- unless ret.nil?
50
- puts "SVN access: OK."
51
- break
47
+ puts "url_parts_num=#{url_parts_num}" if options[:debug?]
48
+ if url_parts_num < 3
49
+ puts "SVN error: can not access to '#{options[:repo]}'."
50
+ exit 1
52
51
  end
53
-
54
- ret = system3 "#{svn} mkdir --parents -m 'yggdrasil init'"\
55
- " --no-auth-cache --non-interactive"\
56
- " --username '#{options[:username]}' --password '#{options[:password]}'"\
57
- " #{options[:repo]}", false
52
+ url = url_parts[0...url_parts_num].join('/')
53
+ puts "try url=#{url}" if options[:debug?]
54
+ ret = system3("#{svn} ls --no-auth-cache --non-interactive" +
55
+ " --username '#{options[:username]}' --password '#{options[:password]}'" +
56
+ " #{url}", false)
58
57
  unless ret.nil?
59
- puts "SVN mkdir: OK."
58
+ puts "SVN access OK: #{url}"
60
59
  break
61
60
  end
62
61
 
63
- puts "SVN error: can not access to '#{options[:repo]}'."
64
- exit 1
62
+ url_parts_num -= 1
65
63
  end
66
64
 
67
- Dir.mkdir config_dir, 0755
68
- File.open(config_dir+'/config', "w") do |f|
65
+ Dir.mkdir @config_dir, 0755 unless File.exist?(@config_dir)
66
+
67
+ if url_parts_num != url_parts.size
68
+ until options[:parents?]
69
+ puts "not exist directory(s): #{url_parts[url_parts_num...url_parts.size].join('/')}"
70
+ print "make directory(s)? [Yn]: "
71
+ input = $stdin.gets
72
+ exit 1 if input.nil?
73
+ input.chomp!
74
+ return if input == 'n'
75
+ break if input == 'Y'
76
+ end
77
+ `rm -rf #@mirror_dir`
78
+ system3 "#{svn} checkout --no-auth-cache --non-interactive" +
79
+ " --username '#{options[:username]}' --password '#{options[:password]}'" +
80
+ " #{url_parts[0...url_parts_num].join('/')} #@mirror_dir"
81
+ add_paths = Array.new
82
+ path = @mirror_dir
83
+ while url_parts_num < url_parts.size
84
+ path += '/' + url_parts[url_parts_num]
85
+ Dir.mkdir path
86
+ system3 "#{svn} add #{path}"
87
+ add_paths << path
88
+ url_parts_num += 1
89
+ end
90
+ system3 "#{svn} commit -m 'yggdrasil init' --no-auth-cache --non-interactive" +
91
+ " --username '#{options[:username]}' --password '#{options[:password]}'" +
92
+ ' ' + add_paths.join(' ')
93
+ system3 "rm -rf #@mirror_dir"
94
+ end
95
+
96
+ File.open(@config_file, "w") do |f|
69
97
  f.write "path=#{ENV['PATH']}\n"\
70
98
  "svn=#{svn}\n"\
71
99
  "svn_version=#{svn_version}\n"\
72
100
  "repo=#{options[:repo]}\n"
73
101
  end
74
102
 
75
- ret = system3 "#{svn} checkout"\
76
- " --no-auth-cache --non-interactive"\
77
- " --username '#{options[:username]}' --password '#{options[:password]}'"\
78
- " #{options[:repo]} #{config_dir+'/mirror'}", false
79
- if ret.nil?
80
- puts "SVN checkout: error."
81
- exit 1
82
- end
103
+ `rm -rf #@mirror_dir`
104
+ system3 "#{svn} checkout"\
105
+ " --no-auth-cache --non-interactive"\
106
+ " --username '#{options[:username]}' --password '#{options[:password]}'"\
107
+ " #{options[:repo]} #@mirror_dir"
83
108
  end
84
109
  end
@@ -13,7 +13,7 @@ class Yggdrasil
13
13
 
14
14
  repos = Array.new
15
15
  if args.size == 0
16
- repos << @repo+@current_dir
16
+ repos << @repo + @current_dir
17
17
  else
18
18
  args.each do |path|
19
19
  path = "#@current_dir/#{path}" unless %r{^/} =~ path
data/lib/yggdrasil/log.rb CHANGED
@@ -8,15 +8,15 @@ class Yggdrasil
8
8
  options = input_user_pass(options)
9
9
 
10
10
  if args.size == 0
11
- dir = @mirror_dir+@current_dir
11
+ dir = @mirror_dir + @current_dir
12
12
  error "current directory is not managed." unless File.exist?(dir)
13
13
  args << dir
14
14
  else
15
15
  args.collect! do |arg|
16
16
  if %r{^/} =~ arg
17
- @mirror_dir+arg
17
+ @mirror_dir + arg
18
18
  else
19
- @mirror_dir+@current_dir+'/'+arg
19
+ @mirror_dir + @current_dir + '/' + arg
20
20
  end
21
21
  end
22
22
  end
@@ -24,26 +24,22 @@ class Yggdrasil
24
24
  return if confirmed_updates.size == 0
25
25
 
26
26
  FileUtils.cd @mirror_dir do
27
- system3 "#@svn revert"\
28
- " --no-auth-cache --non-interactive"\
29
- " --username '#{options[:username]}' --password '#{options[:password]}'"\
30
- " #{confirmed_updates.reverse.join(' ')}"
27
+ system3 "#@svn revert #{confirmed_updates.reverse.join(' ')}"
31
28
 
32
29
  # make ls hash
33
- out = system3("#@svn ls --no-auth-cache --non-interactive"\
34
- " --username '#{options[:username]}' --password '#{options[:password]}'"\
35
- " --depth infinity #@repo")
30
+ out = system3("#@svn ls -R #@repo --no-auth-cache --non-interactive"\
31
+ " --username '#{options[:username]}' --password '#{options[:password]}'")
36
32
  ls_hash = Hash.new
37
33
  out.split(/\n/).each {|relative| ls_hash[relative]=true}
38
34
 
39
35
  # reflect mirror to real file
40
36
  confirmed_updates.each do |file|
41
37
  if ls_hash.has_key?(file)
42
- if File.file?(@mirror_dir+'/'+file)
43
- FileUtils.copy_file @mirror_dir+'/'+file, '/'+file
38
+ if File.file?("#@mirror_dir/#{file}")
39
+ FileUtils.copy_file "#@mirror_dir/#{file}", "/#{file}"
44
40
  end
45
41
  else
46
- system3 "rm -rf #{@mirror_dir+'/'+file}"
42
+ system3 "rm -rf #{@mirror_dir + '/' + file}"
47
43
  end
48
44
  end
49
45
  end
@@ -11,11 +11,11 @@ class Yggdrasil
11
11
 
12
12
  paths = String.new
13
13
  if args.size == 0
14
- paths += ' '+@current_dir.sub(%r{^/}, '')
14
+ paths += ' '+@current_dir.sub(%r{^/*}, '')
15
15
  else
16
16
  args.each do |path|
17
17
  path = "#@current_dir/#{path}" unless %r{^/} =~ path
18
- paths += ' ' + path.sub(%r{^/}, '')
18
+ paths += ' ' + path.sub(%r{^/*}, '')
19
19
  end
20
20
  end
21
21
 
@@ -11,7 +11,7 @@ class Yggdrasil
11
11
 
12
12
  updates = Array.new
13
13
  FileUtils.cd @mirror_dir do
14
- out = system3("#@svn status -qu --depth infinity --no-auth-cache --non-interactive" +
14
+ out = system3("#@svn status -qu --no-auth-cache --non-interactive" +
15
15
  " --username '#{options[:username]}' --password '#{options[:password]}'")
16
16
  out.split(/\n/).each do |line|
17
17
  updates << $1 if /^.*\*.*\s(\S+)\s*$/ =~ line
@@ -56,7 +56,7 @@ class Yggdrasil
56
56
  # reflect mirror to real file
57
57
  confirmed_updates.each do |update_file|
58
58
  if File.exist?(update_file)
59
- FileUtils.copy_file @mirror_dir+'/'+update_file, '/'+update_file
59
+ FileUtils.copy_file "#@mirror_dir/#{update_file}", "/#{update_file}"
60
60
  else
61
61
  system3 "rm -rf /#{update_file}"
62
62
  end
@@ -1,5 +1,5 @@
1
1
  class Yggdrasil
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  CMD = File::basename($0)
4
4
 
5
5
  def Yggdrasil.version
data/lib/yggdrasil.rb CHANGED
@@ -35,7 +35,7 @@ class Yggdrasil
35
35
  when 'help', 'h', '?'
36
36
  help(args[1..-1])
37
37
  when 'init'
38
- init(args[1..-1])
38
+ new(false).init(args[1..-1])
39
39
  when 'list', 'ls'
40
40
  new.list(args[1..-1])
41
41
  when 'log'
@@ -55,9 +55,10 @@ class Yggdrasil
55
55
 
56
56
  # @param [String] cmd
57
57
  def Yggdrasil.system3(cmd, err_exit=true)
58
- out = `#{cmd}`
58
+ out = `#{cmd} 2>&1`
59
+ stat = $?
59
60
 
60
- unless $?.success?
61
+ unless stat.success?
61
62
  return nil unless err_exit
62
63
  $stderr.puts "#{CMD} error: command failure: #{cmd}"
63
64
  $stderr.puts "command output:"
@@ -115,47 +116,50 @@ class Yggdrasil
115
116
  return options
116
117
  end
117
118
 
118
- def initialize
119
-
120
- @config = read_config
121
- ENV["PATH"] = @config[:path]
122
- @svn = @config[:svn]
123
- @repo = @config[:repo]
119
+ def initialize(exist_config = true)
124
120
  @current_dir = `readlink -f .`.chomp
125
- @mirror_dir = ENV["HOME"]+"/.yggdrasil/mirror"
121
+ @config_dir = "#{ENV["HOME"]}/.yggdrasil"
122
+ @config_file = "#@config_dir/config"
123
+ @mirror_dir = "#@config_dir/mirror"
124
+
125
+ return unless exist_config
126
+ configs = read_config
127
+ ENV["PATH"] = configs[:path]
128
+ @svn = configs[:svn]
129
+ @repo = configs[:repo]
126
130
  end
127
131
 
128
132
  # load config value from config file
129
133
  def read_config
130
- @config=Hash.new
134
+ configs = Hash.new
131
135
  begin
132
- config_file = open("#{ENV['HOME']}/.yggdrasil/config")
136
+ File.open(@config_file) do |file|
137
+ l = 0
138
+ while (line = file.gets)
139
+ l += 1
140
+ next if /^\s*#.*$/ =~ line # comment line
141
+ if /^\s*(\S+)\s*=\s*(\S+).*$/ =~ line
142
+ configs[$1.to_sym] = $2
143
+ else
144
+ puts "#{CMD} error: syntax error. :#@config_file(#{l})"
145
+ exit 1
146
+ end
147
+ end
148
+ end
133
149
  rescue
134
- puts "#{CMD} error: can not open config file: #{ENV['HOME']}/.yggdrasil/config"
150
+ puts "#{CMD} error: can not open config file: #@config_file"
135
151
  exit 1
136
152
  end
137
- l = 0
138
- while (line = config_file.gets)
139
- l += 1
140
- next if /^\s*#.*$/ =~ line # comment line
141
- if /^\s*(\S+)\s*=\s*(\S+).*$/ =~ line
142
- @config[$1.to_sym] = $2
143
- else
144
- puts "#{CMD} error: syntax error. :#{ENV['HOME']}/.yggdrasil/config(#{l})"
145
- exit 1
146
- end
147
- end
148
- config_file.close
149
- @config
153
+ configs
150
154
  end
151
155
 
152
156
  def sync_mirror(options)
153
157
  updates = Array.new
154
158
  FileUtils.cd @mirror_dir do
155
- out = system3("#@svn ls #@repo --depth infinity --no-auth-cache --non-interactive" +
159
+ out = system3("#@svn ls #@repo -R --no-auth-cache --non-interactive" +
156
160
  " --username '#{options[:username]}' --password '#{options[:password]}'")
157
161
  files = out.split(/\n/)
158
- out = system3("#@svn status -q --depth infinity --no-auth-cache --non-interactive" +
162
+ out = system3("#@svn status -q --no-auth-cache --non-interactive" +
159
163
  " --username '#{options[:username]}' --password '#{options[:password]}'")
160
164
  out.split(/\n/).each do |line|
161
165
  files << $1 if /^.*\s(\S+)\s*$/ =~ line
@@ -163,17 +167,17 @@ class Yggdrasil
163
167
  files.sort!
164
168
  files.uniq!
165
169
  files.each do |file|
166
- if !File.exist?('/'+file)
170
+ if !File.exist?("/#{file}")
167
171
  system3 "#@svn delete #{file} --force" +
168
172
  " --no-auth-cache --non-interactive"
169
- elsif File.file?('/'+file)
170
- if !File.exist?(@mirror_dir+'/'+file)
171
- system3 "#@svn revert --no-auth-cache --non-interactive #{file}"
173
+ elsif File.file?("/#{file}")
174
+ if !File.exist?("#@mirror_dir/#{file}")
175
+ system3 "#@svn revert #{file}"
172
176
  end
173
- FileUtils.copy_file '/'+file, @mirror_dir+'/'+file
177
+ FileUtils.copy_file "/#{file}", "#@mirror_dir/#{file}"
174
178
  end
175
179
  end
176
- out = system3("#@svn status -q --depth infinity --no-auth-cache --non-interactive" +
180
+ out = system3("#@svn status -q --no-auth-cache --non-interactive" +
177
181
  " --username '#{options[:username]}' --password '#{options[:password]}'")
178
182
  out.split(/\n/).each do |line|
179
183
  updates << $1 if /^.*\s(\S+)\s*$/ =~ line
@@ -186,13 +190,13 @@ class Yggdrasil
186
190
 
187
191
  target_relatives = Array.new
188
192
  if target_paths.size == 0
189
- target_relatives << @current_dir.sub(%r{^/},'')
193
+ target_relatives << @current_dir.sub(%r{^/*},'')
190
194
  else
191
195
  target_paths.each do |path|
192
196
  if %r{^/} =~ path
193
- target_relatives << path.sub(%r{^/},'') # cut first '/'
197
+ target_relatives << path.sub(%r{^/*},'') # cut first '/'
194
198
  else
195
- target_relatives << @current_dir.sub(%r{^/},'') + '/' + path
199
+ target_relatives << @current_dir.sub(%r{^/*},'') + '/' + path
196
200
  end
197
201
  end
198
202
  end
data/spec/add_spec.rb CHANGED
@@ -9,10 +9,10 @@ describe Yggdrasil, "add" do
9
9
 
10
10
  it 'should warn: add non-exist files' do
11
11
  puts '---- should warn: add non-exist files'
12
- out = catch_stdout{Yggdrasil.command %w{add hoge}}
12
+ out = catch_out_err{Yggdrasil.command %w{add hoge}}
13
13
  out.should == "no such file: #{`readlink -f hoge`}"
14
14
 
15
- out = catch_stdout{Yggdrasil.command %w{add /etc/hoge}}
15
+ out = catch_out_err{Yggdrasil.command %w{add /etc/hoge}}
16
16
  out.should == "no such file: /etc/hoge\n"
17
17
  end
18
18
 
data/spec/commit_spec.rb CHANGED
@@ -8,7 +8,7 @@ describe Yggdrasil, "commit" do
8
8
  puts '-- init'
9
9
  Yggdrasil.command %w{init} +
10
10
  %w{--repo svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo/host-name/} +
11
- %w{--username hoge --password foo}
11
+ %w{--username hoge --password foo --parents}
12
12
  end
13
13
 
14
14
  it 'should commit added files' do
data/spec/diff_spec.rb CHANGED
@@ -13,7 +13,7 @@ describe Yggdrasil, "diff" do
13
13
 
14
14
  it 'should success diff (absolute/relative path)' do
15
15
  puts "---- should success diff (absolute/relative path)"
16
- out = catch_stdout do
16
+ out = catch_out_err do
17
17
  FileUtils.cd "/tmp/yggdrasil-test" do
18
18
  Yggdrasil.command(%w{diff /tmp/yggdrasil-test/A B --username hoge --password foo})
19
19
  end
@@ -40,7 +40,7 @@ EOS
40
40
 
41
41
  it 'should success (no path)' do
42
42
  puts "---- should success (no path)"
43
- out = catch_stdout do
43
+ out = catch_out_err do
44
44
  FileUtils.cd "/tmp/yggdrasil-test" do
45
45
  Yggdrasil.command %w{diff --username hoge --password foo}
46
46
  end
@@ -67,7 +67,7 @@ EOS
67
67
 
68
68
  it 'should success (-r)' do
69
69
  puts "---- should success (-r)"
70
- out = catch_stdout do
70
+ out = catch_out_err do
71
71
  FileUtils.cd "/tmp/yggdrasil-test" do
72
72
  Yggdrasil.command %w{diff -r 2:3 A --username hoge --password foo}
73
73
  end
@@ -85,7 +85,7 @@ EOS
85
85
 
86
86
  it 'should success (--revision)' do
87
87
  puts "---- should success (--revision)"
88
- out = catch_stdout do
88
+ out = catch_out_err do
89
89
  FileUtils.cd "/tmp/yggdrasil-test" do
90
90
  Yggdrasil.command %w{diff --revision 3 A --username hoge --password foo}
91
91
  end
@@ -99,6 +99,26 @@ Index: tmp/yggdrasil-test/A
99
99
  hoge
100
100
  hoge
101
101
  +HOGE
102
+ EOS
103
+ end
104
+
105
+ it 'should error: diff with incorrect option' do
106
+ puts "---- should error: diff with incorrect option"
107
+ cmd = %w{diff --hoge --username hoge --password foo}
108
+
109
+ tmp_err = $stderr
110
+ $stderr = StringIO.new
111
+ FileUtils.cd "/" do
112
+ lambda{Yggdrasil.command cmd}.should raise_error(SystemExit)
113
+ end
114
+ out = $stderr.string
115
+ $stderr = tmp_err
116
+ out.sub!(%r{/\S*svn}, 'svn')
117
+ out.should == <<"EOS"
118
+ rspec error: command failure: svn diff --no-auth-cache --non-interactive --username hoge --password foo --hoge
119
+ command output:
120
+ svn: invalid option: --hoge
121
+ Type 'svn help' for usage.
102
122
  EOS
103
123
  end
104
124
  end
data/spec/help_spec.rb CHANGED
@@ -29,31 +29,31 @@ EOS
29
29
 
30
30
  it 'should show subcommands on no subcommands' do
31
31
  puts '---- should show subcommands on no subcommands'
32
- out = catch_stdout{Yggdrasil.command []}
32
+ out = catch_out_err{Yggdrasil.command []}
33
33
  out.should == show_subcommands
34
34
  end
35
35
 
36
36
  it 'should show subcommands on "help"' do
37
37
  puts '---- should show subcommands on "help"'
38
- out = catch_stdout{Yggdrasil.command %w{help}}
38
+ out = catch_out_err{Yggdrasil.command %w{help}}
39
39
  out.should == show_subcommands
40
40
  end
41
41
 
42
42
  it 'should show subcommands on "h"' do
43
43
  puts '---- should show subcommands on "h"'
44
- out = catch_stdout{Yggdrasil.command %w{h}}
44
+ out = catch_out_err{Yggdrasil.command %w{h}}
45
45
  out.should == show_subcommands
46
46
  end
47
47
 
48
48
  it 'should show subcommands on "?"' do
49
49
  puts '---- should show subcommands on "?"'
50
- out = catch_stdout{Yggdrasil.command %w{?}}
50
+ out = catch_out_err{Yggdrasil.command %w{?}}
51
51
  out.should == show_subcommands
52
52
  end
53
53
 
54
54
  it 'should be unknown subcommand on "hoge"' do
55
55
  puts '---- should be unknown subcommand on "hoge"'
56
- out = catch_stdout do
56
+ out = catch_out_err do
57
57
  lambda{Yggdrasil.command(%w{hoge})}.should raise_error(SystemExit)
58
58
  end
59
59
  out.should == "#{File.basename($0)} error: Unknown subcommand: 'hoge'\n\n"
@@ -67,13 +67,13 @@ EOS
67
67
 
68
68
  it 'should show help_help' do
69
69
  puts '---- should show help_help'
70
- out = catch_stdout{Yggdrasil.command %w{help help}}
70
+ out = catch_out_err{Yggdrasil.command %w{help help}}
71
71
  out.should == help_help
72
72
  end
73
73
 
74
74
  it 'should error too many arguments' do
75
75
  puts '---- should error too many arguments'
76
- out = catch_stdout do
76
+ out = catch_out_err do
77
77
  lambda{Yggdrasil.command(%w{help help help})}.should raise_error(SystemExit)
78
78
  end
79
79
  out.should == "#{File.basename($0)} error: too many arguments.\n\n"
@@ -81,7 +81,7 @@ EOS
81
81
 
82
82
  it 'should show help of version' do
83
83
  puts '---- should show help of version'
84
- out = catch_stdout{Yggdrasil.command %w{help version}}
84
+ out = catch_out_err{Yggdrasil.command %w{help version}}
85
85
  out.should == <<"EOS"
86
86
  version: See the program version
87
87
  usage: #{File.basename($0)} version
@@ -91,7 +91,7 @@ EOS
91
91
 
92
92
  it 'should show help of init' do
93
93
  puts '---- should show help of init'
94
- out = catch_stdout{Yggdrasil.command %w{help init}}
94
+ out = catch_out_err{Yggdrasil.command %w{help init}}
95
95
  out.should == <<"EOS"
96
96
  init: Check environment and initialize configuration.
97
97
  usage: #{File.basename($0)} init [OPTIONS...]
@@ -106,7 +106,7 @@ EOS
106
106
 
107
107
  it 'should show help of add' do
108
108
  puts '---- should show help of add'
109
- out = catch_stdout{Yggdrasil.command %w{help add}}
109
+ out = catch_out_err{Yggdrasil.command %w{help add}}
110
110
  out.should == <<"EOS"
111
111
  add: Add files to management list (add to subversion)
112
112
  usage #{File.basename($0)} add [FILES...]
@@ -116,7 +116,7 @@ EOS
116
116
 
117
117
  it 'should show help of commit' do
118
118
  puts '---- should show help of commit'
119
- out = catch_stdout{Yggdrasil.command %w{help commit}}
119
+ out = catch_out_err{Yggdrasil.command %w{help commit}}
120
120
  out.should == <<"EOS"
121
121
  commit (ci): Send changes from your local file to the repository.
122
122
  usage: #{File.basename($0)} commit [OPTIONS...] [FILES...]
@@ -132,7 +132,7 @@ EOS
132
132
 
133
133
  it 'should show help of cleanup' do
134
134
  puts '---- should show help of cleanup'
135
- out = catch_stdout{Yggdrasil.command %w{help cleanup}}
135
+ out = catch_out_err{Yggdrasil.command %w{help cleanup}}
136
136
  out.should == <<"EOS"
137
137
  cleanup: clean up the working copy
138
138
  usage: #{File.basename($0)} cleanup [OPTIONS...]
@@ -146,7 +146,7 @@ EOS
146
146
 
147
147
  it 'should show help of diff' do
148
148
  puts '---- should show help of diff'
149
- out = catch_stdout{Yggdrasil.command %w{help diff}}
149
+ out = catch_out_err{Yggdrasil.command %w{help diff}}
150
150
  out.should == <<"EOS"
151
151
  diff (di): Display the differences between two revisions or paths.
152
152
  usage: #{File.basename($0)} diff [OPTIONS...] [PATH...]
@@ -168,7 +168,7 @@ EOS
168
168
 
169
169
  it 'should show help of list' do
170
170
  puts '---- should show help of list'
171
- out = catch_stdout{Yggdrasil.command %w{help list}}
171
+ out = catch_out_err{Yggdrasil.command %w{help list}}
172
172
  out.should == <<"EOS"
173
173
  list (ls): List directory entries in the repository.
174
174
  usage: #{File.basename($0)} list [OPTIONS...] [PATH...]
@@ -193,7 +193,7 @@ EOS
193
193
 
194
194
  it 'should show help of log' do
195
195
  puts '---- should show help of log'
196
- out = catch_stdout{Yggdrasil.command %w{help log}}
196
+ out = catch_out_err{Yggdrasil.command %w{help log}}
197
197
  out.should == <<"EOS"
198
198
  log: Show the log messages for a set of revision(s) and/or file(s).
199
199
  usage: #{File.basename($0)} log [OPTIONS...] [PATH]
@@ -215,7 +215,7 @@ EOS
215
215
 
216
216
  it 'should show help of status' do
217
217
  puts '---- should show help of status'
218
- out = catch_stdout{Yggdrasil.command %w{help status}}
218
+ out = catch_out_err{Yggdrasil.command %w{help status}}
219
219
  out.should == <<"EOS"
220
220
  status (stat, st): Print the status of managed files and directories.
221
221
  usage: #{File.basename($0)} status [OPTIONS...] [PATH...]
@@ -231,7 +231,7 @@ EOS
231
231
 
232
232
  it 'should show help of update' do
233
233
  puts '---- should show help of update'
234
- out = catch_stdout{Yggdrasil.command %w{help update}}
234
+ out = catch_out_err{Yggdrasil.command %w{help update}}
235
235
  out.should == <<"EOS"
236
236
  update (up): Bring changes from the repository into the local files.
237
237
  usage: #{File.basename($0)} update [PATH...]
@@ -254,7 +254,7 @@ EOS
254
254
 
255
255
  it 'should show help of revert' do
256
256
  puts '---- should show help of revert'
257
- out = catch_stdout{Yggdrasil.command %w{help revert}}
257
+ out = catch_out_err{Yggdrasil.command %w{help revert}}
258
258
  out.should == <<"EOS"
259
259
  revert: Restore pristine working copy file (undo most local edits).
260
260
  usage: #{File.basename($0)} revert [PATH...]
data/spec/init_spec.rb CHANGED
@@ -8,7 +8,7 @@ describe Yggdrasil, "init" do
8
8
 
9
9
  it 'should error: "Not enough arguments provided"' do
10
10
  puts '---- should error: "Not enough arguments provided"'
11
- out = catch_stdout do
11
+ out = catch_out_err do
12
12
  lambda{Yggdrasil.command(%w{init --repo})}.should raise_error(SystemExit)
13
13
  end
14
14
  out.should == "#{File.basename($0)} error: Not enough arguments provided: --repo\n\n"
@@ -17,7 +17,7 @@ describe Yggdrasil, "init" do
17
17
  it 'should error: can not access to SVN server' do
18
18
  puts '---- should error: can not access to SVN server'
19
19
  `rm -rf /tmp/yggdrasil-test/.yggdrasil`
20
- out = catch_stdout do
20
+ out = catch_out_err do
21
21
  cmd_args = %w{init --repo file:///tmp/yggdrasil-test/hoge --username hoge --password foo}
22
22
  lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
23
23
  end
@@ -29,7 +29,7 @@ describe Yggdrasil, "init" do
29
29
  `rm -rf /tmp/yggdrasil-test/.yggdrasil`
30
30
  `rm -rf /tmp/yggdrasil-test/svn-repo`
31
31
 
32
- catch_stdout do # > /dev/null
32
+ catch_out_err do # > /dev/null
33
33
  cmd_args = %w{init --repo file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/ --username hoge --password foo}
34
34
  lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
35
35
  end
@@ -41,12 +41,10 @@ describe Yggdrasil, "init" do
41
41
  `rm -rf /tmp/yggdrasil-test/svn-repo`
42
42
  `svnadmin create /tmp/yggdrasil-test/svn-repo`
43
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"
44
+ Yggdrasil.command %w{init --debug} +
45
+ %w{--repo file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/} +
46
+ %w{--username hoge --password foo},
47
+ "Y\n"
50
48
  end
51
49
 
52
50
  it 'should success: create config file (interactive)' do
@@ -70,17 +68,20 @@ EOS
70
68
  end
71
69
  `svnserve -d`
72
70
 
73
- out = catch_stdout do
71
+ out = catch_out_err do
74
72
  Yggdrasil.command %w{init},
75
73
  "svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo/host-name/\n"\
76
74
  "hoge\n"\
77
- "foo\n"
78
- end
75
+ "foo\n"\
76
+ "Y\n"
77
+ end
79
78
  out.should == \
80
79
  "Input svn repo URL: "\
81
80
  "Input svn username: "\
82
81
  "Input svn password: "\
83
82
  "SVN access test...\n"\
84
- "SVN mkdir: OK.\n"
83
+ "SVN access OK: svn://localhost/tmp/yggdrasil-test/svn-repo\n"\
84
+ "not exist directory(s): mng-repo/host-name\n"\
85
+ "make directory(s)? [Yn]: "
85
86
  end
86
87
  end
data/spec/list_spec.rb CHANGED
@@ -9,14 +9,14 @@ describe Yggdrasil, "list" do
9
9
 
10
10
  it 'should show list (absolute path)' do
11
11
  puts '---- should show list (absolute path)'
12
- out = catch_stdout{Yggdrasil.command(%w{list /tmp} +
12
+ out = catch_out_err{Yggdrasil.command(%w{list /tmp} +
13
13
  %w{--username hoge --password foo})}
14
14
  out.should == "yggdrasil-test/\n"
15
15
  end
16
16
 
17
17
  it 'should show list (relative path)' do
18
18
  puts '---- should show list (relative path)'
19
- out = catch_stdout do
19
+ out = catch_out_err do
20
20
  FileUtils.cd "/tmp" do
21
21
  Yggdrasil.command %w{list yggdrasil-test}+
22
22
  %w{--username hoge --password foo}
@@ -27,7 +27,7 @@ describe Yggdrasil, "list" do
27
27
 
28
28
  it 'should show list (no path)' do
29
29
  puts '---- should show list (no path)'
30
- out = catch_stdout do
30
+ out = catch_out_err do
31
31
  FileUtils.cd "/tmp/yggdrasil-test" do
32
32
  Yggdrasil.command %w{list} +
33
33
  %w{--username hoge --password foo}
@@ -38,8 +38,8 @@ describe Yggdrasil, "list" do
38
38
 
39
39
  it 'should show list (with options)' do
40
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})}
41
+ out = catch_out_err{Yggdrasil.command(%w{list -R --revision 2 --recursive /tmp} +
42
+ %w{--username hoge --password foo})}
43
43
  out.should == "yggdrasil-test/\nyggdrasil-test/A\nyggdrasil-test/B\n"
44
44
  end
45
45
  end
data/spec/log_spec.rb CHANGED
@@ -9,7 +9,7 @@ describe Yggdrasil, "log" do
9
9
 
10
10
  it 'should show log (absolute path)' do
11
11
  puts '---- should show log (absolute path)'
12
- out = catch_stdout{Yggdrasil.command(%w{log /tmp} +
12
+ out = catch_out_err{Yggdrasil.command(%w{log /tmp} +
13
13
  %w{--username hoge --password foo})}
14
14
  out.gsub!(%r{20..-..-.. .*20..\)}, '')
15
15
  out.should == <<"EOS"
@@ -35,7 +35,7 @@ EOS
35
35
 
36
36
  it 'should show log (relative path)' do
37
37
  puts '---- should show log (relative path)'
38
- out = catch_stdout do
38
+ out = catch_out_err do
39
39
  FileUtils.cd "/tmp" do
40
40
  Yggdrasil.command %w{log yggdrasil-test}+
41
41
  %w{--username hoge --password foo}
@@ -65,7 +65,7 @@ EOS
65
65
 
66
66
  it 'should show log (no path)' do
67
67
  puts '---- should show log (no path)'
68
- out = catch_stdout do
68
+ out = catch_out_err do
69
69
  FileUtils.cd "/tmp/yggdrasil-test" do
70
70
  Yggdrasil.command %w{log} +
71
71
  %w{--username hoge --password foo}
@@ -95,7 +95,7 @@ EOS
95
95
 
96
96
  it 'should show log (with options)' do
97
97
  puts '---- should show log (with options)'
98
- out = catch_stdout{Yggdrasil.command(%w{log --revision 2 /tmp} +
98
+ out = catch_out_err{Yggdrasil.command(%w{log --revision 2 /tmp} +
99
99
  %w{--username hoge --password foo})}
100
100
  out.sub!(%r{20..-..-.. .*20..\)}, '')
101
101
  out.should == <<"EOS"
data/spec/revert_spec.rb CHANGED
@@ -22,7 +22,7 @@ describe Yggdrasil, "revert" do
22
22
  end
23
23
 
24
24
  puts "\n-- check revert file (add)"
25
- out = catch_stdout do
25
+ out = catch_out_err do
26
26
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
27
27
  %w{--username hoge --password foo}
28
28
  end
@@ -40,7 +40,7 @@ describe Yggdrasil, "revert" do
40
40
  "0\nY\n"
41
41
 
42
42
  puts "\n-- check revert file (modify)"
43
- out = catch_stdout do
43
+ out = catch_out_err do
44
44
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
45
45
  %w{--username hoge --password foo}
46
46
  end
@@ -56,7 +56,7 @@ describe Yggdrasil, "revert" do
56
56
  "foo\nY\n" # interactive input: password, Y/n
57
57
 
58
58
  puts "\n-- check revert file"
59
- out = catch_stdout do
59
+ out = catch_out_err do
60
60
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
61
61
  %w{--username hoge --password foo}
62
62
  end
@@ -74,14 +74,13 @@ describe Yggdrasil, "revert" do
74
74
  "0\nY\n"
75
75
 
76
76
  puts "\n-- check revert file"
77
- out = catch_stdout do
77
+ out = catch_out_err do
78
78
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
79
79
  %w{--username hoge --password foo}
80
80
  end
81
81
  puts out
82
- out.should == <<"EOS"
83
- M 3 tmp/yggdrasil-test/A
84
- EOS
82
+ out.gsub!(%r{ +}, ' ')
83
+ out.should == "M 3 tmp/yggdrasil-test/A\n"
85
84
  end
86
85
 
87
86
  it 'should not revert deleted file' do
@@ -93,14 +92,14 @@ EOS
93
92
  "0\nn\n"
94
93
 
95
94
  puts "\n-- check status"
96
- out = catch_stdout do
95
+ out = catch_out_err do
97
96
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
98
97
  %w{--username hoge --password foo}
99
98
  end
99
+ out.chomp!
100
100
  puts out
101
- out.should == <<"EOS"
102
- D 3 tmp/yggdrasil-test/A
103
- EOS
101
+ out.gsub!(%r{\s+},' ')
102
+ out.should == "D 3 tmp/yggdrasil-test/A"
104
103
  end
105
104
 
106
105
  it 'should revert all files at once' do
@@ -117,7 +116,7 @@ EOS
117
116
  "0\nY\n"
118
117
 
119
118
  puts "\n-- check status"
120
- out = catch_stdout do
119
+ out = catch_out_err do
121
120
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
122
121
  %w{--username hoge --password foo}
123
122
  end
data/spec/spec_helper.rb CHANGED
@@ -32,7 +32,7 @@ def init_yggdrasil
32
32
  puts '-- init'
33
33
  Yggdrasil.command %w{init} +
34
34
  %w{--repo svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo/host-name/} +
35
- %w{--username hoge --password foo}
35
+ %w{--username hoge --password foo --parents}
36
36
  puts '-- add'
37
37
  `echo hoge > /tmp/yggdrasil-test/A`
38
38
  `echo foo > /tmp/yggdrasil-test/B`
@@ -49,11 +49,11 @@ def init_yggdrasil
49
49
  %w{--username hoge --password foo}
50
50
  end
51
51
 
52
- def catch_stdout
52
+ def catch_out_err
53
53
  exit 1 unless block_given?
54
54
  tmp_out = $stdout
55
55
  $stdout = StringIO.new
56
56
  yield
57
- $stdout,tmp_out = tmp_out, $stdout
57
+ $stdout, tmp_out = tmp_out, $stdout
58
58
  tmp_out.string
59
59
  end
data/spec/status_spec.rb CHANGED
@@ -16,44 +16,47 @@ describe Yggdrasil, "status" do
16
16
 
17
17
  it 'should show status(absolute and relative)' do
18
18
  puts "---- should show status(absolute and relative)"
19
- out = catch_stdout do
19
+ out = catch_out_err do
20
20
  FileUtils.cd "/tmp/yggdrasil-test" do
21
21
  Yggdrasil.command %w{status /tmp/yggdrasil-test/A B --username hoge --password foo}
22
22
  end
23
23
  end
24
+ out.gsub!(%r{ +}, ' ')
24
25
  out.should == <<"EOS"
25
- M 3 tmp/yggdrasil-test/A
26
- D 3 tmp/yggdrasil-test/B
26
+ M 3 tmp/yggdrasil-test/A
27
+ D 3 tmp/yggdrasil-test/B
27
28
  EOS
28
29
  end
29
30
 
30
31
  it 'should show status(/)' do
31
32
  puts "---- should show status(/)"
32
- out = catch_stdout do
33
+ out = catch_out_err do
33
34
  FileUtils.cd "/tmp/yggdrasil-test" do
34
35
  Yggdrasil.command %w{status / --username hoge --password foo}
35
36
  end
36
37
  end
38
+ out.gsub!(%r{ +}, ' ')
37
39
  out.should == <<"EOS"
38
- M 3 tmp/yggdrasil-test/A
39
- D 3 tmp/yggdrasil-test/B
40
- A 0 tmp/yggdrasil-test/c/C
41
- A 0 tmp/yggdrasil-test/c
40
+ M 3 tmp/yggdrasil-test/A
41
+ D 3 tmp/yggdrasil-test/B
42
+ A 0 tmp/yggdrasil-test/c/C
43
+ A 0 tmp/yggdrasil-test/c
42
44
  EOS
43
45
  end
44
46
 
45
47
  it 'should show status (no path)' do
46
48
  puts "---- should show status (no path)"
47
- out = catch_stdout do
49
+ out = catch_out_err do
48
50
  FileUtils.cd "/tmp/yggdrasil-test" do
49
51
  Yggdrasil.command %w{status --username hoge --password foo}
50
52
  end
51
53
  end
54
+ out.gsub!(%r{ +}, ' ')
52
55
  out.should == <<"EOS"
53
- M 3 tmp/yggdrasil-test/A
54
- D 3 tmp/yggdrasil-test/B
55
- A 0 tmp/yggdrasil-test/c/C
56
- A 0 tmp/yggdrasil-test/c
56
+ M 3 tmp/yggdrasil-test/A
57
+ D 3 tmp/yggdrasil-test/B
58
+ A 0 tmp/yggdrasil-test/c/C
59
+ A 0 tmp/yggdrasil-test/c
57
60
  EOS
58
61
  end
59
62
  end
data/spec/version_spec.rb CHANGED
@@ -12,13 +12,13 @@ EOS
12
12
 
13
13
  it 'should show version on "version"' do
14
14
  puts '---- should show version on "version"'
15
- out = catch_stdout{Yggdrasil.command %w{version}}
15
+ out = catch_out_err{Yggdrasil.command %w{version}}
16
16
  out.should == show_version
17
17
  end
18
18
 
19
19
  it 'should show version on "--version"' do
20
20
  puts '---- should show version on "--version"'
21
- out = catch_stdout{Yggdrasil.command %w{--version}}
21
+ out = catch_out_err{Yggdrasil.command %w{--version}}
22
22
  out.should == show_version
23
23
  end
24
24
  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.3
4
+ version: 0.0.4
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-01-16 00:00:00.000000000 Z
12
+ date: 2013-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -98,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  segments:
100
100
  - 0
101
- hash: 1446740146431344687
101
+ hash: -1095897170101989481
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  none: false
104
104
  requirements:
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  segments:
109
109
  - 0
110
- hash: 1446740146431344687
110
+ hash: -1095897170101989481
111
111
  requirements: []
112
112
  rubyforge_project:
113
113
  rubygems_version: 1.8.23