Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Koppe <andy.koppe@gmail.com>2023-02-26 21:43:54 +0300
committerJunio C Hamano <gitster@pobox.com>2023-02-27 20:33:20 +0300
commitee8a88826af1137f0b192caa39b016032ac96af2 (patch)
tree95153ee1300eb2e2c4d039414cb4813a1f68c96f /builtin/checkout.c
parent7556e5d737b917d31ac3729b0f5e2391da7e132a (diff)
restore: fault --staged --worktree with merge opts
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 test for both '--staged' and '--staged --worktree'. Signed-off-by: Andy Koppe <andy.koppe@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r--builtin/checkout.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2a132392fb..25d269e2f8 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -487,15 +487,28 @@ 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)
- die(_("'%s' or '%s' cannot be used with %s"),
- "--ours", "--theirs", "--staged");
-
- if (opts->checkout_index && !opts->checkout_worktree &&
- opts->merge)
- die(_("'%s' or '%s' cannot be used with %s"),
- "--merge", "--conflict", "--staged");
+ /*
+ * Reject --staged option to the restore command when combined with
+ * merge-related options. Use the accept_ref flag to distinguish it
+ * from the checkout command, which does not accept --staged anyway.
+ *
+ * `restore --ours|--theirs --worktree --staged` could mean resolving
+ * conflicted paths to one side in both the worktree and the index,
+ * but does not currently.
+ *
+ * `restore --merge|--conflict=<style>` already recreates conflicts
+ * in both the worktree and the index, so adding --staged would be
+ * meaningless.
+ */
+ if (!opts->accept_ref && opts->checkout_index) {
+ if (opts->writeout_stage)
+ die(_("'%s' or '%s' cannot be used with %s"),
+ "--ours", "--theirs", "--staged");
+
+ if (opts->merge)
+ die(_("'%s' or '%s' cannot be used with %s"),
+ "--merge", "--conflict", "--staged");
+ }
if (opts->patch_mode) {
const char *patch_mode;