2009-08-20 15:47:12 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2010-07-31 08:14:25 +02:00
|
|
|
test_description='sparse checkout tests
|
|
|
|
|
|
|
|
* (tag: removed, master) removed
|
|
|
|
| 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 &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_fail -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 &&
|
2009-08-20 15:47:13 +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
|
|
|
|
'
|
|
|
|
|
|
|
|
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
|
|
|
'
|
|
|
|
|
2011-09-22 13:24:22 +02:00
|
|
|
test_expect_success 'print errors when failed to update worktree' '
|
|
|
|
echo sub >.git/info/sparse-checkout &&
|
|
|
|
git checkout -f init &&
|
|
|
|
mkdir sub &&
|
|
|
|
touch sub/added sub/addedtoo &&
|
|
|
|
test_must_fail git checkout top 2>actual &&
|
|
|
|
cat >expected <<\EOF &&
|
|
|
|
error: The following untracked working tree files would be overwritten by checkout:
|
|
|
|
sub/added
|
|
|
|
sub/addedtoo
|
2016-06-25 08:34:04 +02:00
|
|
|
Please move or remove them before you switch branches.
|
2011-10-14 04:03:18 +02:00
|
|
|
Aborting
|
2011-09-22 13:24:22 +02:00
|
|
|
EOF
|
2016-06-17 22:21:08 +02:00
|
|
|
test_i18ncmp 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
|