Skip to content

Commit e9acbd6

Browse files
committed
Merge branch 'ds/sparse-allow-empty-working-tree'
The sparse-checkout patterns have been forbidden from excluding all paths, leaving an empty working tree, for a long time. This limitation has been lifted. * ds/sparse-allow-empty-working-tree: sparse-checkout: stop blocking empty workdirs
2 parents 95875e0 + ace224a commit e9acbd6

File tree

3 files changed

+13
-41
lines changed

3 files changed

+13
-41
lines changed

t/t1011-read-tree-sparse-checkout.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,19 @@ test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-
7474
test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
7575
git config core.sparsecheckout true &&
7676
echo >.git/info/sparse-checkout &&
77-
read_tree_u_must_fail -m -u HEAD &&
77+
read_tree_u_must_succeed -m -u HEAD &&
7878
git ls-files --stage >result &&
7979
test_cmp expected result &&
8080
git ls-files -t >result &&
81+
cat >expected.swt <<-\EOF &&
82+
S init.t
83+
S sub/added
84+
S sub/addedtoo
85+
S subsub/added
86+
EOF
8187
test_cmp expected.swt result &&
82-
test -f init.t &&
83-
test -f sub/added
88+
! test -f init.t &&
89+
! test -f sub/added
8490
'
8591

8692
test_expect_success 'match directories with trailing slash' '

t/t1091-sparse-checkout-builtin.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ test_expect_success 'set enables config' '
106106
cd empty-config &&
107107
test_commit test file &&
108108
test_path_is_missing .git/config.worktree &&
109-
test_must_fail git sparse-checkout set nothing &&
109+
git sparse-checkout set nothing &&
110110
test_path_is_file .git/config.worktree &&
111-
test_must_fail git config core.sparseCheckout &&
112-
git sparse-checkout set "/*" &&
113111
test_cmp_config true core.sparseCheckout
114112
)
115113
'
@@ -302,8 +300,8 @@ test_expect_success 'revert to old sparse-checkout on empty update' '
302300
echo >file &&
303301
git add file &&
304302
git commit -m "test" &&
305-
test_must_fail git sparse-checkout set nothing 2>err &&
306-
test_i18ngrep "Sparse checkout leaves no entry on working directory" err &&
303+
git sparse-checkout set nothing 2>err &&
304+
test_i18ngrep ! "Sparse checkout leaves no entry on working directory" err &&
307305
test_i18ngrep ! ".git/index.lock" err &&
308306
git sparse-checkout set file
309307
)

unpack-trees.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,8 +1677,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
16771677
}
16781678

16791679
if (!o->skip_sparse_checkout) {
1680-
int empty_worktree = 1;
1681-
16821680
/*
16831681
* Sparse checkout loop #2: set NEW_SKIP_WORKTREE on entries not in loop #1
16841682
* If they will have NEW_SKIP_WORKTREE, also set CE_SKIP_WORKTREE
@@ -1706,19 +1704,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
17061704

17071705
if (apply_sparse_checkout(&o->result, ce, o))
17081706
ret = 1;
1709-
1710-
if (!ce_skip_worktree(ce))
1711-
empty_worktree = 0;
1712-
}
1713-
/*
1714-
* Sparse checkout is meant to narrow down checkout area
1715-
* but it does not make sense to narrow down to empty working
1716-
* tree. This is usually a mistake in sparse checkout rules.
1717-
* Do not allow users to do that.
1718-
*/
1719-
if (o->result.cache_nr && empty_worktree) {
1720-
ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory");
1721-
goto done;
17221707
}
17231708
if (ret == 1) {
17241709
/*
@@ -1779,7 +1764,7 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
17791764
{
17801765
enum update_sparsity_result ret = UPDATE_SPARSITY_SUCCESS;
17811766
struct pattern_list pl;
1782-
int i, empty_worktree;
1767+
int i;
17831768
unsigned old_show_all_errors;
17841769
int free_pattern_list = 0;
17851770

@@ -1810,7 +1795,6 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
18101795

18111796
/* Then loop over entries and update/remove as needed */
18121797
ret = UPDATE_SPARSITY_SUCCESS;
1813-
empty_worktree = 1;
18141798
for (i = 0; i < o->src_index->cache_nr; i++) {
18151799
struct cache_entry *ce = o->src_index->cache[i];
18161800

@@ -1824,28 +1808,12 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
18241808

18251809
if (apply_sparse_checkout(o->src_index, ce, o))
18261810
ret = UPDATE_SPARSITY_WARNINGS;
1827-
1828-
if (!ce_skip_worktree(ce))
1829-
empty_worktree = 0;
1830-
}
1831-
1832-
/*
1833-
* Sparse checkout is meant to narrow down checkout area
1834-
* but it does not make sense to narrow down to empty working
1835-
* tree. This is usually a mistake in sparse checkout rules.
1836-
* Do not allow users to do that.
1837-
*/
1838-
if (o->src_index->cache_nr && empty_worktree) {
1839-
unpack_failed(o, "Sparse checkout leaves no entry on working directory");
1840-
ret = UPDATE_SPARSITY_INDEX_UPDATE_FAILURES;
1841-
goto done;
18421811
}
18431812

18441813
skip_sparse_checkout:
18451814
if (check_updates(o, o->src_index))
18461815
ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES;
18471816

1848-
done:
18491817
display_warning_msgs(o);
18501818
o->show_all_errors = old_show_all_errors;
18511819
if (free_pattern_list)

0 commit comments

Comments
 (0)