Re: [PATCH v2 03/11] clone: add --sparse mode
- From
Elijah Newren <newren@gmail.com>
- Date
- Oct 5, 2019, 19:40 UTC
- Message-ID
- <CABPp-BHaV+XX63Y46b8wHk0rHzdAbfDQDZAQe3pHcA63WerigA@mail.gmail.com>
- In-Reply-To
- <fef41b794a9886664616ce5e5c7902a82a474c2d.1568904188.git.gitgitgadget@gmail.com>
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?
Show 24 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();
> }