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 trunk_path = File.join(trunk, file)
860 branch_path = File.join(branch, file)
862 ctx = make_context(log)
863 ctx.mkdir(trunk, branch)
864 File.open(trunk_path, "w") {}
865 File.open(branch_path, "w") {}
868 rev1 = ctx.commit(@wc_path).revision
870 File.open(branch_path, "w") {|f| f.print(src)}
871 rev2 = ctx.commit(@wc_path).revision
873 assert_nil(ctx.mergeinfo(trunk))
874 ctx.merge(branch, rev1, branch, rev2, trunk)
875 mergeinfo = ctx.mergeinfo(trunk)
876 expected_key = ctx.url_from_path(branch)
877 assert_equal([expected_key], mergeinfo.keys)
878 assert_equal([[1, 2, true]],
879 mergeinfo[expected_key].collect {|range| range.to_a})
880 rev3 = ctx.commit(@wc_path).revision
882 assert_equal(normalize_line_break(src), ctx.cat(trunk_path, rev3))
885 rev4 = ctx.commit(@wc_path).revision
887 ctx.merge(branch, rev3, branch, rev4, trunk)
888 assert(!File.exist?(trunk_path))
890 mergeinfo = ctx.mergeinfo(trunk, rev4)
891 assert_equal([expected_key], mergeinfo.keys)
892 assert_equal([[1, 2, true], [3, 4, true]],
893 mergeinfo[expected_key].collect {|range| range.to_a })
894 ctx.propdel("svn:mergeinfo", trunk)
895 assert_nil ctx.mergeinfo(trunk)
897 ctx.revert(trunk_path)
898 File.open(trunk_path, "a") {|f| f.print(src)}
899 ctx.merge(branch, rev3, branch, rev4, trunk)
900 assert(File.exist?(trunk_path))
901 rev5 = ctx.commit(@wc_path).revision
903 File.open(trunk_path, "a") {|f| f.print(src)}
904 ctx.merge(branch, rev3, branch, rev4, trunk, true, false, true, true)
905 assert(File.exist?(trunk_path))
907 ctx.merge(branch, rev3, branch, rev4, trunk, true, false, true)
908 rev6 = ctx.commit(@wc_path).revision
910 assert(!File.exist?(trunk_path))
917 trunk = File.join(@wc_path, "trunk")
918 branch = File.join(@wc_path, "branch")
919 trunk_path = File.join(trunk, file)
920 branch_path = File.join(branch, file)
922 ctx = make_context(log)
923 ctx.mkdir(trunk, branch)
924 File.open(trunk_path, "w") {}
925 File.open(branch_path, "w") {}
928 rev1 = ctx.commit(@wc_path).revision
930 File.open(branch_path, "w") {|f| f.print(src)}
931 rev2 = ctx.commit(@wc_path).revision
933 assert_nil(ctx.mergeinfo(trunk))
934 ctx.merge_peg(branch, rev1, rev2, trunk)
935 mergeinfo = ctx.mergeinfo(trunk)
936 expected_key = ctx.url_from_path(branch)
937 assert_equal([expected_key], mergeinfo.keys)
938 assert_equal([[1, 2, true]],
939 mergeinfo[expected_key].collect {|range| range.to_a})
940 rev3 = ctx.commit(@wc_path).revision
942 assert_equal(normalize_line_break(src), ctx.cat(trunk_path, rev3))
945 rev4 = ctx.commit(@wc_path).revision
947 ctx.merge_peg(branch, rev3, rev4, trunk)
948 assert(!File.exist?(trunk_path))
950 mergeinfo = ctx.mergeinfo(trunk, rev4)
951 assert_equal([expected_key], mergeinfo.keys)
952 assert_equal([[1, 2, true], [3, 4, true]],
953 mergeinfo[expected_key].collect {|range| range.to_a })
954 ctx.propdel("svn:mergeinfo", trunk)
955 assert_nil(ctx.mergeinfo(trunk))
957 ctx.revert(trunk_path)
958 File.open(trunk_path, "a") {|f| f.print(src)}
959 ctx.merge_peg(branch, rev3, rev4, trunk)
960 assert(File.exist?(trunk_path))
961 rev5 = ctx.commit(@wc_path).revision
963 File.open(trunk_path, "a") {|f| f.print(src)}
964 ctx.merge_peg(branch, rev3, rev4, trunk, nil, true, false, true, true)
965 assert(File.exist?(trunk_path))
967 ctx.merge_peg(branch, rev3, rev4, trunk, nil, true, false, true)
968 rev6 = ctx.commit(@wc_path).revision
970 assert(!File.exist?(trunk_path))
977 path = File.join(@wc_path, file)
979 ctx = make_context(log)
980 File.open(path, "w") {|f| f.print(src)}
982 rev = ctx.commit(@wc_path).revision
984 ctx.up(@wc_path, rev - 1)
985 File.open(path, "w") {|f| f.print(src)}
987 assert_raise(Svn::Error::WC_OBSTRUCTED_UPDATE) do
988 ctx.up(@wc_path, rev)
991 Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1) do |access|
992 assert_raise(Svn::Error::WC_LOCKED) do
997 ctx.set_cancel_func do
998 raise Svn::Error::CANCELLED
1000 Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1) do |access|
1001 assert_raise(Svn::Error::CANCELLED) do
1002 ctx.cleanup(@wc_path)
1004 assert_raise(Svn::Error::WC_LOCKED) do
1005 ctx.commit(@wc_path)
1009 ctx.set_cancel_func(nil)
1010 access = Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1)
1011 assert_nothing_raised do
1012 ctx.cleanup(@wc_path)
1014 assert_nothing_raised do
1015 ctx.commit(@wc_path)
1017 assert_raises(Svn::Error::SvnError) do
1026 path = File.join(@wc_path, file)
1028 ctx = make_context(log)
1029 File.open(path, "w") {|f| f.print(src)}
1031 ctx.commit(@wc_path)
1033 assert_nothing_raised do
1037 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1038 cred.username = @author
1039 cred.password = @password
1040 cred.may_save = true
1042 ctx.relocate(@wc_path, @repos_uri, @repos_svnserve_uri)
1044 ctx = make_context(log)
1045 assert_raises(Svn::Error::AuthnNoProvider) do
1056 dir_path = File.join(@wc_path, dir)
1057 path = File.join(dir_path, file)
1059 ctx = make_context(log)
1061 File.open(path, "w") {}
1063 rev1 = ctx.ci(@wc_path).revision
1065 File.open(path, "w") {|f| f.print(src1)}
1066 rev2 = ctx.ci(@wc_path).revision
1068 ctx.up(@wc_path, rev1)
1070 File.open(path, "w") {|f| f.print(src2)}
1073 assert_raises(Svn::Error::WcFoundConflict) do
1077 ctx.resolved(dir_path, false)
1078 assert_raises(Svn::Error::WcFoundConflict) do
1082 ctx.resolved(dir_path)
1084 assert_nothing_raised do
1085 info = ctx.ci(@wc_path)
1087 assert_not_nil(info)
1088 assert_equal(rev2 + 1, info.revision)
1094 file1 = "sample1.txt"
1095 file2 = "sample2.txt"
1096 path1 = File.join(@wc_path, file1)
1097 path2 = File.join(@wc_path, file2)
1099 ctx = make_context(log)
1100 File.open(path1, "w") {|f| f.print(src)}
1105 ctx.cp(path1, path2)
1108 ctx.set_notify_func do |notify|
1109 infos << [notify.path, notify]
1113 assert_equal([path2].sort,
1114 infos.collect{|path, notify| path}.sort)
1115 path2_notify = infos.assoc(path2)[1]
1116 assert(path2_notify.commit_added?)
1117 assert_equal(File.open(path1) {|f| f.read},
1118 File.open(path2) {|f| f.read})
1124 file1 = "sample1.txt"
1125 file2 = "sample2.txt"
1126 path1 = File.join(@wc_path, file1)
1127 path2 = File.join(@wc_path, file2)
1129 ctx = make_context(log)
1130 File.open(path1, "w") {|f| f.print(src)}
1135 ctx.mv(path1, path2)
1138 ctx.set_notify_func do |notify|
1139 infos << [notify.path, notify]
1143 assert_equal([path1, path2].sort,
1144 infos.collect{|path, notify| path}.sort)
1145 path1_notify = infos.assoc(path1)[1]
1146 assert(path1_notify.commit_deleted?)
1147 path2_notify = infos.assoc(path2)[1]
1148 assert(path2_notify.commit_added?)
1149 assert_equal(src, File.open(path2) {|f| f.read})
1156 file1 = "sample1.txt"
1157 file2 = "sample2.txt"
1158 path1 = File.join(@wc_path, file1)
1159 path2 = File.join(@wc_path, file2)
1161 ctx = make_context(log)
1162 File.open(path1, "w") {|f| f.print(src1)}
1166 File.open(path1, "w") {|f| f.print(src2)}
1167 assert_nothing_raised do
1168 ctx.mv(path1, path2)
1170 ctx.revert([path1, path2])
1173 File.open(path1, "w") {|f| f.print(src2)}
1174 assert_nothing_raised do
1175 ctx.mv_f(path1, path2)
1179 ctx.set_notify_func do |notify|
1184 paths = notifies.collect do |notify|
1187 assert_equal([path1, path2, path2].sort, paths.sort)
1189 deleted_paths = notifies.find_all do |notify|
1190 notify.commit_deleted?
1191 end.collect do |notify|
1194 assert_equal([path1].sort, deleted_paths.sort)
1196 added_paths = notifies.find_all do |notify|
1197 notify.commit_added?
1198 end.collect do |notify|
1201 assert_equal([path2].sort, added_paths.sort)
1203 postfix_txdelta_paths = notifies.find_all do |notify|
1204 notify.commit_postfix_txdelta?
1205 end.collect do |notify|
1208 assert_equal([path2].sort, postfix_txdelta_paths.sort)
1210 assert_equal(src2, File.open(path2) {|f| f.read})
1217 dir_path = File.join(@wc_path, dir)
1218 dir_uri = "#{@repos_uri}/#{dir}"
1219 path = File.join(dir_path, file)
1220 uri = "#{dir_uri}/#{file}"
1221 prop_name = "sample-prop"
1222 prop_value = "sample value"
1223 invalid_mime_type_prop_value = "image"
1225 ctx = make_context(log)
1228 File.open(path, "w") {}
1231 ctx.commit(@wc_path)
1233 assert_equal({}, ctx.prop_get(prop_name, path))
1234 ctx.prop_set(prop_name, prop_value, path)
1235 ctx.commit(@wc_path)
1236 assert_equal({uri => prop_value}, ctx.pget(prop_name, path))
1238 ctx.prop_del(prop_name, path)
1239 ctx.commit(@wc_path)
1240 assert_equal({}, ctx.pg(prop_name, path))
1242 ctx.ps(prop_name, prop_value, path)
1243 ctx.commit(@wc_path)
1244 assert_equal({uri => prop_value}, ctx.pg(prop_name, path))
1246 ctx.ps(prop_name, nil, path)
1247 ctx.commit(@wc_path)
1248 assert_equal({}, ctx.pg(prop_name, path))
1251 ctx.ps(prop_name, prop_value, dir_path)
1254 dir_uri => prop_value,
1257 ctx.pg(prop_name, dir_path))
1260 ctx.pdel(prop_name, dir_path, false)
1262 assert_equal({uri => prop_value}, ctx.pg(prop_name, dir_path))
1265 ctx.pd(prop_name, dir_path)
1267 assert_equal({}, ctx.pg(prop_name, dir_path))
1270 ctx.ps(prop_name, prop_value, dir_path, false)
1272 assert_equal({dir_uri => prop_value}, ctx.pg(prop_name, dir_path))
1274 assert_raises(Svn::Error::BadMimeType) do
1275 ctx.ps(Svn::Core::PROP_MIME_TYPE,
1276 invalid_mime_type_prop_value,
1279 ctx.cleanup(@wc_path)
1281 assert_nothing_raised do
1282 ctx.ps(Svn::Core::PROP_MIME_TYPE,
1283 invalid_mime_type_prop_value,
1286 ctx.commit(@wc_path)
1287 assert_equal({uri => invalid_mime_type_prop_value},
1288 ctx.pg(Svn::Core::PROP_MIME_TYPE, path))
1295 dir_path = File.join(@wc_path, dir)
1296 path = File.join(dir_path, file)
1297 dir_uri = "#{@repos_uri}/#{dir}"
1298 uri = "#{dir_uri}/#{file}"
1304 ctx = make_context(log)
1307 File.open(path, "w") {}
1312 assert_equal([], ctx.prop_list(path))
1314 ctx.ps(name1, value1, path)
1316 assert_equal([uri], ctx.prop_list(path).collect{|item| item.node_name})
1317 assert_equal([{name1 => value1}],
1318 ctx.plist(path).collect{|item| item.prop_hash})
1319 assert_equal([value1], ctx.pl(path).collect{|item| item[name1]})
1322 ctx.ps(name2, value2, dir_path)
1324 assert_equal([uri, dir_uri].sort,
1325 ctx.prop_list(dir_path).collect{|item| item.name})
1326 prop_list = ctx.plist(dir_path).collect{|item| [item.name, item.props]}
1327 props = prop_list.assoc(uri)[1]
1328 dir_props = prop_list.assoc(dir_uri)[1]
1329 assert_equal({name1 => value1, name2 => value2}, props)
1330 assert_equal({name2 => value2}, dir_props)
1333 def recurse_and_depth_choices
1334 [false, true, 'empty', 'files', 'immediates', 'infinity']
1341 ctx = make_context(log)
1343 # when no props set, everything is empty
1344 recurse_and_depth_choices.each do |rd|
1346 ctx.prop_list(@greek.path(:mu), nil, nil, rd),
1347 "prop_list with Depth '#{rd}'")
1350 recurse_and_depth_choices.each do |rd|
1352 ctx.prop_get(rd.to_s, @greek.path(:mu), nil, nil, rd),
1353 "prop_get with Depth '#{rd}'")
1357 recurse_and_depth_choices.each do |rd|
1358 ctx.prop_set(rd.to_s, rd.to_s, @greek.path(:mu), rd)
1360 ctx.commit(@greek.path(:mu))
1363 recurse_and_depth_choices.each do |rd|
1364 assert_equal({@greek.uri(:mu) => rd.to_s},
1365 ctx.prop_get(rd.to_s, @greek.path(:mu), nil, nil, rd),
1366 "prop_get with Depth '#{rd}'")
1370 recurse_and_depth_choices.each {|rd| prop_hash[rd.to_s] = rd.to_s}
1373 recurse_and_depth_choices.each do |rd|
1374 props = ctx.prop_list(@greek.path(:mu), nil, nil, rd)
1375 assert_equal([@greek.uri(:mu)],
1376 props.collect {|item| item.node_name},
1377 "prop_list (node_name) with Depth '#{rd}'")
1379 props = ctx.plist(@greek.path(:mu), nil, nil, rd)
1380 assert_equal([prop_hash],
1381 props.collect {|item| item.prop_hash},
1382 "prop_list (prop_hash) with Depth '#{rd}'")
1384 recurse_and_depth_choices.each do |rd1|
1385 props = ctx.plist(@greek.path(:mu), nil, nil, rd)
1386 assert_equal([rd1.to_s],
1387 props.collect {|item| item[rd1.to_s]},
1388 "prop_list (#{rd1.to_s}]) with Depth '#{rd}'")
1398 ctx = make_context(log)
1400 # when no props set, everything is empty
1401 recurse_and_depth_choices.each do |rd|
1403 ctx.prop_list(@greek.path(:b), nil, nil, rd),
1404 "prop_list with Depth '#{rd}'")
1407 recurse_and_depth_choices.each do |rd|
1409 ctx.prop_get(rd.to_s, @greek.path(:b), nil, nil, rd),
1410 "prop_get with Depth '#{rd}'")
1413 # set some props with various depths
1414 recurse_and_depth_choices.each do |rd|
1415 ctx.prop_set(rd.to_s, rd.to_s, @greek.path(:b), rd)
1417 ctx.commit(@greek.path(:b))
1420 true => [:beta, :b, :lambda, :e, :f, :alpha],
1423 'files' => [:b, :lambda],
1424 'immediates' => [:b, :lambda, :e, :f],
1425 'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
1428 paths = [:b, :e, :alpha, :beta, :f, :lambda]
1430 # how are the props set?
1431 recurse_and_depth_choices.each do |rd|
1432 paths.each do |path|
1433 if expected_props[rd].include?(path)
1434 expected = {@greek.uri(path) => rd.to_s}
1438 assert_equal(expected,
1439 ctx.prop_get(rd.to_s, @greek.path(path), nil, nil, false),
1440 "prop_get #{@greek.resolve(path)} with Depth '#{rd}'")
1444 recurse_and_depth_choices.each do |rd_for_prop|
1445 recurse_and_depth_choices.each do |rd_for_depth|
1447 expected_paths = expected_props[rd_for_depth]
1448 expected_paths &= expected_props[rd_for_prop]
1449 expected_paths.each do |path|
1450 expected[@greek.uri(path)] = rd_for_prop.to_s
1453 assert_equal(expected,
1454 ctx.prop_get(rd_for_prop.to_s, @greek.path(:b),
1455 nil, nil, rd_for_depth),
1456 "prop_get '#{rd_for_prop}' with Depth '#{rd_for_depth}'")
1461 recurse_and_depth_choices.each do |rd|
1462 props = ctx.prop_list(@greek.path(:b), nil, nil, rd)
1463 assert_equal(expected_props[rd].collect {|path| @greek.uri(path)}.sort,
1464 props.collect {|item| item.node_name}.sort,
1465 "prop_list (node_name) with Depth '#{rd}'")
1474 path = File.join(@wc_path, file)
1476 File.open(path, "w") {|f| f.print(src1)}
1478 ctx = make_context(log)
1480 commit_info = ctx.commit(@wc_path)
1481 rev1 = commit_info.revision
1483 assert_equal(normalize_line_break(src1), ctx.cat(path, rev1))
1484 assert_equal(normalize_line_break(src1), ctx.cat(path))
1486 File.open(path, "w") {|f| f.print(src2)}
1488 commit_info = ctx.commit(@wc_path)
1489 rev2 = commit_info.revision
1491 assert_equal(normalize_line_break(src1), ctx.cat(path, rev1))
1492 assert_equal(normalize_line_break(src2), ctx.cat(path, rev2))
1493 assert_equal(normalize_line_break(src2), ctx.cat(path))
1500 path = File.join(@wc_path, file)
1502 File.open(path, "w") {|f| f.print(src)}
1504 ctx = make_context(log)
1506 ctx.commit(@wc_path)
1509 ctx.set_notify_func do |notify|
1510 infos << [notify.path, notify]
1514 assert_equal([file], infos.collect{|path, notify| path})
1515 file_notify = infos.assoc(file)[1]
1516 assert(file_notify.locked?)
1523 path = File.join(@wc_path, file)
1525 File.open(path, "w") {|f| f.print(src)}
1527 ctx = make_context(log)
1529 ctx.commit(@wc_path)
1534 ctx.set_notify_func do |notify|
1535 infos << [notify.path, notify]
1538 assert_equal([file], infos.collect{|path, notify| path})
1539 file_notify = infos.assoc(file)[1]
1540 assert(file_notify.unlocked?)
1545 ctx = make_context(log)
1546 repos_base = File.basename(@repos_path)
1549 ctx.info(@wc_path) do |path, info|
1550 infos << [path, info]
1552 assert_equal([repos_base],
1553 infos.collect{|path, info| path})
1554 top_info = infos.assoc(repos_base)[1]
1555 assert_equal(@repos_uri, top_info.url)
1558 def test_info_with_depth
1562 ctx = make_context(log)
1564 recurse_and_depth_choices.each do |rd|
1565 ctx.info(@greek.path(:mu),nil,nil,rd) do |path, info|
1566 assert_equal @greek.uri(:mu), info.URL
1570 expected_info_by_depth = {
1571 true => [:beta, :b, :lambda, :e, :f, :alpha],
1574 'files' => [:b, :lambda],
1575 'immediates' => [:b, :lambda, :e, :f],
1576 'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
1579 recurse_and_depth_choices.each do |rd|
1581 ctx.info(@greek.path(:b),nil,nil,rd) do |path, info|
1584 assert_equal expected_info_by_depth[rd].map{|s| @greek.uri(s)}.sort,
1590 def test_url_from_path
1592 ctx = make_context(log)
1593 assert_equal(@repos_uri, ctx.url_from_path(@wc_path))
1594 assert_equal(@repos_uri, Svn::Client.url_from_path(@wc_path))
1599 ctx = make_context(log)
1600 Svn::Wc::AdmAccess.open(nil, @wc_path, false, 0) do |adm|
1601 assert_equal(ctx.uuid_from_url(@repos_uri),
1602 ctx.uuid_from_path(@wc_path, adm))
1606 def test_open_ra_session
1608 ctx = make_context(log)
1610 assert_instance_of(Svn::Ra::Session, ctx.open_ra_session(@repos_uri))
1615 new_log = "new sample log"
1618 path = File.join(@wc_path, file)
1620 File.open(path, "w") {|f| f.print(src)}
1622 ctx = make_context(log)
1624 info = ctx.commit(@wc_path)
1628 Svn::Core::PROP_REVISION_AUTHOR => @author,
1629 Svn::Core::PROP_REVISION_DATE => info.date,
1630 Svn::Core::PROP_REVISION_LOG => log,
1634 ctx.revprop_list(@repos_uri, info.revision))
1636 assert_equal([log, info.revision],
1637 ctx.revprop_get(Svn::Core::PROP_REVISION_LOG,
1638 @repos_uri, info.revision))
1640 ctx.revprop(Svn::Core::PROP_REVISION_LOG,
1641 @repos_uri, info.revision))
1643 assert_equal(info.revision,
1644 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1645 @repos_uri, info.revision))
1646 assert_equal([new_log, info.revision],
1647 ctx.rpget(Svn::Core::PROP_REVISION_LOG,
1648 @repos_uri, info.revision))
1649 assert_equal(new_log,
1650 ctx.rp(Svn::Core::PROP_REVISION_LOG,
1651 @repos_uri, info.revision))
1654 Svn::Core::PROP_REVISION_AUTHOR => @author,
1655 Svn::Core::PROP_REVISION_DATE => info.date,
1656 Svn::Core::PROP_REVISION_LOG => new_log,
1660 ctx.rplist(@repos_uri, info.revision))
1662 assert_equal(info.revision,
1663 ctx.revprop_del(Svn::Core::PROP_REVISION_LOG,
1664 @repos_uri, info.revision))
1665 assert_equal([nil, info.revision],
1666 ctx.rpg(Svn::Core::PROP_REVISION_LOG,
1667 @repos_uri, info.revision))
1669 ctx.rp(Svn::Core::PROP_REVISION_LOG,
1670 @repos_uri, info.revision))
1672 assert_equal(info.revision,
1673 ctx.rpset(Svn::Core::PROP_REVISION_LOG, new_log,
1674 @repos_uri, info.revision))
1675 assert_equal(new_log,
1676 ctx.rp(Svn::Core::PROP_REVISION_LOG,
1677 @repos_uri, info.revision))
1678 assert_equal(info.revision,
1679 ctx.rps(Svn::Core::PROP_REVISION_LOG, nil,
1680 @repos_uri, info.revision))
1682 ctx.rp(Svn::Core::PROP_REVISION_LOG,
1683 @repos_uri, info.revision))
1687 Svn::Core::PROP_REVISION_AUTHOR => @author,
1688 Svn::Core::PROP_REVISION_DATE => info.date,
1692 ctx.rpl(@repos_uri, info.revision))
1700 dir_path = File.join(@wc_path, dir)
1701 path = File.join(dir_path, file)
1702 tmp_base_path = File.join(@tmp_path, "tmp")
1703 tmp_dir_path = File.join(tmp_base_path, dir)
1704 tmp_path = File.join(tmp_dir_path, file)
1706 ctx = make_context(log)
1709 File.open(path, "w") {|f| f.print(src)}
1711 rev = ctx.ci(@wc_path).revision
1713 assert_equal(rev, ctx.export(@repos_uri, tmp_base_path))
1714 assert_equal(src, File.open(tmp_path) {|f| f.read})
1722 dir_path = File.join(@wc_path, dir)
1723 path = File.join(@wc_path, file)
1725 ctx = make_context(log)
1728 File.open(path, "w") {|f| f.print(src)}
1730 rev = ctx.ci(@wc_path).revision
1732 dirents, locks = ctx.ls(@wc_path, rev)
1733 assert_equal([dir, file].sort, dirents.keys.sort)
1734 dir_dirent = dirents[dir]
1735 assert(dir_dirent.directory?)
1736 file_dirent = dirents[file]
1737 assert(file_dirent.file?)
1745 prop_name = "sample-prop"
1746 prop_value = "sample value"
1747 dir_path = File.join(@wc_path, dir)
1748 path = File.join(@wc_path, file)
1750 ctx = make_context(log)
1753 File.open(path, "w") {|f| f.print(src)}
1755 ctx.prop_set(prop_name, prop_value, path)
1756 rev = ctx.ci(@wc_path).revision
1759 ctx.list(@wc_path, rev) do |path, dirent, lock, abs_path|
1760 entries << [path, dirent, lock, abs_path]
1762 paths = entries.collect do |path, dirent, lock, abs_path|
1765 assert_equal([["", "/"], [dir, "/"], [file, "/"]].sort, paths.sort)
1766 entries.each do |path, dirent, lock, abs_path|
1769 assert(dirent.directory?)
1770 assert_false(dirent.have_props?)
1772 assert(dirent.file?)
1773 assert_true(dirent.have_props?)
1780 def test_list_with_depth
1784 ctx = make_context(log)
1786 expected_lists_by_depth = {
1787 true => [:beta, :b, :lambda, :e, :f, :alpha],
1788 false => [:b, :lambda, :e, :f],
1790 'files' => [:b, :lambda],
1791 'immediates' => [:b, :lambda, :e, :f],
1792 'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
1795 recurse_and_depth_choices.each do |rd|
1797 ctx.list(@greek.path(:b), 'head' ,nil, rd) do |path, dirent, lock, abs_path|
1798 paths << (path.empty? ? abs_path : File.join(abs_path, path))
1800 assert_equal(expected_lists_by_depth[rd].map{|s| "/#{@greek.resolve(s)}"}.sort,
1808 trunk_src = "trunk source\n"
1809 tag_src = "tag source\n"
1815 trunk_repos_uri = "#{@repos_uri}/#{trunk_dir}"
1816 tag_repos_uri = "#{@repos_uri}/#{tag_dir}/#{tag_name}"
1817 trunk_dir_path = File.join(@wc_path, trunk_dir)
1818 tag_dir_path = File.join(@wc_path, tag_dir)
1819 tag_name_dir_path = File.join(@wc_path, tag_dir, tag_name)
1820 trunk_path = File.join(trunk_dir_path, file)
1821 tag_path = File.join(tag_name_dir_path, file)
1822 path = File.join(@wc_path, file)
1824 ctx = make_context(log)
1826 ctx.mkdir(trunk_dir_path)
1827 File.open(trunk_path, "w") {|f| f.print(trunk_src)}
1829 trunk_rev = ctx.commit(@wc_path).revision
1831 ctx.mkdir(tag_dir_path, tag_name_dir_path)
1832 File.open(tag_path, "w") {|f| f.print(tag_src)}
1834 tag_rev = ctx.commit(@wc_path).revision
1836 assert_equal(youngest_rev, ctx.switch(@wc_path, trunk_repos_uri))
1837 assert_equal(normalize_line_break(trunk_src), ctx.cat(path))
1839 assert_equal(youngest_rev, ctx.switch(@wc_path, tag_repos_uri))
1840 assert_equal(normalize_line_break(tag_src), ctx.cat(path))
1844 ctx.set_notify_func do |notify|
1845 notify_info << [notify.path, notify.action]
1848 assert_equal(trunk_rev, ctx.switch(@wc_path, trunk_repos_uri, trunk_rev))
1849 assert_equal(normalize_line_break(trunk_src), ctx.cat(path))
1851 [path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1852 [@wc_path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1853 [@wc_path, Svn::Wc::NOTIFY_UPDATE_COMPLETED],
1858 assert_equal(tag_rev, ctx.switch(@wc_path, tag_repos_uri, tag_rev))
1859 assert_equal(normalize_line_break(tag_src), ctx.cat(path))
1861 [path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1862 [@wc_path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1863 [@wc_path, Svn::Wc::NOTIFY_UPDATE_COMPLETED],
1868 def test_authentication
1872 path = File.join(@wc_path, file)
1873 svnserve_uri = "#{@repos_svnserve_uri}/#{file}"
1875 File.open(path, "w") {|f| f.print(src)}
1877 ctx = make_context(log)
1879 ctx.commit(@wc_path)
1881 ctx = Svn::Client::Context.new
1883 assert_raises(Svn::Error::AuthnNoProvider) do
1884 ctx.cat(svnserve_uri)
1887 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1888 cred.username = "wrong-#{@author}"
1889 cred.password = @password
1890 cred.may_save = false
1892 assert_raises(Svn::Error::RaNotAuthorized) do
1893 ctx.cat(svnserve_uri)
1896 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1897 cred.username = @author
1898 cred.password = "wrong-#{@password}"
1899 cred.may_save = false
1901 assert_raises(Svn::Error::RaNotAuthorized) do
1902 ctx.cat(svnserve_uri)
1905 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1906 cred.username = @author
1907 cred.password = @password
1908 cred.may_save = false
1910 assert_equal(normalize_line_break(src), ctx.cat(svnserve_uri))
1913 def assert_simple_provider(method)
1917 path = File.join(@wc_path, file)
1918 svnserve_uri = "#{@repos_svnserve_uri}/#{file}"
1920 File.open(path, "w") {|f| f.print(src)}
1922 ctx = make_context(log)
1923 setup_auth_baton(ctx.auth_baton)
1925 ctx.commit(@wc_path)
1927 ctx = Svn::Client::Context.new
1928 setup_auth_baton(ctx.auth_baton)
1930 assert_raises(Svn::Error::RaNotAuthorized) do
1931 ctx.cat(svnserve_uri)
1934 ctx = Svn::Client::Context.new
1935 setup_auth_baton(ctx.auth_baton)
1937 ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1938 cred.username = @author
1939 cred.password = @password
1941 assert_equal(normalize_line_break(src), ctx.cat(svnserve_uri))
1944 def test_simple_provider
1945 assert_simple_provider(:add_simple_provider)
1948 if Svn::Core.respond_to?(:auth_get_windows_simple_provider)
1949 def test_windows_simple_provider
1950 assert_simple_provider(:add_windows_simple_provider)
1954 if Svn::Core.respond_to?(:auth_get_keychain_simple_provider)
1955 def test_keychain_simple_provider
1956 assert_simple_provider(:add_keychain_simple_provider)
1960 def test_username_provider
1962 new_log = "sample new log"
1965 path = File.join(@wc_path, file)
1966 repos_uri = "#{@repos_uri}/#{file}"
1968 File.open(path, "w") {|f| f.print(src)}
1970 ctx = make_context(log)
1972 info = ctx.commit(@wc_path)
1974 ctx = Svn::Client::Context.new
1975 setup_auth_baton(ctx.auth_baton)
1976 ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = @author
1977 ctx.add_username_provider
1978 assert_nothing_raised do
1979 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1980 repos_uri, info.revision)
1983 ctx = Svn::Client::Context.new
1984 setup_auth_baton(ctx.auth_baton)
1985 ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = "#{@author}-NG"
1986 ctx.add_username_provider
1987 assert_raise(Svn::Error::REPOS_HOOK_FAILURE) do
1988 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1989 repos_uri, info.revision)
1992 ctx = Svn::Client::Context.new
1993 setup_auth_baton(ctx.auth_baton)
1994 ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = nil
1995 ctx.add_username_prompt_provider(0) do |cred, realm, may_save|
1997 assert_raise(Svn::Error::REPOS_HOOK_FAILURE) do
1998 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1999 repos_uri, info.revision)
2002 ctx = Svn::Client::Context.new
2003 setup_auth_baton(ctx.auth_baton)
2004 ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = nil
2005 ctx.add_username_prompt_provider(0) do |cred, realm, may_save|
2006 cred.username = @author
2008 assert_nothing_raised do
2009 ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
2010 repos_uri, info.revision)
2014 def test_add_providers
2015 ctx = Svn::Client::Context.new
2016 assert_nothing_raised do
2017 ctx.add_ssl_client_cert_file_provider
2018 ctx.add_ssl_client_cert_pw_file_provider
2019 ctx.add_ssl_server_trust_file_provider
2020 if Svn::Core.respond_to?(:auth_get_windows_ssl_server_trust_provider)
2021 ctx.add_windows_ssl_server_trust_provider
2026 def test_commit_item
2027 assert_raise(NoMethodError) do
2028 Svn::Client::CommitItem.new
2031 assert_raise(NoMethodError) do
2032 Svn::Client::CommitItem2.new
2035 item = Svn::Client::CommitItem3.new
2036 assert_kind_of(Svn::Client::CommitItem3, item)
2040 assert_equal(url, item.dup.url)
2043 def test_log_msg_func_commit_items
2048 path = File.join(@wc_path, file)
2049 repos_uri2 = "#{@repos_uri}/#{file2}"
2051 File.open(path, "w") {|f| f.print(src)}
2053 ctx = make_context(log)
2055 ctx.set_log_msg_func do |items|
2060 ctx.prop_set(Svn::Core::PROP_MIME_TYPE, "text/plain", path)
2061 ctx.commit(@wc_path)
2062 assert_equal([[]], items.collect {|item| item.wcprop_changes})
2063 assert_equal([[]], items.collect {|item| item.incoming_prop_changes})
2064 assert_equal([nil], items.collect {|item| item.outgoing_prop_changes})
2067 ctx.cp(path, repos_uri2)
2068 assert_equal([nil], items.collect {|item| item.wcprop_changes})
2069 assert_equal([nil], items.collect {|item| item.incoming_prop_changes})
2070 assert_equal([nil], items.collect {|item| item.outgoing_prop_changes})
2073 def test_log_msg_func_cancel
2076 dir_path = File.join(@wc_path, dir)
2078 ctx = make_context(log)
2079 ctx.set_log_msg_func do |items|
2080 raise Svn::Error::Cancelled
2083 assert_raise(Svn::Error::Cancelled) do
2084 ctx.commit(@wc_path)
2090 ctx = make_context(log)
2092 "groups" => {"collabnet" => "svn.collab.net"},
2094 "http-proxy-host" => "proxy",
2095 "http-proxy-port" => "8080",
2098 servers_config_file = File.join(@config_path,
2099 Svn::Core::CONFIG_CATEGORY_SERVERS)
2100 File.open(servers_config_file, "w") do |file|
2101 options.each do |section, values|
2102 file.puts("[#{section}]")
2103 values.each do |key, value|
2104 file.puts("#{key} = #{value}")
2108 config = Svn::Core::Config.config(@config_path)
2109 assert_nil(ctx.config)
2110 assert_equal(options, config[Svn::Core::CONFIG_CATEGORY_SERVERS].to_hash)
2112 assert_equal(options,
2113 ctx.config[Svn::Core::CONFIG_CATEGORY_SERVERS].to_hash)
2116 def test_context_mimetypes_map
2117 context = Svn::Client::Context.new
2118 assert_nil(context.mimetypes_map)
2119 context.mimetypes_map = {"txt" => "text/plain"}
2120 assert_equal({"txt" => "text/plain"}, context.mimetypes_map)
2123 def test_context_revprop_table
2124 context = Svn::Client::Context.new
2125 assert_nil(context.revprop_table)
2126 context.revprop_table = {"my-prop" => "XXX"}
2127 assert_equal({"my-prop" => "XXX"}, context.revprop_table)
2130 def assert_changelists
2132 file1 = "hello1.txt"
2133 file2 = "hello2.txt"
2137 path1 = File.join(@wc_path, file1)
2138 path2 = File.join(@wc_path, file2)
2140 ctx = make_context(log)
2141 File.open(path1, "w") {|f| f.print(src)}
2142 File.open(path2, "w") {|f| f.print(src)}
2145 ctx.commit(@wc_path)
2147 assert_equal({}, yield(ctx, changelist1))
2148 assert_equal({nil=>[@wc_path,path1,path2]}, yield(ctx, nil))
2149 assert_equal({}, yield(ctx, []))
2150 assert_equal({}, yield(ctx, [changelist1]))
2151 assert_equal({}, yield(ctx, [changelist2]))
2152 ctx.add_to_changelist(changelist1, path1)
2153 assert_equal({changelist1=>[path1]}, yield(ctx, changelist1))
2154 assert_equal({changelist1=>[path1],nil=>[@wc_path,path2]}, yield(ctx, nil))
2155 assert_equal({}, yield(ctx, []))
2156 assert_equal({changelist1=>[path1]}, yield(ctx, [changelist1]))
2157 assert_equal({}, yield(ctx, [changelist2]))
2159 assert_equal({}, yield(ctx, changelist2))
2160 ctx.add_to_changelist(changelist2, [path1, path2])
2161 assert_equal({changelist2=>[path1, path2]}, yield(ctx, changelist2))
2162 assert_equal({}, yield(ctx, changelist1))
2164 ctx.add_to_changelist(changelist1, [path1, path2])
2165 assert_equal({changelist1=>[path1, path2]}, yield(ctx, changelist1))
2166 assert_equal({}, yield(ctx, changelist2))
2168 ctx.remove_from_changelists(changelist1, path1)
2169 assert_equal({changelist1=>[path2]}, yield(ctx, changelist1))
2170 ctx.remove_from_changelists(changelist1, [path2])
2171 assert_equal({}, yield(ctx, changelist1))
2173 ctx.add_to_changelist(changelist1, path1)
2174 ctx.add_to_changelist(changelist2, path2)
2175 assert_equal({changelist1=>[path1]}, yield(ctx, changelist1))
2176 assert_equal({changelist2=>[path2]}, yield(ctx, changelist2))
2178 assert_equal({changelist1=>[path1]}, yield(ctx, changelist1))
2179 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],changelist2=>[path2],nil=>[@wc_path]}, yield(ctx, nil))
2183 assert_equal({}, yield(ctx, []))
2184 assert_equal({changelist1=>[path1],changelist2=>[path2]},
2185 yield(ctx, [changelist1,changelist2]))
2187 ctx.remove_from_changelists(nil, [path1, path2])
2188 assert_equal({}, yield(ctx, changelist1))
2189 assert_equal({}, yield(ctx, changelist2))
2192 def test_changelists_get_without_block
2193 assert_changelists do |ctx, changelist_name|
2194 ctx.changelists(changelist_name, @wc_path)
2198 def test_changelists_get_with_block
2199 assert_changelists do |ctx, changelist_name|
2200 changelists = Hash.new{|h,k| h[k]=[]}
2201 ctx.changelists(changelist_name, @wc_path) do |path,cl_name|
2202 changelists[cl_name] << path