git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v7 2/5] pull: give the advice for choosing rebase/merge much later

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 14, 2020, 20:26 UTC
Message-ID
<20201214202647.3340193-3-gitster@pobox.com>
In-Reply-To
<20201214202647.3340193-1-gitster@pobox.com>
From: Felipe Contreras <felipe.contreras@gmail.com>

Eventually we want to be omit the advice when we can fast-forward in which case there is no reason to require the user to choose between rebase or merge.

In order to do so, we need to delay giving the advice up to the point where we can check if we can fast-forward or not.

Additionally, config_get_rebase() was probably never its true home.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/pull.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/builtin/pull.c b/builtin/pull.c
index 03e6d53243..ff8e3ce137 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -27,6 +27,8 @@
 #include "commit-reach.h"
 #include "sequencer.h"
 
+static int default_mode;
+
 /**
  * Parses the value of --rebase. If value is a false value, returns
  * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is
@@ -344,20 +346,7 @@ static enum rebase_type config_get_rebase(void)
 	if (!git_config_get_value("pull.rebase", &value))
 		return parse_config_rebase("pull.rebase", value, 1);
 
-	if (opt_verbosity >= 0 && !opt_ff) {
-		advise(_("Pulling without specifying how to reconcile divergent branches is\n"
-			 "discouraged. You can squelch this message by running one of the following\n"
-			 "commands sometime before your next pull:\n"
-			 "\n"
-			 "  git config pull.rebase false  # merge (the default strategy)\n"
-			 "  git config pull.rebase true   # rebase\n"
-			 "  git config pull.ff only       # fast-forward only\n"
-			 "\n"
-			 "You can replace \"git config\" with \"git config --global\" to set a default\n"
-			 "preference for all repositories. You can also pass --rebase, --no-rebase,\n"
-			 "or --ff-only on the command line to override the configured default per\n"
-			 "invocation.\n"));
-	}
+	default_mode = 1;
 
 	return REBASE_FALSE;
 }
@@ -1040,6 +1029,21 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 	if (opt_rebase && merge_heads.nr > 1)
 		die(_("Cannot rebase onto multiple branches."));
 
+	if (default_mode && opt_verbosity >= 0 && !opt_ff) {
+		advise(_("Pulling without specifying how to reconcile divergent branches is\n"
+			 "discouraged. You can squelch this message by running one of the following\n"
+			 "commands sometime before your next pull:\n"
+			 "\n"
+			 "  git config pull.rebase false  # merge (the default strategy)\n"
+			 "  git config pull.rebase true   # rebase\n"
+			 "  git config pull.ff only       # fast-forward only\n"
+			 "\n"
+			 "You can replace \"git config\" with \"git config --global\" to set a default\n"
+			 "preference for all repositories. You can also pass --rebase, --no-rebase,\n"
+			 "or --ff-only on the command line to override the configured default per\n"
+			 "invocation.\n"));
+	}
+
 	if (opt_rebase) {
 		int ret = 0;
 		int ran_ff = 0;
-- 
2.30.0-rc0-186-g20447144ec
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 21 in “making pull advice not to trigger when unneeded”
  1. 0/5 making pull advice not to trigger when unneededJunio C Hamano, Dec 14, 2020
  2. 2/5 pull: give the advice for choosing rebase/merge much laterJunio C Hamano, Dec 14, 2020
  3. 3/5 pull: get rid of unnecessary global variableJunio C Hamano, Dec 14, 2020
  4. Felipe ContrerasDec 14, 2020
  5. Junio C HamanoDec 14, 2020
  6. Felipe ContrerasDec 15, 2020
  7. 4/5 pull: correct condition to trigger non-ff adviceJunio C Hamano, Dec 14, 2020
  8. Felipe ContrerasDec 14, 2020
  9. Junio C HamanoDec 14, 2020
  10. Felipe ContrerasDec 15, 2020
  11. 1/5 pull: refactor fast-forward checkJunio C Hamano, Dec 14, 2020
  12. 5/5 pull: display default warning only when non-ffJunio C Hamano, Dec 14, 2020
  13. Felipe ContrerasDec 14, 2020
  14. Junio C HamanoDec 14, 2020
  15. Felipe ContrerasDec 15, 2020
  16. Felipe ContrerasDec 15, 2020
  17. Junio C HamanoDec 15, 2020
  18. Felipe ContrerasDec 15, 2020
  19. Felipe ContrerasDec 18, 2020
  20. Junio C HamanoDec 23, 2020
  21. Felipe ContrerasDec 23, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.