2006-10-09 07:48:06 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='read-tree -m -u checks working tree files'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
2011-05-25 22:10:41 +02:00
|
|
|
. "$TEST_DIRECTORY"/lib-read-tree.sh
|
2006-10-09 07:48:06 +02:00
|
|
|
|
|
|
|
# two-tree test
|
|
|
|
|
|
|
|
test_expect_success 'two-way setup' '
|
|
|
|
|
2006-12-05 01:00:46 +01:00
|
|
|
mkdir subdir &&
|
2006-10-09 07:48:06 +02:00
|
|
|
echo >file1 file one &&
|
|
|
|
echo >file2 file two &&
|
2006-12-05 01:00:46 +01:00
|
|
|
echo >subdir/file1 file one in subdirectory &&
|
|
|
|
echo >subdir/file2 file two in subdirectory &&
|
|
|
|
git update-index --add file1 file2 subdir/file1 subdir/file2 &&
|
2006-10-09 07:48:06 +02:00
|
|
|
git commit -m initial &&
|
|
|
|
|
|
|
|
git branch side &&
|
|
|
|
git tag -f branch-point &&
|
|
|
|
|
|
|
|
echo file2 is not tracked on the master anymore &&
|
2006-12-05 01:00:46 +01:00
|
|
|
rm -f file2 subdir/file2 &&
|
|
|
|
git update-index --remove file2 subdir/file2 &&
|
|
|
|
git commit -a -m "master removes file2 and subdir/file2"
|
2006-10-09 07:48:06 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'two-way not clobbering' '
|
|
|
|
|
|
|
|
echo >file2 master creates untracked file2 &&
|
2006-12-05 01:00:46 +01:00
|
|
|
echo >subdir/file2 master creates untracked subdir/file2 &&
|
2014-04-28 14:57:35 +02:00
|
|
|
if err=$(read_tree_u_must_succeed -m -u master side 2>&1)
|
2006-10-09 07:48:06 +02:00
|
|
|
then
|
|
|
|
echo should have complained
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo "happy to see $err"
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
2006-12-05 01:00:46 +01:00
|
|
|
echo file2 >.gitignore
|
|
|
|
|
|
|
|
test_expect_success 'two-way with incorrect --exclude-per-directory (1)' '
|
|
|
|
|
2014-04-28 14:57:35 +02:00
|
|
|
if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1)
|
2006-12-05 01:00:46 +01:00
|
|
|
then
|
|
|
|
echo should have complained
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo "happy to see $err"
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'two-way with incorrect --exclude-per-directory (2)' '
|
|
|
|
|
2014-04-28 14:57:35 +02:00
|
|
|
if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1)
|
2006-12-05 01:00:46 +01:00
|
|
|
then
|
|
|
|
echo should have complained
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo "happy to see $err"
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'two-way clobbering a ignored file' '
|
|
|
|
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore master side
|
2006-12-05 01:00:46 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
rm -f .gitignore
|
|
|
|
|
2006-10-09 07:48:06 +02:00
|
|
|
# three-tree test
|
|
|
|
|
2006-12-05 01:00:46 +01:00
|
|
|
test_expect_success 'three-way not complaining on an untracked path in both' '
|
2006-10-09 07:48:06 +02:00
|
|
|
|
2006-12-05 01:00:46 +01:00
|
|
|
rm -f file2 subdir/file2 &&
|
2006-10-09 07:48:06 +02:00
|
|
|
git checkout side &&
|
|
|
|
echo >file3 file three &&
|
2006-12-05 01:00:46 +01:00
|
|
|
echo >subdir/file3 file three &&
|
|
|
|
git update-index --add file3 subdir/file3 &&
|
|
|
|
git commit -a -m "side adds file3 and removes file2" &&
|
2006-10-09 07:48:06 +02:00
|
|
|
|
|
|
|
git checkout master &&
|
|
|
|
echo >file2 file two is untracked on the master side &&
|
2006-12-05 01:00:46 +01:00
|
|
|
echo >subdir/file2 file two is untracked on the master side &&
|
2006-10-09 07:48:06 +02:00
|
|
|
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u branch-point master side
|
2006-10-09 07:48:06 +02:00
|
|
|
'
|
|
|
|
|
2007-02-04 05:49:16 +01:00
|
|
|
test_expect_success 'three-way not clobbering a working tree file' '
|
2006-12-05 01:00:46 +01:00
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
rm -f file2 subdir/file2 file3 subdir/file3 &&
|
|
|
|
git checkout master &&
|
|
|
|
echo >file3 file three created in master, untracked &&
|
|
|
|
echo >subdir/file3 file three created in master, untracked &&
|
2014-04-28 14:57:35 +02:00
|
|
|
if err=$(read_tree_u_must_succeed -m -u branch-point master side 2>&1)
|
2006-12-05 01:00:46 +01:00
|
|
|
then
|
|
|
|
echo should have complained
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo "happy to see $err"
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
|
|
|
echo >.gitignore file3
|
|
|
|
|
|
|
|
test_expect_success 'three-way not complaining on an untracked file' '
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
rm -f file2 subdir/file2 file3 subdir/file3 &&
|
|
|
|
git checkout master &&
|
|
|
|
echo >file3 file three created in master, untracked &&
|
|
|
|
echo >subdir/file3 file three created in master, untracked &&
|
|
|
|
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore branch-point master side
|
2006-12-05 01:00:46 +01:00
|
|
|
'
|
|
|
|
|
2008-03-16 19:42:50 +01:00
|
|
|
test_expect_success '3-way not overwriting local changes (setup)' '
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout -b side-a branch-point &&
|
|
|
|
echo >>file1 "new line to be kept in the merge result" &&
|
|
|
|
git commit -a -m "side-a changes file1" &&
|
|
|
|
git checkout -b side-b branch-point &&
|
|
|
|
echo >>file2 "new line to be kept in the merge result" &&
|
|
|
|
git commit -a -m "side-b changes file2" &&
|
|
|
|
git checkout side-a
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '3-way not overwriting local changes (our side)' '
|
|
|
|
|
|
|
|
# At this point, file1 from side-a should be kept as side-b
|
|
|
|
# did not touch it.
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
|
|
|
|
echo >>file1 "local changes" &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u branch-point side-a side-b &&
|
2008-03-16 19:42:50 +01:00
|
|
|
grep "new line to be kept" file1 &&
|
|
|
|
grep "local changes" file1
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '3-way not overwriting local changes (their side)' '
|
|
|
|
|
|
|
|
# At this point, file2 from side-b should be taken as side-a
|
|
|
|
# did not touch it.
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
|
|
|
|
echo >>file2 "local changes" &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_fail -m -u branch-point side-a side-b &&
|
2008-03-16 19:42:50 +01:00
|
|
|
! grep "new line to be kept" file2 &&
|
|
|
|
grep "local changes" file2
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-06-07 22:53:28 +02:00
|
|
|
test_expect_success 'funny symlink in work tree' '
|
2008-03-19 05:59:39 +01:00
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout -b sym-b side-b &&
|
|
|
|
mkdir -p a &&
|
|
|
|
>a/b &&
|
|
|
|
git add a/b &&
|
|
|
|
git commit -m "side adds a/b" &&
|
|
|
|
|
|
|
|
rm -fr a &&
|
|
|
|
git checkout -b sym-a side-a &&
|
|
|
|
mkdir -p a &&
|
2013-06-07 22:53:28 +02:00
|
|
|
test_ln_s_add ../b a/b &&
|
2008-03-19 05:59:39 +01:00
|
|
|
git commit -m "we add a/b" &&
|
|
|
|
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u sym-a sym-a sym-b
|
2008-03-19 05:59:39 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-06-07 22:53:28 +02:00
|
|
|
test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
|
2008-03-19 05:59:39 +01:00
|
|
|
|
2018-06-15 20:13:39 +02:00
|
|
|
test_when_finished "chmod u+w a 2>/dev/null; rm -fr a b" &&
|
|
|
|
|
2008-03-19 05:59:39 +01:00
|
|
|
rm -fr a b &&
|
|
|
|
git reset --hard &&
|
|
|
|
|
|
|
|
git checkout sym-a &&
|
|
|
|
chmod a-w a &&
|
|
|
|
test_must_fail git read-tree -m -u sym-a sym-a sym-b
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2008-03-18 00:47:18 +01:00
|
|
|
test_expect_success 'D/F setup' '
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
|
|
|
|
git checkout side-a &&
|
|
|
|
rm -f subdir/file2 &&
|
|
|
|
mkdir subdir/file2 &&
|
|
|
|
echo qfwfq >subdir/file2/another &&
|
|
|
|
git add subdir/file2/another &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "side-a changes file2 to directory"
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'D/F' '
|
|
|
|
|
|
|
|
git checkout side-b &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u branch-point side-b side-a &&
|
2008-03-18 00:47:18 +01:00
|
|
|
git ls-files -u >actual &&
|
|
|
|
(
|
2018-07-02 02:23:56 +02:00
|
|
|
a=$(git rev-parse branch-point:subdir/file2) &&
|
|
|
|
b=$(git rev-parse side-a:subdir/file2/another) &&
|
|
|
|
echo "100644 $a 1 subdir/file2" &&
|
|
|
|
echo "100644 $a 2 subdir/file2" &&
|
2008-03-18 00:47:18 +01:00
|
|
|
echo "100644 $b 3 subdir/file2/another"
|
|
|
|
) >expect &&
|
2017-10-06 21:00:06 +02:00
|
|
|
test_cmp expect actual
|
2008-03-18 00:47:18 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'D/F resolve' '
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout side-b &&
|
|
|
|
git merge-resolve branch-point -- side-b side-a
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'D/F recursive' '
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout side-b &&
|
|
|
|
git merge-recursive branch-point -- side-b side-a
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2006-10-09 07:48:06 +02:00
|
|
|
test_done
|