Skip to content

Commit a554228

Browse files
committed
Merge branch 'en/sparse-checkout'
The behaviour of "sparse-checkout" in the state "git clone --no-checkout" left was changed accidentally in 2.27, which has been corrected. * en/sparse-checkout: sparse-checkout: avoid staging deletions of all files
2 parents 524caf8 + b5bfc08 commit a554228

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

builtin/sparse-checkout.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ static int update_working_directory(struct pattern_list *pl)
9999
struct lock_file lock_file = LOCK_INIT;
100100
struct repository *r = the_repository;
101101

102+
/* If no branch has been checked out, there are no updates to make. */
103+
if (is_index_unborn(r->index))
104+
return UPDATE_SPARSITY_SUCCESS;
105+
102106
memset(&o, 0, sizeof(o));
103107
o.verbose_update = isatty(2);
104108
o.update = 1;

t/t1091-sparse-checkout-builtin.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,28 @@ test_expect_success 'clone --sparse' '
100100
check_files clone a
101101
'
102102

103+
test_expect_success 'interaction with clone --no-checkout (unborn index)' '
104+
git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout &&
105+
git -C clone_no_checkout sparse-checkout init --cone &&
106+
git -C clone_no_checkout sparse-checkout set folder1 &&
107+
108+
git -C clone_no_checkout sparse-checkout list >actual &&
109+
cat >expect <<-\EOF &&
110+
folder1
111+
EOF
112+
test_cmp expect actual &&
113+
114+
# nothing checked out, expect "No such file or directory"
115+
! ls clone_no_checkout/* >actual &&
116+
test_must_be_empty actual &&
117+
test_path_is_missing clone_no_checkout/.git/index &&
118+
119+
# No branch is checked out until we manually switch to one
120+
git -C clone_no_checkout switch master &&
121+
test_path_is_file clone_no_checkout/.git/index &&
122+
check_files clone_no_checkout a folder1
123+
'
124+
103125
test_expect_success 'set enables config' '
104126
git init empty-config &&
105127
(

0 commit comments

Comments
 (0)