{"thread":{"id":"34223","subject":"[PATCH] octopus: fallback on empty tree for ancestor","startedAt":"2013-06-20T00:27:14Z","lastAt":"2013-06-20T00:27:14Z","messageCount":1,"participants":["R. Andrew Ohana"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"221419","messageId":"1371688034-12145-1-git-send-email-andrew.ohana@gmail.com","threadId":"34223","inReplyTo":"andrew.ohana@gmail.com","subject":"[PATCH] octopus: fallback on empty tree for ancestor","fromName":"R. Andrew Ohana","fromEmail":"andrew.ohana@gmail.com","sentAt":"2013-06-20T00:27:14Z","receivedAt":"2013-06-20T00:27:14Z","isPatch":true,"sender":{"key":"andrew.ohana@gmail.com","avatar":null},"body":"From: \"R. Andrew Ohana\" <andrew.ohana@gmail.com>\n\nThis is preferable to just aborting when no\ncommon ancestor is found since it handles merges\nof intersecting branches.\n\nThis is incredibly useful functionality when\nconsolidating multiple repositories (potentially\nafter using filter-branch to fix paths).\n\nSee http://stackoverflow.com/questions/10874149.\n\nSigned-off-by: R. Andrew Ohana <andrew.ohana@gmail.com>\n---\n git-merge-octopus.sh | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/git-merge-octopus.sh b/git-merge-octopus.sh\nindex 8643f74..582ae69 100755\n--- a/git-merge-octopus.sh\n+++ b/git-merge-octopus.sh\n@@ -48,6 +48,7 @@ MRC=$(git rev-parse --verify -q $head)\n MRT=$(git write-tree)\n NON_FF_MERGE=0\n OCTOPUS_FAILURE=0\n+EMPTY_TREE=$(git hash-object -t tree /dev/null)\n for SHA1 in $remotes\n do\n \tcase \"$OCTOPUS_FAILURE\" in\n@@ -67,7 +68,9 @@ do\n \t\teval pretty_name=\\${GITHEAD_$SHA1_UP:-$pretty_name}\n \tfi\n \tcommon=$(git merge-base --all $SHA1 $MRC) ||\n-\t\tdie \"Unable to find common commit with $pretty_name\"\n+\t\t# Try with an empty tree if no common ancestor was\n+\t\t# found, since it is common to all trees.\n+\t\tcommon=$EMPTY_TREE\n \n \tcase \"$LF$common$LF\" in\n \t*\"$LF$SHA1$LF\"*)\n-- \n1.8.2.1\n"}]}