'an empty .git/info/sparse-checkout is not the same as a missing one, but the opposite, why?
First core.sparsecheckout is set to true.
And I created an empty .git/info/sparse-checkout file. This causes I'm not able to checkout a new branch recently fetched from remote.
Then I tried to delete the empty .git/info/sparse-checkout file, and now I can checkout.
I understand the fact, and I know I can include /* in .git/info/sparse-checkout to make it work.
I just wonder why? what's the rational behind this? isn't it confusing?
As to me, both an empty sparse-checkout file, and a missing one, are saying: "nothing is specified to go with sparse checkout", therefore git should checkout everything.
I guess what I need is a more convincing explanation of the current choice, not how this is implemented.
Solution 1:[1]
Not really: if the .git/info/sparse-checkout is present, the sparse checkout mechasnism kicks in, and look for files/folder to checkout.
See unpack-trees.c:
if (!o->skip_sparse_checkout) {
if (add_excludes_from_file_to_list(
git_path("info/sparse-checkout"), "", 0, &el, 0) < 0)
If it finds no files/folders to checkout (because .git/info/sparse-checkout is empty), it checks out... nothing.
But if .git/info/sparse-checkout isn't there in the first place, this isn't a sparse checkout at all, and Git would check out everything.
Note that, before Git 2.36 (Q2 2022), "git sparse-checkout init "(man)failed to write into $GIT_DIR/info directory when the repository was created without one, which has been corrected to auto-create it.
See commit 7f44842 (21 Jan 2022) by Jonathan Tan (jhowtan).
(Merged by Junio C Hamano -- gitster -- in commit bb754fe, 09 Feb 2022)
sparse-checkout: create leading directoryHelped-by: Jose Lopes
Signed-off-by: Jonathan Tan
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.cthat does not have a leading directory check.
(The other one inwrite_patterns_and_update()does.)Note that the test needs to explicitly specify a template when running "
git init"(man) because the default template used in the tests has the info/ directory included.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
