Skip to content

Commit c07eee1

Browse files
Eric WongJunio C Hamano
authored andcommitted
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>
1 parent d281786 commit c07eee1

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

contrib/git-svn/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ git-svn.html : git-svn.txt
2929
asciidoc -b xhtml11 -d manpage \
3030
-f ../../Documentation/asciidoc.conf $<
3131
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
3433

3534
# we can test NO_OPTIMIZE_COMMITS independently of LC_ALL
3635
full-test:

contrib/git-svn/git-svn.perl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,13 +2841,20 @@ sub rmdirs {
28412841
exec qw/git-ls-tree --name-only -r -z/, $self->{c} or croak $!;
28422842
}
28432843
local $/ = "\0";
2844+
my @svn_path = split m#/#, $self->{svn_path};
28442845
while (<$fh>) {
28452846
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+
}
28502855
}
2856+
close $fh;
2857+
28512858
my ($r, $p, $bat) = ($self->{r}, $self->{pool}, $self->{bat});
28522859
foreach my $d (sort { $b =~ tr#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
28532860
$self->close_directory($bat->{$d}, $p);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)