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:
authorJunio C Hamano <gitster@pobox.com>2023-03-20 01:03:10 +0300
committerJunio C Hamano <gitster@pobox.com>2023-03-20 01:03:10 +0300
commit67076b85b8f82c751fe634abb112139d6e32a5f1 (patch)
tree4654b1f98b7aee0bc82bf225a419df880a0b9d40 /builtin/checkout.c
parentb0d2440442e3455887bd0afaa2c630ef9c4e583d (diff)
parentee8a88826af1137f0b192caa39b016032ac96af2 (diff)
Merge branch 'ak/restore-both-incompatible-with-conflicts'
"git restore" supports options like "--ours" that are only meaningful during a conflicted merge, but these options are only meaningful when updating the working tree files. These options are marked to be incompatible when both "--staged" and "--worktree" are in effect. * ak/restore-both-incompatible-with-conflicts: restore: fault --staged --worktree with merge opts
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 21a4335abb..2b3ae6032d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -490,15 +490,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) {
enum add_p_mode patch_mode;