{"thread":{"id":"1580","subject":"[PATCH] Infamous 'octopus merge'","startedAt":"2005-08-19T01:05:05Z","lastAt":"2005-08-19T01:05:05Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"7536","messageId":"7v4q9meny6.fsf@assigned-by-dhcp.cox.net","threadId":"1580","inReplyTo":null,"subject":"[PATCH] Infamous 'octopus merge'","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-19T01:05:05Z","receivedAt":"2005-08-19T01:05:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This script uses the list of heads and their origin multi-head \"git\nfetch\" left in the $GIT_DIR/FETCH_HEAD file, and makes an octopus\nmerge on top of the current HEAD using them.\n\nThe implementation tries to be strict for the sake of safety.  It\ninsists that your working tree is clean (no local changes) and matches\nthe HEAD, and when any of the merged heads does not automerge, the\nwhole process is aborted and tries to rewind your working tree is to\nthe original state.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n Makefile           |    1 +\n git-octopus-script |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 65 insertions(+), 0 deletions(-)\n create mode 100755 git-octopus-script\n\nbad69944391b17bf5d4060b19e24013807409b28\ndiff --git a/Makefile b/Makefile\n--- a/Makefile\n+++ b/Makefile\n@@ -72,6 +72,7 @@ SCRIPTS += git-count-objects-script\n # SCRIPTS += git-send-email-script\n SCRIPTS += git-revert-script\n SCRIPTS += git-show-branches-script\n+SCRIPTS += git-octopus-script\n \n PROG=   git-update-cache git-diff-files git-init-db git-write-tree \\\n \tgit-read-tree git-commit-tree git-cat-file git-fsck-cache \\\ndiff --git a/git-octopus-script b/git-octopus-script\nnew file mode 100755\n--- /dev/null\n+++ b/git-octopus-script\n@@ -0,0 +1,64 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2005 Junio C Hamano\n+#\n+# Resolve two or more trees recorded in $GIT_DIR/FETCH_HEAD.\n+#\n+. git-sh-setup-script || die \"Not a git archive\"\n+\n+usage () {\n+    die \"usage: git octopus\"\n+}\n+\n+# Sanity check the heads early.\n+while read SHA1 REPO\n+do\n+\ttest $(git-cat-file -t $SHA1) = \"commit\" ||\n+\t\tdie \"$REPO given to octopus is not a commit\"\n+done <\"$GIT_DIR/FETCH_HEAD\"\n+\n+head=$(git-rev-parse --verify HEAD) || exit\n+\n+git-update-cache --refresh ||\n+\tdie \"Your working tree is dirty.\"\n+test \"$(git-diff-cache --cached \"$head\")\" = \"\" ||\n+\tdie \"Your working tree does not match HEAD.\"\n+\n+# MRC is the current \"merge reference commit\"\n+# MRT is the current \"merge result tree\"\n+\n+MRC=$head MRT=$head MSG='Octopus merge of the following: ' PARENT=\"-p $head\"\n+while read SHA1 REPO\n+do\n+\tcommon=$(git-merge-base $MRC $SHA1) ||\n+\t\tdie \"Unable to find common commit between $SHA1 and $MRC\"\n+\n+\tgit-read-tree -u -m $common $MRT $SHA1 || exit\n+\tnext=$(git-write-tree 2>/dev/null)\n+\tif test $? -ne 0\n+\tthen\n+\t\tgit-merge-cache -o git-merge-one-file-script -a || {\n+\t\tgit-read-tree --reset \"$head\"\n+\t\tgit-checkout-tree -f -q -u -a\n+\t\tdie \"Automatic merge failed; should not be doing Octopus\"\n+\t\t}\n+\t\tnext=$(git-write-tree 2>/dev/null)\n+\tfi\n+\tPARENT=\"$PARENT -p $SHA1\"\n+\tMRC=$common\n+\tMRT=$next\n+\tMSG=\"$MSG\n+\t$REPO\"\n+done <\"$GIT_DIR/FETCH_HEAD\"\n+\n+# Just to be careful in case the user feeds nonsense to us.\n+if test \"$MRT\" = \"$head\"\n+then\n+\techo \"No changes.\"\n+\texit 0\n+fi\n+\n+result_commit=$(echo \"$MSG\" | git-commit-tree $MRT $PARENT)\n+echo \"Committed octopus merge $result_commit\"\n+echo $result_commit >\"$GIT_DIR\"/HEAD\n+git-diff-tree -p $head $result_commit | git-apply --stat\n"}]}