t6042: Add a testcase where undetected rename causes silent file deletion

There are cases where history should merge cleanly, and which current git
does merge cleanly despite not detecting a rename; however the merge
currently nukes files that should not be removed.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Newren 2011-08-11 23:19:37 -06:00 коммит произвёл Junio C Hamano
Родитель 7b4ed5941c
Коммит a0551f212e
1 изменённых файлов: 65 добавлений и 0 удалений

Просмотреть файл

@ -133,4 +133,69 @@ test_expect_failure 'missed conflict if rename not detected' '
test_must_fail git merge -s recursive D^0
'
# Tests for undetected rename/add-source causing a file to erroneously be
# deleted (and for mishandled rename/rename(1to1) causing the same issue).
#
# This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
# same file is renamed on both sides to the same thing; it should trigger
# the 1to2 logic, which it would do if the add-source didn't cause issues
# for git's rename detection):
# Commit A: new file: a
# Commit B: rename a->b
# Commit C: rename a->b, add unrelated a
test_expect_success 'setup undetected rename/add-source causes data loss' '
git rm -rf . &&
git clean -fdqx &&
rm -rf .git &&
git init &&
printf "1\n2\n3\n4\n5\n" >a &&
git add a &&
git commit -m A &&
git tag A &&
git checkout -b B A &&
git mv a b &&
git commit -m B &&
git checkout -b C A &&
git mv a b &&
echo foobar >a &&
git add a &&
git commit -m C
'
test_expect_failure 'detect rename/add-source and preserve all data' '
git checkout B^0 &&
git merge -s recursive C^0 &&
test 2 -eq $(git ls-files -s | wc -l) &&
test 2 -eq $(git ls-files -u | wc -l) &&
test 0 -eq $(git ls-files -o | wc -l) &&
test -f a &&
test -f b &&
test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
'
test_expect_failure 'detect rename/add-source and preserve all data, merge other way' '
git checkout C^0 &&
git merge -s recursive B^0 &&
test 2 -eq $(git ls-files -s | wc -l) &&
test 2 -eq $(git ls-files -u | wc -l) &&
test 0 -eq $(git ls-files -o | wc -l) &&
test -f a &&
test -f b &&
test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
'
test_done