@matheusbsbs / matheus-bagliano / commits / c07eee1f2a
Fork 0

git-svn: fix --rmdir when using SVN:: libraries

When tracking directories with nearly all of its files at the most nested levels, --rmdir would accidentally go too far when deleting. Of course, we'll add a test for this condition, too. Makefile: automatically run new tests as they appear in t/ Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed Jun 19, 2006 at 17:59 UTC c07eee1f2ab9e9b168e050c0ef0b48d039c71470
3 files changed +41 -6
contrib/git-svn/Makefile
+1 -2
@@ -29,8 +29,7 @@ git-svn.html : git-svn.txt
29 asciidoc -b xhtml11 -d manpage \
30 -f ../../Documentation/asciidoc.conf $<
31 test: git-svn
32 - cd t && $(SHELL) ./t0000-contrib-git-svn.sh $(TEST_FLAGS)
33 - cd t && $(SHELL) ./t0001-contrib-git-svn-props.sh $(TEST_FLAGS)
32 + cd t && for i in t????-*.sh; do $(SHELL) ./$$i $(TEST_FLAGS); done
33
34 # we can test NO_OPTIMIZE_COMMITS independently of LC_ALL
35 full-test:
contrib/git-svn/git-svn.perl
+11 -4
@@ -2841,13 +2841,20 @@ sub rmdirs {
2841 exec qw/git-ls-tree --name-only -r -z/, $self->{c} or croak $!;
2842 }
2843 local $/ = "\0";
2844 + my @svn_path = split m#/#, $self->{svn_path};
2845 while (<$fh>) {
2846 chomp;
2846 - $_ = $self->{svn_path} . '/' . $_;
2847 - my ($dn) = ($_ =~ m#^(.*?)/?(?:[^/]+)$#);
2848 - delete $rm->{$dn};
2849 - last unless %$rm;
2847 + my @dn = (@svn_path, (split m#/#, $_));
2848 + while (pop @dn) {
2849 + delete $rm->{join '/', @dn};
2850 + }
2851 + unless (%$rm) {
2852 + close $fh;
2853 + return;
2854 + }
2855 }
2856 + close $fh;
2857 +
2858 my ($r, $p, $bat) = ($self->{r}, $self->{pool}, $self->{bat});
2859 foreach my $d (sort { $b =~ tr#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
2860 $self->close_directory($bat->{$d}, $p);
contrib/git-svn/t/t0002-deep-rmdir.sh new
+29
@@ -0,0 +1,29 @@
1 +test_description='git-svn rmdir'
2 +. ./lib-git-svn.sh
3 +
4 +test_expect_success 'initialize repo' "
5 + mkdir import &&
6 + cd import &&
7 + mkdir -p deeply/nested/directory/number/1 &&
8 + mkdir -p deeply/nested/directory/number/2 &&
9 + echo foo > deeply/nested/directory/number/1/file &&
10 + echo foo > deeply/nested/directory/number/2/another &&
11 + svn import -m 'import for git-svn' . $svnrepo &&
12 + cd ..
13 + "
14 +
15 +test_expect_success 'mirror via git-svn' "
16 + git-svn init $svnrepo &&
17 + git-svn fetch &&
18 + git checkout -f -b test-rmdir remotes/git-svn
19 + "
20 +
21 +test_expect_success 'Try a commit on rmdir' "
22 + git rm -f deeply/nested/directory/number/2/another &&
23 + git commit -a -m 'remove another' &&
24 + git-svn commit --rmdir HEAD &&
25 + svn ls -R $svnrepo | grep ^deeply/nested/directory/number/1
26 + "
27 +
28 +
29 +test_done