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

[PATCH] pull: avoid running both merge and rebase

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 27, 2020, 21:51 UTC
Message-ID
<pull.739.git.git.1585345900763.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

When opt_rebase is true, we still first check if we can fast-forward. If the branch is fast-forwardable, then we can avoid the rebase and just use merge to do the fast-forward logic. However, when commit a6d7eb2c7a ("pull: optionally rebase submodules (remote submodule changes only)", 2017-06-23) added the ability to rebase submodules it accidentally caused us to run BOTH a merge and a rebase. Add a flag to avoid doing both.

This was found when a user had both pull.rebase and rebase.autosquash set to true. In such a case, the running of both merge and rebase would cause ORIG_HEAD to be updated twice (and match HEAD at the end instead of the commit before the rebase started), against expectation.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
    pull: avoid running both merge and rebase
    
    Cc: Norbert Kiesel nkiesel@gmail.com [nkiesel@gmail.com], Jeff King 
    peff@peff.net [peff@peff.net]
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-739%2Fnewren%2Favoid-merge-and-rebase-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-739/newren/avoid-merge-and-rebase-v1
Pull-Request: https://github.com/git/git/pull/739
 builtin/pull.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/builtin/pull.c b/builtin/pull.c
index 3e624d1e008..19899b45c1d 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -976,6 +976,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 
 	if (opt_rebase) {
 		int ret = 0;
+		int ran_ff = 0;
 		if ((recurse_submodules == RECURSE_SUBMODULES_ON ||
 		     recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) &&
 		    submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head))
@@ -992,10 +993,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 			if (is_descendant_of(merge_head, list)) {
 				/* we can fast-forward this without invoking rebase */
 				opt_ff = "--ff-only";
+				ran_ff = 1;
 				ret = run_merge();
 			}
 		}
-		ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point);
+		if (!ran_ff)
+			ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point);
 
 		if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON ||
 			     recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND))

base-commit: 274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 of 7 in “pull: avoid running both merge and rebase”
  1. pull: avoid running both merge and rebaseElijah Newren via GitGitGadget, Mar 27, 2020
  2. Junio C HamanoMar 27, 2020
  3. Jeff KingMar 28, 2020
  4. Derrick StoleeMar 28, 2020
  5. Elijah NewrenMar 28, 2020
  6. Elijah NewrenMar 28, 2020
  7. GGG Cc: bug, was Re: [PATCH] pull: avoid running both merge and rebaseJohannes Schindelin, Apr 4, 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.