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 if [ "$1" = "-h" ] && [ $# -eq 1 ]; then
19 usage: ${tgname:-tg} index-merge-one-file <s1_hash> <s2_hash> <s3_hash> <path> <s1_mode> <s2_mode> <s3_mode>"
23 [ $# -eq 7 ] ||
exit 1
25 # We only handle auto merging existing files with the same mode
27 case "${1:-:}${2:-:}${3:-:}${4:-:}${5:-:}${6:-:}${7:-:}" in *":"*) exit 1; esac
28 [ "$5" = "$6" ] && [ "$6" = "$7" ] ||
exit 1
30 # Check for "just-in-case" things that shouldn't get in here:
32 # a) all three hashes are the same (handled same as next case)
33 # b) $2 and $3 are the same
34 # c) $1 and $2 are the same
35 # d) $1 and $3 are the same
37 # For the "just-in-case"s it doesn't actually matter what the mode is
39 if [ "$2" = "$3" ]; then
41 elif [ "$1" = "$2" ]; then
43 elif [ "$1" = "$3" ]; then
47 if [ -z "$newhash" ]; then
48 # mode must match 100\o\o\o
49 case "$6" in 100[0-7][0-7][0-7]);;*) exit 1; esac
50 if [ "$4" = ".topdeps" ] ||
[ "$4" = ".topmsg" ]; then
51 # resolution for these two is always silently "ours" never a merge
54 tg_tmp_dir
="${TG_TMP_DIR:-/tmp}"
55 basef
="$tg_tmp_dir/tgmerge_$$_base"
56 oursf
="$tg_tmp_dir/tgmerge_$$_ours"
57 thrsf
="$tg_tmp_dir/tgmerge_$$_thrs"
58 trap 'rm -f "$basef" "$oursf" "$thrsf"' EXIT
65 git cat-file blob
"$1" >"$basef" ||
exit 1
66 git cat-file blob
"$2" >"$oursf" ||
exit 1
67 git cat-file blob
"$3" >"$thrsf" ||
exit 1
68 git merge-file
--quiet "$oursf" "$basef" "$thrsf" >/dev
/null
2>&1 ||
exit 1
69 printf '%s\n' "Auto-merging $4"
70 newhash
="$(git hash-object -w --stdin <"$oursf" 2>/dev/null)"
74 [ -n "$newhash" ] ||
exit 1
75 git update-index
--cacheinfo "$6" "$newhash" "$4"