1 require "my-assertions"
7 class SvnClientTest < Test::Unit::TestCase
19 assert_equal(Svn::Core.subr_version, Svn::Client.version)
22 def test_add_not_recurse
25 dir_path = File.join(@wc_path, dir)
26 path = File.join(dir_path, dir)
27 uri = "#{@repos_uri}/#{dir}/#{dir}"
29 ctx = make_context(log)
30 FileUtils.mkdir(dir_path)
32 ctx.add(dir_path, false)
35 assert_raise(Svn::Error::FS_NOT_FOUND) do
45 dir_path = File.join(@wc_path, dir)
46 path = File.join(dir_path, file)
47 uri = "#{@repos_uri}/#{dir}/#{file}"
49 ctx = make_context(log)
50 FileUtils.mkdir(dir_path)
51 File.open(path, "w") {|f| f.print(src)}
55 assert_equal(src, ctx.cat(uri))
63 dir_path = File.join(@wc_path, dir)
64 path = File.join(dir_path, file)
65 uri = "#{@repos_uri}/#{dir}/#{file}"
67 ctx = make_context(log)
68 FileUtils.mkdir(dir_path)
69 File.open(path, "w") {|f| f.print(src)}
70 ctx.add(dir_path, false)
73 assert_raise(Svn::Error::ENTRY_EXISTS) do
74 ctx.add(dir_path, true, false)
77 ctx.add(dir_path, true, true)
79 assert_equal(src, ctx.cat(uri))
82 def test_add_no_ignore
87 dir_path = File.join(@wc_path, dir)
88 path = File.join(dir_path, file)
89 uri = "#{@repos_uri}/#{dir}/#{file}"
91 ctx = make_context(log)
92 FileUtils.mkdir(dir_path)
93 ctx.add(dir_path, false)
94 ctx.propset(Svn::Core::PROP_IGNORE, file, dir_path)
97 File.open(path, "w") {|f| f.print(src)}
99 ctx.add(dir_path, true, true, false)
101 assert_raise(Svn::Error::FS_NOT_FOUND) do
105 ctx.add(dir_path, true, true, true)
107 assert_equal(src, ctx.cat(uri))
113 deep_dir = ["d", "e", "e", "p"]
115 dir_uri = "#{@repos_uri}/#{dir}"
116 deep_dir_uri = "#{@repos_uri}/#{deep_dir.join('/')}"
117 dir2_uri = "#{@repos_uri}/#{dir2}"
118 dir_path = File.join(@wc_path, dir)
119 deep_dir_path = File.join(@wc_path, *deep_dir)
120 dir2_path = File.join(@wc_path, dir2)
122 ctx = make_context(log)
124 assert(!File.exist?(dir_path))
126 assert(File.exist?(dir_path))
127 assert_raises(Svn::Error::EntryExists) do
130 old_rev = ctx.commit(@wc_path).revision
132 new_rev = ctx.mkdir(dir2_uri).revision
133 assert_equal(old_rev + 1, new_rev)
134 assert_raises(Svn::Error::FsAlreadyExists) do
137 assert(!File.exist?(dir2_path))
139 assert(File.exist?(dir2_path))
141 assert_raises(Svn::Error::SvnError) do
142 ctx.mkdir(deep_dir_path)
146 def test_mkdir_multiple
151 dirs_path = dirs.collect{|d| File.join(@wc_path, d)}
152 dirs_uri = dirs.collect{|d| "#{@repos_uri}/#{d}"}
154 ctx = make_context(log)
157 ctx.set_notify_func do |notify|
158 infos << [notify.path, notify]
161 dirs_path.each do |path|
162 assert(!File.exist?(path))
165 assert_equal(dirs_path.sort,
166 infos.collect{|path, notify| path}.sort)
167 assert_equal(dirs_path.collect{true},
168 infos.collect{|path, notify| notify.add?})
169 dirs_path.each do |path|
170 assert(File.exist?(path))
175 assert_equal(dirs_path.sort,
176 infos.collect{|path, notify| path}.sort)
177 assert_equal(dirs_path.collect{true},
178 infos.collect{|path, notify| notify.commit_added?})
181 def test_mkdir_multiple2
186 dirs_path = dirs.collect{|d| File.join(@wc_path, d)}
187 dirs_uri = dirs.collect{|d| "#{@repos_uri}/#{d}"}
189 ctx = make_context(log)
192 ctx.set_notify_func do |notify|
193 infos << [notify.path, notify]
196 dirs_path.each do |path|
197 assert(!File.exist?(path))
199 ctx.mkdir(*dirs_path)
200 assert_equal(dirs_path.sort,
201 infos.collect{|path, notify| path}.sort)
202 assert_equal(dirs_path.collect{true},
203 infos.collect{|path, notify| notify.add?})
204 dirs_path.each do |path|
205 assert(File.exist?(path))
210 assert_equal(dirs_path.sort,
211 infos.collect{|path, notify| path}.sort)
212 assert_equal(dirs_path.collect{true},
213 infos.collect{|path, notify| notify.commit_added?})
218 src = "sample source\n"
221 path = File.join(@wc_path, file)
222 dir_path = File.join(@wc_path, dir)
224 ctx = make_context(log)
226 File.open(path, "w") {|f| f.print(src)}
231 ctx.delete([path, dir_path])
233 assert(!File.exist?(path))
234 assert(!File.exist?(dir_path))
237 File.open(path, "w") {|f| f.print(src)}
241 File.open(path, "w") {|f| f.print(src * 2)}
242 assert_raises(Svn::Error::ClientModified) do
245 assert_nothing_raised do
246 ctx.delete(path, true)
249 assert(!File.exist?(path))
252 def test_delete_alias
254 src = "sample source\n"
257 path = File.join(@wc_path, file)
258 dir_path = File.join(@wc_path, dir)
260 ctx = make_context(log)
262 File.open(path, "w") {|f| f.print(src)}
267 ctx.rm([path, dir_path])
269 assert(!File.exist?(path))
270 assert(!File.exist?(dir_path))
273 File.open(path, "w") {|f| f.print(src)}
277 File.open(path, "w") {|f| f.print(src * 2)}
278 assert_raises(Svn::Error::ClientModified) do
281 assert_nothing_raised do
285 assert(!File.exist?(path))
287 File.open(path, "w") {|f| f.print(src)}
292 ctx.rm_f(path, dir_path)
294 assert(!File.exist?(path))
295 assert(!File.exist?(dir_path))
301 deep_dir = File.join(%w(a b c d e))
303 deep_dir_path = File.join(@wc_path, deep_dir)
304 path = File.join(deep_dir_path, file)
305 tmp_deep_dir_path = File.join(@tmp_path, deep_dir)
306 tmp_path = File.join(tmp_deep_dir_path, file)
308 ctx = make_context(log)
310 FileUtils.mkdir_p(tmp_deep_dir_path)
311 File.open(tmp_path, "w") {|f| f.print(src)}
313 ctx.import(@tmp_path, @repos_uri)
316 assert_equal(src, File.open(path){|f| f.read})
323 dir1_path = File.join(@wc_path, dir1)
324 dir2_path = File.join(dir1_path, dir2)
326 ctx = make_context(log)
327 assert_equal(Svn::Core::INVALID_REVNUM,ctx.commit(@wc_path).revision)
329 assert_equal(0, youngest_rev)
330 assert_equal(1, ctx.commit(@wc_path).revision)
332 assert_equal(Svn::Core::INVALID_REVNUM,ctx.commit(@wc_path, false).revision)
333 assert_equal(2, ctx.ci(@wc_path).revision)
338 file1 = "sample1.txt"
339 file2 = "sample2.txt"
341 dir_path = File.join(@wc_path, dir)
342 path1 = File.join(@wc_path, file1)
343 path2 = File.join(dir_path, file2)
345 ctx = make_context(log)
346 File.open(path1, "w") {}
348 rev1 = ctx.commit(@wc_path).revision
352 File.open(path2, "w") {}
355 rev = ctx.status(@wc_path) do |path, status|
356 infos << [path, status]
359 assert_equal(youngest_rev, rev)
360 assert_equal([dir_path, path2].sort,
361 infos.collect{|path, status| path}.sort)
362 dir_status = infos.assoc(dir_path).last
363 assert(dir_status.text_added?)
364 assert(dir_status.entry.dir?)
365 assert(dir_status.entry.add?)
366 path2_status = infos.assoc(path2).last
367 assert(!path2_status.text_added?)
368 assert_nil(path2_status.entry)
372 rev = ctx.st(@wc_path, rev1, true, true) do |path, status|
373 infos << [path, status]
376 assert_equal(rev1, rev)
377 assert_equal([@wc_path, dir_path, path1, path2].sort,
378 infos.collect{|path, status| path}.sort)
379 wc_status = infos.assoc(@wc_path).last
380 assert(wc_status.text_normal?)
381 assert(wc_status.entry.dir?)
382 assert(wc_status.entry.normal?)
383 dir_status = infos.assoc(dir_path).last
384 assert(dir_status.text_added?)
385 assert(dir_status.entry.dir?)
386 assert(dir_status.entry.add?)
387 path1_status = infos.assoc(path1).last
388 assert(path1_status.text_normal?)
389 assert(path1_status.entry.file?)
390 assert(path1_status.entry.normal?)
391 path2_status = infos.assoc(path2).last
392 assert(!path2_status.text_added?)
393 assert_nil(path2_status.entry)
396 ctx.prop_set(Svn::Core::PROP_IGNORE, file2, dir_path)
399 rev = ctx.status(@wc_path, nil, true, true, true, false) do |path, status|
400 infos << [path, status]
403 assert_equal(rev1, rev)
404 assert_equal([@wc_path, dir_path, path1].sort,
405 infos.collect{|path, status| path}.sort)
409 rev = ctx.status(@wc_path, nil, true, true, true, true) do |path, status|
410 infos << [path, status]
413 assert_equal(rev1, rev)
414 assert_equal([@wc_path, dir_path, path1, path2].sort,
415 infos.collect{|path, status| path}.sort)
418 def test_status_with_depth
422 ctx = make_context(log)
424 # make everything out-of-date
425 ctx.prop_set('propname', 'propvalue', @greek.path(:b), :infinity)
427 recurse_and_depth_choices.each do |rd|
428 ctx.status(@greek.path(:mu), nil, rd) do |path, status|
429 assert_equal @greek.uri(:mu), status.url
433 expected_statuses_by_depth = {
434 true => [:beta, :b, :lambda, :e, :f, :alpha],
435 false => [:b, :lambda, :e, :f],
437 'files' => [:b, :lambda],
438 'immediates' => [:b, :lambda, :e, :f],
439 'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
442 recurse_and_depth_choices.each do |rd|
444 ctx.status(@greek.path(:b), nil, rd) do |path, status|
447 assert_equal(expected_statuses_by_depth[rd].map{|s| @greek.uri(s)}.sort,
457 dir_path = File.join(@wc_path, dir)
458 path = File.join(dir_path, file)
461 ctx = make_context(log)
463 File.open(path, "w"){|f| f.print(content)}
467 FileUtils.rm_rf(@wc_path)
468 ctx.checkout(@repos_uri, @wc_path)
469 assert(File.exist?(path))
471 FileUtils.rm_rf(@wc_path)
472 ctx.co(@repos_uri, @wc_path, nil, nil, false)
473 assert(!File.exist?(path))
479 path = File.join(@wc_path, file)
481 File.open(path, "w"){|f| f.print(content)}
483 ctx = make_context(log)
485 assert_nothing_raised do
486 ctx.update(File.join(@wc_path, "non-exist"), youngest_rev)
490 commit_info = ctx.commit(@wc_path)
493 assert(!File.exist?(path))
494 assert_equal(commit_info.revision,
495 ctx.update(path, commit_info.revision))
496 assert_equal(content, File.read(path))
499 assert(!File.exist?(path))
500 assert_equal([commit_info.revision],
501 ctx.update([path], commit_info.revision))
502 assert_equal(content, File.read(path))
504 assert_raise(Svn::Error::FS_NO_SUCH_REVISION) do
506 ctx.update(path, commit_info.revision + 1)
508 ctx.cleanup(@wc_path)
511 assert_nothing_raised do
512 ctx.update(path + "non-exist", commit_info.revision)
522 dir_path = File.join(@wc_path, dir)
523 path1 = File.join(@wc_path, file1)
524 path2 = File.join(@wc_path, file2)
525 path3 = File.join(dir_path, file3)
528 ctx = make_context(log)
529 File.open(path1, "w"){|f| f.print(content)}
530 File.open(path2, "w"){|f| f.print(content)}
534 File.open(path3, "w"){|f| f.print(content)}
536 commit_info = ctx.commit(@wc_path)
538 File.open(path1, "w"){}
539 assert_equal("", File.open(path1){|f| f.read})
542 assert_equal(content, File.open(path1){|f| f.read})
544 File.open(path1, "w"){}
545 File.open(path2, "w"){}
546 assert_equal("", File.open(path1){|f| f.read})
547 assert_equal("", File.open(path2){|f| f.read})
548 ctx.revert([path1, path2])
549 assert_equal(content, File.open(path1){|f| f.read})
550 assert_equal(content, File.open(path2){|f| f.read})
552 File.open(path1, "w"){}
553 File.open(path2, "w"){}
554 File.open(path3, "w"){}
555 assert_equal("", File.open(path1){|f| f.read})
556 assert_equal("", File.open(path2){|f| f.read})
557 assert_equal("", File.open(path3){|f| f.read})
559 assert_equal(content, File.open(path1){|f| f.read})
560 assert_equal(content, File.open(path2){|f| f.read})
561 assert_equal(content, File.open(path3){|f| f.read})
563 File.open(path1, "w"){}
564 File.open(path2, "w"){}
565 File.open(path3, "w"){}
566 assert_equal("", File.open(path1){|f| f.read})
567 assert_equal("", File.open(path2){|f| f.read})
568 assert_equal("", File.open(path3){|f| f.read})
569 ctx.revert(@wc_path, false)
570 assert_equal("", File.open(path1){|f| f.read})
571 assert_equal("", File.open(path2){|f| f.read})
572 assert_equal("", File.open(path3){|f| f.read})
574 File.open(path1, "w"){}
575 File.open(path2, "w"){}
576 File.open(path3, "w"){}
577 assert_equal("", File.open(path1){|f| f.read})
578 assert_equal("", File.open(path2){|f| f.read})
579 assert_equal("", File.open(path3){|f| f.read})
581 assert_equal("", File.open(path1){|f| f.read})
582 assert_equal("", File.open(path2){|f| f.read})
583 assert_equal(content, File.open(path3){|f| f.read})
593 file1 = "sample1.txt"
594 file2 = "sample2.txt"
595 file3 = "sample3.txt"
596 path1 = File.join(@wc_path, file1)
597 path2 = File.join(@wc_path, file2)
598 path3 = File.join(@wc_path, file3)
599 abs_path1 = File.join('', file1)
600 abs_path2 = File.join('', file2)
601 abs_path3 = File.join('', file3)
603 ctx = make_context(log1)
604 File.open(path1, "w") {|f| f.print(src1)}
606 rev1 = ctx.ci(@wc_path).revision
608 ctx = make_context(log2)
610 rev2 = ctx.ci(@wc_path).revision
612 ctx = make_context(log3)
614 File.open(path1, "w") {|f| f.print(src2)}
615 File.open(path3, "w") {|f| f.print(src3)}
616 rev3 = ctx.ci(@wc_path).revision
618 changed_paths_lists = {}
621 keys = [@wc_path, path1, path2, path3]
624 changed_paths_lists[key] = []
626 args = [key, 1, "HEAD", 0, true, nil]
627 ctx.log(*args) do |changed_paths, rev, author, date, message|
629 changed_paths_lists[key] << changed_paths
630 messages[key] << message
633 changed_paths_list = changed_paths_lists[@wc_path]
635 assert_equal([rev1, rev2, rev3], revs[@wc_path])
636 assert_equal([rev1, rev3], revs[path1])
637 assert_equal([rev1, rev2], revs[path2])
638 assert_equal([rev1, rev3], revs[path3])
639 assert_equal([log1, log2, log3], messages[@wc_path])
641 expected = [[abs_path1], [abs_path2], [abs_path1, abs_path3]]
642 actual = changed_paths_list.collect {|changed_paths| changed_paths.keys}
643 assert_nested_sorted_array(expected, actual)
645 assert_equal('A', changed_paths_list[0][abs_path1].action)
646 assert_false(changed_paths_list[0][abs_path1].copied?)
647 assert_equal('A', changed_paths_list[1][abs_path2].action)
648 assert_true(changed_paths_list[1][abs_path2].copied?)
649 assert_equal(abs_path1, changed_paths_list[1][abs_path2].copyfrom_path)
650 assert_equal(rev1, changed_paths_list[1][abs_path2].copyfrom_rev)
651 assert_equal('M', changed_paths_list[2][abs_path1].action)
652 assert_equal('A', changed_paths_list[2][abs_path3].action)
658 path = File.join(@wc_path, file)
659 FileUtils.touch(path)
661 ctx = make_context(log)
663 commit_info = ctx.commit(@wc_path)
664 rev = commit_info.revision
666 assert_equal(log, ctx.log_message(path, rev))
672 srcs = %w(first second third)
674 path = File.join(@wc_path, file)
676 ctx = make_context(log)
678 File.open(path, "w") {|f| f.puts(srcs[0])}
680 commit_info = ctx.commit(@wc_path)
681 infos << [0, commit_info.revision, @author, commit_info.date, srcs[0]]
683 File.open(path, "a") {|f| f.puts(srcs[1])}
684 commit_info = ctx.commit(@wc_path)
685 infos << [1, commit_info.revision, @author, commit_info.date, srcs[1]]
687 File.open(path, "a") {|f| f.puts(srcs[2])}
688 commit_info = ctx.commit(@wc_path)
689 infos << [2, commit_info.revision, @author, commit_info.date, srcs[2]]
692 ctx.blame(path) do |line_no, revision, author, date, line|
693 result << [line_no, revision, author, date, line]
695 assert_equal(infos, result)
698 ctx.prop_set(Svn::Core::PROP_MIME_TYPE, "image/DUMMY", path)
701 assert_raise(Svn::Error::CLIENT_IS_BINARY_FILE) do
711 path = File.join(@wc_path, file)
713 File.open(path, "w") {|f| f.print(before)}
715 ctx = make_context(log)
717 commit_info = ctx.commit(@wc_path)
718 rev1 = commit_info.revision
720 File.open(path, "w") {|f| f.print(after)}
722 out_file = Tempfile.new("svn")
723 err_file = Tempfile.new("svn")
724 ctx.diff([], path, rev1, path, "WORKING", out_file.path, err_file.path)
726 assert_match(/-#{before}\+#{after}\z/, out_file.read)
728 commit_info = ctx.commit(@wc_path)
729 rev2 = commit_info.revision
730 out_file = Tempfile.new("svn")
731 ctx.diff([], path, rev1, path, rev2, out_file.path, err_file.path)
733 assert_match(/-#{before}\+#{after}\z/, out_file.read)
741 path = File.join(@wc_path, file)
743 File.open(path, "w") {|f| f.print(before)}
745 ctx = make_context(log)
747 commit_info = ctx.commit(@wc_path)
748 rev1 = commit_info.revision
750 File.open(path, "w") {|f| f.print(after)}
752 out_file = Tempfile.new("svn")
753 err_file = Tempfile.new("svn")
754 ctx.diff_peg([], path, rev1, "WORKING", out_file.path, err_file.path)
756 assert_match(/-#{before}\+#{after}\z/, out_file.read)
758 commit_info = ctx.commit(@wc_path)
759 rev2 = commit_info.revision
760 out_file = Tempfile.new("svn")
761 ctx.diff_peg([], path, rev1, rev2, out_file.path, err_file.path)
763 assert_match(/-#{before}\+#{after}\z/, out_file.read)
766 def test_diff_summarize
771 path = File.join(@wc_path, file)
773 File.open(path, "w") {|f| f.print(before)}
775 ctx = make_context(log)
777 commit_info = ctx.commit(@wc_path)
778 rev1 = commit_info.revision
780 File.open(path, "w") {|f| f.print(after)}
782 commit_info = ctx.commit(@wc_path)
783 rev2 = commit_info.revision
786 ctx.diff_summarize(@wc_path, rev1, @wc_path, rev2) do |diff|
789 assert_equal([file], diffs.collect {|d| d.path})
790 kinds = diffs.collect do |d|
791 [d.kind_normal?, d.kind_added?, d.kind_modified?, d.kind_deleted?]
793 assert_equal([[false, false, true, false]], kinds)
794 assert_equal([false], diffs.collect {|d| d.prop_changed?})
795 node_kinds = diffs.collect do |d|
796 [d.node_kind_none?, d.node_kind_file?,
797 d.node_kind_dir?, d.node_kind_unknown?]
799 assert_equal([[false, true, false, false]], node_kinds)
802 def test_diff_summarize_peg
806 before_file = "before.txt"
807 after_file = "after.txt"
808 moved_file = "moved.txt"
809 before_path = File.join(@wc_path, before_file)
810 after_path = File.join(@wc_path, after_file)
811 moved_path = File.join(@wc_path, moved_file)
813 File.open(before_path, "w") {|f| f.print(before)}
815 ctx = make_context(log)
817 commit_info = ctx.commit(@wc_path)
818 rev1 = commit_info.revision
820 ctx.mv(before_path, after_path)
821 commit_info = ctx.commit(@wc_path)
822 rev2 = commit_info.revision
824 File.open(after_path, "w") {|f| f.print(after)}
825 commit_info = ctx.commit(@wc_path)
826 rev3 = commit_info.revision
828 File.open(after_path, "w") {|f| f.print(before)}
829 commit_info = ctx.commit(@wc_path)
830 rev4 = commit_info.revision
832 ctx.mv(after_path, moved_path)
833 commit_info = ctx.commit(@wc_path)
834 rev5 = commit_info.revision
837 ctx.diff_summarize_peg(@repos_uri, rev3, rev4, rev3) do |diff|
840 assert_equal([after_file], diffs.collect {|d| d.path})
841 kinds = diffs.collect do |d|
842 [d.kind_normal?, d.kind_added?, d.kind_modified?, d.kind_deleted?]
844 assert_equal([[false, false, true, false]], kinds)
845 assert_equal([false], diffs.collect {|d| d.prop_changed?})
846 node_kinds = diffs.collect do |d|
847 [d.node_kind_none?, d.node_kind_file?,
848 d.node_kind_dir?, d.node_kind_unknown?]
850 assert_equal([[false, true, false, false]], node_kinds)
857 trunk = File.join(@wc_path, "trunk")
858 branch = File.join(@wc_path, "branch")
859 branch_relative_uri = "/branch"
860 branch_uri = "#{@repos_uri}#{branch_relative_uri}"
861 trunk_path = File.join(trunk, file)
862 trunk_path_uri = "#{@repos_uri}/trunk/#{file}"
863 branch_path = File.join(branch, file)
864 branch_path_relative_uri = "#{branch_relative_uri}/#{file}"
865 branch_path_uri = "#{@repos_uri}#{branch_path_relative_uri}"
867 ctx = make_context(log)
868 ctx.mkdir(trunk, branch)
869 File.open(trunk_path, "w") {}
870 File.open(branch_path, "w") {}
873 rev1 = ctx.commit(@wc_path).revision
875 File.open(branch_path, "w") {|f| f.print(src)}
876 rev2 = ctx.commit(@wc_path).revision
879 ctx.log_merged(trunk, nil, branch_uri, nil) do |entry|
880 merged_entries << entry
882 assert_equal_log_entries([], merged_entries)
883 assert_nil(ctx.merged(trunk))
886 yield(ctx, branch, rev1, rev2, trunk)
887 ctx.log_merged(trunk, nil, branch_uri, nil) do |entry|
888 merged_entries << entry
890 assert_equal_log_entries([
892 {branch_path_relative_uri => ["M", nil, -1]},
895 "svn:author" => @author,
902 mergeinfo = ctx.merged(trunk)
903 assert_not_nil(mergeinfo)
904 assert_equal([branch_uri], mergeinfo.keys)
905 ranges = mergeinfo[branch_uri].collect {|range| range.to_a}
906 assert_equal([[1, 2, true]], ranges)
908 rev3 = ctx.commit(@wc_path).revision
910 assert_equal(normalize_line_break(src), ctx.cat(trunk_path, rev3))
913 rev4 = ctx.commit(@wc_path).revision
915 yield(ctx, branch, rev3, rev4, trunk)
916 assert(!File.exist?(trunk_path))
919 ctx.log_merged(trunk, rev4, branch_uri, rev4) do |entry|
920 merged_entries << entry
922 assert_equal_log_entries([
924 {branch_path_relative_uri => ["D", nil, -1]},
927 "svn:author" => @author,
932 ] * 2, merged_entries)
934 ctx.propdel("svn:mergeinfo", trunk)
936 ctx.log_merged(trunk, rev4, branch_uri, rev4) do |entry|
937 merged_entries << entry
939 assert_equal_log_entries([], merged_entries)
942 ctx.revert(trunk_path)
943 File.open(trunk_path, "a") {|f| f.print(src)}
944 yield(ctx, branch, rev3, rev4, trunk)
945 rev5 = ctx.commit(@wc_path).revision
946 assert(File.exist?(trunk_path))
948 yield(ctx, branch, rev3, rev4, trunk, nil, false, true, true)
950 ctx.status(trunk) do |path, status|
953 assert_equal([], statuses)
955 yield(ctx, branch, rev3, rev4, trunk, nil, false, true)
957 ctx.status(trunk) do |path, status|
960 assert_not_equal([], statuses)
964 assert_merge do |ctx, from, from_rev1, from_rev2, to, *rest|
965 ctx.merge(from, from_rev1, from, from_rev2, to, *rest)
970 assert_merge do |ctx, from, from_rev1, from_rev2, to, *rest|
971 ctx.merge_peg(from, from_rev1, from_rev2, to, nil, *rest)
979 path = File.join(@wc_path, file)
981 ctx = make_context(log)
982 File.open(path, "w") {|f| f.print(src)}
984 rev = ctx.commit(@wc_path).revision
986 ctx.up(@wc_path, rev - 1)
987 File.open(path, "w") {|f| f.print(src)}
989 assert_raise(Svn::Error::WC_OBSTRUCTED_UPDATE) do
990 ctx.up(@wc_path, rev)
993 Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1) do |access|
994 assert_raise(Svn::Error::WC_LOCKED) do
999 ctx.set_cancel_func do
1000 raise Svn::Error::CANCELLED
1002 Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1) do |access|
1003 assert_raise(Svn::Error::CANCELLED) do
1004 ctx.cleanup(@wc_path)
1006 assert_raise(Svn::Error::WC_LOCKED) do
1007 ctx.commit(@wc_path)
1011 ctx.set_cancel_func(nil)
1012 access = Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1)
1013 assert_nothing_raised do
1014 ctx.cleanup(@wc_path)
1016 assert_nothing_raised do
1017 ctx.commit(@wc_path)
1019 assert_raises(Svn::Error::SvnError) do
1028 path = File.join(@wc_path, file)
1030 ctx = make_context(log)
1031 File.open(path, "w") {|f| f.print(src)}
1033 ctx.commit(@wc_path)
1035 assert_nothing_raised do
1039 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1040 cred.username = @author
1041 cred.password = @password
1042 cred.may_save = true
1044 ctx.relocate(@wc_path, @repos_uri, @repos_svnserve_uri)
1046 ctx = make_context(log)
1047 assert_raises(Svn::Error::AuthnNoProvider) do
1058 dir_path = File.join(@wc_path, dir)
1059 path = File.join(dir_path, file)
1061 ctx = make_context(log)
1063 File.open(path, "w") {}
1065 rev1 = ctx.ci(@wc_path).revision
1067 File.open(path, "w") {|f| f.print(src1)}
1068 rev2 = ctx.ci(@wc_path).revision
1070 ctx.up(@wc_path, rev1)
1072 File.open(path, "w") {|f| f.print(src2)}
1075 assert_raises(Svn::Error::WcFoundConflict) do
1079 ctx.resolved(dir_path, false)
1080 assert_raises(Svn::Error::WcFoundConflict) do
1084 ctx.resolved(dir_path)
1086 assert_nothing_raised do
1087 info = ctx.ci(@wc_path)
1089 assert_not_nil(info)
1090 assert_equal(rev2 + 1, info.revision)
1096 file1 = "sample1.txt"
1097 file2 = "sample2.txt"
1098 path1 = File.join(@wc_path, file1)
1099 path2 = File.join(@wc_path, file2)
1101 ctx = make_context(log)
1102 File.open(path1, "w") {|f| f.print(src)}
1107 ctx.cp(path1, path2)
1110 ctx.set_notify_func do |notify|
1111 infos << [notify.path, notify]
1115 assert_equal([path2].sort,
1116 infos.collect{|path, notify| path}.sort)
1117 path2_notify = infos.assoc(path2)[1]
1118 assert(path2_notify.commit_added?)
1119 assert_equal(File.open(path1) {|f| f.read},
1120 File.open(path2) {|f| f.read})
1126 file1 = "sample1.txt"
1127 file2 = "sample2.txt"
1128 path1 = File.join(@wc_path, file1)
1129 path2 = File.join(@wc_path, file2)
1131 ctx = make_context(log)
1132 File.open(path1, "w") {|f| f.print(src)}
1137 ctx.mv(path1, path2)
1140 ctx.set_notify_func do |notify|
1141 infos << [notify.path, notify]
1145 assert_equal([path1, path2].sort,
1146 infos.collect{|path, notify| path}.sort)
1147 path1_notify = infos.assoc(path1)[1]
1148 assert(path1_notify.commit_deleted?)
1149 path2_notify = infos.assoc(path2)[1]
1150 assert(path2_notify.commit_added?)
1151 assert_equal(src, File.open(path2) {|f| f.read})
1158 file1 = "sample1.txt"
1159 file2 = "sample2.txt"
1160 path1 = File.join(@wc_path, file1)
1161 path2 = File.join(@wc_path, file2)
1163 ctx = make_context(log)
1164 File.open(path1, "w") {|f| f.print(src1)}
1168 File.open(path1, "w") {|f| f.print(src2)}
1169 assert_nothing_raised do
1170 ctx.mv(path1, path2)
1172 ctx.revert([path1, path2])
1175 File.open(path1, "w") {|f| f.print(src2)}
1176 assert_nothing_raised do
1177 ctx.mv_f(path1, path2)
1181 ctx.set_notify_func do |notify|
1186 paths = notifies.collect do |notify|
1189 assert_equal([path1, path2, path2].sort, paths.sort)
1191 deleted_paths = notifies.find_all do |notify|
1192 notify.commit_deleted?
1193 end.collect do |notify|
1196 assert_equal([path1].sort, deleted_paths.sort)
1198 added_paths = notifies.find_all do |notify|
1199 notify.commit_added?
1200 end.collect do |notify|
1203 assert_equal([path2].sort, added_paths.sort)
1205 postfix_txdelta_paths = notifies.find_all do |notify|
1206 notify.commit_postfix_txdelta?
1207 end.collect do |notify|
1210 assert_equal([path2].sort, postfix_txdelta_paths.sort)
1212 assert_equal(src2, File.open(path2) {|f| f.read})
1219 dir_path = File.join(@wc_path, dir)
1220 dir_uri = "#{@repos_uri}/#{dir}"
1221 path = File.join(dir_path, file)
1222 uri = "#{dir_uri}/#{file}"
1223 prop_name = "sample-prop"
1224 prop_value = "sample value"
1225 invalid_mime_type_prop_value = "image"
1227 ctx = make_context(log)
1230 File.open(path, "w") {}
1233 ctx.commit(@wc_path)
1235 assert_equal({}, ctx.prop_get(prop_name, path))
1236 ctx.prop_set(prop_name, prop_value, path)
1237 ctx.commit(@wc_path)
1238 assert_equal({uri => prop_value}, ctx.pget(prop_name, path))
1240 ctx.prop_del(prop_name, path)
1241 ctx.commit(@wc_path)
1242 assert_equal({}, ctx.pg(prop_name, path))
1244 ctx.ps(prop_name, prop_value, path)
1245 ctx.commit(@wc_path)
1246 assert_equal({uri => prop_value}, ctx.pg(prop_name, path))
1248 ctx.ps(prop_name, nil, path)
1249 ctx.commit(@wc_path)
1250 assert_equal({}, ctx.pg(prop_name, path))
1253 ctx.ps(prop_name, prop_value, dir_path)
1256 dir_uri => prop_value,
1259 ctx.pg(prop_name, dir_path))
1262 ctx.pdel(prop_name, dir_path, false)
1264 assert_equal({uri => prop_value}, ctx.pg(prop_name, dir_path))
1267 ctx.pd(prop_name, dir_path)
1269 assert_equal({}, ctx.pg(prop_name, dir_path))
1272 ctx.ps(prop_name, prop_value, dir_path, false)
1274 assert_equal({dir_uri => prop_value}, ctx.pg(prop_name, dir_path))
1276 assert_raises(Svn::Error::BadMimeType) do
1277 ctx.ps(Svn::Core::PROP_MIME_TYPE,
1278 invalid_mime_type_prop_value,
1281 ctx.cleanup(@wc_path)
1283 assert_nothing_raised do
1284 ctx.ps(Svn::Core::PROP_MIME_TYPE,
1285 invalid_mime_type_prop_value,
1288 ctx.commit(@wc_path)
1289 assert_equal({uri => invalid_mime_type_prop_value},
1290 ctx.pg(Svn::Core::PROP_MIME_TYPE, path))
1297 dir_path = File.join(@wc_path, dir)
1298 path = File.join(dir_path, file)
1299 dir_uri = "#{@repos_uri}/#{dir}"
1300 uri = "#{dir_uri}/#{file}"
1306 ctx = make_context(log)
1309 File.open(path, "w") {}
1314 assert_equal([], ctx.prop_list(path))
1316 ctx.ps(name1, value1, path)
1318 assert_equal([uri], ctx.prop_list(path).collect{|item| item.node_name})
1319 assert_equal([{name1 => value1}],
1320 ctx.plist(path).collect{|item| item.prop_hash})
1321 assert_equal([value1], ctx.pl(path).collect{|item| item[name1]})
1324 ctx.ps(name2, value2, dir_path)
1326 assert_equal([uri, dir_uri].sort,
1327 ctx.prop_list(dir_path).collect{|item| item.name})
1328 prop_list = ctx.plist(dir_path).collect{|item| [item.name, item.props]}
1329 props = prop_list.assoc(uri)[1]
1330 dir_props = prop_list.assoc(dir_uri)[1]
1331 assert_equal({name1 => value1, name2 => value2}, props)
1332 assert_equal({name2 => value2}, dir_props)
1335 def recurse_and_depth_choices
1336 [false, true, 'empty', 'files', 'immediates', 'infinity']
1343 ctx = make_context(log)
1345 # when no props set, everything is empty
1346 recurse_and_depth_choices.each do |rd|
1348 ctx.prop_list(@greek.path(:mu), nil, nil, rd),
1349 "prop_list with Depth '#{rd}'")
1352 recurse_and_depth_choices.each do |rd|
1354 ctx.prop_get(rd.to_s, @greek.path(:mu), nil, nil, rd),
1355 "prop_get with Depth '#{rd}'")
1359 recurse_and_depth_choices.each do |rd|
1360 ctx.prop_set(rd.to_s, rd.to_s, @greek.path(:mu), rd)
1362 ctx.commit(@greek.path(:mu))
1365 recurse_and_depth_choices.each do |rd|
1366 assert_equal({@greek.uri(:mu) => rd.to_s},
1367 ctx.prop_get(rd.to_s, @greek.path(:mu), nil, nil, rd),
1368 "prop_get with Depth '#{rd}'")
1372 recurse_and_depth_choices.each {|rd| prop_hash[rd.to_s] = rd.to_s}
1375 recurse_and_depth_choices.each do |rd|
1376 props = ctx.prop_list(@greek.path(:mu), nil, nil, rd)
1377 assert_equal([@greek.uri(:mu)],
1378 props.collect {|item| item.node_name},
1379 "prop_list (node_name) with Depth '#{rd}'")
1381 props = ctx.plist(@greek.path(:mu), nil, nil, rd)
1382 assert_equal([prop_hash],
1383 props.collect {|item| item.prop_hash},
1384 "prop_list (prop_hash) with Depth '#{rd}'")
1386 recurse_and_depth_choices.each do |rd1|
1387 props = ctx.plist(@greek.path(:mu), nil, nil, rd)
1388 assert_equal([rd1.to_s],
1389 props.collect {|item| item[rd1.to_s]},
1390 "prop_list (#{rd1.to_s}]) with Depth '#{rd}'")
1400 ctx = make_context(log)
1402 # when no props set, everything is empty
1403 recurse_and_depth_choices.each do |rd|
1405 ctx.prop_list(@greek.path(:b), nil, nil, rd),
1406 "prop_list with Depth '#{rd}'")
1409 recurse_and_depth_choices.each do |rd|
1411 ctx.prop_get(rd.to_s, @greek.path(:b), nil, nil, rd),
1412 "prop_get with Depth '#{rd}'")
1415 # set some props with various depths
1416 recurse_and_depth_choices.each do |rd|
1417 ctx.prop_set(rd.to_s, rd.to_s, @greek.path(:b), rd)
1419 ctx.commit(@greek.path(:b))
1422 true => [:beta, :b, :lambda, :e, :f, :alpha],
1425 'files' => [:b, :lambda],
1426 'immediates' => [:b, :lambda, :e, :f],
1427 'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
1430 paths = [:b, :e, :alpha, :beta, :f, :lambda]
1432 # how are the props set?
1433 recurse_and_depth_choices.each do |rd|
1434 paths.each do |path|
1435 if expected_props[rd].include?(path)
1436 expected = {@greek.uri(path) => rd.to_s}
1440 assert_equal(expected,
1441 ctx.prop_get(rd.to_s, @greek.path(path), nil, nil, false),
1442 "prop_get #{@greek.resolve(path)} with Depth '#{rd}'")
1446 recurse_and_depth_choices.each do |rd_for_prop|
1447 recurse_and_depth_choices.each do |rd_for_depth|
1449 expected_paths = expected_props[rd_for_depth]
1450 expected_paths &= expected_props[rd_for_prop]
1451 expected_paths.each do |path|
1452 expected[@greek.uri(path)] = rd_for_prop.to_s
1455 assert_equal(expected,
1456 ctx.prop_get(rd_for_prop.to_s, @greek.path(:b),
1457 nil, nil, rd_for_depth),
1458 "prop_get '#{rd_for_prop}' with Depth '#{rd_for_depth}'")
1463 recurse_and_depth_choices.each do |rd|
1464 props = ctx.prop_list(@greek.path(:b), nil, nil, rd)
1465 assert_equal(expected_props[rd].collect {|path| @greek.uri(path)}.sort,
1466 props.collect {|item| item.node_name}.sort,
1467 "prop_list (node_name) with Depth '#{rd}'")
1476 path = File.join(@wc_path, file)
1478 File.open(path, "w") {|f| f.print(src1)}
1480 ctx = make_context(log)
1482 commit_info = ctx.commit(@wc_path)
1483 rev1 = commit_info.revision
1485 assert_equal(normalize_line_break(src1), ctx.cat(path, rev1))
1486 assert_equal(normalize_line_break(src1), ctx.cat(path))
1488 File.open(path, "w") {|f| f.print(src2)}
1490 commit_info = ctx.commit(@wc_path)
1491 rev2 = commit_info.revision
1493 assert_equal(normalize_line_break(src1), ctx.cat(path, rev1))
1494 assert_equal(normalize_line_break(src2), ctx.cat(path, rev2))
1495 assert_equal(normalize_line_break(src2), ctx.cat(path))
1502 path = File.join(@wc_path, file)
1504 File.open(path, "w") {|f| f.print(src)}
1506 ctx = make_context(log)
1508 ctx.commit(@wc_path)
1511 ctx.set_notify_func do |notify|
1512 infos << [notify.path, notify]
1516 assert_equal([file], infos.collect{|path, notify| path})
1517 file_notify = infos.assoc(file)[1]
1518 assert(file_notify.locked?)
1525 path = File.join(@wc_path, file)
1527 File.open(path, "w") {|f| f.print(src)}
1529 ctx = make_context(log)
1531 ctx.commit(@wc_path)
1536 ctx.set_notify_func do |notify|
1537 infos << [notify.path, notify]
1540 assert_equal([file], infos.collect{|path, notify| path})
1541 file_notify = infos.assoc(file)[1]
1542 assert(file_notify.unlocked?)
1547 ctx = make_context(log)
1548 repos_base = File.basename(@repos_path)
1551 ctx.info(@wc_path) do |path, info|
1552 infos << [path, info]
1554 assert_equal([repos_base],
1555 infos.collect{|path, info| path})
1556 top_info = infos.assoc(repos_base)[1]
1557 assert_equal(@repos_uri, top_info.url)
1560 def test_info_with_depth
1564 ctx = make_context(log)
1566 recurse_and_depth_choices.each do |rd|
1567 ctx.info(@greek.path(:mu),nil,nil,rd) do |path, info|
1568 assert_equal @greek.uri(:mu), info.URL
1572 expected_info_by_depth = {
1573 true => [:beta, :b, :lambda, :e, :f, :alpha],
1576 'files' => [:b, :lambda],
1577 'immediates' => [:b, :lambda, :e, :f],
1578 'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
1581 recurse_and_depth_choices.each do |rd|
1583 ctx.info(@greek.path(:b),nil,nil,rd) do |path, info|
1586 assert_equal expected_info_by_depth[rd].map{|s| @greek.uri(s)}.sort,
1592 def test_url_from_path
1594 ctx = make_context(log)
1595 assert_equal(@repos_uri, ctx.url_from_path(@wc_path))
1596 assert_equal(@repos_uri, Svn::Client.url_from_path(@wc_path))
1601 ctx = make_context(log)
1602 Svn::Wc::AdmAccess.open(nil, @wc_path, false, 0) do |adm|
1603 assert_equal(ctx.uuid_from_url(@repos_uri),
1604 ctx.uuid_from_path(@wc_path, adm))
1608 def test_open_ra_session
1610 ctx = make_context(log)
1612 assert_instance_of(Svn::Ra::Session, ctx.open_ra_session(@repos_uri))
1617 new_log = "new sample log"
1620 path = File.join(@wc_path, file)
1622 File.open(path, "w") {|f| f.print(src)}
1624 ctx = make_context(log)
1626 info = ctx.commit(@wc_path)
1630 Svn::Core::PROP_REVISION_AUTHOR => @author,
1631 Svn::Core::PROP_REVISION_DATE => info.date,
1632 Svn::Core::PROP_REVISION_LOG => log,
1636 ctx.revprop_list(@repos_uri, info.revision))
1638 assert_equal([log, info.revision],
1639 ctx.revprop_get(Svn::Core::PROP_REVISION_LOG,
1640 @repos_uri, info.revision))
1642 ctx.revprop(Svn::Core::PROP_REVISION_LOG,
1643 @repos_uri, info.revision))
1645 assert_equal(info.revision,
1646 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1647 @repos_uri, info.revision))
1648 assert_equal([new_log, info.revision],
1649 ctx.rpget(Svn::Core::PROP_REVISION_LOG,
1650 @repos_uri, info.revision))
1651 assert_equal(new_log,
1652 ctx.rp(Svn::Core::PROP_REVISION_LOG,
1653 @repos_uri, info.revision))
1656 Svn::Core::PROP_REVISION_AUTHOR => @author,
1657 Svn::Core::PROP_REVISION_DATE => info.date,
1658 Svn::Core::PROP_REVISION_LOG => new_log,
1662 ctx.rplist(@repos_uri, info.revision))
1664 assert_equal(info.revision,
1665 ctx.revprop_del(Svn::Core::PROP_REVISION_LOG,
1666 @repos_uri, info.revision))
1667 assert_equal([nil, info.revision],
1668 ctx.rpg(Svn::Core::PROP_REVISION_LOG,
1669 @repos_uri, info.revision))
1671 ctx.rp(Svn::Core::PROP_REVISION_LOG,
1672 @repos_uri, info.revision))
1674 assert_equal(info.revision,
1675 ctx.rpset(Svn::Core::PROP_REVISION_LOG, new_log,
1676 @repos_uri, info.revision))
1677 assert_equal(new_log,
1678 ctx.rp(Svn::Core::PROP_REVISION_LOG,
1679 @repos_uri, info.revision))
1680 assert_equal(info.revision,
1681 ctx.rps(Svn::Core::PROP_REVISION_LOG, nil,
1682 @repos_uri, info.revision))
1684 ctx.rp(Svn::Core::PROP_REVISION_LOG,
1685 @repos_uri, info.revision))
1689 Svn::Core::PROP_REVISION_AUTHOR => @author,
1690 Svn::Core::PROP_REVISION_DATE => info.date,
1694 ctx.rpl(@repos_uri, info.revision))
1702 dir_path = File.join(@wc_path, dir)
1703 path = File.join(dir_path, file)
1704 tmp_base_path = File.join(@tmp_path, "tmp")
1705 tmp_dir_path = File.join(tmp_base_path, dir)
1706 tmp_path = File.join(tmp_dir_path, file)
1708 ctx = make_context(log)
1711 File.open(path, "w") {|f| f.print(src)}
1713 rev = ctx.ci(@wc_path).revision
1715 assert_equal(rev, ctx.export(@repos_uri, tmp_base_path))
1716 assert_equal(src, File.open(tmp_path) {|f| f.read})
1724 dir_path = File.join(@wc_path, dir)
1725 path = File.join(@wc_path, file)
1727 ctx = make_context(log)
1730 File.open(path, "w") {|f| f.print(src)}
1732 rev = ctx.ci(@wc_path).revision
1734 dirents, locks = ctx.ls(@wc_path, rev)
1735 assert_equal([dir, file].sort, dirents.keys.sort)
1736 dir_dirent = dirents[dir]
1737 assert(dir_dirent.directory?)
1738 file_dirent = dirents[file]
1739 assert(file_dirent.file?)
1747 prop_name = "sample-prop"
1748 prop_value = "sample value"
1749 dir_path = File.join(@wc_path, dir)
1750 path = File.join(@wc_path, file)
1752 ctx = make_context(log)
1755 File.open(path, "w") {|f| f.print(src)}
1757 ctx.prop_set(prop_name, prop_value, path)
1758 rev = ctx.ci(@wc_path).revision
1761 ctx.list(@wc_path, rev) do |path, dirent, lock, abs_path|
1762 entries << [path, dirent, lock, abs_path]
1764 paths = entries.collect do |path, dirent, lock, abs_path|
1767 assert_equal([["", "/"], [dir, "/"], [file, "/"]].sort, paths.sort)
1768 entries.each do |path, dirent, lock, abs_path|
1771 assert(dirent.directory?)
1772 assert_false(dirent.have_props?)
1774 assert(dirent.file?)
1775 assert_true(dirent.have_props?)
1782 def test_list_with_depth
1786 ctx = make_context(log)
1788 expected_lists_by_depth = {
1789 true => [:beta, :b, :lambda, :e, :f, :alpha],
1790 false => [:b, :lambda, :e, :f],
1792 'files' => [:b, :lambda],
1793 'immediates' => [:b, :lambda, :e, :f],
1794 'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
1797 recurse_and_depth_choices.each do |rd|
1799 ctx.list(@greek.path(:b), 'head' ,nil, rd) do |path, dirent, lock, abs_path|
1800 paths << (path.empty? ? abs_path : File.join(abs_path, path))
1802 assert_equal(expected_lists_by_depth[rd].map{|s| "/#{@greek.resolve(s)}"}.sort,
1810 trunk_src = "trunk source\n"
1811 tag_src = "tag source\n"
1817 trunk_repos_uri = "#{@repos_uri}/#{trunk_dir}"
1818 tag_repos_uri = "#{@repos_uri}/#{tag_dir}/#{tag_name}"
1819 trunk_dir_path = File.join(@wc_path, trunk_dir)
1820 tag_dir_path = File.join(@wc_path, tag_dir)
1821 tag_name_dir_path = File.join(@wc_path, tag_dir, tag_name)
1822 trunk_path = File.join(trunk_dir_path, file)
1823 tag_path = File.join(tag_name_dir_path, file)
1824 path = File.join(@wc_path, file)
1826 ctx = make_context(log)
1828 ctx.mkdir(trunk_dir_path)
1829 File.open(trunk_path, "w") {|f| f.print(trunk_src)}
1831 trunk_rev = ctx.commit(@wc_path).revision
1833 ctx.mkdir(tag_dir_path, tag_name_dir_path)
1834 File.open(tag_path, "w") {|f| f.print(tag_src)}
1836 tag_rev = ctx.commit(@wc_path).revision
1838 assert_equal(youngest_rev, ctx.switch(@wc_path, trunk_repos_uri))
1839 assert_equal(normalize_line_break(trunk_src), ctx.cat(path))
1841 assert_equal(youngest_rev, ctx.switch(@wc_path, tag_repos_uri))
1842 assert_equal(normalize_line_break(tag_src), ctx.cat(path))
1846 ctx.set_notify_func do |notify|
1847 notify_info << [notify.path, notify.action]
1850 assert_equal(trunk_rev, ctx.switch(@wc_path, trunk_repos_uri, trunk_rev))
1851 assert_equal(normalize_line_break(trunk_src), ctx.cat(path))
1853 [path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1854 [@wc_path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1855 [@wc_path, Svn::Wc::NOTIFY_UPDATE_COMPLETED],
1860 assert_equal(tag_rev, ctx.switch(@wc_path, tag_repos_uri, tag_rev))
1861 assert_equal(normalize_line_break(tag_src), ctx.cat(path))
1863 [path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1864 [@wc_path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1865 [@wc_path, Svn::Wc::NOTIFY_UPDATE_COMPLETED],
1870 def test_authentication
1874 path = File.join(@wc_path, file)
1875 svnserve_uri = "#{@repos_svnserve_uri}/#{file}"
1877 File.open(path, "w") {|f| f.print(src)}
1879 ctx = make_context(log)
1881 ctx.commit(@wc_path)
1883 ctx = Svn::Client::Context.new
1885 assert_raises(Svn::Error::AuthnNoProvider) do
1886 ctx.cat(svnserve_uri)
1889 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1890 cred.username = "wrong-#{@author}"
1891 cred.password = @password
1892 cred.may_save = false
1894 assert_raises(Svn::Error::RaNotAuthorized) do
1895 ctx.cat(svnserve_uri)
1898 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1899 cred.username = @author
1900 cred.password = "wrong-#{@password}"
1901 cred.may_save = false
1903 assert_raises(Svn::Error::RaNotAuthorized) do
1904 ctx.cat(svnserve_uri)
1907 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1908 cred.username = @author
1909 cred.password = @password
1910 cred.may_save = false
1912 assert_equal(normalize_line_break(src), ctx.cat(svnserve_uri))
1915 def assert_simple_provider(method)
1919 path = File.join(@wc_path, file)
1920 svnserve_uri = "#{@repos_svnserve_uri}/#{file}"
1922 File.open(path, "w") {|f| f.print(src)}
1924 ctx = make_context(log)
1925 setup_auth_baton(ctx.auth_baton)
1927 ctx.commit(@wc_path)
1929 ctx = Svn::Client::Context.new
1930 setup_auth_baton(ctx.auth_baton)
1932 assert_raises(Svn::Error::RaNotAuthorized) do
1933 ctx.cat(svnserve_uri)
1936 ctx = Svn::Client::Context.new
1937 setup_auth_baton(ctx.auth_baton)
1939 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1940 cred.username = @author
1941 cred.password = @password
1943 assert_equal(normalize_line_break(src), ctx.cat(svnserve_uri))
1946 def test_simple_provider
1947 assert_simple_provider(:add_simple_provider)
1950 if Svn::Core.respond_to?(:auth_get_windows_simple_provider)
1951 def test_windows_simple_provider
1952 assert_simple_provider(:add_windows_simple_provider)
1956 if Svn::Core.respond_to?(:auth_get_keychain_simple_provider)
1957 def test_keychain_simple_provider
1958 assert_simple_provider(:add_keychain_simple_provider)
1962 def test_username_provider
1964 new_log = "sample new log"
1967 path = File.join(@wc_path, file)
1968 repos_uri = "#{@repos_uri}/#{file}"
1970 File.open(path, "w") {|f| f.print(src)}
1972 ctx = make_context(log)
1974 info = ctx.commit(@wc_path)
1976 ctx = Svn::Client::Context.new
1977 setup_auth_baton(ctx.auth_baton)
1978 ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = @author
1979 ctx.add_username_provider
1980 assert_nothing_raised do
1981 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1982 repos_uri, info.revision)
1985 ctx = Svn::Client::Context.new
1986 setup_auth_baton(ctx.auth_baton)
1987 ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = "#{@author}-NG"
1988 ctx.add_username_provider
1989 assert_raise(Svn::Error::REPOS_HOOK_FAILURE) do
1990 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1991 repos_uri, info.revision)
1994 ctx = Svn::Client::Context.new
1995 setup_auth_baton(ctx.auth_baton)
1996 ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = nil
1997 ctx.add_username_prompt_provider(0) do |cred, realm, may_save|
1999 assert_raise(Svn::Error::REPOS_HOOK_FAILURE) do
2000 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
2001 repos_uri, info.revision)
2004 ctx = Svn::Client::Context.new
2005 setup_auth_baton(ctx.auth_baton)
2006 ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = nil
2007 ctx.add_username_prompt_provider(0) do |cred, realm, may_save|
2008 cred.username = @author
2010 assert_nothing_raised do
2011 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
2012 repos_uri, info.revision)
2016 def test_add_providers
2017 ctx = Svn::Client::Context.new
2018 assert_nothing_raised do
2019 ctx.add_ssl_client_cert_file_provider
2020 ctx.add_ssl_client_cert_pw_file_provider
2021 ctx.add_ssl_server_trust_file_provider
2022 if Svn::Core.respond_to?(:auth_get_windows_ssl_server_trust_provider)
2023 ctx.add_windows_ssl_server_trust_provider
2028 def test_commit_item
2029 assert_raise(NoMethodError) do
2030 Svn::Client::CommitItem.new
2033 assert_raise(NoMethodError) do
2034 Svn::Client::CommitItem2.new
2037 item = Svn::Client::CommitItem3.new
2038 assert_kind_of(Svn::Client::CommitItem3, item)
2042 assert_equal(url, item.dup.url)
2045 def test_log_msg_func_commit_items
2050 path = File.join(@wc_path, file)
2051 repos_uri2 = "#{@repos_uri}/#{file2}"
2053 File.open(path, "w") {|f| f.print(src)}
2055 ctx = make_context(log)
2057 ctx.set_log_msg_func do |items|
2062 ctx.prop_set(Svn::Core::PROP_MIME_TYPE, "text/plain", path)
2063 ctx.commit(@wc_path)
2064 assert_equal([[]], items.collect {|item| item.wcprop_changes})
2065 assert_equal([[]], items.collect {|item| item.incoming_prop_changes})
2066 assert_equal([nil], items.collect {|item| item.outgoing_prop_changes})
2069 ctx.cp(path, repos_uri2)
2070 assert_equal([nil], items.collect {|item| item.wcprop_changes})
2071 assert_equal([nil], items.collect {|item| item.incoming_prop_changes})
2072 assert_equal([nil], items.collect {|item| item.outgoing_prop_changes})
2075 def test_log_msg_func_cancel
2078 dir_path = File.join(@wc_path, dir)
2080 ctx = make_context(log)
2081 ctx.set_log_msg_func do |items|
2082 raise Svn::Error::Cancelled
2085 assert_raise(Svn::Error::Cancelled) do
2086 ctx.commit(@wc_path)
2092 ctx = make_context(log)
2094 "groups" => {"collabnet" => "svn.collab.net"},
2096 "http-proxy-host" => "proxy",
2097 "http-proxy-port" => "8080",
2100 servers_config_file = File.join(@config_path,
2101 Svn::Core::CONFIG_CATEGORY_SERVERS)
2102 File.open(servers_config_file, "w") do |file|
2103 options.each do |section, values|
2104 file.puts("[#{section}]")
2105 values.each do |key, value|
2106 file.puts("#{key} = #{value}")
2110 config = Svn::Core::Config.config(@config_path)
2111 assert_nil(ctx.config)
2112 assert_equal(options, config[Svn::Core::CONFIG_CATEGORY_SERVERS].to_hash)
2114 assert_equal(options,
2115 ctx.config[Svn::Core::CONFIG_CATEGORY_SERVERS].to_hash)
2118 def test_context_mimetypes_map
2119 context = Svn::Client::Context.new
2120 assert_nil(context.mimetypes_map)
2121 context.mimetypes_map = {"txt" => "text/plain"}
2122 assert_equal({"txt" => "text/plain"}, context.mimetypes_map)
2125 def test_context_revprop_table
2126 context = Svn::Client::Context.new
2127 assert_nil(context.revprop_table)
2128 context.revprop_table = {"my-prop" => "XXX"}
2129 assert_equal({"my-prop" => "XXX"}, context.revprop_table)
2132 def assert_changelists
2134 file1 = "hello1.txt"
2135 file2 = "hello2.txt"
2139 path1 = File.join(@wc_path, file1)
2140 path2 = File.join(@wc_path, file2)
2142 ctx = make_context(log)
2143 File.open(path1, "w") {|f| f.print(src)}
2144 File.open(path2, "w") {|f| f.print(src)}
2147 ctx.commit(@wc_path)
2149 assert_equal({}, yield(ctx, changelist1))
2150 assert_equal({nil=>[@wc_path,path1,path2]}, yield(ctx, nil))
2151 assert_equal({}, yield(ctx, []))
2152 assert_equal({}, yield(ctx, [changelist1]))
2153 assert_equal({}, yield(ctx, [changelist2]))
2154 ctx.add_to_changelist(changelist1, path1)
2155 assert_equal({changelist1=>[path1]}, yield(ctx, changelist1))
2156 assert_equal({changelist1=>[path1],nil=>[@wc_path,path2]}, yield(ctx, nil))
2157 assert_equal({}, yield(ctx, []))
2158 assert_equal({changelist1=>[path1]}, yield(ctx, [changelist1]))
2159 assert_equal({}, yield(ctx, [changelist2]))
2161 assert_equal({}, yield(ctx, changelist2))
2162 ctx.add_to_changelist(changelist2, [path1, path2])
2163 assert_equal({changelist2=>[path1, path2]}, yield(ctx, changelist2))
2164 assert_equal({}, yield(ctx, changelist1))
2166 ctx.add_to_changelist(changelist1, [path1, path2])
2167 assert_equal({changelist1=>[path1, path2]}, yield(ctx, changelist1))
2168 assert_equal({}, yield(ctx, changelist2))
2170 ctx.remove_from_changelists(changelist1, path1)
2171 assert_equal({changelist1=>[path2]}, yield(ctx, changelist1))
2172 ctx.remove_from_changelists(changelist1, [path2])
2173 assert_equal({}, yield(ctx, changelist1))
2175 ctx.add_to_changelist(changelist1, path1)
2176 ctx.add_to_changelist(changelist2, path2)
2177 assert_equal({changelist1=>[path1]}, yield(ctx, changelist1))
2178 assert_equal({changelist2=>[path2]}, yield(ctx, changelist2))
2180 assert_equal({changelist1=>[path1]}, yield(ctx, changelist1))
2181 assert_equal({changelist2=>[path2]}, yield(ctx, changelist2))
2182 assert_equal({changelist1=>[path1]}, yield(ctx, [changelist1]))
2183 assert_equal({changelist2=>[path2]}, yield(ctx, [changelist2]))
2184 assert_equal({changelist1=>[path1],changelist2=>[path2],nil=>[@wc_path]}, yield(ctx, nil))
2185 assert_equal({}, yield(ctx, []))
2186 assert_equal({changelist1=>[path1],changelist2=>[path2]},
2187 yield(ctx, [changelist1,changelist2]))
2189 ctx.remove_from_changelists(nil, [path1, path2])
2190 assert_equal({}, yield(ctx, changelist1))
2191 assert_equal({}, yield(ctx, changelist2))
2194 def test_changelists_get_without_block
2195 assert_changelists do |ctx, changelist_name|
2196 ctx.changelists(changelist_name, @wc_path)
2200 def test_changelists_get_with_block
2201 assert_changelists do |ctx, changelist_name|
2202 changelists = Hash.new{|h,k| h[k]=[]}
2203 ctx.changelists(changelist_name, @wc_path) do |path,cl_name|
2204 changelists[cl_name] << path