Skip to content

Commit ee28152

Browse files
author
Junio C Hamano
committed
Update git-merge-one-file-script.
With this change, git-merge-one-file-script ceases to smudge files in the work tree when recording the trivial merge results (conflicting auto-merge failure case does not touch the work tree file as before). Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 0ff5bf7 commit ee28152

File tree

1 file changed

+26
-38
lines changed

1 file changed

+26
-38
lines changed

git-merge-one-file-script

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,69 @@
66
# $2 - file in branch1 SHA1 (or empty)
77
# $3 - file in branch2 SHA1 (or empty)
88
# $4 - pathname in repository
9-
#
9+
# $5 - orignal file mode (or empty)
10+
# $6 - file in branch1 mode (or empty)
11+
# $7 - file in branch2 mode (or empty)
1012
#
1113
# Handle some trivial cases.. The _really_ trivial cases have
1214
# 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
18-
dir=$(dirname "$4")
19-
mkdir -p "$dir" || exit
15+
# do any merges that migth change the tree layout.
2016

2117
case "${1:-.}${2:-.}${3:-.}" in
2218
#
23-
# deleted in both
19+
# Deleted in both.
2420
#
2521
"$1..")
26-
echo "ERROR: $4 is removed in both branches"
27-
echo "ERROR: This is a potential rename conflict"
22+
echo "ERROR: $4 is removed in both branches."
23+
echo "ERROR: This is a potential rename conflict."
2824
exit 1;;
2925
#
30-
# deleted in one and unchanged in the other
26+
# Deleted in one and unchanged in the other.
3127
#
3228
"$1.." | "$1.$1" | "$1$1.")
3329
echo "Removing $4"
34-
rm -f -- "$4" && exec git-update-cache --remove -- "$4" ;;
30+
exec git-update-cache --force-remove "$4" ;;
3531
#
36-
# added in one
32+
# Added in one.
3733
#
3834
".$2." | "..$3" )
3935
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" ;;
36+
echo "Adding $4 with perm $mode."
37+
exec git-update-cache --add --cacheinfo "$6$7" "$2$3" "$4" ;;
4538
#
46-
# Added in both (check for same permissions)
39+
# Added in both (check for same permissions).
4740
#
48-
".$2$2")
41+
".$3$2")
4942
if [ "$6" != "$7" ]; then
50-
echo "ERROR: File $4 added in both branches, permissions conflict $6->$7"
43+
echo "ERROR: File $4 added identically in both branches,"
44+
echo "ERROR: but permissions conflict $6->$7."
5145
exit 1
5246
fi
5347
case "$6" in *7??) mode=+x;; *) mode=-x;; esac
5448
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" ;;
49+
exec git-update-cache --add --cacheinfo "$6" "$2" "$4" ;;
5950
#
60-
# Modified in both, but differently ;(
51+
# Modified in both, but differently.
6152
#
6253
"$1$2$3")
63-
echo "Auto-merging $4"
54+
echo "Auto-merging $4."
6455
orig=$(git-unpack-file $1)
6556
src1=$(git-unpack-file $2)
6657
src2=$(git-unpack-file $3)
6758
merge "$src2" "$orig" "$src1"
6859
ret=$?
6960
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
61+
echo "ERROR: Permissions $5->$6->$7 don't match."
7562
fi
7663
if [ $ret -ne 0 ]; then
77-
echo "ERROR: Leaving conflict merge in $src2"
64+
echo "ERROR: Leaving conflict merge in $src2."
7865
exit 1
7966
fi
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" ;;
67+
sha1=$(git-write-blob "$src2") || {
68+
echo "ERROR: Leaving conflict merge in $src2."
69+
}
70+
exec git-update-cache --add --cacheinfo "$6" $sha1 "$4" ;;
8371
*)
84-
echo "Not handling case $4: $1 -> $2 -> $3" ;;
72+
echo "ERROR: Not handling case $4: $1 -> $2 -> $3" ;;
8573
esac
8674
exit 1

0 commit comments

Comments
 (0)