svn-command 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,7 +46,7 @@ module Subversion
46
46
  before_externals ||= ''
47
47
  before_externals = before_externals.strip.colorize_svn_status_lines + "\n" if before_externals != ""
48
48
 
49
- externals = externals.join
49
+ externals = externals.join.strip
50
50
  externals =
51
51
  '_'*40 + ' externals '.underline + '_'*40 + "\n" +
52
52
  externals.reject { |line|
data/lib/svn_command.rb CHANGED
@@ -241,7 +241,7 @@ module Subversion
241
241
  when nil
242
242
  puts "You are using svn-command, a replacement/wrapper for the standard svn command."
243
243
  puts "svn-command is installed at: #{$0}"
244
- puts "Wrapping svn executable at: #{Subversion.executable} (use the full path to bypass this wrapper)"
244
+ puts "Use the full path to bypass this wrapper: #{Subversion.executable}"
245
245
  puts
246
246
  puts Subversion.help(subcommand).gsub(<<End, '')
247
247
 
@@ -402,16 +402,23 @@ End
402
402
  puts( ('-'*100).green )
403
403
  puts "What do you want to do with '#{file.white.underline}'?".white.bold
404
404
  begin
405
+ if !File.exist?(file)
406
+ raise "#{file} doesn't seem to exist -- even though it was reported by svn status"
407
+ end
405
408
  if File.file?(file)
409
+ puts "File contents:"
406
410
  # Only show the first x bytes so that we don't accidentally dump the contens of some 20 GB log file to screen...
407
- puts File.read(file, 3000) || ''
411
+ contents = File.read(file, 3000) || ''
412
+ print contents
413
+ puts if contents[-1] && contents[-1].chr != "\n" # Make sure we end with a newline character
414
+ puts "..." if contents.length >= 3000 # So they know that there may be more to the file than what's shown
408
415
  elsif File.directory?(file)
409
416
  puts "Directory contains:"
410
417
  Dir.new(file).reject {|f| ['.','..'].include? f}.each do |f|
411
418
  puts f
412
419
  end
413
420
  else
414
- raise "#{file} is not a file or directory -- what *is* it??"
421
+ raise "#{file} is not a file or directory -- what *is* it then???"
415
422
  end
416
423
  end
417
424
  print(
@@ -434,9 +441,13 @@ End
434
441
  when 'd'
435
442
  puts
436
443
 
437
- print "Are you pretty much *SURE* you want to 'rm -rf #{file}'? (y)es, (n)o > "
438
444
  response = ""
439
- response = $stdin.getc.chr while !['y', 'n', "\n"].include?(begin response.downcase!; response end)
445
+ if File.directory?(file)
446
+ print "Are you pretty much *SURE* you want to 'rm -rf #{file}'? (y)es, (n)o > "
447
+ response = $stdin.getc.chr while !['y', 'n', "\n"].include?(begin response.downcase!; response end)
448
+ else
449
+ response = "y"
450
+ end
440
451
 
441
452
  if response == 'y'
442
453
  print "\nDeleting... "
@@ -44,6 +44,13 @@ class ArgEscapingTest < BaseSvnCommandTest
44
44
  # Don't worry, this'll never happen, because the shell will expand the * *before* it gets to SvnCommand. But if you *did* sneak in an asterisk to SvnCommand.execute somehow, this is what would happen...
45
45
  SvnCommand.execute("add dir/* --non-recursive")
46
46
  assert_equal "svn add --non-recursive 'dir/*'", Subversion.executed.join
47
+ # Actually, I lied... The * will *not* be expanded if there are no matching files. But that seems like a bash/shell problem, not our concern. Demo:
48
+ # > mkdir foo
49
+ # > echo foo/*
50
+ # foo/*
51
+ # > touch foo/file
52
+ # > echo foo/*
53
+ # foo/file
47
54
  end
48
55
  def test_multiline
49
56
  SvnCommand.execute(args = "commit -m 'This is a
@@ -185,21 +192,30 @@ end
185
192
  # Custom subcommands
186
193
 
187
194
  #-----------------------------------------------------------------------------------------------------------------------------
195
+
196
+ # Notes about this test:
197
+ # If you start seeing errors like this:
198
+ # NoMethodError: undefined method `chr' for nil:NilClass
199
+ # coming from one of the $stdin.getc.chr lines, it means that you didn't feed it enough simulated input! It was expectin to get
200
+ # another character from stdin but you didn't supply one!
201
+
188
202
  class SvnEachUnaddedTest < BaseSvnCommandTest
189
- def setup
190
- super
203
+ def stub_status_1
191
204
  Subversion.stubs(:status).returns("
192
205
  M gemables/calculator/test/calculator_test.rb
193
206
  X gemables/calculator/tasks/shared
194
- ? gemables/calculator/lib/calculator.rb
207
+ ? gemables/calculator/lib/unused.rb
195
208
  ")
209
+ end
210
+ def setup
211
+ super
196
212
  FileUtils.mkdir_p('gemables/calculator/lib/')
197
- File.open(@filename = 'gemables/calculator/lib/calculator.rb', 'w') do |file|
198
- file.puts "line 1 of calculator.rb"
199
- end
213
+ # file = 'gemables/calculator/lib/useless_directory'
214
+ # FileUtils.rmdir(file) if File.exist?(file)
215
+ File.open(@filename = 'gemables/calculator/lib/unused.rb', 'w') { |file| file.puts "line 1 of unused.rb" }
200
216
  end
201
217
  def teardown
202
- file = 'gemables/calculator/lib/calculator.rb'
218
+ file = 'gemables/calculator/lib/unused.rb'
203
219
  FileUtils.rm(file) if File.exist?(file)
204
220
  FileUtils.rmdir('gemables/calculator/lib/')
205
221
  FileUtils.rmdir('gemables/calculator/')
@@ -207,47 +223,64 @@ X gemables/calculator/tasks/shared
207
223
  end
208
224
 
209
225
  def test_add
226
+ stub_status_1
210
227
  output = simulate_input('a') do
211
228
  capture_output { SvnCommand.execute('each_unadded dir') }
212
229
  end
213
- assert_match /What do you want to do with .*calculator\.rb/, output
230
+ assert_match /What do you want to do with .*unused\.rb/, output
214
231
  assert_match /Adding/, output
215
- assert_equal "svn add gemables/calculator/lib/calculator.rb", Subversion.executed.join
232
+ assert_equal "svn add gemables/calculator/lib/unused.rb", Subversion.executed.join
216
233
  end
217
234
  def test_ignore
235
+ stub_status_1
218
236
  output = simulate_input('i') do
219
237
  capture_output { SvnCommand.execute('each_unadded dir') }
220
238
  end
221
- assert_match /What do you want to do with .*calculator\.rb/, output
239
+ assert_match /What do you want to do with .*unused\.rb/, output
222
240
  assert_match /Ignoring/, output
223
241
  assert_equal [
224
242
  "svn propget svn:ignore gemables/calculator/lib",
225
- "svn propset svn:ignore 'calculator.rb' gemables/calculator/lib"
243
+ "svn propset svn:ignore 'unused.rb' gemables/calculator/lib"
226
244
  ], Subversion.executed
227
245
  end
228
246
  def test_preview_is_now_automatic
247
+ stub_status_1
229
248
  output = simulate_input(
230
249
  #"p" + # Preview
250
+ "\n" + # Blank line to do nothing (and exit loop)
231
251
  "\n" # Blank line to do nothing (and exit loop)
232
252
  ) do
233
253
  capture_output { SvnCommand.execute('each_unadded dir') }
234
254
  end
235
- assert_match /What do you want to do with .*calculator\.rb/, output
236
- assert_match "line 1 of calculator.rb".to_re, output
255
+ assert_match /What do you want to do with .*unused\.rb/, output
256
+ assert_match "line 1 of unused.rb".to_re, output
237
257
  end
238
258
  def test_delete
259
+ Subversion.stubs(:status).returns("
260
+ M gemables/calculator/test/calculator_test.rb
261
+ X gemables/calculator/tasks/shared
262
+ ? gemables/calculator/lib/unused.rb
263
+ ? gemables/calculator/lib/useless_directory
264
+ ")
265
+ FileUtils.mkdir_p(@dirname = 'gemables/calculator/lib/useless_directory')
266
+ File.open( 'gemables/calculator/lib/useless_directory/foo', 'w') { |file| file.puts "line 1 of foo" }
267
+
268
+ assert File.exist?( @dirname )
239
269
  assert File.exist?( @filename )
240
270
  output = simulate_input(
241
271
  'd' + # Delete
242
- 'y' # Yes I'm sure
272
+ # (The file doesn't require confirmation.)
273
+ 'd' + # Delete
274
+ 'y' # Yes I'm sure (The non-empty directory does.)
243
275
  ) do
244
276
  capture_output { SvnCommand.execute('each_unadded dir') }
245
277
  end
246
- assert_match /What do you want to do with .*calculator\.rb/, output
247
- assert_match "Are you pretty much".to_re, output
248
- assert_match /Deleting/, output
249
- #print output
278
+ assert_match /What do you want to do with .*unused\.rb/, output
279
+ assert_match /What do you want to do with .*useless_directory/, output
280
+ assert_match /Are you .*SURE/, output
281
+ assert_match /Deleting.*Deleting/m, output
250
282
  assert !File.exist?( @filename )
283
+ assert !File.exist?( @dirname )
251
284
  end
252
285
  end #class
253
286
 
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: svn-command
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.4
6
+ version: 0.0.5
7
7
  date: 2007-03-15 00:00:00 -07:00
8
8
  summary: A nifty wrapper command for Subversion's command-line svn client
9
9
  require_paths: