From: Nguyễn Thái Ngọc Duy Date: Thu, 20 Aug 2009 13:47:13 +0000 (+0700) Subject: sparse checkout: inhibit empty worktree X-Git-Tag: v1.7.0-rc0~103^2~6 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9e1afb16753d583a696c988d33f45655f81e8f7c;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/t/t1009-read-tree-sparse-checkout.sh b/t/t1009-read-tree-sparse-checkout.sh index 2192f5abc..62246dbf9 100755 --- a/t/t1009-read-tree-sparse-checkout.sh +++ b/t/t1009-read-tree-sparse-checkout.sh @@ -55,20 +55,16 @@ test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse- test -f sub/added ' -cat >expected.swt < .git/info/sparse-checkout && - git read-tree -m -u HEAD && + test_must_fail git read-tree -m -u HEAD && git ls-files --stage > result && test_cmp expected result && git ls-files -t > result && test_cmp expected.swt result && - test ! -f init.t && - test ! -f sub/added + test -f init.t && + test -f sub/added ' cat >expected.swt <skip_sparse_checkout) { + int empty_worktree = 1; for (i = 0;i < o->result.cache_nr;i++) { struct cache_entry *ce = o->result.cache[i]; @@ -512,8 +513,14 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options */ if (ce_skip_worktree(ce)) ce->ce_flags &= ~(CE_UPDATE | CE_REMOVE); + else + empty_worktree = 0; } + if (o->result.cache_nr && empty_worktree) { + ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory"); + goto done; + } } o->src_index = NULL;