svn_wc 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +7 -3
  2. data/lib/svn_wc.rb +30 -7
  3. data/test/svn_wc_test.rb +244 -3
  4. metadata +4 -4
@@ -5,7 +5,7 @@ Operate on the working copy of a (remote) Subversion (svn) repository.
5
5
 
6
6
  == VERSION:
7
7
 
8
- Version 0.0.5
8
+ Version 0.0.6
9
9
 
10
10
 
11
11
  == SYNOPSIS:
@@ -280,13 +280,17 @@ Author:: {David Wright}[http://www.dwright.us/] <david_v_wright@yahoo.com>
280
280
 
281
281
  == ACKNOWLEDGEMENTS:
282
282
 
283
- * Much of this code was guided from reading the {SVN Ruby Bindings unit tests}[https://svn.collab.net/repos/svn/trunk/subversion/bindings/swig/ruby/test/]
283
+ * Much of this code was guided from reading the {SVN Ruby Bindings unit tests}[http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/swig/ruby/]
284
284
 
285
285
  * {Doxygen Docs}[http://svn.collab.net/svn-doxygen/search.php?query=svn_wc_entry]
286
286
  Ruby -> Svn::Wc::Entry
287
287
  Doxygen Docs -> svn_wc_entry
288
288
 
289
- * The Doxyogen Modules {docs}[http://svn.collab.net/svn-doxygen/modules.html]
289
+ The collab.net Docs/code seem to have moved to being hosted by Apache:
290
+ or can view here: (I cant seem to find the Doxyogen docs anymore)
291
+ {Ruby SWIG Code}[https://trac.mathweb.org/tntbase/browser/trunk/SVN/src-trunk/subversion/bindings/swig/ruby/test?rev=4&order=name]
292
+ or can view here:
293
+ {Ruby SWIG Code}[http://www.opensource.apple.com/source/subversion/subversion-16/subversion/subversion/bindings/swig/ruby/test/]
290
294
 
291
295
  * Tim Coulter did some work with the {Ruby bindings as well}[http://www.oneofthewolves.com/svn_repos/svn_repos.rb]
292
296
 
@@ -132,7 +132,7 @@ module SvnWc
132
132
  #
133
133
  class RepoAccess
134
134
 
135
- VERSION = '0.0.3'
135
+ VERSION = '0.0.6'
136
136
 
137
137
  # initialization
138
138
  # three optional parameters
@@ -371,7 +371,12 @@ module SvnWc
371
371
  # alias up
372
372
  def update(paths=[])
373
373
 
374
- if paths.empty? then paths = self.svn_repo_working_copy end
374
+ if paths.empty?
375
+ paths = self.svn_repo_working_copy
376
+ else
377
+ @limit_to_dir_path = paths
378
+ end
379
+
375
380
  #XXX update is a bummer, just returns the rev num, not affected files
376
381
  #(svn command line up, also returns altered/new files - mimic that)
377
382
  # hence our inplace hack (_pre/_post update_entries)
@@ -390,7 +395,6 @@ module SvnWc
390
395
  # #Svn::Error::FS_NO_SUCH_REVISION,
391
396
  # #Svn::Error::WcNotDirectory,
392
397
  # #Svn::Error::EntryNotFound => e
393
- # Exception => e
394
398
  rescue Exception => err
395
399
  raise RepoAccessError, "Update Failed: #{err.message}"
396
400
  end
@@ -413,11 +417,18 @@ module SvnWc
413
417
  ##puts "#{ent[:status]} | #{ent[:repo_rev]} | #{ent[:entry_name]}"
414
418
  e_name = ent[:entry_name]
415
419
  stat = ent[:status]
420
+
421
+ if @limit_to_dir_path # limit files returned to this (and subdir's of) dir
422
+ fle = File.join(self.svn_repo_working_copy, e_name)
423
+ next unless fle.include? @limit_to_dir_path
424
+ end
425
+
416
426
  @pre_up_entries.push e_name
417
427
  ## how does it handle deletes?
418
428
  #if info()[:rev] != ent[:repo_rev]
419
429
  # puts "changed file: #{File.join(paths, ent[:entry_name])} | #{ent[:status]} "
420
430
  #end
431
+
421
432
  if stat == 'M' then @modified_entries.push "#{stat}\t#{e_name}" end
422
433
  end
423
434
  end
@@ -428,11 +439,20 @@ module SvnWc
428
439
  #
429
440
  def _post_update_entries #:nodoc:
430
441
  post_up_entries = Array.new
431
- list_entries.each { |ent| post_up_entries.push ent[:entry_name] }
442
+ list_entries.each { |ent|
443
+ if @limit_to_dir_path # limit files returned to this (and subdir's of) dir
444
+ fle = File.join(self.svn_repo_working_copy, ent[:entry_name])
445
+ next unless fle.include? @limit_to_dir_path
446
+ end
447
+ post_up_entries.push ent[:entry_name]
448
+ }
432
449
 
433
450
  added = post_up_entries - @pre_up_entries
434
451
  removed = @pre_up_entries - post_up_entries
435
452
 
453
+ #raise "#{post_up_entries}\n#{@pre_up_entries}"
454
+ #raise "#{added} - #{removed}"
455
+
436
456
  if added.length > 0
437
457
  added.each {|e_add| @modified_entries.push "A\t#{e_add}" }
438
458
  end
@@ -623,14 +643,15 @@ module SvnWc
623
643
  def list_entries(dir=self.svn_repo_working_copy, file=nil, verbose=false)
624
644
 
625
645
  @entry_list, @show, @verbose = [], true, verbose
626
-
646
+
627
647
  Svn::Wc::AdmAccess.open(nil, dir, false, 5) do |adm|
628
648
  @adm = adm
629
649
  if file.nil?
630
650
  #also see walk_entries (in svn bindings) has callback
631
651
  adm.read_entries.keys.sort.each { |ef|
632
- next unless ef.length >= 1 # why this check and not file.exists?
633
- _collect_get_entry_info(File.join(dir, ef))
652
+ next unless ef.length >= 1
653
+ svn_entry = File.join(dir, ef)
654
+ _collect_get_entry_info svn_entry
634
655
  }
635
656
  else
636
657
  _collect_get_entry_info(file)
@@ -641,6 +662,7 @@ module SvnWc
641
662
  @entry_list
642
663
  end
643
664
 
665
+
644
666
  #
645
667
  # private
646
668
  #
@@ -654,6 +676,7 @@ module SvnWc
654
676
  if File.directory?(abs_path_file)
655
677
  Dir.entries(abs_path_file).each do |de|
656
678
  next if de == '..' or de == '.' or de == '.svn'
679
+
657
680
  status_info = _get_entry_info(File.join(abs_path_file, de))
658
681
  @entry_list.push status_info if status_info and not status_info.empty?
659
682
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  # Copyright (c) 2009 David Wright
2
3
  #
3
4
  # You are free to modify and use this file under the terms of the GNU LGPL.
@@ -298,7 +299,7 @@ class TestSvnWc < Test::Unit::TestCase
298
299
  begin
299
300
  info = svn.info(file)
300
301
  orig_rev = info[:rev]
301
- fail 'is not under version control'
302
+ fail 'cant get info on non checked in file'
302
303
  rescue SvnWc::RepoAccessError => e
303
304
  assert e.message.match(/is not under version control/)
304
305
  ensure
@@ -324,6 +325,82 @@ class TestSvnWc < Test::Unit::TestCase
324
325
  assert_equal rev+1, n_rev
325
326
  end
326
327
 
328
+ def test_add_new_file_with_utf8_symbol_and_commit_and_delete
329
+ # fail on svn 1.6.6 (Centos 5.8) with utf8 issue
330
+ # attributing to utf8 issues, which may be incorrect
331
+ v = `svn --version`.match(/svn, version (\d+\.\d+\.\d+)\s/)[1] rescue '1.6.7'
332
+ if '1.6.6' <= v
333
+ puts "skipping utf8 test for svn version: #{v}"
334
+ return
335
+ end
336
+
337
+ svn = SvnWc::RepoAccess.new(YAML::dump(@conf), true, true)
338
+ file = new_unique_file_at_path2('£20')
339
+ begin
340
+ svn.info(file)
341
+ fail 'file not in svn'
342
+ rescue SvnWc::RepoAccessError => e
343
+ #cant get info: bad URI(is not URI?):
344
+ assert e.message.match(/cant get info/)
345
+ end
346
+
347
+ assert_nothing_raised{svn.add file}
348
+ assert_equal 'A', svn.status[0][:status]
349
+ assert svn.status[0][:path].match(File.basename(file))
350
+ rev = svn.commit file
351
+ assert rev >= 1
352
+ svn.delete file
353
+ assert_equal 'D', svn.status[0][:status]
354
+ assert svn.status[0][:path].match(File.basename(file))
355
+ # commit our delete
356
+ n_rev = svn.commit file
357
+ assert_equal [], svn.status
358
+ assert_equal rev+1, n_rev
359
+ end
360
+
361
+ def test_add_new_file_with_utf8_symbols_and_commit_and_delete
362
+ # fail on svn 1.6.6 (Centos 5.8) with utf8 issue
363
+ # attributing to utf8 issues, which may be incorrect
364
+ v = `svn --version`.match(/svn, version (\d+\.\d+\.\d+)\s/)[1] rescue '1.6.7'
365
+ if '1.6.6' <= v
366
+ puts "skipping utf8 test for svn version: #{v}"
367
+ return
368
+ end
369
+
370
+ svn = SvnWc::RepoAccess.new(YAML::dump(@conf), true, true)
371
+ file = new_unique_file_at_path2('£20_ߣáçkqùë_Jâçqùë')
372
+ begin
373
+ svn.info(file)
374
+ fail 'file not in svn'
375
+ rescue SvnWc::RepoAccessError => e
376
+ #cant get info: bad URI(is not URI?):
377
+ assert e.message.match(/cant get info/)
378
+ end
379
+
380
+ assert_nothing_raised{svn.add file}
381
+
382
+ begin
383
+ svn.add file
384
+ rescue SvnWc::RepoAccessError => e
385
+ assert e.message.match(/is already under version control/)
386
+ end
387
+
388
+ #assert_equal 'A', svn.status[0][:status]
389
+ # why '?' and not 'A'!?
390
+ assert_equal '?', svn.status[0][:status]
391
+ #assert svn.status[0][:path].match(File.basename(file))
392
+ #assert_equal File.basename(svn.status[0][:path]), File.basename(file)
393
+ rev = svn.commit file
394
+ assert rev >= 1
395
+ svn.delete file
396
+ assert_equal 'D', svn.status[0][:status]
397
+ assert svn.status[0][:path].match(File.basename(file))
398
+ # commit our delete
399
+ n_rev = svn.commit file
400
+ assert_equal [], svn.status
401
+ assert_equal rev+1, n_rev
402
+ end
403
+
327
404
  def test_add_new_dir_and_file_and_commit_and_delete_with_pre_open_instance
328
405
  @@svn_wc.set_conf @conf_file
329
406
  @@svn_wc.do_checkout true
@@ -381,7 +458,55 @@ class TestSvnWc < Test::Unit::TestCase
381
458
  assert File.file?(f[3])
382
459
  assert FileUtils.rm_rf(File.dirname(f[3]))
383
460
  end
461
+
462
+ def test_operations_on_specific_dir_not_process_others
463
+ svn = SvnWc::RepoAccess.new(@conf_file, true, true)
384
464
 
465
+ f = []
466
+ (1..4).each { |d|
467
+ wc_new_dir = File.join @conf['svn_repo_working_copy'], "dir#{d}"
468
+ FileUtils.mkdir wc_new_dir
469
+ wc_new_file = "test_#{d}.txt"
470
+ f[d] = File.join wc_new_dir, wc_new_file
471
+ FileUtils.touch f[d]
472
+ }
473
+
474
+ begin
475
+ svn.info(f[1])
476
+ fail 'is not under version control'
477
+ rescue SvnWc::RepoAccessError => e
478
+ assert e.message.match(/is not a working copy/)
479
+ end
480
+ #svn.add [File.dirname(f[1]), File.dirname(f[2]), File.dirname(f[4])]
481
+ #rev = svn.commit [File.dirname(f[1]), File.dirname(f[2]), File.dirname(f[4]), f[1], f[2], f[4]]
482
+ #assert rev >= 1
483
+
484
+ assert !svn.status(File.dirname(f[2])).to_s.match(/dir1/)
485
+ assert svn.status(File.dirname(f[2])).to_s.match(/dir2/)
486
+ assert !svn.status(File.dirname(f[2])).to_s.match(/dir3/)
487
+ assert !svn.status(File.dirname(f[2])).to_s.match(/dir4/)
488
+
489
+ assert !svn.status(File.dirname(f[3])).to_s.match(/dir1/)
490
+ assert svn.status(File.dirname(f[3])).to_s.match(/dir3/)
491
+ assert !svn.status(File.dirname(f[3])).to_s.match(/dir2/)
492
+ assert !svn.status(File.dirname(f[3])).to_s.match(/dir4/)
493
+
494
+ # not it repo yet
495
+ assert_raise(SvnWc::RepoAccessError) { svn.list(File.dirname(f[3])) }
496
+ svn.add [File.dirname(f[2]), File.dirname(f[3])]
497
+ rev = svn.commit [File.dirname(f[2]), File.dirname(f[3]), f[2], f[3]]
498
+
499
+ # list by dir matches specific only
500
+ assert svn.list(File.dirname(f[3]))[1].to_s.match(/test_3.txt/)
501
+ assert !svn.list(File.dirname(f[3]))[1].to_s.match(/test_2.txt/)
502
+
503
+ # list matches all
504
+ assert svn.list.to_s.match(/test_2.txt/)
505
+ assert svn.list.to_s.match(/test_3.txt/)
506
+
507
+
508
+ end
509
+
385
510
  def test_add_commit_update_file_status_revision_modify_diff_revert
386
511
  svn = SvnWc::RepoAccess.new(YAML::dump(@conf), true, true)
387
512
  f = new_unique_file_at_path
@@ -459,7 +584,7 @@ class TestSvnWc < Test::Unit::TestCase
459
584
  svn.update, 'added 3 files into another working copy of the repo, update
460
585
  on current repo finds them, good!'
461
586
 
462
- # Confirm can do add/delete/modified simultaniously
587
+ # Confirm can do add/delete/modified simultaneously
463
588
  # modify, 1 committed file, current repo
464
589
  lf = File.join @conf['svn_repo_working_copy'], fe[0]
465
590
  File.open(lf, 'a') {|fl| fl.write('local repo file is modified')}
@@ -479,6 +604,54 @@ class TestSvnWc < Test::Unit::TestCase
479
604
 
480
605
  end
481
606
 
607
+ def test_update_can_act_on_specific_dir
608
+ svn = SvnWc::RepoAccess.new(YAML::dump(@conf), true, true)
609
+
610
+ rev = svn.info()[:rev]
611
+ assert_equal [rev, []], svn.update
612
+
613
+ # add 3 files to a nested subdir under repo root
614
+ dir = 't/t/t'
615
+ (rev1, file) = check_out_new_working_copy_add_commit_new_entry_into_subdir(dir)
616
+ assert_equal rev+1, rev1
617
+
618
+ # add 3 files to a different nested subdir under repo root
619
+ dir2 = 'f/f/f'
620
+ (rev2, file2) = check_out_new_working_copy_add_commit_new_entry_into_subdir(dir2)
621
+ assert_equal rev+2, rev2
622
+
623
+ # find first nested subdir file
624
+ assert_equal \
625
+ [(rev + 2), ["A\t#{dir}/#{File.basename file}", "A\tt/t/t", "A\tt/t"]],
626
+ svn.update(File.join(@conf['svn_repo_working_copy'], 't')),
627
+ 'found file under first subdir path of the repo, but not the second subdir, good!'
628
+
629
+ # find second nested subdir file
630
+ assert_equal \
631
+ [(rev + 2), ["A\t#{dir2}/#{File.basename file2}", "A\tf/f/f", "A\tf/f"]], #svn.update(File.join(@conf['svn_repo_working_copy'], dir2)),
632
+ svn.update(File.join(@conf['svn_repo_working_copy'], 'f')),
633
+ 'update can accept a path to update and only act on that path, great!'
634
+
635
+ dir3 = 't'
636
+ (rev3, nf, nf2) = check_out_new_working_copy_add_commit_new_entries(dir, dir3)
637
+
638
+ # second nested subdir file - should not see added file
639
+ assert_equal \
640
+ [rev3, []], svn.update(File.join(@conf['svn_repo_working_copy'], 'f')),
641
+ 'update can act on passed path (or not act :)'
642
+
643
+ # first nested subdir file - should find 1 new file
644
+ assert_equal [rev3, ["A\t#{dir}/#{File.basename nf}"]],
645
+ svn.update(File.join(@conf['svn_repo_working_copy'], dir)),
646
+ 'svn update can update based specified on non-top level path, great!'
647
+
648
+ # first nested subdir file - should find second new file
649
+ assert_equal [rev3, ["A\t#{dir3}/#{File.basename nf2}"]],
650
+ svn.update(File.join(@conf['svn_repo_working_copy'], dir3)),
651
+ 'svn update can update based specified on non-top level path, great!'
652
+
653
+ end
654
+
482
655
  def test_add_exception_on_already_added_file
483
656
  svn = SvnWc::RepoAccess.new(YAML::dump(@conf), true, true)
484
657
  this_wc_rev = 0
@@ -617,7 +790,7 @@ class TestSvnWc < Test::Unit::TestCase
617
790
  svn.add dir_ent, recurse=true, force=true
618
791
  rev = svn.commit repo_wc
619
792
 
620
- entries = svn.list_entries
793
+ entries = svn.list_entries.sort_by{|h| h[:entry_name]}
621
794
 
622
795
  assert_equal File.basename(entries[0][:entry_name]),
623
796
  File.basename(file)
@@ -782,10 +955,19 @@ class TestSvnWc < Test::Unit::TestCase
782
955
 
783
956
  def new_unique_file_at_path(wc_repo=@conf['svn_repo_working_copy'])
784
957
  #Tempfile.new('test_', wc_repo).path
958
+ FileUtils.mkdir_p wc_repo unless File.directory? wc_repo
785
959
  new_file_name = File.join(wc_repo, "test_#{Time.now.usec.to_s}.txt")
786
960
  FileUtils.touch new_file_name
787
961
  new_file_name
788
962
  end
963
+
964
+ def new_unique_file_at_path2(f_name=nil, wc_repo=nil)
965
+ wc_repo =@conf['svn_repo_working_copy'] if wc_repo.nil?
966
+ #Tempfile.new('test_', wc_repo).path
967
+ new_file_name = File.join(wc_repo, "test_#{f_name}_#{Time.now.usec.to_s}.txt")
968
+ FileUtils.touch new_file_name
969
+ new_file_name
970
+ end
789
971
 
790
972
  def _working_copy_repo_at_path(wc_repo=@wc_repo2)
791
973
  conf = @conf
@@ -821,6 +1003,64 @@ class TestSvnWc < Test::Unit::TestCase
821
1003
  return rev, ff
822
1004
  end
823
1005
 
1006
+ def check_out_new_working_copy_add_commit_new_entry_into_subdir(dir)
1007
+ svn = _working_copy_repo_at_path
1008
+
1009
+ ff = Array.new
1010
+ f = new_unique_file_at_path(File.join(svn.svn_repo_working_copy, dir))
1011
+ #p svn
1012
+
1013
+ #svn.add f
1014
+ #rev = svn.commit f
1015
+ #puts File.exists? f
1016
+ dirs = dir.split('/')
1017
+ d_to_add = []
1018
+ dp = ''
1019
+ dirs.each do |d|
1020
+ dp << "/#{d}"
1021
+ d = File.join(svn.svn_repo_working_copy, dp)
1022
+ #puts "adding #{d}"
1023
+ d_to_add.push d
1024
+ # just have to add the top level subdir path
1025
+ # then all under it is found
1026
+ break
1027
+ end
1028
+ #d_to_add.push f
1029
+
1030
+ #puts d_to_add.inspect
1031
+
1032
+ svn.add d_to_add
1033
+ rev = svn.commit d_to_add
1034
+ raise 'cant get rev' unless rev
1035
+ return rev, f
1036
+ end
1037
+
1038
+ def check_out_new_working_copy_add_commit_new_entries(dir, dir2)
1039
+ svn = _working_copy_repo_at_path
1040
+
1041
+ f = new_unique_file_at_path(File.join(svn.svn_repo_working_copy, dir))
1042
+ f2 = new_unique_file_at_path(File.join(svn.svn_repo_working_copy, dir2))
1043
+ #p svn
1044
+
1045
+ svn.add f
1046
+ svn.add f2
1047
+ rev = svn.commit f
1048
+ rev = svn.commit f2
1049
+ raise 'file not created' unless File.exists?(f) and File.exists?(f2)
1050
+ raise 'cant get rev' unless rev
1051
+ return rev, f, f2
1052
+ end
1053
+
1054
+ def touch_file_add_to_svn(svn, dir)
1055
+ f = new_unique_file_at_path dir
1056
+
1057
+ svn.add f
1058
+ rev = svn.commit f
1059
+ raise 'file not created' unless File.exists?(f)
1060
+ raise 'cant get rev' unless rev
1061
+ return rev, f
1062
+ end
1063
+
824
1064
  def modify_file_and_commit_into_another_working_repo
825
1065
  svn = _working_copy_repo_at_path
826
1066
  f = new_unique_file_at_path(svn.svn_repo_working_copy)
@@ -831,6 +1071,7 @@ class TestSvnWc < Test::Unit::TestCase
831
1071
  return rev, f
832
1072
  end
833
1073
 
1074
+
834
1075
  end
835
1076
 
836
1077
  if VERSION < '1.8.7'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svn_wc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Wright
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-11 00:00:00 -07:00
18
+ date: 2012-02-07 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21