yggdrasil 0.0.14 → 0.0.15

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.
@@ -120,6 +120,7 @@ Valid options:
120
120
  --server ARG : specify a server address and port
121
121
  e.g. 192.168.1.35:4000
122
122
  see also 'yggserve help'
123
+ --force : force operation to run
123
124
 
124
125
  EOS
125
126
  when 'list', 'ls' ########################################### list (ls)
@@ -9,7 +9,7 @@ class Yggdrasil
9
9
  {'--username'=>:username, '--password'=>:password,
10
10
  '--repo'=>:repo, '--parents'=>:parents?,
11
11
  '--non-interactive'=>:non_interactive?,
12
- '--server'=>:server })
12
+ '--force'=>:force?, '--server'=>:server })
13
13
  @options[:ro_username] = @options[:username] if @options.has_key?(:username)
14
14
  @options[:ro_password] = @options[:password] if @options.has_key?(:password)
15
15
 
@@ -24,7 +24,24 @@ class Yggdrasil
24
24
  error 'can not find version string: svn --version' unless /version (\d+\.\d+\.\d+) / =~ out
25
25
  svn_version=$1
26
26
 
27
- error "already exist config file: #@config_file" if File.exist?(@config_file)
27
+ while File.exist?(@config_file)
28
+ if @options[:force?]
29
+ `rm -rf #@config_file`
30
+ break
31
+ end
32
+ puts "Already exist config file: #@config_file"
33
+ exit 1 if @options[:non_interactive?]
34
+ print "Overwrite? [Yn]:"
35
+ res = $stdin.gets
36
+ puts
37
+ return nil unless res
38
+ res.chomp!
39
+ return nil if res == 'n'
40
+ if res == 'Y'
41
+ `rm -rf #@config_file`
42
+ break
43
+ end
44
+ end
28
45
 
29
46
  get_server_config(true) if @options.has_key?(:server)
30
47
 
@@ -49,6 +66,7 @@ class Yggdrasil
49
66
  end
50
67
  url_parts = @options[:repo].split('/')
51
68
  url_parts_num = url_parts.size
69
+ url = ''
52
70
  loop do
53
71
  if url_parts_num < 3
54
72
  if anon_access
@@ -78,27 +96,31 @@ class Yggdrasil
78
96
 
79
97
  if url_parts_num != url_parts.size
80
98
  until @options[:parents?]
81
- msg = "not exist directory(s): #{url_parts[url_parts_num...url_parts.size].join('/')}"
99
+ break if @options[:force?]
100
+ msg = "not exist directory(s) in repository: #{url_parts[url_parts_num...url_parts.size].join('/')}"
82
101
  error msg if @options[:non_interactive?]
83
102
  puts msg
84
- print 'make directory(s)? [Yn]: '
103
+ print 'make directory(s)? [Yn]:'
85
104
  input = $stdin.gets
86
105
  error 'can not gets $stdin' if input.nil?
106
+ puts
87
107
  input.chomp!
88
108
  return if input == 'n'
89
109
  break if input == 'Y'
90
110
  end
91
111
  input_user_pass
92
112
  `rm -rf #@mirror_dir`
93
- system3 "#{svn} checkout --no-auth-cache --non-interactive" +
113
+ system3 "#{svn} checkout -N --no-auth-cache --non-interactive" +
94
114
  " --username '#{@options[:ro_username]}' --password '#{@options[:ro_password]}'" +
95
115
  " #{url_parts[0...url_parts_num].join('/')} #@mirror_dir"
96
116
  add_paths = Array.new
97
117
  path = @mirror_dir
98
118
  while url_parts_num < url_parts.size
119
+ url += '/' + url_parts[url_parts_num]
99
120
  path += '/' + url_parts[url_parts_num]
100
121
  Dir.mkdir path
101
122
  system3 "#{svn} add #{path}"
123
+ puts "add #{url}"
102
124
  add_paths << path
103
125
  url_parts_num += 1
104
126
  end
@@ -135,10 +157,10 @@ class Yggdrasil
135
157
 
136
158
  def init_get_repo_interactive
137
159
  loop do
138
- print 'Input svn repo URL: '
160
+ print 'Input svn repo URL:'
139
161
  input = $stdin.gets
140
162
  error 'can not input svn repo URL' unless input
141
-
163
+ puts
142
164
  if %r{^(http://|https://|file://|svn://|private)} =~ input
143
165
  @options[:repo] = input
144
166
  break
@@ -1,5 +1,5 @@
1
1
  class Yggdrasil
2
- VERSION = '0.0.14'
2
+ VERSION = '0.0.15'
3
3
 
4
4
  def version
5
5
  puts <<"EOS"
@@ -66,16 +66,17 @@ 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
+ puts
72
73
  input.chomp!
73
74
  return if input.size == 0
74
75
  @options[:username] = @options[:ro_username] = input
75
76
  end
76
77
  until @options.has_key?(:password) do
77
78
  error 'Can\'t get username or password' if @options.has_key?(:non_interactive?)
78
- print 'Input svn password: '
79
+ print 'Input svn password:'
79
80
  #input = `sh -c 'read -s hoge;echo $hoge'`
80
81
  system3 'stty -echo', false
81
82
  input = $stdin.gets
data/spec/help_spec.rb CHANGED
@@ -107,6 +107,7 @@ Valid options:
107
107
  --server ARG : specify a server address and port
108
108
  e.g. 192.168.1.35:4000
109
109
  see also 'yggserve help'
110
+ --force : force operation to run
110
111
 
111
112
  EOS
112
113
  end
data/spec/init_spec.rb CHANGED
@@ -33,8 +33,10 @@ describe Yggdrasil, 'init' do
33
33
  %w{--non-interactive}
34
34
  lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
35
35
  end
36
- err.should ==
37
- "#{File.basename($0)} error: not exist directory(s): mng-repo/host-name\n\n"
36
+ err.should == <<"EOS"
37
+ #{File.basename($0)} error: not exist directory(s) in repository: mng-repo/host-name
38
+
39
+ EOS
38
40
  end
39
41
 
40
42
  it 'should error: need password' do
@@ -112,14 +114,17 @@ EOS
112
114
  "foo\n"\
113
115
  "Y\n"
114
116
  end
115
- out.should == \
116
- 'Input svn repo URL: '\
117
- "check SVN access...\n"\
118
- 'Input svn username: '\
119
- "Input svn password: \n"\
120
- "SVN access OK: svn://localhost/tmp/yggdrasil-test/svn-repo\n"\
121
- "not exist directory(s): mng-repo/host-name\n"\
122
- 'make directory(s)? [Yn]: '
117
+ out.should == <<"EOS"
118
+ Input svn repo URL:
119
+ check SVN access...
120
+ Input svn username:
121
+ Input svn password:
122
+ SVN access OK: svn://localhost/tmp/yggdrasil-test/svn-repo
123
+ not exist directory(s) in repository: mng-repo/host-name
124
+ make directory(s)? [Yn]:
125
+ add svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo
126
+ add svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo/host-name
127
+ EOS
123
128
  end
124
129
 
125
130
  it 'should make checker example at init' do
@@ -161,6 +166,71 @@ EOS
161
166
  File.exist?('/tmp/yggdrasil-test/.yggdrasil/config').should be_true
162
167
  end
163
168
 
169
+ it 'should alert and cancel: already exist config file' do
170
+ puts '---- should alert and cancel: already exist config file'
171
+ out = catch_out do
172
+ cmd_args = %w{init --repo file:///tmp/yggdrasil-test/hoge --username hoge --password foo}
173
+ Yggdrasil.command cmd_args, "n\n"
174
+ end
175
+ out.should == <<"EOS"
176
+ Already exist config file: /tmp/yggdrasil-test/.yggdrasil/config
177
+ Overwrite? [Yn]:
178
+ EOS
179
+ end
180
+
181
+ it 'should alert and overwrite: already exist config file' do
182
+ puts '---- should alert and overwrite: already exist config file'
183
+ out = catch_out do
184
+ cmd_args = %w{init --repo private}
185
+ Yggdrasil.command cmd_args, "Y\n"
186
+ end
187
+ out.should == <<"EOS"
188
+ Already exist config file: /tmp/yggdrasil-test/.yggdrasil/config
189
+ Overwrite? [Yn]:
190
+ check SVN access...
191
+ SVN access OK: file:///tmp/yggdrasil-test/.yggdrasil/private_repo
192
+ EOS
193
+ config = `cat /tmp/yggdrasil-test/.yggdrasil/config | grep repo=`
194
+ config.should == <<"EOS"
195
+ repo=file:///tmp/yggdrasil-test/.yggdrasil/private_repo
196
+ EOS
197
+ end
198
+
199
+ it 'should error --non-interactive: already exist config file' do
200
+ puts '---- should error --non-interactive: already exist config file'
201
+ out = catch_out do
202
+ cmd_args = %w{init --repo file:///tmp/yggdrasil-test/svn-repo}+
203
+ %w{--username hoge --password foo} +
204
+ %w{--non-interactive}
205
+ lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
206
+ end
207
+ out.should == <<"EOS"
208
+ Already exist config file: /tmp/yggdrasil-test/.yggdrasil/config
209
+ EOS
210
+ config = `cat /tmp/yggdrasil-test/.yggdrasil/config | grep repo=`
211
+ config.should == <<"EOS"
212
+ repo=file:///tmp/yggdrasil-test/.yggdrasil/private_repo
213
+ EOS
214
+ end
215
+
216
+ it 'should do --force: already exist config file' do
217
+ puts '---- should do --force: already exist config file'
218
+ out = catch_out do
219
+ cmd_args = %w{init}+
220
+ %w{--repo svn://localhost/tmp/yggdrasil-test/svn-repo/servers/hoge/} +
221
+ %w{--username hoge --password foo}+
222
+ %w{--non-interactive --force}
223
+ Yggdrasil.command cmd_args
224
+ end
225
+ out.should == <<"EOS"
226
+ check SVN access...
227
+ SVN access OK: svn://localhost/tmp/yggdrasil-test/svn-repo/servers
228
+ add svn://localhost/tmp/yggdrasil-test/svn-repo/servers/hoge
229
+ EOS
230
+ config = `cat /tmp/yggdrasil-test/.yggdrasil/config | grep repo=`
231
+ config.should == "repo=svn://localhost/tmp/yggdrasil-test/svn-repo/servers/hoge\n"
232
+ end
233
+
164
234
  after(:all) do
165
235
  sock = TCPSocket.open('localhost', 4000)
166
236
  sock.puts('quit')
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.14
4
+ version: 0.0.15
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-02-20 00:00:00.000000000 Z
12
+ date: 2013-04-22 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: 1459074757574721274
119
+ hash: 4459761969192795769
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: 1459074757574721274
128
+ hash: 4459761969192795769
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 1.8.25