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>
This commit is contained in:
parent
d6b38f61c8
commit
9e1afb1675
@ -55,20 +55,16 @@ test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-
|
|||||||
test -f sub/added
|
test -f sub/added
|
||||||
'
|
'
|
||||||
|
|
||||||
cat >expected.swt <<EOF
|
|
||||||
S init.t
|
|
||||||
S sub/added
|
|
||||||
EOF
|
|
||||||
test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
|
test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
|
||||||
git config core.sparsecheckout true &&
|
git config core.sparsecheckout true &&
|
||||||
echo > .git/info/sparse-checkout &&
|
echo > .git/info/sparse-checkout &&
|
||||||
git read-tree -m -u HEAD &&
|
test_must_fail git read-tree -m -u HEAD &&
|
||||||
git ls-files --stage > result &&
|
git ls-files --stage > result &&
|
||||||
test_cmp expected result &&
|
test_cmp expected result &&
|
||||||
git ls-files -t > result &&
|
git ls-files -t > result &&
|
||||||
test_cmp expected.swt result &&
|
test_cmp expected.swt result &&
|
||||||
test ! -f init.t &&
|
test -f init.t &&
|
||||||
test ! -f sub/added
|
test -f sub/added
|
||||||
'
|
'
|
||||||
|
|
||||||
cat >expected.swt <<EOF
|
cat >expected.swt <<EOF
|
||||||
|
@ -498,6 +498,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!o->skip_sparse_checkout) {
|
if (!o->skip_sparse_checkout) {
|
||||||
|
int empty_worktree = 1;
|
||||||
for (i = 0;i < o->result.cache_nr;i++) {
|
for (i = 0;i < o->result.cache_nr;i++) {
|
||||||
struct cache_entry *ce = o->result.cache[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))
|
if (ce_skip_worktree(ce))
|
||||||
ce->ce_flags &= ~(CE_UPDATE | CE_REMOVE);
|
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;
|
o->src_index = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user