Re: [PATCH v2 03/11] clone: add --sparse mode
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Oct 7, 2019, 13:56 UTC
- Message-ID
- <c57c71d3-ddd6-464d-a442-713707ee94f6@gmail.com>
- In-Reply-To
- <CABPp-BHaV+XX63Y46b8wHk0rHzdAbfDQDZAQe3pHcA63WerigA@mail.gmail.com>
On 10/5/2019 3:40 PM, Elijah Newren wrote:
Show 14 quoted lines
> On Thu, Sep 19, 2019 at 3:06 PM Derrick Stolee via GitGitGadget > <gitgitgadget@gmail.com> wrote: > >> During the 'git sparse-checkout init' call, we must first look >> to see if HEAD is valid, or else we will fail while trying to >> update the working directory. The first checkout will actually >> update the working directory correctly. > > This is new since the RFC series, but I'm not sure I understand. Is > the issue you're fixing here that a 'git init somerepo' would hit this > codepath and print funny errors because HEAD doesn't exist yet and > thus the whole `git read-tree -mu HEAD` stuff can't work? Or that > when the remote has HEAD pointing at a bad commit that you get error > messages different than expected?
At the point where `git clone --sparse` calls `git sparse-checkout init`, there is no HEAD. We need to initialize the sparse-checkout before the clone operation populates the working directory and creates the HEAD ref. For that reason, `git read-tree -mu HEAD` wouldn't work. But that's fine, since there is nothing to do. The index update will happen later.
Show 25 quoted lines
>
>> diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
>> index 895479970d..656e6ebdd5 100644
>> --- a/builtin/sparse-checkout.c
>> +++ b/builtin/sparse-checkout.c
>> @@ -99,6 +99,7 @@ static int sparse_checkout_init(int argc, const char **argv)
>> char *sparse_filename;
>> FILE *fp;
>> int res;
>> + struct object_id oid;
>>
>> if (sc_enable_config())
>> return 1;
>> @@ -120,6 +121,11 @@ static int sparse_checkout_init(int argc, const char **argv)
>> fprintf(fp, "/*\n!/*/\n");
>> fclose(fp);
>>
>> + if (get_oid("HEAD", &oid)) {
>> + /* assume we are in a fresh repo */
>> + return 0;
>> + }
>> +
>> reset_dir:
>> return update_working_directory();
>> }