mirror of
https://github.com/git/git.git
synced 2026-01-10 10:13:33 +00:00
On Windows, a file cannot be removed unless all file handles to it have been released. Hence it is particularly important to close handles when spawning children (which would probably not even know that they hold on to those handles). The example chosen for this test is a custom merge driver that indeed has no idea that it blocks the deletion of index.lock. The full use case is a daemon that lives on after the merge, with subsequent invocations handing off to the daemon, thereby avoiding hefty start-up costs. We simulate this behavior by simply sleeping one second. Note that the test only fails on Windows, due to the file locking issue. Since we have no way to say "expect failure with MINGW, success otherwise", we simply skip this test on Windows for now. Signed-off-by: Ben Wijen <ben@wijen.net> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
198 lines
4.0 KiB
Bash
Executable File
198 lines
4.0 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2007 Junio C Hamano
|
|
#
|
|
|
|
test_description='per path merge controlled by merge attribute'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success setup '
|
|
|
|
for f in text binary union
|
|
do
|
|
echo Initial >$f && git add $f || return 1
|
|
done &&
|
|
test_tick &&
|
|
git commit -m Initial &&
|
|
|
|
git branch side &&
|
|
for f in text binary union
|
|
do
|
|
echo Master >>$f && git add $f || return 1
|
|
done &&
|
|
test_tick &&
|
|
git commit -m Master &&
|
|
|
|
git checkout side &&
|
|
for f in text binary union
|
|
do
|
|
echo Side >>$f && git add $f || return 1
|
|
done &&
|
|
test_tick &&
|
|
git commit -m Side &&
|
|
|
|
git tag anchor
|
|
'
|
|
|
|
test_expect_success merge '
|
|
|
|
{
|
|
echo "binary -merge"
|
|
echo "union merge=union"
|
|
} >.gitattributes &&
|
|
|
|
if git merge master
|
|
then
|
|
echo Gaah, should have conflicted
|
|
false
|
|
else
|
|
echo Ok, conflicted.
|
|
fi
|
|
'
|
|
|
|
test_expect_success 'check merge result in index' '
|
|
|
|
git ls-files -u | grep binary &&
|
|
git ls-files -u | grep text &&
|
|
! (git ls-files -u | grep union)
|
|
|
|
'
|
|
|
|
test_expect_success 'check merge result in working tree' '
|
|
|
|
git cat-file -p HEAD:binary >binary-orig &&
|
|
grep "<<<<<<<" text &&
|
|
cmp binary-orig binary &&
|
|
! grep "<<<<<<<" union &&
|
|
grep Master union &&
|
|
grep Side union
|
|
|
|
'
|
|
|
|
test_expect_success 'retry the merge with longer context' '
|
|
echo text conflict-marker-size=32 >>.gitattributes &&
|
|
git checkout -m text &&
|
|
sed -ne "/^\([<=>]\)\1\1\1*/{
|
|
s/ .*$//
|
|
p
|
|
}" >actual text &&
|
|
grep ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" actual &&
|
|
grep "================================" actual &&
|
|
grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
|
|
'
|
|
|
|
cat >./custom-merge <<\EOF
|
|
#!/bin/sh
|
|
|
|
orig="$1" ours="$2" theirs="$3" exit="$4" path=$5
|
|
(
|
|
echo "orig is $orig"
|
|
echo "ours is $ours"
|
|
echo "theirs is $theirs"
|
|
echo "path is $path"
|
|
echo "=== orig ==="
|
|
cat "$orig"
|
|
echo "=== ours ==="
|
|
cat "$ours"
|
|
echo "=== theirs ==="
|
|
cat "$theirs"
|
|
) >"$ours+"
|
|
cat "$ours+" >"$ours"
|
|
rm -f "$ours+"
|
|
exit "$exit"
|
|
EOF
|
|
chmod +x ./custom-merge
|
|
|
|
test_expect_success 'custom merge backend' '
|
|
|
|
echo "* merge=union" >.gitattributes &&
|
|
echo "text merge=custom" >>.gitattributes &&
|
|
|
|
git reset --hard anchor &&
|
|
git config --replace-all \
|
|
merge.custom.driver "./custom-merge %O %A %B 0 %P" &&
|
|
git config --replace-all \
|
|
merge.custom.name "custom merge driver for testing" &&
|
|
|
|
git merge master &&
|
|
|
|
cmp binary union &&
|
|
sed -e 1,3d text >check-1 &&
|
|
o=$(git unpack-file master^:text) &&
|
|
a=$(git unpack-file side^:text) &&
|
|
b=$(git unpack-file master:text) &&
|
|
sh -c "./custom-merge $o $a $b 0 'text'" &&
|
|
sed -e 1,3d $a >check-2 &&
|
|
cmp check-1 check-2 &&
|
|
rm -f $o $a $b
|
|
'
|
|
|
|
test_expect_success 'custom merge backend' '
|
|
|
|
git reset --hard anchor &&
|
|
git config --replace-all \
|
|
merge.custom.driver "./custom-merge %O %A %B 1 %P" &&
|
|
git config --replace-all \
|
|
merge.custom.name "custom merge driver for testing" &&
|
|
|
|
if git merge master
|
|
then
|
|
echo "Eh? should have conflicted"
|
|
false
|
|
else
|
|
echo "Ok, conflicted"
|
|
fi &&
|
|
|
|
cmp binary union &&
|
|
sed -e 1,3d text >check-1 &&
|
|
o=$(git unpack-file master^:text) &&
|
|
a=$(git unpack-file anchor:text) &&
|
|
b=$(git unpack-file master:text) &&
|
|
sh -c "./custom-merge $o $a $b 0 'text'" &&
|
|
sed -e 1,3d $a >check-2 &&
|
|
cmp check-1 check-2 &&
|
|
sed -e 1,3d -e 4q $a >check-3 &&
|
|
echo "path is text" >expect &&
|
|
cmp expect check-3 &&
|
|
rm -f $o $a $b
|
|
'
|
|
|
|
test_expect_success 'up-to-date merge without common ancestor' '
|
|
test_create_repo repo1 &&
|
|
test_create_repo repo2 &&
|
|
test_tick &&
|
|
(
|
|
cd repo1 &&
|
|
>a &&
|
|
git add a &&
|
|
git commit -m initial
|
|
) &&
|
|
test_tick &&
|
|
(
|
|
cd repo2 &&
|
|
git commit --allow-empty -m initial
|
|
) &&
|
|
test_tick &&
|
|
(
|
|
cd repo1 &&
|
|
git fetch ../repo2 master &&
|
|
git merge --allow-unrelated-histories FETCH_HEAD
|
|
)
|
|
'
|
|
|
|
test_expect_success !MINGW 'custom merge does not lock index' '
|
|
git reset --hard anchor &&
|
|
write_script sleep-one-second.sh <<-\EOF &&
|
|
sleep 1 &
|
|
EOF
|
|
|
|
test_write_lines >.gitattributes \
|
|
"* merge=ours" "text merge=sleep-one-second" &&
|
|
test_config merge.ours.driver true &&
|
|
test_config merge.sleep-one-second.driver ./sleep-one-second.sh &&
|
|
git merge master
|
|
'
|
|
|
|
test_done
|