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

[PATCH] octopus: fallback on empty tree for ancestor

From
ROR. Andrew Ohana <andrew.ohana@gmail.com>
Date
Jun 20, 2013, 00:27 UTC
Message-ID
<1371688034-12145-1-git-send-email-andrew.ohana@gmail.com>
In-Reply-To
<andrew.ohana@gmail.com>
From: "R. Andrew Ohana" <andrew.ohana@gmail.com>

This is preferable to just aborting when no common ancestor is found since it handles merges of intersecting branches.

This is incredibly useful functionality when consolidating multiple repositories (potentially after using filter-branch to fix paths).

See http://stackoverflow.com/questions/10874149.
Signed-off-by: R. Andrew Ohana <andrew.ohana@gmail.com>
---
 git-merge-octopus.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/git-merge-octopus.sh b/git-merge-octopus.sh
index 8643f74..582ae69 100755
--- a/git-merge-octopus.sh
+++ b/git-merge-octopus.sh
@@ -48,6 +48,7 @@ MRC=$(git rev-parse --verify -q $head)
 MRT=$(git write-tree)
 NON_FF_MERGE=0
 OCTOPUS_FAILURE=0
+EMPTY_TREE=$(git hash-object -t tree /dev/null)
 for SHA1 in $remotes
 do
 	case "$OCTOPUS_FAILURE" in
@@ -67,7 +68,9 @@ do
 		eval pretty_name=\${GITHEAD_$SHA1_UP:-$pretty_name}
 	fi
 	common=$(git merge-base --all $SHA1 $MRC) ||
-		die "Unable to find common commit with $pretty_name"
+		# Try with an empty tree if no common ancestor was
+		# found, since it is common to all trees.
+		common=$EMPTY_TREE
 
 	case "$LF$common$LF" in
 	*"$LF$SHA1$LF"*)
-- 
1.8.2.1
Message 1 of 1 in “octopus: fallback on empty tree for ancestor”
  1. octopus: fallback on empty tree for ancestorR. Andrew Ohana, Jun 20, 2013

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.