git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Andy Koppe <andy.koppe@gmail.com>
To: git@vger.kernel.org
Cc: pclouds@gmail.com, Andy Koppe <andy.koppe@gmail.com>
Subject: [PATCH] restore: fault --staged --worktree with merge opts
Date: Sat, 18 Feb 2023 16:39:36 +0000	[thread overview]
Message-ID: <20230218163936.980-1-andy.koppe@gmail.com> (raw)

The 'restore' command already rejects the --merge, --conflict, --ours
and --theirs options when combined with --staged, but accepts them when
--worktree is added as well.

Unfortunately that doesn't appear to do anything useful. The --ours and
--theirs options seem to be ignored when both --staged and --worktree
are given, whereas with --merge or --conflict, the command has the same
effect as if the --staged option wasn't present.

So reject those options with '--staged --worktree' as well, using
opts->accept_ref to distinguish restore from checkout.

Add tests for both --staged and '--staged --worktree'.

Signed-off-by: Andy Koppe <andy.koppe@gmail.com>
---

CI run: https://github.com/ak2/git/actions/runs/4210823089

Some more explanation: when finding that 'restore --staged --worktree'
with --ours or --theirs was accepted, I assumed that it would do the
equivalent of 'restore --ours/--theirs <paths> && add --update <paths>'.
As it doesn't do that, I think it's better to raise the same error as
without --worktree.

 builtin/checkout.c |  6 ++----
 t/t2070-restore.sh | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index a5155cf55c..b09322f7c8 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -489,13 +489,11 @@ static int checkout_paths(const struct checkout_opts *opts,
 		die(_("'%s' must be used when '%s' is not specified"),
 		    "--worktree", "--source");
 
-	if (opts->checkout_index && !opts->checkout_worktree &&
-	    opts->writeout_stage)
+	if (!opts->accept_ref && opts->checkout_index && opts->writeout_stage)
 		die(_("'%s' or '%s' cannot be used with %s"),
 		    "--ours", "--theirs", "--staged");
 
-	if (opts->checkout_index && !opts->checkout_worktree &&
-	    opts->merge)
+	if (!opts->accept_ref && opts->checkout_index && opts->merge)
 		die(_("'%s' or '%s' cannot be used with %s"),
 		    "--merge", "--conflict", "--staged");
 
diff --git a/t/t2070-restore.sh b/t/t2070-restore.sh
index 7c43ddf1d9..373dc1657e 100755
--- a/t/t2070-restore.sh
+++ b/t/t2070-restore.sh
@@ -137,4 +137,26 @@ test_expect_success 'restore --staged invalidates cache tree for deletions' '
 	test_must_fail git rev-parse HEAD:new1
 '
 
+test_expect_success 'restore with merge options rejects --staged' '
+	test_must_fail git restore --staged --merge . -- 2>err1 &&
+	test_i18ngrep "cannot be used with" err1 &&
+	test_must_fail git restore --staged --conflict=diff3 . -- 2>err2 &&
+	test_i18ngrep "cannot be used with" err2 &&
+	test_must_fail git restore --staged --ours . -- 2>err3 &&
+	test_i18ngrep "cannot be used with" err3 &&
+	test_must_fail git restore --staged --theirs . -- 2>err4 &&
+	test_i18ngrep "cannot be used with" err4
+'
+
+test_expect_success 'restore with merge options rejects --staged --worktree' '
+	test_must_fail git restore --staged --worktree --merge . -- 2>err1 &&
+	test_i18ngrep "cannot be used with" err1 &&
+	test_must_fail git restore --staged --worktree --conflict=diff3 . -- 2>err2 &&
+	test_i18ngrep "cannot be used with" err2 &&
+	test_must_fail git restore --staged --worktree --ours . -- 2>err3 &&
+	test_i18ngrep "cannot be used with" err3 &&
+	test_must_fail git restore --staged --worktree --theirs . -- 2>err4 &&
+	test_i18ngrep "cannot be used with" err4
+'
+
 test_done
-- 
2.39.0


             reply	other threads:[~2023-02-18 16:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-18 16:39 Andy Koppe [this message]
2023-02-21 18:38 ` [PATCH] restore: fault --staged --worktree with merge opts Junio C Hamano
2023-02-21 22:27   ` Andy Koppe
2023-02-22 23:09     ` Junio C Hamano
2023-02-26 18:43       ` [PATCH v2] " Andy Koppe
2023-02-28  1:02         ` Junio C Hamano

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=20230218163936.980-1-andy.koppe@gmail.com \
    --to=andy.koppe@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@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).