README_DOCS.rst: update tg prev and tg next usage summary
[topgit/pro.git] / t / t1200-index-merge-one-file.sh
blob268d5d39101ee030268b0aef206431f7f31ce1c6
1 #!/bin/sh
3 test_description='check tg index-merge-one-file works correctly'
5 . ./test-lib.sh
7 test_plan 325
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
13 test_asv_cache '
14 commit1 sha1 4cb29ea
15 commit2 sha1 85c3040
16 commit3 sha1 2488d99
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
26 cat <<EOT >check
27 100644 $comit1 1 test
28 100644 $comit2 2 test
29 100644 $comit3 3 test
30 EOT
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
37 >"$PWD/.toolran" &&
38 "$tg_imof" \$USE_STRATEGY "\$@"
39 EOT
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
43 prepare_test() {
44 rm -f .git/index
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
56 # $1 expected result
57 # 0 is none
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
61 check_index() {
62 cnt=0
63 badname=
64 badmode=
65 sawstage0=
66 while read mode hash stage name junk && [ -n "$name" ]; do
67 cnt=$(( $cnt + 1 ))
68 [ "$name" = "$2" ] || badname=1
69 [ "$mode" = "100644" ] || badmode=1
70 [ "$stage" != "0" ] || sawstage0="${hash:-1}"
71 done <<-EOT
72 $(git ls-files --full-name -s :/)
73 EOT
74 [ -z "$badname" ] || say_color error "# found wrong name in index"
75 [ -z "$badmode" ] || say_color error "# found wrong (not 100644) mode in index"
76 isbad=
77 if [ "$1" = "0" ]; then
78 if [ $cnt -gt 0 ]; then
79 isbad=1
80 say_color error "# expected no index entries, found $cnt"
82 elif [ "$1" = "-1" ]; then
83 if [ $cnt -lt 2 ]; then
84 isbad=1
85 say_color error "# expected at least 2 index entries, found $cnt"
87 if [ -n "$sawstage0" ]; then
88 isbad=1
89 say_color error "# expected only conflict index stages but found stage 0"
91 else
92 eval check="\"\$version$1\""
93 if [ $cnt -ne 1 ]; then
94 isbad=1
95 say_color error "# expected exactly one index entry, found $cnt"
96 elif [ -z "$sawstage0" ]; then
97 isbad=1
98 say_color error "# expected exactly one stage 0 index entry"
99 elif [ "$check" != "$sawstage0" ]; then
100 isbad=1
101 say_color error "# expected stage 0 hash $check but found $sawstage0"
104 [ -z "$isbad" ] || git ls-files --full-name --abbrev -s | sed 's/^/# /'
105 return ${isbad:-0}
108 check_table() {
109 if [ "$1" = "3" ]; then
110 shift
111 check_index "-1" "$@"
112 else
113 check_index "$@"
117 run_index_merge() {
118 strat=
119 case "$1" in
120 'r') strat="--remove";;
121 't') strat="--theirs";;
122 'm') strat="--merge";;
123 'o');;
124 *) die;;
125 esac
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 || :
132 [ -e ".toolran" ] ||
134 GIT_INDEX_FILE=".git/index-save" && export GIT_INDEX_FILE &&
135 ucnt="$(( $(git ls-files --unmerged --full-name --abbrev :/ | wc -l) ))" || : &&
136 [ "$ucnt" = "0" ]
137 ) ||
139 say_color error "git merge-index did not run our tool"
140 return 1
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"
166 # Test Table
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)
171 done <<EOT
172 0 0 0 r 0 0
173 0 0 0 t 0 0
174 0 0 0 o 0 0
175 0 0 0 m 0 0
176 0 0 1 r 0 1
177 0 0 1 t 1 1
178 0 0 1 o 0 1
179 0 0 1 m 1 1
180 0 0 2 r 0 2
181 0 0 2 t 2 2
182 0 0 2 o 0 2
183 0 0 2 m 2 2
184 0 1 0 r 0 1
185 0 1 0 t 0 1
186 0 1 0 o 1 1
187 0 1 0 m 1 1
188 0 1 1 r 0 1
189 0 1 1 t 1 1
190 0 1 1 o 1 1
191 0 1 1 m 1 1
192 0 1 2 r 0 3
193 0 1 2 t 2 3
194 0 1 2 o 1 3
195 0 1 2 m 3 3
196 0 2 0 r 0 2
197 0 2 0 t 0 2
198 0 2 0 o 2 2
199 0 2 0 m 2 2
200 0 2 1 r 0 3
201 0 2 1 t 1 3
202 0 2 1 o 2 3
203 0 2 1 m 3 3
204 0 2 2 r 0 2
205 0 2 2 t 2 2
206 0 2 2 o 2 2
207 0 2 2 m 2 2
208 1 0 0 r 0 0
209 1 0 0 t 0 0
210 1 0 0 o 0 0
211 1 0 0 m 0 0
212 1 0 1 r 0 0
213 1 0 1 t 1 0
214 1 0 1 o 0 0
215 1 0 1 m 0 0
216 1 0 2 r 0 3
217 1 0 2 t 2 3
218 1 0 2 o 0 3
219 1 0 2 m 3 3
220 1 1 0 r 0 0
221 1 1 0 t 0 0
222 1 1 0 o 1 0
223 1 1 0 m 0 0
224 1 1 1 r 0 1
225 1 1 1 t 1 1
226 1 1 1 o 1 1
227 1 1 1 m 1 1
228 1 1 2 r 0 2
229 1 1 2 t 2 2
230 1 1 2 o 1 2
231 1 1 2 m 2 2
232 1 2 0 r 0 3
233 1 2 0 t 0 3
234 1 2 0 o 2 3
235 1 2 0 m 3 3
236 1 2 1 r 0 2
237 1 2 1 t 1 2
238 1 2 1 o 2 2
239 1 2 1 m 2 2
240 1 2 2 r 0 2
241 1 2 2 t 2 2
242 1 2 2 o 2 2
243 1 2 2 m 2 2
244 2 0 0 r 0 0
245 2 0 0 t 0 0
246 2 0 0 o 0 0
247 2 0 0 m 0 0
248 2 0 1 r 0 3
249 2 0 1 t 1 3
250 2 0 1 o 0 3
251 2 0 1 m 3 3
252 2 0 2 r 0 0
253 2 0 2 t 2 0
254 2 0 2 o 0 0
255 2 0 2 m 0 0
256 2 1 0 r 0 3
257 2 1 0 t 0 3
258 2 1 0 o 1 3
259 2 1 0 m 3 3
260 2 1 1 r 0 1
261 2 1 1 t 1 1
262 2 1 1 o 1 1
263 2 1 1 m 1 1
264 2 1 2 r 0 1
265 2 1 2 t 2 1
266 2 1 2 o 1 1
267 2 1 2 m 1 1
268 2 2 0 r 0 0
269 2 2 0 t 0 0
270 2 2 0 o 2 0
271 2 2 0 m 0 0
272 2 2 1 r 0 1
273 2 2 1 t 1 1
274 2 2 1 o 2 1
275 2 2 1 m 1 1
276 2 2 2 r 0 2
277 2 2 2 t 2 2
278 2 2 2 o 2 2
279 2 2 2 m 2 2
282 test_done