Skip to content

Commit

Permalink
t7610-mergetool: use test_cmp instead of test $(cat file) = $txt
Browse files Browse the repository at this point in the history
Fix that anti-pattern by a sequence of echo and test_cmp.

The patch was generated with this command:

   sed -i -e '/test.*(cat/s/^\(\t*\)test "..cat \(.*\))" = \(".*"\)\(.*\)/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/' t7610-mergetool.sh

This helps on Windows, where test_cmp avoids spawning a process when
there is no difference.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
j6t authored and gitster committed Jun 12, 2019
1 parent b4a04c8 commit e10dffd
Showing 1 changed file with 90 additions and 45 deletions.
135 changes: 90 additions & 45 deletions t/t7610-mergetool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@ test_expect_success 'custom mergetool' '
yes "d" | git mergetool file11 &&
yes "d" | git mergetool file12 &&
yes "l" | git mergetool submod &&
test "$(cat file1)" = "master updated" &&
test "$(cat file2)" = "master new" &&
test "$(cat subdir/file3)" = "master new sub" &&
test "$(cat submod/bar)" = "branch1 submodule" &&
echo "master updated" >expect &&
test_cmp expect file1 &&
echo "master new" >expect &&
test_cmp expect file2 &&
echo "master new sub" >expect &&
test_cmp expect subdir/file3 &&
echo "branch1 submodule" >expect &&
test_cmp expect submod/bar &&
git commit -m "branch1 resolved with mergetool"
'

Expand All @@ -160,10 +164,14 @@ test_expect_success 'gui mergetool' '
yes "d" | git mergetool --gui file11 &&
yes "d" | git mergetool --gui file12 &&
yes "l" | git mergetool --gui submod &&
test "$(cat file1)" = "gui master updated" &&
test "$(cat file2)" = "gui master new" &&
test "$(cat subdir/file3)" = "gui master new sub" &&
test "$(cat submod/bar)" = "branch1 submodule" &&
echo "gui master updated" >expect &&
test_cmp expect file1 &&
echo "gui master new" >expect &&
test_cmp expect file2 &&
echo "gui master new sub" >expect &&
test_cmp expect subdir/file3 &&
echo "branch1 submodule" >expect &&
test_cmp expect submod/bar &&
git commit -m "branch1 resolved with mergetool"
'

Expand All @@ -179,10 +187,14 @@ test_expect_success 'gui mergetool without merge.guitool set falls back to merge
yes "d" | git mergetool --gui file11 &&
yes "d" | git mergetool --gui file12 &&
yes "l" | git mergetool --gui submod &&
test "$(cat file1)" = "master updated" &&
test "$(cat file2)" = "master new" &&
test "$(cat subdir/file3)" = "master new sub" &&
test "$(cat submod/bar)" = "branch1 submodule" &&
echo "master updated" >expect &&
test_cmp expect file1 &&
echo "master new" >expect &&
test_cmp expect file2 &&
echo "master new sub" >expect &&
test_cmp expect subdir/file3 &&
echo "branch1 submodule" >expect &&
test_cmp expect submod/bar &&
git commit -m "branch1 resolved with mergetool"
'

Expand All @@ -207,7 +219,8 @@ test_expect_success 'mergetool crlf' '
test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect submod/bar &&
git commit -m "branch1 resolved with mergetool - autocrlf"
'

Expand All @@ -219,7 +232,8 @@ test_expect_success 'mergetool in subdir' '
cd subdir &&
test_must_fail git merge master &&
yes "" | git mergetool file3 &&
test "$(cat file3)" = "master new sub"
echo "master new sub" >expect &&
test_cmp expect file3
)
'

Expand All @@ -237,9 +251,12 @@ test_expect_success 'mergetool on file in parent dir' '
yes "d" | git mergetool ../file11 &&
yes "d" | git mergetool ../file12 &&
yes "l" | git mergetool ../submod &&
test "$(cat ../file1)" = "master updated" &&
test "$(cat ../file2)" = "master new" &&
test "$(cat ../submod/bar)" = "branch1 submodule" &&
echo "master updated" >expect &&
test_cmp expect ../file1 &&
echo "master new" >expect &&
test_cmp expect ../file2 &&
echo "branch1 submodule" >expect &&
test_cmp expect ../submod/bar &&
git commit -m "branch1 resolved with mergetool - subdir"
)
'
Expand All @@ -266,11 +283,15 @@ test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
test_must_fail git merge master &&
yes "r" | git mergetool ../submod &&
yes "d" "d" | git mergetool --no-prompt &&
test "$(cat ../file1)" = "master updated" &&
test "$(cat ../file2)" = "master new" &&
test "$(cat file3)" = "master new sub" &&
echo "master updated" >expect &&
test_cmp expect ../file1 &&
echo "master new" >expect &&
test_cmp expect ../file2 &&
echo "master new sub" >expect &&
test_cmp expect file3 &&
( cd .. && git submodule update -N ) &&
test "$(cat ../submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect ../submod/bar &&
git commit -m "branch2 resolved by mergetool from subdir"
)
'
Expand All @@ -285,11 +306,15 @@ test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
test_must_fail git merge master &&
yes "r" | git mergetool ../submod &&
yes "d" "d" | git mergetool --no-prompt &&
test "$(cat ../file1)" = "master updated" &&
test "$(cat ../file2)" = "master new" &&
test "$(cat file3)" = "master new sub" &&
echo "master updated" >expect &&
test_cmp expect ../file1 &&
echo "master new" >expect &&
test_cmp expect ../file2 &&
echo "master new sub" >expect &&
test_cmp expect file3 &&
( cd .. && git submodule update -N ) &&
test "$(cat ../submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect ../submod/bar &&
git commit -m "branch2 resolved by mergetool from subdir"
)
'
Expand Down Expand Up @@ -345,7 +370,8 @@ test_expect_success 'mergetool takes partial path' '
yes "" | git mergetool subdir &&
test "$(cat subdir/file3)" = "master new sub"
echo "master new sub" >expect &&
test_cmp expect subdir/file3
'

test_expect_success 'mergetool delete/delete conflict' '
Expand Down Expand Up @@ -415,9 +441,11 @@ test_expect_success 'deleted vs modified submodule' '
yes "d" | git mergetool file11 file12 &&
yes "r" | git mergetool submod &&
rmdir submod && mv submod-movedaside submod &&
test "$(cat submod/bar)" = "branch1 submodule" &&
echo "branch1 submodule" >expect &&
test_cmp expect submod/bar &&
git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect submod/bar &&
output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping module" &&
Expand Down Expand Up @@ -461,9 +489,11 @@ test_expect_success 'deleted vs modified submodule' '
yes "" | git mergetool both &&
yes "d" | git mergetool file11 file12 &&
yes "l" | git mergetool submod &&
test "$(cat submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect submod/bar &&
git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect submod/bar &&
output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping module"
Expand All @@ -486,9 +516,11 @@ test_expect_success 'file vs modified submodule' '
yes "d" | git mergetool file11 file12 &&
yes "r" | git mergetool submod &&
rmdir submod && mv submod-movedaside submod &&
test "$(cat submod/bar)" = "branch1 submodule" &&
echo "branch1 submodule" >expect &&
test_cmp expect submod/bar &&
git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect submod/bar &&
output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping module" &&
Expand All @@ -502,7 +534,8 @@ test_expect_success 'file vs modified submodule' '
yes "d" | git mergetool file11 file12 &&
yes "l" | git mergetool submod &&
git submodule update -N &&
test "$(cat submod)" = "not a submodule" &&
echo "not a submodule" >expect &&
test_cmp expect submod &&
output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping file" &&
Expand All @@ -519,7 +552,8 @@ test_expect_success 'file vs modified submodule' '
yes "r" | git mergetool submod &&
test -d submod.orig &&
git submodule update -N &&
test "$(cat submod)" = "not a submodule" &&
echo "not a submodule" >expect &&
test_cmp expect submod &&
output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping file" &&
Expand All @@ -533,9 +567,11 @@ test_expect_success 'file vs modified submodule' '
yes "" | git mergetool both &&
yes "d" | git mergetool file11 file12 &&
yes "l" | git mergetool submod &&
test "$(cat submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect submod/bar &&
git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect submod/bar &&
output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping module"
Expand Down Expand Up @@ -589,17 +625,21 @@ test_expect_success 'submodule in subdirectory' '
cd subdir &&
yes "l" | git mergetool subdir_module
) &&
test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
echo "test$test_count.b" >expect &&
test_cmp expect subdir/subdir_module/file15 &&
git submodule update -N &&
test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
echo "test$test_count.b" >expect &&
test_cmp expect subdir/subdir_module/file15 &&
git reset --hard &&
git submodule update -N &&
test_must_fail git merge test$test_count.a &&
yes "r" | git mergetool subdir/subdir_module &&
test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
echo "test$test_count.b" >expect &&
test_cmp expect subdir/subdir_module/file15 &&
git submodule update -N &&
test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
echo "test$test_count.a" >expect &&
test_cmp expect subdir/subdir_module/file15 &&
git commit -m "branch1 resolved with mergetool"
'

Expand All @@ -616,7 +656,8 @@ test_expect_success 'directory vs modified submodule' '
test_must_fail git merge master &&
test -n "$(git ls-files -u)" &&
yes "l" | git mergetool submod &&
test "$(cat submod/file16)" = "not a submodule" &&
echo "not a submodule" >expect &&
test_cmp expect submod/file16 &&
rm -rf submod.orig &&
git reset --hard &&
Expand All @@ -625,12 +666,14 @@ test_expect_success 'directory vs modified submodule' '
test ! -e submod.orig &&
yes "r" | git mergetool submod &&
test -d submod.orig &&
test "$(cat submod.orig/file16)" = "not a submodule" &&
echo "not a submodule" >expect &&
test_cmp expect submod.orig/file16 &&
rm -r submod.orig &&
mv submod-movedaside/.git submod &&
( cd submod && git clean -f && git reset --hard ) &&
git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect submod/bar &&
git reset --hard &&
rm -rf submod-movedaside &&
Expand All @@ -640,15 +683,17 @@ test_expect_success 'directory vs modified submodule' '
test -n "$(git ls-files -u)" &&
yes "l" | git mergetool submod &&
git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" &&
echo "master submodule" >expect &&
test_cmp expect submod/bar &&
git reset --hard &&
git submodule update -N &&
test_must_fail git merge test$test_count &&
test -n "$(git ls-files -u)" &&
test ! -e submod.orig &&
yes "r" | git mergetool submod &&
test "$(cat submod/file16)" = "not a submodule" &&
echo "not a submodule" >expect &&
test_cmp expect submod/file16 &&
git reset --hard master &&
( cd submod && git clean -f && git reset --hard ) &&
Expand Down

0 comments on commit e10dffd

Please sign in to comment.