Add git-write-blob.
[git.git] / git-merge-one-file-script
blobcefbe634d888e33c8baba485517c32ad418ae142
1 #!/bin/sh
3 # This is the git merge script, called with
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
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
16 # if the directory is newly added in a branch, it might not exist
17 # in the current tree
18 dir=$(dirname "$4")
19 mkdir -p "$dir" || exit
21 case "${1:-.}${2:-.}${3:-.}" in
23 # deleted in both
25 "$1..")
26 echo "ERROR: $4 is removed in both branches"
27 echo "ERROR: This is a potential rename conflict"
28 exit 1;;
30 # deleted in one and unchanged in the other
32 "$1.." | "$1.$1" | "$1$1.")
33 echo "Removing $4"
34 rm -f -- "$4" && exec git-update-cache --remove -- "$4" ;;
36 # added in one
38 ".$2." | "..$3" )
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" ;;
46 # Added in both (check for same permissions)
48 ".$2$2")
49 if [ "$6" != "$7" ]; then
50 echo "ERROR: File $4 added in both branches, permissions conflict $6->$7"
51 exit 1
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" ;;
60 # Modified in both, but differently ;(
62 "$1$2$3")
63 echo "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=$?
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"
74 exit 1
76 if [ $ret -ne 0 ]; then
77 echo "ERROR: Leaving conflict merge in $src2"
78 exit 1
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" ;;
84 echo "Not handling case $4: $1 -> $2 -> $3" ;;
85 esac
86 exit 1