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

[PATCH] rebase: fix fork-point with zero arguments

From
John Keeping <john@keeping.me.uk>
Date
Jan 9, 2014, 19:47 UTC
Message-ID
<65fed28c9346aa98a0d9edcbb0c2b483abc0189f.1389296828.git.john@keeping.me.uk>
In-Reply-To
<20140109160603.GR7102@inner.h.apk.li>

When no arguments are specified, $switch_to is empty so we end up passing the empty string to "git merge-base --fork-point", which causes an error. git-rebase carries on at this point, but in fact we have failed to apply the fork-point operation.

It turns out that the test in t3400 that was meant to test this didn't actually need the fork-point behaviour, so enhance it to make sure that the fork-point is applied correctly. The modified test fails without the change to git-rebase.sh in this patch.

Reported-by: Andreas Krey <a.krey@gmx.de>
Signed-off-by: John Keeping <john@keeping.me.uk>
---
 git-rebase.sh     |  3 ++-
 t/t3400-rebase.sh | 12 ++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index 7185dc8..8a3efa2 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -534,7 +534,8 @@ esac
 
 if test "$fork_point" = t
 then
-	new_upstream=$(git merge-base --fork-point "$upstream_name" "$switch_to")
+	new_upstream=$(git merge-base --fork-point "$upstream_name" \
+			"${switch_to:-HEAD}")
 	if test -n "$new_upstream"
 	then
 		upstream=$new_upstream
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index 998503d..6d94b1f 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -135,11 +135,19 @@ test_expect_success 'fail when upstream arg is missing and not configured' '
 '
 
 test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
+	git checkout -b default-base master &&
 	git checkout -b default topic &&
 	git config branch.default.remote . &&
-	git config branch.default.merge refs/heads/master &&
+	git config branch.default.merge refs/heads/default-base &&
 	git rebase &&
-	git rev-parse --verify master >expect &&
+	git rev-parse --verify default-base >expect &&
+	git rev-parse default~1 >actual &&
+	test_cmp expect actual &&
+	git checkout default-base &&
+	git reset --hard HEAD^ &&
+	git checkout default &&
+	git rebase &&
+	git rev-parse --verify default-base >expect &&
 	git rev-parse default~1 >actual &&
 	test_cmp expect actual
 '
-- 
1.8.5.226.g0d60d77
Previous: Andreas KreyNext: Duy Nguyen
Message 5 of 6 in “[BUG] git symbolic-ref does not recognize @ as the shortcut for HEAD”
  1. Mathieu LemoineJan 9, 2014
  2. [BUG] "git rebase": fatal: Not a valid object name: ''Andreas Krey, Jan 9, 2014
  3. John KeepingJan 9, 2014
  4. Andreas KreyJan 9, 2014
  5. rebase: fix fork-point with zero argumentsJohn Keeping, Jan 9, 2014
  6. Duy NguyenJan 15, 2014

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.