@matheusbsbs / matheus-bagliano / commits / 9e1afb1675
Fork 0

sparse checkout: inhibit empty worktree

The way sparse checkout works, users may empty their worktree completely, because of non-matching sparse-checkout spec, or empty spec. I believe this is not desired. This patch makes Git refuse to produce such worktree. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 20, 2009 at 20:47 UTC 9e1afb16753d583a696c988d33f45655f81e8f7c
2 files changed +10 -7
t/t1009-read-tree-sparse-checkout.sh
+3 -7
@@ -55,20 +55,16 @@ test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-
55 test -f sub/added
56 '
57
58 -cat >expected.swt <<EOF
59 -S init.t
60 -S sub/added
61 -EOF
58 test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
59 git config core.sparsecheckout true &&
60 echo > .git/info/sparse-checkout &&
65 - git read-tree -m -u HEAD &&
61 + test_must_fail git read-tree -m -u HEAD &&
62 git ls-files --stage > result &&
63 test_cmp expected result &&
64 git ls-files -t > result &&
65 test_cmp expected.swt result &&
70 - test ! -f init.t &&
71 - test ! -f sub/added
66 + test -f init.t &&
67 + test -f sub/added
68 '
69
70 cat >expected.swt <<EOF
unpack-trees.c
+7
@@ -498,6 +498,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
498 }
499
500 if (!o->skip_sparse_checkout) {
501 + int empty_worktree = 1;
502 for (i = 0;i < o->result.cache_nr;i++) {
503 struct cache_entry *ce = o->result.cache[i];
504
@@ -512,8 +513,14 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
513 */
514 if (ce_skip_worktree(ce))
515 ce->ce_flags &= ~(CE_UPDATE | CE_REMOVE);
516 + else
517 + empty_worktree = 0;
518
519 }
520 + if (o->result.cache_nr && empty_worktree) {
521 + ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory");
522 + goto done;
523 + }
524 }
525
526 o->src_index = NULL;