From: Junio C Hamano <gitster@pobox.com>
To: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Derrick Stolee <stolee@gmail.com>,
Lessley Dennington <lessleydennington@gmail.com>,
Victoria Dye <vdye@github.com>, Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH v3 03/10] sparse-checkout: add sanity-checks on initial sparsity state
Date: Mon, 13 Dec 2021 10:11:55 -0800 [thread overview]
Message-ID: <xmqq7dc8e5n8.fsf@gitster.g> (raw)
In-Reply-To: <f3af5edb25d5bed46996a1b826ae0c8306eeb912.1639108573.git.gitgitgadget@gmail.com> (Elijah Newren via GitGitGadget's message of "Fri, 10 Dec 2021 03:56:06 +0000")
"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Elijah Newren <newren@gmail.com>
>
> Most sparse-checkout subcommands (list, add, reapply, disable)
> only make sense when already in a sparse state. Add a quick check
> that will error out early if this is not the case.
>
> Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
> Reviewed-by: Victoria Dye <vdye@github.com>
> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
> builtin/sparse-checkout.c | 12 ++++++++++++
> t/t1091-sparse-checkout-builtin.sh | 10 +++++++++-
> 2 files changed, 21 insertions(+), 1 deletion(-)
I won't complain too much but some looks a bit questionable to die
on. For example, when asked to "please disable" something that is
already disabled, I do not think the user's intention includes "if
already disabled, please die"; rather it is "I want the end result
to be in the disabled state", isn't it?
I think what is common among the ones that I find questionable to
die is that they do not use end-user input from argv. "Please add X
to sparsity patterns" may not make much sense when we are not already
sparse", unlike "Please disable", for example.
Side note. I suspect that it can be argued that we might just
auto-enable sparse state upon the first request to add
something, but I personally feel that is dwimming too much, as
behaviours of git in normal mode and sparse mode are so
different.
So, for the same reason, I think "list" that shows "there is
nothing" without an error, when sparse-checkout is not active, would
also be perfectly defensible, and some people may find that dying a
bit too much in such a situation.
Or does the system work differently between
(A) core_apply_sparse_checkout is true and the sparsity pattern list is
empty, and
(B) sparse-checkout is not in effect at all.
If that is the case, please ignore all of the above.
> diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
> index e252b82136e..e9f644ac362 100644
> --- a/builtin/sparse-checkout.c
> +++ b/builtin/sparse-checkout.c
> @@ -56,6 +56,9 @@ static int sparse_checkout_list(int argc, const char **argv)
> char *sparse_filename;
> int res;
>
> + if (!core_apply_sparse_checkout)
> + die(_("this worktree is not sparse"));
> +
> argc = parse_options(argc, argv, NULL,
> builtin_sparse_checkout_list_options,
> builtin_sparse_checkout_list_usage, 0);
> @@ -671,6 +674,9 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix)
> OPT_END(),
> };
>
> + if (!core_apply_sparse_checkout)
> + die(_("no sparse-checkout to add to"));
> +
> repo_read_index(the_repository);
>
> argc = parse_options(argc, argv, prefix,
> @@ -719,6 +725,9 @@ static int sparse_checkout_reapply(int argc, const char **argv)
> OPT_END(),
> };
>
> + if (!core_apply_sparse_checkout)
> + die(_("must be in a sparse-checkout to reapply sparsity patterns"));
> +
> argc = parse_options(argc, argv, NULL,
> builtin_sparse_checkout_reapply_options,
> builtin_sparse_checkout_reapply_usage, 0);
> @@ -740,6 +749,9 @@ static int sparse_checkout_disable(int argc, const char **argv)
> struct pattern_list pl;
> struct strbuf match_all = STRBUF_INIT;
>
> + if (!core_apply_sparse_checkout)
> + die(_("no active sparse-checkout to disable"));
> +
> argc = parse_options(argc, argv, NULL,
> builtin_sparse_checkout_disable_options,
> builtin_sparse_checkout_disable_usage, 0);
> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
> index 272ba1b566b..90a281bcf64 100755
> --- a/t/t1091-sparse-checkout-builtin.sh
> +++ b/t/t1091-sparse-checkout-builtin.sh
> @@ -41,7 +41,15 @@ test_expect_success 'setup' '
> )
> '
>
> -test_expect_success 'git sparse-checkout list (empty)' '
> +test_expect_success 'git sparse-checkout list (not sparse)' '
> + test_must_fail git -C repo sparse-checkout list >list 2>err &&
> + test_must_be_empty list &&
> + test_i18ngrep "this worktree is not sparse" err
> +'
> +
> +test_expect_success 'git sparse-checkout list (not sparse)' '
> + git -C repo sparse-checkout set &&
> + rm repo/.git/info/sparse-checkout &&
> git -C repo sparse-checkout list >list 2>err &&
> test_must_be_empty list &&
> test_i18ngrep "this worktree is not sparse (sparse-checkout file may not exist)" err
next prev parent reply other threads:[~2021-12-13 18:11 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-04 20:00 [PATCH 0/6] sparse-checkout: make set subsume init Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 1/6] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 2/6] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 3/6] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-04 21:40 ` Victoria Dye
2021-12-07 17:04 ` Elijah Newren
2021-12-07 20:36 ` Lessley Dennington
2021-12-07 16:42 ` Derrick Stolee
2021-12-07 18:18 ` Elijah Newren
2021-12-04 20:00 ` [PATCH 4/6] git-sparse-checkout.txt: update to document that set handles init Elijah Newren via GitGitGadget
2021-12-04 21:48 ` Victoria Dye
2021-12-07 16:45 ` Derrick Stolee
2021-12-07 17:06 ` Elijah Newren
2021-12-07 20:42 ` Lessley Dennington
2021-12-07 21:13 ` Elijah Newren
2021-12-07 22:36 ` Lessley Dennington
2021-12-04 20:00 ` [PATCH 5/6] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 6/6] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget
2021-12-07 16:48 ` [PATCH 0/6] sparse-checkout: make set subsume init Derrick Stolee
2021-12-07 20:20 ` [PATCH v2 00/10] " Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 01/10] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 02/10] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 03/10] sparse-checkout: add sanity-checks on initial sparsity state Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 04/10] sparse-checkout: disallow --no-stdin as an argument to set Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 05/10] sparse-checkout: split out code for tweaking settings config Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 06/10] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 07/10] sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 08/10] git-sparse-checkout.txt: update to document init/set/reapply changes Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 09/10] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-07 20:20 ` [PATCH v2 10/10] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget
2021-12-07 21:05 ` [PATCH v2 00/10] sparse-checkout: make set subsume init Derrick Stolee
2021-12-08 14:16 ` Victoria Dye
2021-12-10 3:56 ` [PATCH v3 " Elijah Newren via GitGitGadget
2021-12-10 3:56 ` [PATCH v3 01/10] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-10 3:56 ` [PATCH v3 02/10] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-10 3:56 ` [PATCH v3 03/10] sparse-checkout: add sanity-checks on initial sparsity state Elijah Newren via GitGitGadget
2021-12-13 18:11 ` Junio C Hamano [this message]
2021-12-14 2:25 ` Elijah Newren
2021-12-10 3:56 ` [PATCH v3 04/10] sparse-checkout: disallow --no-stdin as an argument to set Elijah Newren via GitGitGadget
2021-12-10 3:56 ` [PATCH v3 05/10] sparse-checkout: split out code for tweaking settings config Elijah Newren via GitGitGadget
2021-12-10 3:56 ` [PATCH v3 06/10] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-10 3:56 ` [PATCH v3 07/10] sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} Elijah Newren via GitGitGadget
2021-12-13 18:23 ` Junio C Hamano
2021-12-14 2:39 ` Elijah Newren
2021-12-10 3:56 ` [PATCH v3 08/10] git-sparse-checkout.txt: update to document init/set/reapply changes Elijah Newren via GitGitGadget
2021-12-10 3:56 ` [PATCH v3 09/10] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-10 3:56 ` [PATCH v3 10/10] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget
2021-12-14 4:09 ` [PATCH v4 00/10] sparse-checkout: make set subsume init Elijah Newren via GitGitGadget
2021-12-14 4:09 ` [PATCH v4 01/10] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-14 4:09 ` [PATCH v4 02/10] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-14 4:09 ` [PATCH v4 03/10] sparse-checkout: add sanity-checks on initial sparsity state Elijah Newren via GitGitGadget
2021-12-14 4:09 ` [PATCH v4 04/10] sparse-checkout: disallow --no-stdin as an argument to set Elijah Newren via GitGitGadget
2021-12-14 4:09 ` [PATCH v4 05/10] sparse-checkout: split out code for tweaking settings config Elijah Newren via GitGitGadget
2021-12-14 4:09 ` [PATCH v4 06/10] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-14 4:09 ` [PATCH v4 07/10] sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} Elijah Newren via GitGitGadget
2021-12-23 0:47 ` Jiang Xin
2021-12-23 17:09 ` Elijah Newren
2021-12-23 19:09 ` Junio C Hamano
2021-12-14 4:09 ` [PATCH v4 08/10] git-sparse-checkout.txt: update to document init/set/reapply changes Elijah Newren via GitGitGadget
2021-12-14 4:09 ` [PATCH v4 09/10] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-14 7:38 ` Bagas Sanjaya
2021-12-14 7:48 ` Elijah Newren
2021-12-14 4:09 ` [PATCH v4 10/10] clone: avoid using deprecated `sparse-checkout init` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq7dc8e5n8.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=lessleydennington@gmail.com \
--cc=newren@gmail.com \
--cc=stolee@gmail.com \
--cc=vdye@github.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.
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 NNTP newsgroup(s).