[PATCH 1/2] fast-import: Handle directories changing into symlinks
Signed-off-by: Elijah Newren <newren@gmail.com>
---
I hesitated a bit to put the testcase in t9350-fast-export.sh instead of
t9300-fast-import.sh. However, this patch fixes a bug where
fast-export <args> | fast-import
accidentally munges data, and t9300-fast-import.sh has no calls to
fast-export while t9350-fast-export.sh has calls to both fast-export and
fast-import. If I should design a test for t9300-fast-import.sh instead
of (or in addition to) what I have here, let me know.
fast-import.c | 5 +++++
t/t9350-fast-export.sh | 24 ++++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 129a786..064348e 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1528,6 +1528,11 @@ static int tree_content_remove(
for (i = 0; i < t->entry_count; i++) {
e = t->entries[i];
if (e->name->str_len == n && !strncmp(p, e->name->str_dat, n)) {
+ if (slash1 && S_ISLNK(e->versions[1].mode))
+ /* p was already removed by an earlier change
+ * of a parent directory to a symlink.
+ */
+ return 1;
if (!slash1 || !S_ISDIR(e->versions[1].mode))
goto del_entry;
if (!e->tree)
diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
index d43f37c..1ee1461 100755
--- a/t/t9350-fast-export.sh
+++ b/t/t9350-fast-export.sh
@@ -376,4 +376,28 @@ test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
+test_expect_success 'directory becomes symlink' '
+ git init dirtosymlink &&
+ git init result &&
+ (
+ cd dirtosymlink &&
+ mkdir foo &&
+ mkdir bar &&
+ echo hello > foo/world &&
+ echo hello > bar/world &&
+ git add foo/world bar/world &&
+ git commit -q -mone &&
+ git rm -r foo &&
+ ln -s bar foo &&
+ git add foo &&
+ git commit -q -mtwo
+ ) &&
+ (
+ cd dirtosymlink &&
+ git fast-export master -- foo |
+ (cd ../result && git fast-import --quiet)
+ ) &&
+ (cd result && git show master:foo)
+'
+
test_done
--
1.6.6.1