git-merge-one-file-scripton commit [PATCH 2/3] Rename git-diff-tree-helper to git-diff-helper. (99665af)
   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 "ERROR: $4 is removed in both branches."
  23        echo "ERROR: This is a potential rename conflict."
  24        exit 1;;
  25#
  26# Deleted in one and unchanged in the other.
  27#
  28"$1.." | "$1.$1" | "$1$1.")
  29        echo "Removing $4"
  30        exec git-update-cache --force-remove "$4" ;;
  31#
  32# Added in one.
  33#
  34".$2." | "..$3" )
  35        case "$6$7" in *7??) mode=+x;; *) mode=-x;; esac
  36        echo "Adding $4 with perm $mode."
  37        exec git-update-cache --add --cacheinfo "$6$7" "$2$3" "$4" ;;
  38#
  39# Added in both (check for same permissions).
  40#
  41".$3$2")
  42        if [ "$6" != "$7" ]; then
  43                echo "ERROR: File $4 added identically in both branches,"
  44                echo "ERROR: but permissions conflict $6->$7."
  45                exit 1
  46        fi
  47        case "$6" in *7??) mode=+x;; *) mode=-x;; esac
  48        echo "Adding $4 with perm $mode"
  49        exec git-update-cache --add --cacheinfo "$6" "$2" "$4" ;;
  50#
  51# Modified in both, but differently.
  52#
  53"$1$2$3")
  54        echo "Auto-merging $4."
  55        orig=`git-unpack-file $1`
  56        src1=`git-unpack-file $2`
  57        src2=`git-unpack-file $3`
  58        merge "$src2" "$orig" "$src1"
  59        ret=$?
  60        if [ "$6" != "$7" ]; then
  61                echo "ERROR: Permissions $5->$6->$7 don't match."
  62        fi
  63        if [ $ret -ne 0 ]; then
  64                echo "ERROR: Leaving conflict merge in $src2."
  65                exit 1
  66        fi
  67        sha1=`git-write-blob "$src2"` || {
  68                echo "ERROR: Leaving conflict merge in $src2."
  69        }
  70        exec git-update-cache --add --cacheinfo "$6" $sha1 "$4" ;;
  71*)
  72        echo "ERROR: Not handling case $4: $1 -> $2 -> $3" ;;
  73esac
  74exit 1