summaryrefslogtreecommitdiff
path: root/t/t1091-sparse-checkout-builtin.sh
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2019-11-21 22:04:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-11-22 07:11:44 (GMT)
commite091228e17e88b1bc16cb50d5c3aff10dc5119d1 (patch)
tree22ed9de6fbd48944e5ffc5547bd01ade3300caca /t/t1091-sparse-checkout-builtin.sh
parente9de487aa36aa75b5c9068c6bd07cfb8bf2ee955 (diff)
downloadgit-e091228e17e88b1bc16cb50d5c3aff10dc5119d1.zip
git-e091228e17e88b1bc16cb50d5c3aff10dc5119d1.tar.gz
git-e091228e17e88b1bc16cb50d5c3aff10dc5119d1.tar.bz2
sparse-checkout: update working directory in-process
The sparse-checkout builtin used 'git read-tree -mu HEAD' to update the skip-worktree bits in the index and to update the working directory. This extra process is overly complex, and prone to failure. It also requires that we write our changes to the sparse-checkout file before trying to update the index. Remove this extra process call by creating a direct call to unpack_trees() in the same way 'git read-tree -mu HEAD' does. In addition, provide an in-memory list of patterns so we can avoid reading from the sparse-checkout file. This allows us to test a proposed change to the file before writing to it. An earlier version of this patch included a bug when the 'set' command failed due to the "Sparse checkout leaves no entry on working directory" error. It would not rollback the index.lock file, so the replay of the old sparse-checkout specification would fail. A test in t1091 now covers that scenario. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t1091-sparse-checkout-builtin.sh')
-rwxr-xr-xt/t1091-sparse-checkout-builtin.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index b88d08d..53aeb59 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -248,4 +248,32 @@ test_expect_success 'cone mode: set with nested folders' '
test_cmp repo/.git/info/sparse-checkout expect
'
+test_expect_success 'revert to old sparse-checkout on bad update' '
+ echo update >repo/deep/deeper2/a &&
+ cp repo/.git/info/sparse-checkout expect &&
+ test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
+ test_i18ngrep "Cannot update sparse checkout" err &&
+ test_cmp repo/.git/info/sparse-checkout expect &&
+ ls repo/deep >dir &&
+ cat >expect <<-EOF &&
+ a
+ deeper1
+ deeper2
+ EOF
+ test_cmp dir expect
+'
+
+test_expect_success 'revert to old sparse-checkout on empty update' '
+ git init empty-test &&
+ (
+ echo >file &&
+ git add file &&
+ git commit -m "test" &&
+ test_must_fail git sparse-checkout set nothing 2>err &&
+ test_i18ngrep "Sparse checkout leaves no entry on working directory" err &&
+ test_i18ngrep ! ".git/index.lock" err &&
+ git sparse-checkout set file
+ )
+'
+
test_done