Skip to content

Commit b8cd1bb

Browse files
newrengitster
authored andcommitted
t6036, t6043: increase code coverage for file collision handling
Stolee's coverage reports found a few code blocks for file collision conflicts that had not previously been covered by testcases; add a few more testcases to cover those too. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48c9cb9 commit b8cd1bb

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

t/t6036-recursive-corner-cases.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,57 @@ test_expect_success 'git detects differently handled merges conflict' '
240240
)
241241
'
242242

243+
# Repeat the above testcase with precisely the same setup, other than with
244+
# the two merge bases having different orderings of commit timestamps so
245+
# that they are reversed in the order they are provided to merge-recursive,
246+
# so that we can improve code coverage.
247+
test_expect_success 'git detects differently handled merges conflict, swapped' '
248+
(
249+
cd rename-add &&
250+
251+
# Difference #1: Do cleanup from previous testrun
252+
git reset --hard &&
253+
git clean -fdqx &&
254+
255+
# Difference #2: Change commit timestamps
256+
btime=$(git log --no-walk --date=raw --format=%cd B | awk "{print \$1}") &&
257+
ctime=$(git log --no-walk --date=raw --format=%cd C | awk "{print \$1}") &&
258+
newctime=$(($btime+1)) &&
259+
git fast-export --no-data --all | sed -e s/$ctime/$newctime/ | git fast-import --force --quiet &&
260+
# End of differences; rest is copy-paste of last test
261+
262+
git checkout D^0 &&
263+
test_must_fail git merge -s recursive E^0 &&
264+
265+
git ls-files -s >out &&
266+
test_line_count = 3 out &&
267+
git ls-files -u >out &&
268+
test_line_count = 3 out &&
269+
git ls-files -o >out &&
270+
test_line_count = 1 out &&
271+
272+
git rev-parse >expect \
273+
C:new_a D:new_a E:new_a &&
274+
git rev-parse >actual \
275+
:1:new_a :2:new_a :3:new_a &&
276+
test_cmp expect actual &&
277+
278+
# Test that the two-way merge in new_a is as expected
279+
git cat-file -p D:new_a >ours &&
280+
git cat-file -p E:new_a >theirs &&
281+
>empty &&
282+
test_must_fail git merge-file \
283+
-L "HEAD" \
284+
-L "" \
285+
-L "E^0" \
286+
ours empty theirs &&
287+
sed -e "s/^\([<=>]\)/\1\1\1/" ours >expect &&
288+
git hash-object new_a >actual &&
289+
git hash-object ours >expect &&
290+
test_cmp expect actual
291+
)
292+
'
293+
243294
#
244295
# criss-cross + modify/delete:
245296
#

t/t6043-merge-rename-directories.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,6 +3163,43 @@ test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2)
31633163
)
31643164
'
31653165

3166+
test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2), other direction' '
3167+
(
3168+
cd 10c &&
3169+
3170+
git reset --hard &&
3171+
git clean -fdqx &&
3172+
3173+
git checkout B^0 &&
3174+
mkdir y &&
3175+
echo important >y/c &&
3176+
3177+
test_must_fail git merge -s recursive A^0 >out 2>err &&
3178+
test_i18ngrep "CONFLICT (rename/rename)" out &&
3179+
test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3180+
3181+
git ls-files -s >out &&
3182+
test_line_count = 6 out &&
3183+
git ls-files -u >out &&
3184+
test_line_count = 3 out &&
3185+
git ls-files -o >out &&
3186+
test_line_count = 3 out &&
3187+
3188+
git rev-parse >actual \
3189+
:0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3190+
git rev-parse >expect \
3191+
O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3192+
test_cmp expect actual &&
3193+
3194+
git hash-object y/c~HEAD >actual &&
3195+
git rev-parse O:x/c >expect &&
3196+
test_cmp expect actual &&
3197+
3198+
echo important >expect &&
3199+
test_cmp expect y/c
3200+
)
3201+
'
3202+
31663203
# Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
31673204
# Commit O: z/{a,b,c_1}, x/{d,e,f_2}
31683205
# Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham

0 commit comments

Comments
 (0)