2006-10-09 05:48:06 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='read-tree -m -u checks working tree files'
|
|
|
|
|
2020-11-18 23:44:21 +00:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-18 23:44:19 +00:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2006-10-09 05:48:06 +00:00
|
|
|
. ./test-lib.sh
|
2011-05-25 20:10:41 +00:00
|
|
|
. "$TEST_DIRECTORY"/lib-read-tree.sh
|
2006-10-09 05:48:06 +00:00
|
|
|
|
|
|
|
# two-tree test
|
|
|
|
|
|
|
|
test_expect_success 'two-way setup' '
|
|
|
|
|
2006-12-05 00:00:46 +00:00
|
|
|
mkdir subdir &&
|
2006-10-09 05:48:06 +00:00
|
|
|
echo >file1 file one &&
|
|
|
|
echo >file2 file two &&
|
2006-12-05 00:00:46 +00: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 05:48:06 +00:00
|
|
|
git commit -m initial &&
|
|
|
|
|
|
|
|
git branch side &&
|
|
|
|
git tag -f branch-point &&
|
|
|
|
|
2020-11-18 23:44:21 +00:00
|
|
|
echo file2 is not tracked on the main branch anymore &&
|
2006-12-05 00:00:46 +00:00
|
|
|
rm -f file2 subdir/file2 &&
|
|
|
|
git update-index --remove file2 subdir/file2 &&
|
2020-11-18 23:44:21 +00:00
|
|
|
git commit -a -m "main removes file2 and subdir/file2"
|
2006-10-09 05:48:06 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'two-way not clobbering' '
|
|
|
|
|
2020-11-18 23:44:21 +00:00
|
|
|
echo >file2 main creates untracked file2 &&
|
|
|
|
echo >subdir/file2 main creates untracked subdir/file2 &&
|
|
|
|
if err=$(read_tree_u_must_succeed -m -u main side 2>&1)
|
2006-10-09 05:48:06 +00:00
|
|
|
then
|
|
|
|
echo should have complained
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo "happy to see $err"
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
2006-12-05 00:00:46 +00:00
|
|
|
echo file2 >.gitignore
|
|
|
|
|
|
|
|
test_expect_success 'two-way with incorrect --exclude-per-directory (1)' '
|
|
|
|
|
2020-11-18 23:44:21 +00:00
|
|
|
if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore main side 2>&1)
|
2006-12-05 00:00:46 +00: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)' '
|
|
|
|
|
2020-11-18 23:44:21 +00:00
|
|
|
if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore main side 2>&1)
|
2006-12-05 00:00:46 +00:00
|
|
|
then
|
|
|
|
echo should have complained
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo "happy to see $err"
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'two-way clobbering a ignored file' '
|
|
|
|
|
2020-11-18 23:44:21 +00:00
|
|
|
read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore main side
|
2006-12-05 00:00:46 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
rm -f .gitignore
|
|
|
|
|
2006-10-09 05:48:06 +00:00
|
|
|
# three-tree test
|
|
|
|
|
2006-12-05 00:00:46 +00:00
|
|
|
test_expect_success 'three-way not complaining on an untracked path in both' '
|
2006-10-09 05:48:06 +00:00
|
|
|
|
2006-12-05 00:00:46 +00:00
|
|
|
rm -f file2 subdir/file2 &&
|
2006-10-09 05:48:06 +00:00
|
|
|
git checkout side &&
|
|
|
|
echo >file3 file three &&
|
2006-12-05 00:00:46 +00: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 05:48:06 +00:00
|
|
|
|
2020-11-18 23:44:21 +00:00
|
|
|
git checkout main &&
|
|
|
|
echo >file2 file two is untracked on the main side &&
|
|
|
|
echo >subdir/file2 file two is untracked on the main side &&
|
2006-10-09 05:48:06 +00:00
|
|
|
|
2020-11-18 23:44:21 +00:00
|
|
|
read_tree_u_must_succeed -m -u branch-point main side
|
2006-10-09 05:48:06 +00:00
|
|
|
'
|
|
|
|
|
2007-02-04 04:49:16 +00:00
|
|
|
test_expect_success 'three-way not clobbering a working tree file' '
|
2006-12-05 00:00:46 +00:00
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
rm -f file2 subdir/file2 file3 subdir/file3 &&
|
2020-11-18 23:44:21 +00:00
|
|
|
git checkout main &&
|
|
|
|
echo >file3 file three created in main, untracked &&
|
|
|
|
echo >subdir/file3 file three created in main, untracked &&
|
|
|
|
if err=$(read_tree_u_must_succeed -m -u branch-point main side 2>&1)
|
2006-12-05 00:00:46 +00: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 &&
|
2020-11-18 23:44:21 +00:00
|
|
|
git checkout main &&
|
|
|
|
echo >file3 file three created in main, untracked &&
|
|
|
|
echo >subdir/file3 file three created in main, untracked &&
|
2006-12-05 00:00:46 +00:00
|
|
|
|
2020-11-18 23:44:21 +00:00
|
|
|
read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore branch-point main side
|
2006-12-05 00:00:46 +00:00
|
|
|
'
|
|
|
|
|
2008-03-16 18:42:50 +00: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 20:10:41 +00:00
|
|
|
read_tree_u_must_succeed -m -u branch-point side-a side-b &&
|
2008-03-16 18:42:50 +00: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 20:10:41 +00:00
|
|
|
read_tree_u_must_fail -m -u branch-point side-a side-b &&
|
2008-03-16 18:42:50 +00:00
|
|
|
! grep "new line to be kept" file2 &&
|
|
|
|
grep "local changes" file2
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-06-07 20:53:28 +00:00
|
|
|
test_expect_success 'funny symlink in work tree' '
|
2008-03-19 04:59:39 +00: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 20:53:28 +00:00
|
|
|
test_ln_s_add ../b a/b &&
|
2008-03-19 04:59:39 +00:00
|
|
|
git commit -m "we add a/b" &&
|
|
|
|
|
2011-05-25 20:10:41 +00:00
|
|
|
read_tree_u_must_succeed -m -u sym-a sym-a sym-b
|
2008-03-19 04:59:39 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-06-07 20:53:28 +00:00
|
|
|
test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
|
2008-03-19 04:59:39 +00:00
|
|
|
|
2018-06-15 18:13:39 +00:00
|
|
|
test_when_finished "chmod u+w a 2>/dev/null; rm -fr a b" &&
|
|
|
|
|
2008-03-19 04:59:39 +00: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-17 23:47:18 +00: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 20:10:41 +00:00
|
|
|
read_tree_u_must_succeed -m -u branch-point side-b side-a &&
|
2008-03-17 23:47:18 +00:00
|
|
|
git ls-files -u >actual &&
|
|
|
|
(
|
2018-07-02 00:23:56 +00: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-17 23:47:18 +00:00
|
|
|
echo "100644 $b 3 subdir/file2/another"
|
|
|
|
) >expect &&
|
2017-10-06 19:00:06 +00:00
|
|
|
test_cmp expect actual
|
2008-03-17 23:47:18 +00: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 05:48:06 +00:00
|
|
|
test_done
|