3 # tg--index-merge-one-file -- auto merge a file without touching working tree
4 # Copyright (C) 2017 Kyle J. McKay
8 # $TG_TMP_DIR => location to store temporary files
9 # $1 => stage 1 hash or empty
10 # $2 => stage 2 hash or empty
11 # $3 => stage 3 hash or empty
12 # $4 => full pathname in index
13 # $5 => stage 1 mode (6 octal digits) or empty
17 [ $# -eq 7 ] ||
exit 1
19 # We only handle auto merging existing files with the same mode
21 case "${1:-:}${2:-:}${3:-:}${4:-:}${5:-:}${6:-:}${7:-:}" in *":"*) exit 1; esac
22 [ "$5" = "$6" ] && [ "$6" = "$7" ] ||
exit 1
24 # Check for "just-in-case" things that shouldn't get in here:
26 # a) all three hashes are the same (handled same as next case)
27 # b) $2 and $3 are the same
28 # c) $1 and $2 are the same
29 # d) $1 and $3 are the same
31 # For the "just-in-case"s it doesn't actually matter what the mode is
33 if [ "$2" = "$3" ]; then
35 elif [ "$1" = "$2" ]; then
37 elif [ "$1" = "$3" ]; then
41 if [ -z "$newhash" ]; then
42 # mode must match 100\o\o\o
43 case "$6" in 100[0-7][0-7][0-7]);;*) exit 1; esac
44 if [ "$4" = ".topdeps" ] ||
[ "$4" = ".topmsg" ]; then
45 # resolution for these two is always silently "ours" never a merge
48 tg_tmp_dir
="${TG_TMP_DIR:-/tmp}"
49 basef
="$tg_tmp_dir/tgmerge_$$_base"
50 oursf
="$tg_tmp_dir/tgmerge_$$_ours"
51 thrsf
="$tg_tmp_dir/tgmerge_$$_thrs"
52 trap 'rm -f "$basef" "$oursf" "$thrsf"' EXIT
59 git cat-file blob
"$1" >"$basef" ||
exit 1
60 git cat-file blob
"$2" >"$oursf" ||
exit 1
61 git cat-file blob
"$3" >"$thrsf" ||
exit 1
62 git merge-file
--quiet "$oursf" "$basef" "$thrsf" >/dev
/null
2>&1 ||
exit 1
63 printf '%s\n' "Auto-merging $4"
64 newhash
="$(git hash-object -w --stdin <"$oursf" 2>/dev/null)"
68 [ -n "$newhash" ] ||
exit 1
69 git update-index
--cacheinfo "$6" "$newhash" "$4"