3 test_description
='check tg index-merge-one-file works correctly'
9 version1
="$(printf '%s\n' one two three | git hash-object -w -t blob --stdin)" || die
10 version2
="$(printf '%s\n' alpha beta gamma | git hash-object -w -t blob --stdin)" || die
11 version3
="$(printf '%s\n' setup check | git hash-object -w -t blob --stdin)" || die
18 commit1 sha256 c5df06a
19 commit2 sha256 404b87a
20 commit3 sha256 20ef10c
22 test_v_asv comit1 commit1
23 test_v_asv comit2 commit2
24 test_v_asv comit3 commit3
32 tg_exec_path
="$(tg --exec-path)" && [ -n "$tg_exec_path" ] || die
33 tg_imof
="$tg_exec_path/tg--index-merge-one-file"
34 [ -f "$tg_imof" ] && [ -x "$tg_imof" ] || die
36 write_script run-index-merge-one-file
<<EOT || die
38 "$tg_imof" \$USE_STRATEGY "\$@"
41 # $1, $2, $3 => "<n>" in $version<n> for hash of base (1), ours (2), theirs (3) stages
42 # $4 file name to use for all three
45 [ "$1$2$3" = "000" ] ||
47 [ -z "$1" ] ||
[ "$1" = "0" ] ||
48 eval printf \''100644 %s 1\011%s\n'\' "\"\$version$1\"" '"$4"' #'
49 [ -z "$2" ] ||
[ "$2" = "0" ] ||
50 eval printf \''100644 %s 2\011%s\n'\' "\"\$version$2\"" '"$4"' #'
51 [ -z "$1" ] ||
[ "$3" = "0" ] ||
52 eval printf \''100644 %s 3\011%s\n'\' "\"\$version$3\"" '"$4"' #'
53 } | git update-index
--index-info
58 # 1, 2 or 3 is $version<n> hash at stage 0
59 # -1 is 2 or more stage >0 entries but no stage 0 entries
60 # $2 expected file name for all entries
66 while read mode
hash stage name junk
&& [ -n "$name" ]; do
68 [ "$name" = "$2" ] || badname
=1
69 [ "$mode" = "100644" ] || badmode
=1
70 [ "$stage" != "0" ] || sawstage0
="${hash:-1}"
72 $(git ls-files --full-name -s :/)
74 [ -z "$badname" ] || say_color error
"# found wrong name in index"
75 [ -z "$badmode" ] || say_color error
"# found wrong (not 100644) mode in index"
77 if [ "$1" = "0" ]; then
78 if [ $cnt -gt 0 ]; then
80 say_color error
"# expected no index entries, found $cnt"
82 elif [ "$1" = "-1" ]; then
83 if [ $cnt -lt 2 ]; then
85 say_color error
"# expected at least 2 index entries, found $cnt"
87 if [ -n "$sawstage0" ]; then
89 say_color error
"# expected only conflict index stages but found stage 0"
92 eval check
="\"\$version$1\""
93 if [ $cnt -ne 1 ]; then
95 say_color error
"# expected exactly one index entry, found $cnt"
96 elif [ -z "$sawstage0" ]; then
98 say_color error
"# expected exactly one stage 0 index entry"
99 elif [ "$check" != "$sawstage0" ]; then
101 say_color error
"# expected stage 0 hash $check but found $sawstage0"
104 [ -z "$isbad" ] || git ls-files
--full-name --abbrev -s |
sed 's/^/# /'
109 if [ "$1" = "3" ]; then
111 check_index
"-1" "$@"
120 'r') strat
="--remove";;
121 't') strat
="--theirs";;
122 'm') strat
="--merge";;
126 sane_unset USE_STRATEGY
127 [ -z "$strat" ] || USE_STRATEGY
="$strat" && export USE_STRATEGY
128 rm -f ".toolran" ".git/index-save"
129 cp -f ".git/index" ".git/index-save"
130 #ucnt="$(( $(git ls-files --unmerged --full-name --abbrev :/ | wc -l) ))" || :
131 git merge-index
"$PWD/run-index-merge-one-file" -a ||
:
134 GIT_INDEX_FILE
=".git/index-save" && export GIT_INDEX_FILE
&&
135 ucnt
="$(( $(git ls-files --unmerged --full-name --abbrev :/ | wc -l) ))" ||
: &&
139 say_color error
"git merge-index did not run our tool"
144 test_expect_success
'setup' '
145 prepare_test 1 2 3 test &&
146 git ls-files --full-name --abbrev -s >lsfiles &&
147 test_cmp lsfiles check
150 while read base ours theirs strategy tgresult gresult
; do
151 test_expect_success
"b=$base o=$ours t=$theirs s=$strategy r=$tgresult .topdeps" '
152 prepare_test "$base" "$ours" "$theirs" ".topdeps" &&
153 run_index_merge "$strategy" &&
154 check_table "$tgresult" ".topdeps"
156 test_expect_success
"b=$base o=$ours t=$theirs s=$strategy r=$tgresult .topmsg" '
157 prepare_test "$base" "$ours" "$theirs" ".topmsg" &&
158 run_index_merge "$strategy" &&
159 check_table "$tgresult" ".topmsg"
161 test_expect_success
"b=$base o=$ours t=$theirs s=$strategy r=$gresult testfile" '
162 prepare_test "$base" "$ours" "$theirs" "testfile" &&
163 run_index_merge "$strategy" &&
164 check_table "$gresult" "testfile"
167 # BASE OURS THEIRS STRATEGY TGRESULT GRESULT
168 # where BASE, OURS, THEIRS can be 0 (none), 1 (version1) or 2 (version2)
169 # STRATEGY is 'r' (remove), 't' (theirs), 'o' (ours) or 'm' (merge)
170 # RESULT is 0, 1, 2 or 3 (conflicted)