git-merge-octopus.shon commit git-fetch/push/pull: documentation. (d6a7359)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5# Resolve two or more trees.
   6#
   7
   8# The first parameters up to -- are merge bases; the rest are heads.
   9bases= head= remotes= sep_seen=
  10for arg
  11do
  12        case ",$sep_seen,$head,$arg," in
  13        *,--,)
  14                sep_seen=yes
  15                ;;
  16        ,yes,,*)
  17                head=$arg
  18                ;;
  19        ,yes,*)
  20                remotes="$remotes$arg "
  21                ;;
  22        *)
  23                bases="$bases$arg "
  24                ;;
  25        esac
  26done
  27
  28# Reject if this is not an Octopus -- resolve should be used instead.
  29case "$remotes" in
  30?*' '?*)
  31        ;;
  32*)
  33        exit 2 ;;
  34esac
  35
  36# MRC is the current "merge reference commit"
  37# MRT is the current "merge result tree"
  38
  39MRC=$head MSG= PARENT="-p $head"
  40MRT=$(git-write-tree)
  41CNT=1 ;# counting our head
  42NON_FF_MERGE=0
  43for SHA1 in $remotes
  44do
  45        common=$(git-merge-base $MRC $SHA1) ||
  46                die "Unable to find common commit with $SHA1"
  47
  48        if test "$common" = $SHA1
  49        then
  50                echo "Already up-to-date with $SHA1"
  51                continue
  52        fi
  53
  54        CNT=`expr $CNT + 1`
  55        PARENT="$PARENT -p $SHA1"
  56
  57        if test "$common,$NON_FF_MERGE" = "$MRC,0"
  58        then
  59                # The first head being merged was a fast-forward.
  60                # Advance MRC to the head being merged, and use that
  61                # tree as the intermediate result of the merge.
  62                # We still need to count this as part of the parent set.
  63
  64                echo "Fast forwarding to: $SHA1"
  65                git-read-tree -u -m $head $SHA1 || exit
  66                MRC=$SHA1 MRT=$(git-write-tree)
  67                continue
  68        fi
  69
  70        NON_FF_MERGE=1
  71
  72        echo "Trying simple merge with $SHA1"
  73        git-read-tree -u -m $common $MRT $SHA1 || exit 2
  74        next=$(git-write-tree 2>/dev/null)
  75        if test $? -ne 0
  76        then
  77                echo "Simple merge did not work, trying automatic merge."
  78                git-merge-index -o git-merge-one-file -a ||
  79                exit 2 ; # Automatic merge failed; should not be doing Octopus
  80                next=$(git-write-tree 2>/dev/null)
  81        fi
  82        MRC=$common
  83        MRT=$next
  84done
  85
  86exit 0