@@ -27,7 +27,7 @@ SUBDIRECTORY_OK=Yes
2727cd_to_toplevel
2828require_work_tree
2929
30- if ! test " $# " -eq 7
30+ if test $# ! = 7
3131then
3232 echo " $LONG_USAGE "
3333 exit 1
@@ -38,7 +38,8 @@ case "${1:-.}${2:-.}${3:-.}" in
3838# Deleted in both or deleted in one and unchanged in the other
3939#
4040" $1 .." | " $1 .$1 " | " $1$1 ." )
41- if [ " $2 " ]; then
41+ if test -n " $2 "
42+ then
4243 echo " Removing $4 "
4344 else
4445 # read-tree checked that index matches HEAD already,
@@ -48,7 +49,8 @@ case "${1:-.}${2:-.}${3:-.}" in
4849 # we do not have it in the index, though.
4950 exec git update-index --remove -- " $4 "
5051 fi
51- if test -f " $4 " ; then
52+ if test -f " $4 "
53+ then
5254 rm -f -- " $4 " &&
5355 rmdir -p " $( expr " z$4 " : ' z\(.*\)/' ) " 2> /dev/null || :
5456 fi &&
@@ -67,7 +69,7 @@ case "${1:-.}${2:-.}${3:-.}" in
6769 echo " Adding $4 "
6870 if test -f " $4 "
6971 then
70- echo " ERROR: untracked $4 is overwritten by the merge."
72+ echo " ERROR: untracked $4 is overwritten by the merge." >&2
7173 exit 1
7274 fi
7375 git update-index --add --cacheinfo " $7 " " $3 " " $4 " &&
@@ -78,9 +80,10 @@ case "${1:-.}${2:-.}${3:-.}" in
7880# Added in both, identically (check for same permissions).
7981#
8082" .$3$2 " )
81- if [ " $6 " != " $7 " ]; then
82- echo " ERROR: File $4 added identically in both branches,"
83- echo " ERROR: but permissions conflict $6 ->$7 ."
83+ if test " $6 " ! = " $7 "
84+ then
85+ echo " ERROR: File $4 added identically in both branches," >&2
86+ echo " ERROR: but permissions conflict $6 ->$7 ." >&2
8487 exit 1
8588 fi
8689 echo " Adding $4 "
@@ -95,71 +98,63 @@ case "${1:-.}${2:-.}${3:-.}" in
9598
9699 case " ,$6 ,$7 ," in
97100 * ,120000,* )
98- echo " ERROR: $4 : Not merging symbolic link changes."
101+ echo " ERROR: $4 : Not merging symbolic link changes." >&2
99102 exit 1
100103 ;;
101104 * ,160000,* )
102- echo " ERROR: $4 : Not merging conflicting submodule changes."
105+ echo " ERROR: $4 : Not merging conflicting submodule changes." >&2
103106 exit 1
104107 ;;
105108 esac
106109
107- src2=` git-unpack-file $3 `
110+ src1=$( git-unpack-file $2 )
111+ src2=$( git-unpack-file $3 )
108112 case " $1 " in
109113 ' ' )
110114 echo " Added $4 in both, but differently."
111- # This extracts OUR file in $orig, and uses git apply to
112- # remove lines that are unique to ours.
113- orig=` git-unpack-file $2 `
114- sz0=` wc -c < " $orig " `
115- @@DIFF@@ -u -La/$orig -Lb/$orig $orig $src2 | git apply --no-add
116- sz1=` wc -c < " $orig " `
117-
118- # If we do not have enough common material, it is not
119- # worth trying two-file merge using common subsections.
120- expr $sz0 \< $sz1 \* 2 > /dev/null || : > $orig
115+ orig=$( git-unpack-file $2 )
116+ create_virtual_base " $orig " " $src2 "
121117 ;;
122118 * )
123119 echo " Auto-merging $4 "
124- orig=` git-unpack-file $1 `
120+ orig=$( git-unpack-file $1 )
125121 ;;
126122 esac
127123
128- # Be careful for funny filename such as "-L" in "$4", which
129- # would confuse "merge" greatly.
130- src1=` git-unpack-file $2 `
131124 git merge-file " $src1 " " $orig " " $src2 "
132125 ret=$?
133126 msg=
134- if [ $ret -ne 0 ]; then
127+ if test $ret ! = 0 || test -z " $1 "
128+ then
135129 msg=' content conflict'
130+ ret=1
136131 fi
137132
138133 # Create the working tree file, using "our tree" version from the
139134 # index, and then store the result of the merge.
140135 git checkout-index -f --stage=2 -- " $4 " && cat " $src1 " > " $4 " || exit 1
141136 rm -f -- " $orig " " $src1 " " $src2 "
142137
143- if [ " $6 " != " $7 " ]; then
144- if [ -n " $msg " ]; then
138+ if test " $6 " ! = " $7 "
139+ then
140+ if test -n " $msg "
141+ then
145142 msg=" $msg , "
146143 fi
147144 msg=" ${msg} permissions conflict: $5 ->$6 ,$7 "
148145 ret=1
149146 fi
150- if [ " $1 " = ' ' ]; then
151- ret=1
152- fi
153147
154- if [ $ret -ne 0 ]; then
155- echo " ERROR: $msg in $4 "
148+ if test $ret ! = 0
149+ then
150+ echo " ERROR: $msg in $4 " >&2
156151 exit 1
157152 fi
158153 exec git update-index -- " $4 "
159154 ;;
160155
161156* )
162- echo " ERROR: $4 : Not handling case $1 -> $2 -> $3 "
157+ echo " ERROR: $4 : Not handling case $1 -> $2 -> $3 " >&2
163158 ;;
164159esac
165160exit 1
0 commit comments