git-commit-vandalism/t/t4122-apply-symlink-inside.sh
Junio C Hamano 16a4c6176a read-tree -m -u: avoid getting confused by intermediate symlinks.
When switching from a branch with both x86_64/boot/Makefile and
i386/boot/Makefile to another branch that has x86_64/boot as a
symlink pointing at ../i386/boot, the code incorrectly removed
i386/boot/Makefile.

This was because we first removed everything under x86_64/boot
to make room to create a symbolic link x86_64/boot, then removed
x86_64/boot/Makefile which no longer exists but now is pointing
at i386/boot/Makefile, thanks to the symlink we just created.

This fixes it by using the has_symlink_leading_path() function
introduced previously for git-apply in the checkout codepath.
Earlier, "git checkout" was broken in t4122 test due to this
bug, and the test had an extra "git reset --hard" as a
workaround, which is removed because it is not needed anymore.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-05-11 22:33:31 -07:00

57 lines
1012 B
Bash
Executable File

#!/bin/sh
test_description='apply to deeper directory without getting fooled with symlink'
. ./test-lib.sh
lecho () {
for l_
do
echo "$l_"
done
}
test_expect_success setup '
mkdir -p arch/i386/boot arch/x86_64 &&
lecho 1 2 3 4 5 >arch/i386/boot/Makefile &&
ln -s ../i386/boot arch/x86_64/boot &&
git add . &&
test_tick &&
git commit -m initial &&
git branch test &&
rm arch/x86_64/boot &&
mkdir arch/x86_64/boot &&
lecho 2 3 4 5 6 >arch/x86_64/boot/Makefile &&
git add . &&
test_tick &&
git commit -a -m second &&
git format-patch --binary -1 --stdout >test.patch
'
test_expect_success apply '
git checkout test &&
git diff --exit-code test &&
git diff --exit-code --cached test &&
git apply --index test.patch
'
test_expect_success 'check result' '
git diff --exit-code master &&
git diff --exit-code --cached master &&
test_tick &&
git commit -m replay &&
T1=$(git rev-parse "master^{tree}") &&
T2=$(git rev-parse "HEAD^{tree}") &&
test "z$T1" = "z$T2"
'
test_done