git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Derrick Stolee" <derrickstolee@github.com>,
	"Elijah Newren" <newren@gmail.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Martin Ågren" <martin.agren@gmail.com>,
	"Phillip Wood" <phillip.wood123@gmail.com>,
	"Elijah Newren" <newren@gmail.com>,
	"Elijah Newren" <newren@gmail.com>
Subject: [PATCH v4 9/9] rebase: provide better error message for apply options vs. merge config
Date: Sun, 22 Jan 2023 06:12:40 +0000	[thread overview]
Message-ID: <5cb00e5103bd701a90ea3f5b3532fa184b6e6ae9.1674367961.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1466.v4.git.1674367961.gitgitgadget@gmail.com>

From: Elijah Newren <newren@gmail.com>

When config which selects the merge backend (currently,
rebase.autosquash=true or rebase.updateRefs=true) conflicts with other
options on the command line (such as --whitespace=fix), make the error
message specifically call out the config option and specify how to
override that config option on the command line.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/git-rebase.txt           |  2 +-
 builtin/rebase.c                       | 27 ++++++++++++++++++++------
 t/t3422-rebase-incompatible-options.sh | 24 +++++++++++++++++++++++
 3 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 9f794f5bdcc..c357f6c3d5c 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -648,7 +648,7 @@ are incompatible with the following options:
  * --merge
  * --strategy
  * --strategy-option
- * --[no-]autosquash
+ * --autosquash
  * --rebase-merges
  * --interactive
  * --exec
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 2358605b254..dd7e2c788f5 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -122,6 +122,8 @@ struct rebase_options {
 	int reapply_cherry_picks;
 	int fork_point;
 	int update_refs;
+	int config_autosquash;
+	int config_update_refs;
 };
 
 #define REBASE_OPTIONS_INIT {			  	\
@@ -136,6 +138,10 @@ struct rebase_options {
 		.fork_point = -1,			\
 		.reapply_cherry_picks = -1,             \
 		.allow_empty_message = 1,               \
+		.autosquash = -1,                       \
+		.config_autosquash = -1,                \
+		.update_refs = -1,                      \
+		.config_update_refs = -1,               \
 	}
 
 static struct replay_opts get_replay_opts(const struct rebase_options *opts)
@@ -778,7 +784,7 @@ static int rebase_config(const char *var, const char *value, void *data)
 	}
 
 	if (!strcmp(var, "rebase.autosquash")) {
-		opts->autosquash = git_config_bool(var, value);
+		opts->config_autosquash = git_config_bool(var, value);
 		return 0;
 	}
 
@@ -795,7 +801,7 @@ static int rebase_config(const char *var, const char *value, void *data)
 	}
 
 	if (!strcmp(var, "rebase.updaterefs")) {
-		opts->update_refs = git_config_bool(var, value);
+		opts->config_update_refs = git_config_bool(var, value);
 		return 0;
 	}
 
@@ -1393,7 +1399,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
 	    (options.action != ACTION_NONE) ||
 	    (options.exec.nr > 0) ||
-	    options.autosquash) {
+	    (options.autosquash == -1 && options.config_autosquash == 1) ||
+	    options.autosquash == 1) {
 		allow_preemptive_ff = 0;
 	}
 	if (options.committer_date_is_author_date || options.ignore_date)
@@ -1504,20 +1511,28 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			if (strcmp(options.git_am_opts.v[i], "-q"))
 				break;
 
-		if (i >= 0) {
+		if (i >= 0 || options.type == REBASE_APPLY) {
 			if (is_merge(&options))
 				die(_("apply options and merge options "
 					  "cannot be used together"));
+			else if (options.autosquash == -1 && options.config_autosquash == 1)
+				die(_("apply options are incompatible with rebase.autosquash.  Consider adding --no-autosquash"));
+			else if (options.update_refs == -1 && options.config_update_refs == 1)
+				die(_("apply options are incompatible with rebase.updateRefs.  Consider adding --no-update-refs"));
 			else
 				options.type = REBASE_APPLY;
 		}
 	}
 
-	if (options.update_refs)
+	if (options.update_refs == 1)
 		imply_merge(&options, "--update-refs");
+	options.update_refs = (options.update_refs >= 0) ? options.update_refs :
+			     ((options.config_update_refs >= 0) ? options.config_update_refs : 0);
 
-	if (options.autosquash)
+	if (options.autosquash == 1)
 		imply_merge(&options, "--autosquash");
+	options.autosquash = (options.autosquash >= 0) ? options.autosquash :
+			     ((options.config_autosquash >= 0) ? options.config_autosquash : 0);
 
 	if (options.type == REBASE_UNSPECIFIED) {
 		if (!strcmp(options.default_backend, "merge"))
diff --git a/t/t3422-rebase-incompatible-options.sh b/t/t3422-rebase-incompatible-options.sh
index 6a17b571ec7..4711b37a288 100755
--- a/t/t3422-rebase-incompatible-options.sh
+++ b/t/t3422-rebase-incompatible-options.sh
@@ -94,6 +94,30 @@ test_rebase_am_only () {
 		git checkout B^0 &&
 		test_must_fail git rebase $opt --root A
 	"
+
+	test_expect_success "$opt incompatible with rebase.autosquash" "
+		git checkout B^0 &&
+		test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
+		grep -e --no-autosquash err
+	"
+
+	test_expect_success "$opt incompatible with rebase.updateRefs" "
+		git checkout B^0 &&
+		test_must_fail git -c rebase.updateRefs=true rebase $opt A 2>err &&
+		grep -e --no-update-refs err
+	"
+
+	test_expect_success "$opt okay with overridden rebase.autosquash" "
+		test_when_finished \"git reset --hard B^0\" &&
+		git checkout B^0 &&
+		git -c rebase.autosquash=true rebase --no-autosquash $opt A
+	"
+
+	test_expect_success "$opt okay with overridden rebase.updateRefs" "
+		test_when_finished \"git reset --hard B^0\" &&
+		git checkout B^0 &&
+		git -c rebase.updateRefs=true rebase --no-update-refs $opt A
+	"
 }
 
 # Check options which imply --apply
-- 
gitgitgadget

  parent reply	other threads:[~2023-01-22  6:13 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-19  5:36 [PATCH] rebase: mark --update-refs as requiring the merge backend Elijah Newren via GitGitGadget
2023-01-19 21:47 ` Derrick Stolee
2023-01-20  1:54   ` Elijah Newren
2023-01-20 15:27   ` Junio C Hamano
2023-01-20 16:47     ` Elijah Newren
2023-01-20  4:56 ` [PATCH v2 0/2] " Elijah Newren via GitGitGadget
2023-01-20  4:56   ` [PATCH v2 1/2] rebase: remove completely useless -C option Elijah Newren via GitGitGadget
2023-01-20  5:40     ` Eric Sunshine
2023-01-20  6:42       ` Elijah Newren
2023-01-20  9:55     ` Martin Ågren
2023-01-20 15:32       ` Elijah Newren
2023-01-20 12:05     ` Junio C Hamano
2023-01-20 15:31       ` Elijah Newren
2023-01-20 16:15         ` Junio C Hamano
2023-01-21  4:52           ` Elijah Newren
2023-01-22  0:02             ` Junio C Hamano
2023-01-20  4:56   ` [PATCH v2 2/2] rebase: mark --update-refs as requiring the merge backend Elijah Newren via GitGitGadget
2023-01-20 16:46     ` Phillip Wood
2023-01-21  1:34       ` Elijah Newren
2023-01-21  1:55   ` [PATCH v3 0/7] rebase: fix several code/testing/documentation issues around flag incompatibilities Elijah Newren via GitGitGadget
2023-01-21  1:55     ` [PATCH v3 1/7] rebase: mark --update-refs as requiring the merge backend Elijah Newren via GitGitGadget
2023-01-21  1:55     ` [PATCH v3 2/7] rebase: flag --apply and --merge as incompatible Elijah Newren via GitGitGadget
2023-01-21  1:55     ` [PATCH v3 3/7] rebase: remove --allow-empty-message from incompatible opts Elijah Newren via GitGitGadget
2023-01-21 15:09       ` Phillip Wood
2023-01-21  1:55     ` [PATCH v3 4/7] rebase: fix docs about incompatibilities with --root Elijah Newren via GitGitGadget
2023-01-21  1:55     ` [PATCH v3 5/7] rebase: add coverage of other incompatible options Elijah Newren via GitGitGadget
2023-01-21 15:20       ` Phillip Wood
2023-01-21 19:25         ` Phillip Wood
2023-01-22  5:11           ` Elijah Newren
2023-01-21  1:55     ` [PATCH v3 6/7] rebase: clarify the OPT_CMDMODE incompatibilities Elijah Newren via GitGitGadget
2023-01-21  1:55     ` [PATCH v3 7/7] rebase: fix formatting of rebase --reapply-cherry-picks option in docs Elijah Newren via GitGitGadget
2023-01-21 15:21       ` Phillip Wood
2023-01-22  6:12     ` [PATCH v4 0/9] rebase: fix several code/testing/documentation issues around flag incompatibilities Elijah Newren via GitGitGadget
2023-01-22  6:12       ` [PATCH v4 1/9] rebase: mark --update-refs as requiring the merge backend Elijah Newren via GitGitGadget
2023-01-22  6:12       ` [PATCH v4 2/9] rebase: flag --apply and --merge as incompatible Elijah Newren via GitGitGadget
2023-01-22  6:12       ` [PATCH v4 3/9] rebase: remove --allow-empty-message from incompatible opts Elijah Newren via GitGitGadget
2023-01-22  6:12       ` [PATCH v4 4/9] rebase: fix docs about incompatibilities with --root Elijah Newren via GitGitGadget
2023-01-22  6:12       ` [PATCH v4 5/9] rebase: add coverage of other incompatible options Elijah Newren via GitGitGadget
2023-01-23 20:08         ` Phillip Wood
2023-01-24  2:36           ` Elijah Newren
2023-01-24 10:27             ` Phillip Wood
2023-01-24 13:16               ` Phillip Wood
2023-01-24 14:48                 ` Junio C Hamano
2023-01-24 15:41                 ` Elijah Newren
2023-01-24 16:48                   ` Phillip Wood
2023-01-24 17:12                     ` Elijah Newren
2023-01-24 19:21                       ` Phillip Wood
2023-01-22  6:12       ` [PATCH v4 6/9] rebase: clarify the OPT_CMDMODE incompatibilities Elijah Newren via GitGitGadget
2023-01-22  6:12       ` [PATCH v4 7/9] rebase: fix formatting of rebase --reapply-cherry-picks option in docs Elijah Newren via GitGitGadget
2023-01-22  6:12       ` [PATCH v4 8/9] rebase: put rebase_options initialization in single place Elijah Newren via GitGitGadget
2023-01-22  6:12       ` Elijah Newren via GitGitGadget [this message]
2023-01-23 15:56       ` [PATCH v4 0/9] rebase: fix several code/testing/documentation issues around flag incompatibilities Derrick Stolee
2023-01-24  2:05         ` Elijah Newren
2023-01-25  4:03       ` [PATCH v5 00/10] " Elijah Newren via GitGitGadget
2023-01-25  4:03         ` [PATCH v5 01/10] rebase: mark --update-refs as requiring the merge backend Elijah Newren via GitGitGadget
2023-01-25  4:03         ` [PATCH v5 02/10] rebase: flag --apply and --merge as incompatible Elijah Newren via GitGitGadget
2023-01-25  4:03         ` [PATCH v5 03/10] rebase: remove --allow-empty-message from incompatible opts Elijah Newren via GitGitGadget
2023-01-25  4:03         ` [PATCH v5 04/10] rebase: fix docs about incompatibilities with --root Elijah Newren via GitGitGadget
2023-01-25  4:03         ` [PATCH v5 05/10] rebase: fix incompatiblity checks for --[no-]reapply-cherry-picks Elijah Newren via GitGitGadget
2023-01-25 14:14           ` Phillip Wood
2023-01-25  4:03         ` [PATCH v5 06/10] rebase: add coverage of other incompatible options Elijah Newren via GitGitGadget
2023-01-25  4:03         ` [PATCH v5 07/10] rebase: clarify the OPT_CMDMODE incompatibilities Elijah Newren via GitGitGadget
2023-01-25  4:03         ` [PATCH v5 08/10] rebase: fix formatting of rebase --reapply-cherry-picks option in docs Elijah Newren via GitGitGadget
2023-01-25  4:03         ` [PATCH v5 09/10] rebase: put rebase_options initialization in single place Elijah Newren via GitGitGadget
2023-01-25  4:03         ` [PATCH v5 10/10] rebase: provide better error message for apply options vs. merge config Elijah Newren via GitGitGadget
2023-01-25 14:17         ` [PATCH v5 00/10] rebase: fix several code/testing/documentation issues around flag incompatibilities Phillip Wood
2023-01-25 16:39         ` Junio C Hamano
2023-01-25 16:48           ` Elijah Newren
2023-02-02 10:29         ` rebase --merge vs --whitespace=fix, was " Johannes Schindelin
2023-02-02 23:48           ` Elijah Newren

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=5cb00e5103bd701a90ea3f5b3532fa184b6e6ae9.1674367961.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=git@vger.kernel.org \
    --cc=martin.agren@gmail.com \
    --cc=newren@gmail.com \
    --cc=phillip.wood123@gmail.com \
    --cc=sunshine@sunshineco.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).