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