@matheusbsbs / matheus-bagliano / commits / 12a6d752fb
Fork 0

git-svn: handle our top-level path being deleted and later re-added

Previously, git-svn would ignore cases where the path we're tracking is removed from the repository. This was to prevent heads with follow-parent from ending up with a tree full of empty revisions (and thus breaking rename detection). The previous behavior is fine until the path we're tracking is re-added later on, leading to the old files being merged in with the new files in the directory (because the old files were never marked as deleted) We will now only remove all the old files locally that were deleted remotely iff we detect the directory we're in is being created from scratch. Thanks for Marcus D. Hanwell for the bug report and Peter Baumann for the analysis. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Wong committed Dec 14, 2007 at 08:39 UTC 12a6d752fb61b10194b2897defb2b34e09099b12
2 files changed +53
git-svn.perl
+14
@@ -3045,6 +3045,20 @@ sub add_file {
3045
3046 sub add_directory {
3047 my ($self, $path, $cp_path, $cp_rev) = @_;
3048 + my $gpath = $self->git_path($path);
3049 + if ($gpath eq '') {
3050 + my ($ls, $ctx) = command_output_pipe(qw/ls-tree
3051 + -r --name-only -z/,
3052 + $self->{c});
3053 + local $/ = "\0";
3054 + while (<$ls>) {
3055 + chomp;
3056 + $self->{gii}->remove($_);
3057 + print "\tD\t$_\n" unless $::_q;
3058 + }
3059 + command_close_pipe($ls, $ctx);
3060 + $self->{empty}->{$path} = 0;
3061 + }
3062 my ($dir, $file) = ($path =~ m#^(.*?)/?([^/]+)$#);
3063 delete $self->{empty}->{$dir};
3064 $self->{empty}->{$path} = 1;
t/t9103-git-svn-tracked-directory-removed.sh new
+39
@@ -0,0 +1,39 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2007 Eric Wong
4 +#
5 +
6 +test_description='git-svn tracking removed top-level path'
7 +. ./lib-git-svn.sh
8 +
9 +test_expect_success 'make history for tracking' '
10 + mkdir import &&
11 + mkdir import/trunk &&
12 + echo hello >> import/trunk/README &&
13 + svn import -m initial import $svnrepo &&
14 + rm -rf import &&
15 + svn co $svnrepo/trunk trunk &&
16 + echo bye bye >> trunk/README &&
17 + svn rm -m "gone" $svnrepo/trunk &&
18 + rm -rf trunk &&
19 + mkdir trunk &&
20 + echo "new" > trunk/FOLLOWME &&
21 + svn import -m "new trunk" trunk $svnrepo/trunk
22 +'
23 +
24 +test_expect_success 'clone repo with git' '
25 + git svn clone -s $svnrepo x &&
26 + test -f x/FOLLOWME &&
27 + test ! -f x/README
28 +'
29 +
30 +test_expect_success 'make sure r2 still has old file' '
31 + cd x &&
32 + test -n "$(git svn find-rev r1)" &&
33 + git reset --hard $(git svn find-rev r1) &&
34 + test -f README &&
35 + test ! -f FOLLOWME &&
36 + test x$(git svn find-rev r2) = x
37 +'
38 +
39 +test_done