]> git.ipfire.org Git - thirdparty/git.git/blame - git-merge-one-file-script
Fix SIGSEGV on unmerged files in git-diff-files -p
[thirdparty/git.git] / git-merge-one-file-script
CommitLineData
839a7a06
LT
1#!/bin/sh
2#
3# This is the git merge script, called with
4#
e3b4be7f
LT
5# $1 - original file SHA1 (or empty)
6# $2 - file in branch1 SHA1 (or empty)
7# $3 - file in branch2 SHA1 (or empty)
839a7a06 8# $4 - pathname in repository
ee28152d
JH
9# $5 - orignal file mode (or empty)
10# $6 - file in branch1 mode (or empty)
11# $7 - file in branch2 mode (or empty)
839a7a06 12#
e3b4be7f 13# Handle some trivial cases.. The _really_ trivial cases have
0fc65a45 14# been handled already by git-read-tree, but that one doesn't
ee28152d 15# do any merges that migth change the tree layout.
0a9ea850 16
e3b4be7f 17case "${1:-.}${2:-.}${3:-.}" in
839a7a06 18#
ee28152d 19# Deleted in both.
e2b6a9d0
JB
20#
21"$1..")
ee28152d
JH
22 echo "ERROR: $4 is removed in both branches."
23 echo "ERROR: This is a potential rename conflict."
e2b6a9d0
JB
24 exit 1;;
25#
ee28152d 26# Deleted in one and unchanged in the other.
839a7a06 27#
e3b4be7f 28"$1.." | "$1.$1" | "$1$1.")
e2b6a9d0 29 echo "Removing $4"
ee28152d 30 exec git-update-cache --force-remove "$4" ;;
839a7a06 31#
ee28152d 32# Added in one.
839a7a06 33#
e2b6a9d0 34".$2." | "..$3" )
21a08dcb 35 case "$6$7" in *7??) mode=+x;; *) mode=-x;; esac
ee28152d
JH
36 echo "Adding $4 with perm $mode."
37 exec git-update-cache --add --cacheinfo "$6$7" "$2$3" "$4" ;;
e2b6a9d0 38#
ee28152d 39# Added in both (check for same permissions).
e2b6a9d0 40#
ee28152d 41".$3$2")
e2b6a9d0 42 if [ "$6" != "$7" ]; then
ee28152d
JH
43 echo "ERROR: File $4 added identically in both branches,"
44 echo "ERROR: but permissions conflict $6->$7."
e2b6a9d0
JB
45 exit 1
46 fi
21a08dcb
JH
47 case "$6" in *7??) mode=+x;; *) mode=-x;; esac
48 echo "Adding $4 with perm $mode"
ee28152d 49 exec git-update-cache --add --cacheinfo "$6" "$2" "$4" ;;
e3b4be7f 50#
ee28152d 51# Modified in both, but differently.
e3b4be7f
LT
52#
53"$1$2$3")
ee28152d 54 echo "Auto-merging $4."
c7d1d4e1
JH
55 orig=`git-unpack-file $1`
56 src1=`git-unpack-file $2`
57 src2=`git-unpack-file $3`
0a9ea850 58 merge "$src2" "$orig" "$src1"
e2b6a9d0
JB
59 ret=$?
60 if [ "$6" != "$7" ]; then
ee28152d 61 echo "ERROR: Permissions $5->$6->$7 don't match."
e2b6a9d0 62 fi
e2b6a9d0 63 if [ $ret -ne 0 ]; then
ee28152d 64 echo "ERROR: Leaving conflict merge in $src2."
0a9ea850
JB
65 exit 1
66 fi
c7d1d4e1 67 sha1=`git-write-blob "$src2"` || {
ee28152d
JH
68 echo "ERROR: Leaving conflict merge in $src2."
69 }
70 exec git-update-cache --add --cacheinfo "$6" $sha1 "$4" ;;
e3b4be7f 71*)
ee28152d 72 echo "ERROR: Not handling case $4: $1 -> $2 -> $3" ;;
e3b4be7f
LT
73esac
74exit 1