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# 10# 11# Handle some trivial cases.. The _really_ trivial cases have 12# been handled already by git-read-tree, but that one doesn't 13# do any merges that migth change the tree layout 14# 15 16# if the directory is newly added in a branch, it might not exist 17# in the current tree 18dir=$(dirname "$4") 19mkdir-p"$dir"||exit 20 21case"${1:-.}${2:-.}${3:-.}"in 22# 23# deleted in both 24# 25"$1..") 26echo"ERROR:$4is removed in both branches" 27echo"ERROR: This is a potential rename conflict" 28exit1;; 29# 30# deleted in one and unchanged in the other 31# 32"$1.."|"$1.$1"|"$1$1.") 33echo"Removing$4" 34rm-f --"$4"&&exec git-update-cache --remove --"$4";; 35# 36# added in one 37# 38".$2."|"..$3") 39case"$6$7"in*7??) mode=+x;; *) mode=-x;;esac 40echo"Adding$4with perm$mode" 41rm-f --"$4"&& 42 git-cat-file blob "$2$3">"$4"&& 43chmod"$mode"--"$4"&& 44exec git-update-cache --add --"$4";; 45# 46# Added in both (check for same permissions) 47# 48".$2$2") 49if["$6"!="$7"];then 50echo"ERROR: File$4added in both branches, permissions conflict$6->$7" 51exit1 52fi 53case"$6"in*7??) mode=+x;; *) mode=-x;;esac 54echo"Adding$4with perm$mode" 55rm-f --"$4"&& 56 git-cat-file blob "$2">"$4"&& 57chmod"$mode"--"$4"&& 58exec git-update-cache --add --"$4";; 59# 60# Modified in both, but differently ;( 61# 62"$1$2$3") 63echo"Auto-merging$4" 64 orig=$(git-unpack-file $1) 65 src1=$(git-unpack-file $2) 66 src2=$(git-unpack-file $3) 67 merge "$src2""$orig""$src1" 68 ret=$? 69if["$6"!="$7"];then 70echo"ERROR: Permissions$5->$6->$7don't match merging$src2" 71if[$ret-ne0];then 72echo"ERROR: Leaving conflict merge in$src2" 73fi 74exit1 75fi 76if[$ret-ne0];then 77echo"ERROR: Leaving conflict merge in$src2" 78exit1 79fi 80case"$6"in*7??) mode=+x;; *) mode=-x;;esac 81rm-f --"$4"&&cat"$src2">"$4"&&chmod"$mode"--"$4"&& 82exec git-update-cache --add --"$4";; 83*) 84echo"Not handling case$4:$1->$2->$3";; 85esac 86exit1