Skip to content

Commit 7f44842

Browse files
jonathantanmygitster
authored andcommitted
sparse-checkout: create leading directory
When creating the sparse-checkout file, Git does not create the leading directory, "$GIT_DIR/info", if it does not exist. This causes problems if the repository does not have that directory. Therefore, ensure that the leading directory is created. This is the only "open" in builtin/sparse-checkout.c that does not have a leading directory check. (The other one in write_patterns_and_update() does.) Note that the test needs to explicitly specify a template when running "git init" because the default template used in the tests has the "info/" directory included. Helped-by: Jose Lopes <[email protected]> Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9d7761 commit 7f44842

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

builtin/sparse-checkout.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,9 @@ static int sparse_checkout_init(int argc, const char **argv)
450450
FILE *fp;
451451

452452
/* assume we are in a fresh repo, but update the sparse-checkout file */
453+
if (safe_create_leading_directories(sparse_filename))
454+
die(_("unable to create leading directories of %s"),
455+
sparse_filename);
453456
fp = xfopen(sparse_filename, "w");
454457
if (!fp)
455458
die(_("failed to open '%s'"), sparse_filename);

t/t1091-sparse-checkout-builtin.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ test_expect_success 'git sparse-checkout init' '
7171
check_files repo a
7272
'
7373

74+
test_expect_success 'git sparse-checkout init in empty repo' '
75+
test_when_finished rm -rf empty-repo blank-template &&
76+
git init --template= empty-repo &&
77+
git -C empty-repo sparse-checkout init
78+
'
79+
7480
test_expect_success 'git sparse-checkout list after init' '
7581
git -C repo sparse-checkout list >actual &&
7682
cat >expect <<-\EOF &&

0 commit comments

Comments
 (0)