2009-08-20 15:47:12 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2010-07-31 08:14:25 +02:00
|
|
|
test_description='sparse checkout tests
|
|
|
|
|
2020-11-19 00:44:21 +01:00
|
|
|
* (tag: removed, main) removed
|
2010-07-31 08:14:25 +02:00
|
|
|
| D sub/added
|
|
|
|
* (HEAD, tag: top) modified and added
|
|
|
|
| M init.t
|
|
|
|
| A sub/added
|
|
|
|
* (tag: init) init
|
|
|
|
A init.t
|
|
|
|
'
|
2009-08-20 15:47:12 +02:00
|
|
|
|
|
|
|
. ./test-lib.sh
|
2011-05-25 22:10:41 +02:00
|
|
|
. "$TEST_DIRECTORY"/lib-read-tree.sh
|
2009-08-20 15:47:12 +02:00
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
2018-03-25 21:20:46 +02:00
|
|
|
test_commit init &&
|
|
|
|
echo modified >>init.t &&
|
|
|
|
|
2016-07-16 07:06:25 +02:00
|
|
|
cat >expected <<-EOF &&
|
2018-03-25 21:20:46 +02:00
|
|
|
100644 $(git hash-object init.t) 0 init.t
|
2016-07-16 07:06:25 +02:00
|
|
|
100644 $EMPTY_BLOB 0 sub/added
|
|
|
|
100644 $EMPTY_BLOB 0 sub/addedtoo
|
|
|
|
100644 $EMPTY_BLOB 0 subsub/added
|
2010-07-31 08:14:25 +02:00
|
|
|
EOF
|
|
|
|
cat >expected.swt <<-\EOF &&
|
|
|
|
H init.t
|
|
|
|
H sub/added
|
2011-05-02 14:47:43 +02:00
|
|
|
H sub/addedtoo
|
2010-11-07 19:04:58 +01:00
|
|
|
H subsub/added
|
2010-07-31 08:14:25 +02:00
|
|
|
EOF
|
|
|
|
|
2010-11-07 19:04:58 +01:00
|
|
|
mkdir sub subsub &&
|
2011-05-02 14:47:43 +02:00
|
|
|
touch sub/added sub/addedtoo subsub/added &&
|
|
|
|
git add init.t sub/added sub/addedtoo subsub/added &&
|
2009-08-20 15:47:12 +02:00
|
|
|
git commit -m "modified and added" &&
|
|
|
|
git tag top &&
|
|
|
|
git rm sub/added &&
|
|
|
|
git commit -m removed &&
|
|
|
|
git tag removed &&
|
|
|
|
git checkout top &&
|
2010-07-31 08:14:25 +02:00
|
|
|
git ls-files --stage >result &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test_cmp expected result
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'read-tree without .git/info/sparse-checkout' '
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD &&
|
2010-07-31 08:14:25 +02:00
|
|
|
git ls-files --stage >result &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test_cmp expected result &&
|
2010-07-31 08:14:25 +02:00
|
|
|
git ls-files -t >result &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test_cmp expected.swt result
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
|
2010-10-31 02:46:54 +01:00
|
|
|
echo >.git/info/sparse-checkout &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD &&
|
2010-07-31 08:14:25 +02:00
|
|
|
git ls-files -t >result &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test_cmp expected.swt result &&
|
|
|
|
test -f init.t &&
|
|
|
|
test -f sub/added
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
|
|
|
|
git config core.sparsecheckout true &&
|
2010-07-31 08:14:25 +02:00
|
|
|
echo >.git/info/sparse-checkout &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed --no-sparse-checkout -m -u HEAD &&
|
2010-07-31 08:14:25 +02:00
|
|
|
git ls-files -t >result &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test_cmp expected.swt result &&
|
|
|
|
test -f init.t &&
|
|
|
|
test -f sub/added
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
|
|
|
|
git config core.sparsecheckout true &&
|
2010-07-31 08:14:25 +02:00
|
|
|
echo >.git/info/sparse-checkout &&
|
2020-05-04 20:27:43 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD &&
|
2010-07-31 08:14:25 +02:00
|
|
|
git ls-files --stage >result &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test_cmp expected result &&
|
2010-07-31 08:14:25 +02:00
|
|
|
git ls-files -t >result &&
|
2020-05-04 20:27:43 +02:00
|
|
|
cat >expected.swt <<-\EOF &&
|
|
|
|
S init.t
|
|
|
|
S sub/added
|
|
|
|
S sub/addedtoo
|
|
|
|
S subsub/added
|
|
|
|
EOF
|
2009-08-20 15:47:12 +02:00
|
|
|
test_cmp expected.swt result &&
|
2020-05-04 20:27:43 +02:00
|
|
|
! test -f init.t &&
|
|
|
|
! test -f sub/added
|
2009-08-20 15:47:12 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'match directories with trailing slash' '
|
2010-07-31 08:14:25 +02:00
|
|
|
cat >expected.swt-noinit <<-\EOF &&
|
|
|
|
S init.t
|
|
|
|
H sub/added
|
2011-05-02 14:47:43 +02:00
|
|
|
H sub/addedtoo
|
2010-11-07 19:04:58 +01:00
|
|
|
S subsub/added
|
2010-07-31 08:14:25 +02:00
|
|
|
EOF
|
|
|
|
|
2009-08-20 15:47:12 +02:00
|
|
|
echo sub/ > .git/info/sparse-checkout &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD &&
|
2009-08-20 15:47:12 +02:00
|
|
|
git ls-files -t > result &&
|
2010-07-31 08:14:25 +02:00
|
|
|
test_cmp expected.swt-noinit result &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test ! -f init.t &&
|
|
|
|
test -f sub/added
|
|
|
|
'
|
|
|
|
|
2010-11-26 19:17:46 +01:00
|
|
|
test_expect_success 'match directories without trailing slash' '
|
2011-05-02 14:47:43 +02:00
|
|
|
echo sub >.git/info/sparse-checkout &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD &&
|
2010-07-31 08:14:25 +02:00
|
|
|
git ls-files -t >result &&
|
2010-11-26 19:17:46 +01:00
|
|
|
test_cmp expected.swt-noinit result &&
|
|
|
|
test ! -f init.t &&
|
|
|
|
test -f sub/added
|
|
|
|
'
|
|
|
|
|
2011-05-09 17:43:01 +02:00
|
|
|
test_expect_success 'match directories with negated patterns' '
|
|
|
|
cat >expected.swt-negation <<\EOF &&
|
|
|
|
S init.t
|
|
|
|
S sub/added
|
|
|
|
H sub/addedtoo
|
|
|
|
S subsub/added
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat >.git/info/sparse-checkout <<\EOF &&
|
|
|
|
sub
|
|
|
|
!sub/added
|
|
|
|
EOF
|
|
|
|
git read-tree -m -u HEAD &&
|
|
|
|
git ls-files -t >result &&
|
|
|
|
test_cmp expected.swt-negation result &&
|
|
|
|
test ! -f init.t &&
|
|
|
|
test ! -f sub/added &&
|
|
|
|
test -f sub/addedtoo
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'match directories with negated patterns (2)' '
|
|
|
|
cat >expected.swt-negation2 <<\EOF &&
|
|
|
|
H init.t
|
|
|
|
H sub/added
|
|
|
|
S sub/addedtoo
|
|
|
|
H subsub/added
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat >.git/info/sparse-checkout <<\EOF &&
|
|
|
|
/*
|
|
|
|
!sub
|
|
|
|
sub/added
|
|
|
|
EOF
|
|
|
|
git read-tree -m -u HEAD &&
|
|
|
|
git ls-files -t >result &&
|
|
|
|
test_cmp expected.swt-negation2 result &&
|
|
|
|
test -f init.t &&
|
|
|
|
test -f sub/added &&
|
|
|
|
test ! -f sub/addedtoo
|
|
|
|
'
|
|
|
|
|
2010-11-26 19:17:46 +01:00
|
|
|
test_expect_success 'match directory pattern' '
|
2011-05-02 14:47:43 +02:00
|
|
|
echo "s?b" >.git/info/sparse-checkout &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD &&
|
2010-11-26 19:17:46 +01:00
|
|
|
git ls-files -t >result &&
|
|
|
|
test_cmp expected.swt-noinit result &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test ! -f init.t &&
|
|
|
|
test -f sub/added
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout area changes' '
|
2010-07-31 08:14:25 +02:00
|
|
|
cat >expected.swt-nosub <<-\EOF &&
|
|
|
|
H init.t
|
|
|
|
S sub/added
|
2011-05-02 14:47:43 +02:00
|
|
|
S sub/addedtoo
|
2010-11-07 19:04:58 +01:00
|
|
|
S subsub/added
|
2010-07-31 08:14:25 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
echo init.t >.git/info/sparse-checkout &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD &&
|
2010-07-31 08:14:25 +02:00
|
|
|
git ls-files -t >result &&
|
|
|
|
test_cmp expected.swt-nosub result &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test -f init.t &&
|
|
|
|
test ! -f sub/added
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'read-tree updates worktree, absent case' '
|
2010-07-31 08:14:25 +02:00
|
|
|
echo sub/added >.git/info/sparse-checkout &&
|
2009-08-20 15:47:12 +02:00
|
|
|
git checkout -f top &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD^ &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test ! -f init.t
|
|
|
|
'
|
|
|
|
|
2022-01-14 16:59:39 +01:00
|
|
|
test_expect_success 'read-tree will not throw away dirty changes, non-sparse' '
|
|
|
|
echo "/*" >.git/info/sparse-checkout &&
|
|
|
|
read_tree_u_must_succeed -m -u HEAD &&
|
|
|
|
|
|
|
|
echo dirty >init.t &&
|
|
|
|
read_tree_u_must_fail -m -u HEAD^ &&
|
|
|
|
test_path_is_file init.t &&
|
|
|
|
grep -q dirty init.t
|
|
|
|
'
|
|
|
|
|
unpack-trees: fix accidental loss of user changes
For sparse-checkouts, we don't want unpack-trees to error out on files
that are missing from the worktree, so there has traditionally been
logic to make it skip the verify_uptodate() check for these.
Unfortunately, it was skipping the verify_uptodate() check for files
that were expected to *become* SKIP_WORKTREE. For files that were not
already SKIP_WORKTREE, that can cause us to later delete the file in
apply_sparse_checkout(). Only skip the check for files that were
already SKIP_WORKTREE as well to avoid lightly discarding important
changes users may have made to files.
Note 1: unpack-trees.c is already a bit complex, and the logic around
CE_SKIP_WORKTREE and CE_NEW_SKIP_WORKTREE in that file are no exception.
I also tried just replacing CE_NEW_SKIP_WORKTREE with CE_SKIP_WORKTREE
in the verify_uptodate() check instead of checking for both flags, and
found that it also fixed this bug and passed all the tests. I also
attempted to devise a few testcases that might trip either variant of my
fix and was unable to find any problems. It may be that just checking
CE_SKIP_WORKTREE is a better fix, but I'm not sure. I thought it
was a bit safer to strictly reduce the number of cases where we skip the
up-to-date check rather than just toggling which kind of cases skip it,
and thus went with the current variant of the fix.
Note 2: I also wondered if verify_absent() might have a similar bug, but
despite my attempts to try to devise a testcase that would trigger such
a thing, I couldn't find any problematic testcases. Thus, this patch
makes no attempt to apply similar changes to verify_absent() and
verify_absent_if_directory().
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-14 16:59:40 +01:00
|
|
|
test_expect_success 'read-tree will not throw away dirty changes, sparse' '
|
2022-01-14 16:59:39 +01:00
|
|
|
echo "/*" >.git/info/sparse-checkout &&
|
|
|
|
read_tree_u_must_succeed -m -u HEAD &&
|
|
|
|
|
|
|
|
echo dirty >init.t &&
|
|
|
|
echo sub/added >.git/info/sparse-checkout &&
|
|
|
|
read_tree_u_must_fail -m -u HEAD^ &&
|
|
|
|
test_path_is_file init.t &&
|
|
|
|
grep -q dirty init.t
|
|
|
|
'
|
|
|
|
|
2009-08-20 15:47:12 +02:00
|
|
|
test_expect_success 'read-tree updates worktree, dirty case' '
|
2010-07-31 08:14:25 +02:00
|
|
|
echo sub/added >.git/info/sparse-checkout &&
|
2009-08-20 15:47:12 +02:00
|
|
|
git checkout -f top &&
|
2010-07-31 08:14:25 +02:00
|
|
|
echo dirty >init.t &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD^ &&
|
2009-08-20 15:47:12 +02:00
|
|
|
grep -q dirty init.t &&
|
|
|
|
rm init.t
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'read-tree removes worktree, dirty case' '
|
2010-07-31 08:14:25 +02:00
|
|
|
echo init.t >.git/info/sparse-checkout &&
|
2009-08-20 15:47:12 +02:00
|
|
|
git checkout -f top &&
|
2010-07-31 08:14:25 +02:00
|
|
|
echo dirty >added &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -m -u HEAD^ &&
|
2009-08-20 15:47:12 +02:00
|
|
|
grep -q dirty added
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'read-tree adds to worktree, absent case' '
|
2010-07-31 08:14:25 +02:00
|
|
|
echo init.t >.git/info/sparse-checkout &&
|
2009-08-20 15:47:12 +02:00
|
|
|
git checkout -f removed &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -u -m HEAD^ &&
|
2009-08-20 15:47:12 +02:00
|
|
|
test ! -f sub/added
|
|
|
|
'
|
|
|
|
|
2010-07-31 08:14:29 +02:00
|
|
|
test_expect_success 'read-tree adds to worktree, dirty case' '
|
2010-07-31 08:14:25 +02:00
|
|
|
echo init.t >.git/info/sparse-checkout &&
|
2009-08-20 15:47:12 +02:00
|
|
|
git checkout -f removed &&
|
|
|
|
mkdir sub &&
|
2010-07-31 08:14:25 +02:00
|
|
|
echo dirty >sub/added &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed -u -m HEAD^ &&
|
2009-08-20 15:47:12 +02:00
|
|
|
grep -q dirty sub/added
|
|
|
|
'
|
|
|
|
|
2010-07-31 08:14:26 +02:00
|
|
|
test_expect_success 'index removal and worktree narrowing at the same time' '
|
|
|
|
echo init.t >.git/info/sparse-checkout &&
|
|
|
|
echo sub/added >>.git/info/sparse-checkout &&
|
|
|
|
git checkout -f top &&
|
|
|
|
echo init.t >.git/info/sparse-checkout &&
|
|
|
|
git checkout removed &&
|
|
|
|
git ls-files sub/added >result &&
|
|
|
|
test ! -f sub/added &&
|
2019-11-27 08:51:43 +01:00
|
|
|
test_must_be_empty result
|
2010-07-31 08:14:26 +02:00
|
|
|
'
|
|
|
|
|
2010-07-31 08:14:27 +02:00
|
|
|
test_expect_success 'read-tree --reset removes outside worktree' '
|
|
|
|
echo init.t >.git/info/sparse-checkout &&
|
|
|
|
git checkout -f top &&
|
|
|
|
git reset --hard removed &&
|
|
|
|
git ls-files sub/added >result &&
|
2018-07-27 19:48:11 +02:00
|
|
|
test_must_be_empty result
|
2010-07-31 08:14:27 +02:00
|
|
|
'
|
|
|
|
|
unpack-trees: failure to set SKIP_WORKTREE bits always just a warning
Setting and clearing of the SKIP_WORKTREE bit is not only done when
users run 'sparse-checkout'; other commands such as 'checkout' also run
through unpack_trees() which has logic for handling this special bit.
As such, we need to consider how they handle special cases. A couple
comparison points should help explain the rationale for changing how
unpack_trees() handles these bits:
Ignoring sparse checkouts for a moment, if you are switching
branches and have dirty changes, it is only considered an error that
will prevent the branch switching from being successful if the dirty
file happens to be one of the paths with different contents.
SKIP_WORKTREE has always been considered advisory; for example, if
rebase or merge need or even want to materialize a path as part of
their work, they have always been allowed to do so regardless of the
SKIP_WORKTREE setting. This has been used for unmerged paths, but
it was often used for paths it wasn't needed just because it made
the code simpler. It was a best-effort consideration, and when it
materialized paths contrary to the SKIP_WORKTREE setting, it was
never required to even print a warning message.
In the past if you trying to run e.g. 'git checkout' and:
1) you had a path that was materialized and had some dirty changes
2) the path was listed in $GITDIR/info/sparse-checkout
3) this path did not different between the current and target branches
then despite the comparison points above, the inability to set
SKIP_WORKTREE was treated as a *hard* error that would abort the
checkout operation. This is completely inconsistent with how
SKIP_WORKTREE is handled elsewhere, and rather annoying for users as
leaving the paths materialized in the working copy (with a simple
warning) should present no problem at all.
Downgrade any errors from inability to toggle the SKIP_WORKTREE bit to a
warning and allow the operations to continue.
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-03-27 01:49:00 +01:00
|
|
|
test_expect_success 'print warnings when some worktree updates disabled' '
|
2011-09-22 13:24:22 +02:00
|
|
|
echo sub >.git/info/sparse-checkout &&
|
|
|
|
git checkout -f init &&
|
|
|
|
mkdir sub &&
|
|
|
|
touch sub/added sub/addedtoo &&
|
unpack-trees: failure to set SKIP_WORKTREE bits always just a warning
Setting and clearing of the SKIP_WORKTREE bit is not only done when
users run 'sparse-checkout'; other commands such as 'checkout' also run
through unpack_trees() which has logic for handling this special bit.
As such, we need to consider how they handle special cases. A couple
comparison points should help explain the rationale for changing how
unpack_trees() handles these bits:
Ignoring sparse checkouts for a moment, if you are switching
branches and have dirty changes, it is only considered an error that
will prevent the branch switching from being successful if the dirty
file happens to be one of the paths with different contents.
SKIP_WORKTREE has always been considered advisory; for example, if
rebase or merge need or even want to materialize a path as part of
their work, they have always been allowed to do so regardless of the
SKIP_WORKTREE setting. This has been used for unmerged paths, but
it was often used for paths it wasn't needed just because it made
the code simpler. It was a best-effort consideration, and when it
materialized paths contrary to the SKIP_WORKTREE setting, it was
never required to even print a warning message.
In the past if you trying to run e.g. 'git checkout' and:
1) you had a path that was materialized and had some dirty changes
2) the path was listed in $GITDIR/info/sparse-checkout
3) this path did not different between the current and target branches
then despite the comparison points above, the inability to set
SKIP_WORKTREE was treated as a *hard* error that would abort the
checkout operation. This is completely inconsistent with how
SKIP_WORKTREE is handled elsewhere, and rather annoying for users as
leaving the paths materialized in the working copy (with a simple
warning) should present no problem at all.
Downgrade any errors from inability to toggle the SKIP_WORKTREE bit to a
warning and allow the operations to continue.
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-03-27 01:49:00 +01:00
|
|
|
# Use -q to suppress "Previous HEAD position" and "Head is now at" msgs
|
|
|
|
git checkout -q top 2>actual &&
|
2011-09-22 13:24:22 +02:00
|
|
|
cat >expected <<\EOF &&
|
unpack-trees: failure to set SKIP_WORKTREE bits always just a warning
Setting and clearing of the SKIP_WORKTREE bit is not only done when
users run 'sparse-checkout'; other commands such as 'checkout' also run
through unpack_trees() which has logic for handling this special bit.
As such, we need to consider how they handle special cases. A couple
comparison points should help explain the rationale for changing how
unpack_trees() handles these bits:
Ignoring sparse checkouts for a moment, if you are switching
branches and have dirty changes, it is only considered an error that
will prevent the branch switching from being successful if the dirty
file happens to be one of the paths with different contents.
SKIP_WORKTREE has always been considered advisory; for example, if
rebase or merge need or even want to materialize a path as part of
their work, they have always been allowed to do so regardless of the
SKIP_WORKTREE setting. This has been used for unmerged paths, but
it was often used for paths it wasn't needed just because it made
the code simpler. It was a best-effort consideration, and when it
materialized paths contrary to the SKIP_WORKTREE setting, it was
never required to even print a warning message.
In the past if you trying to run e.g. 'git checkout' and:
1) you had a path that was materialized and had some dirty changes
2) the path was listed in $GITDIR/info/sparse-checkout
3) this path did not different between the current and target branches
then despite the comparison points above, the inability to set
SKIP_WORKTREE was treated as a *hard* error that would abort the
checkout operation. This is completely inconsistent with how
SKIP_WORKTREE is handled elsewhere, and rather annoying for users as
leaving the paths materialized in the working copy (with a simple
warning) should present no problem at all.
Downgrade any errors from inability to toggle the SKIP_WORKTREE bit to a
warning and allow the operations to continue.
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-03-27 01:49:00 +01:00
|
|
|
warning: The following paths were already present and thus not updated despite sparse patterns:
|
2011-09-22 13:24:22 +02:00
|
|
|
sub/added
|
|
|
|
sub/addedtoo
|
unpack-trees: failure to set SKIP_WORKTREE bits always just a warning
Setting and clearing of the SKIP_WORKTREE bit is not only done when
users run 'sparse-checkout'; other commands such as 'checkout' also run
through unpack_trees() which has logic for handling this special bit.
As such, we need to consider how they handle special cases. A couple
comparison points should help explain the rationale for changing how
unpack_trees() handles these bits:
Ignoring sparse checkouts for a moment, if you are switching
branches and have dirty changes, it is only considered an error that
will prevent the branch switching from being successful if the dirty
file happens to be one of the paths with different contents.
SKIP_WORKTREE has always been considered advisory; for example, if
rebase or merge need or even want to materialize a path as part of
their work, they have always been allowed to do so regardless of the
SKIP_WORKTREE setting. This has been used for unmerged paths, but
it was often used for paths it wasn't needed just because it made
the code simpler. It was a best-effort consideration, and when it
materialized paths contrary to the SKIP_WORKTREE setting, it was
never required to even print a warning message.
In the past if you trying to run e.g. 'git checkout' and:
1) you had a path that was materialized and had some dirty changes
2) the path was listed in $GITDIR/info/sparse-checkout
3) this path did not different between the current and target branches
then despite the comparison points above, the inability to set
SKIP_WORKTREE was treated as a *hard* error that would abort the
checkout operation. This is completely inconsistent with how
SKIP_WORKTREE is handled elsewhere, and rather annoying for users as
leaving the paths materialized in the working copy (with a simple
warning) should present no problem at all.
Downgrade any errors from inability to toggle the SKIP_WORKTREE bit to a
warning and allow the operations to continue.
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-03-27 01:49:00 +01:00
|
|
|
|
|
|
|
After fixing the above paths, you may want to run `git sparse-checkout reapply`.
|
2011-09-22 13:24:22 +02:00
|
|
|
EOF
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expected actual
|
2011-09-22 13:24:22 +02:00
|
|
|
'
|
|
|
|
|
2013-04-13 01:12:08 +02:00
|
|
|
test_expect_success 'checkout without --ignore-skip-worktree-bits' '
|
|
|
|
echo "*" >.git/info/sparse-checkout &&
|
|
|
|
git checkout -f top &&
|
|
|
|
test_path_is_file init.t &&
|
|
|
|
echo sub >.git/info/sparse-checkout &&
|
|
|
|
git checkout &&
|
|
|
|
echo modified >> sub/added &&
|
|
|
|
git checkout . &&
|
|
|
|
test_path_is_missing init.t &&
|
|
|
|
git diff --exit-code HEAD
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout with --ignore-skip-worktree-bits' '
|
|
|
|
echo "*" >.git/info/sparse-checkout &&
|
|
|
|
git checkout -f top &&
|
|
|
|
test_path_is_file init.t &&
|
|
|
|
echo sub >.git/info/sparse-checkout &&
|
|
|
|
git checkout &&
|
|
|
|
echo modified >> sub/added &&
|
|
|
|
git checkout --ignore-skip-worktree-bits . &&
|
|
|
|
test_path_is_file init.t &&
|
|
|
|
git diff --exit-code HEAD
|
|
|
|
'
|
|
|
|
|
2009-08-20 15:47:12 +02:00
|
|
|
test_done
|