git-merge-one-file-scripton commit Leave merge failures in the filesystem (2a68a86)
   1#!/bin/sh
   2#
   3# This is the git merge script, called with
   4#
   5#   $1 - original file SHA1 (or empty)
   6#   $2 - file in branch1 SHA1 (or empty)
   7#   $3 - file in branch2 SHA1 (or empty)
   8#   $4 - pathname in repository
   9#   $5 - orignal file mode (or empty)
  10#   $6 - file in branch1 mode (or empty)
  11#   $7 - file in branch2 mode (or empty)
  12#
  13# Handle some trivial cases.. The _really_ trivial cases have
  14# been handled already by git-read-tree, but that one doesn't
  15# do any merges that migth change the tree layout.
  16
  17case "${1:-.}${2:-.}${3:-.}" in
  18#
  19# Deleted in both.
  20#
  21"$1..")
  22        echo "WARNING: $4 is removed in both branches."
  23        echo "WARNING: This is a potential rename conflict."
  24        exec git-update-cache --remove -- "$4" ;;
  25#
  26# Deleted in one and unchanged in the other.
  27#
  28"$1.." | "$1.$1" | "$1$1.")
  29        echo "Removing $4"
  30        rm -f -- "$4"
  31        exec git-update-cache --remove -- "$4" ;;
  32#
  33# Added in one.
  34#
  35".$2." | "..$3" )
  36        case "$6$7" in *7??) mode=+x;; *) mode=-x;; esac
  37        echo "Adding $4 with perm $mode."
  38        git-cat-file blob "$2$3" > "$4"
  39        chmod $mode -- "$4"
  40        exec git-update-cache --add -- "$4" ;;
  41#
  42# Added in both (check for same permissions).
  43#
  44".$3$2")
  45        if [ "$6" != "$7" ]; then
  46                echo "ERROR: File $4 added identically in both branches,"
  47                echo "ERROR: but permissions conflict $6->$7."
  48                exit 1
  49        fi
  50        case "$6" in *7??) mode=+x;; *) mode=-x;; esac
  51        echo "Adding $4 with perm $mode"
  52        git-cat-file blob "$2" > "$4"
  53        chmod $mode -- "$4"
  54        exec git-update-cache --add -- "$4" ;;
  55#
  56# Modified in both, but differently.
  57#
  58"$1$2$3")
  59        echo "Auto-merging $4."
  60        orig=`git-unpack-file $1`
  61        src1=`git-unpack-file $2`
  62        src2=`git-unpack-file $3`
  63        merge -p "$src1" "$orig" "$src2" > "$4"
  64        ret=$?
  65        rm -f -- "$orig" "$src1" "$src2"
  66        if [ "$6" != "$7" ]; then
  67                echo "ERROR: Permissions $5->$6->$7 don't match."
  68                ret=1
  69        fi
  70        if [ $ret -ne 0 ]; then
  71                # Reset the index to the first branch, making
  72                # git-diff-file useful
  73                git-update-cache --add --cacheinfo "$6" "$2" "$4"
  74                echo "ERROR: Merge conflict in $4."
  75                exit 1
  76        fi
  77        exec git-update-cache --add -- "$4" ;;
  78*)
  79        echo "ERROR: Not handling case $4: $1 -> $2 -> $3" ;;
  80esac
  81exit 1