From: Junio C Hamano <gitster@pobox.com>
To: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, warmsocks@gmail.com, stolee@gmail.com,
Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH] sparse-checkout: avoid staging deletions of all files
Date: Thu, 04 Jun 2020 09:57:51 -0700 [thread overview]
Message-ID: <xmqq4krqrcog.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <pull.801.git.git.1591258657818.gitgitgadget@gmail.com> (Elijah Newren via GitGitGadget's message of "Thu, 04 Jun 2020 08:17:37 +0000")
"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> ... Thus, instead of all the files appearing deleted in `git
> status` being known to git as a special artifact of not yet being on a
> branch, our recording of an empty index made it suddenly look to git as
> though it was definitely on a branch with ALL files staged for deletion!
> A subsequent checkout or switch then had to contend with the fact that
> it wasn't on an initial_checkout but had a bunch of staged deletions.
Nicely analysed and explained.
> Make sure that sparse-checkout changes nothing in the index other than
> the SKIP_WORKTREE bit; in particular, when the index is unborn we do not
> have any branch checked out so there is no sparsification or
> de-sparsification work to do. Simply return from
> update_working_directory() early.
OK, and that would avoid writing out an empty index, leaving the
"is_index_unborn()" still true after we are done. Makes sense.
> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
> sparse-checkout: avoid staging deletions of all files
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-801%2Fnewren%2Fsparse-checkout-and-unborn-index-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-801/newren/sparse-checkout-and-unborn-index-v1
> Pull-Request: https://github.com/git/git/pull/801
>
> builtin/sparse-checkout.c | 4 ++++
> t/t1091-sparse-checkout-builtin.sh | 19 +++++++++++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
> index 95d08824172..595463be68e 100644
> --- a/builtin/sparse-checkout.c
> +++ b/builtin/sparse-checkout.c
> @@ -99,6 +99,10 @@ static int update_working_directory(struct pattern_list *pl)
> struct lock_file lock_file = LOCK_INIT;
> struct repository *r = the_repository;
>
> + /* If no branch has been checked out, there are no updates to make. */
> + if (is_index_unborn(r->index))
> + return UPDATE_SPARSITY_SUCCESS;
> +
> memset(&o, 0, sizeof(o));
> o.verbose_update = isatty(2);
> o.update = 1;
> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
> index 88cdde255cd..bc287e5c1fa 100755
> --- a/t/t1091-sparse-checkout-builtin.sh
> +++ b/t/t1091-sparse-checkout-builtin.sh
> @@ -100,6 +100,25 @@ test_expect_success 'clone --sparse' '
> check_files clone a
> '
>
> +test_expect_success 'interaction with clone --no-checkout (unborn index)' '
> + git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout &&
> + git -C clone_no_checkout sparse-checkout init --cone &&
> + git -C clone_no_checkout sparse-checkout set folder1 &&
> + git -C clone_no_checkout sparse-checkout list >actual &&
> + cat >expect <<-\EOF &&
> + folder1
> + EOF
> + test_cmp expect actual &&
> + ls clone_no_checkout >actual &&
> + test_must_be_empty actual &&
> + test_path_is_missing clone_no_checkout/.git/index &&
> +
> + # No branch is checked out until we manually switch to one
> + git -C clone_no_checkout switch master &&
> + test_path_is_file clone_no_checkout/.git/index &&
> + check_files clone_no_checkout a folder1
> +'
> +
> test_expect_success 'set enables config' '
> git init empty-config &&
> (
>
> base-commit: 20514004ddf1a3528de8933bc32f284e175e1012
next prev parent reply other threads:[~2020-06-04 16:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-04 8:17 [PATCH] sparse-checkout: avoid staging deletions of all files Elijah Newren via GitGitGadget
2020-06-04 14:48 ` Derrick Stolee
2020-06-04 15:05 ` Elijah Newren
2020-06-04 15:23 ` Derrick Stolee
2020-06-04 17:08 ` Junio C Hamano
2020-06-04 17:18 ` Junio C Hamano
2020-06-04 17:21 ` Junio C Hamano
2020-06-04 16:57 ` Junio C Hamano [this message]
2020-06-05 2:41 ` [PATCH v2] " Elijah Newren via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq4krqrcog.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=newren@gmail.com \
--cc=stolee@gmail.com \
--cc=warmsocks@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).