Use -y where possible in test t7610-mergetool
PATCH v2 2/5 Use -y where possible in test t7610-mergetool
In these tests, there are many situations where
'echo "" | git mergetool' is used. This replaces all of those occurrences with 'git mergetool -y' for simplicity and readability.
--- t/t7610-mergetool.sh | 62 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
t/t7610-mergetool.sh +31 -31
@@ -131,10 +131,10 @@ test_expect_success 'custom mergetool' ' git checkout -b test$test_count branch1 && git submodule update -N && test_expect_code 1 git merge master >/dev/null 2>&1 && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && - ( yes "" | git mergetool file1 file1 ) && - ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) && - ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && + git mergetool -y both >/dev/null 2>&1 && + git mergetool -y file1 file1 && + git mergetool -y file2 "spaced name" >/dev/null 2>&1 && + git mergetool -y subdir/file3 >/dev/null 2>&1 && ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
@@ -154,11 +154,11 @@ test_expect_success 'mergetool crlf' ' test_config core.autocrlf true && git checkout -b test$test_count branch1 && test_expect_code 1 git merge master >/dev/null 2>&1 && - ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && - ( yes "" | git mergetool file2 >/dev/null 2>&1 ) && - ( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && - ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && + git mergetool file1 >/dev/null 2>&1 && + git mergetool file2 >/dev/null 2>&1 && + git mergetool "spaced name" >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && + git mergetool subdir/file3 >/dev/null 2>&1 && ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod >/dev/null 2>&1 ) &&
@@ -177,7 +177,7 @@ test_expect_success 'mergetool in subdir' ' ( cd subdir && test_expect_code 1 git merge master >/dev/null 2>&1 && - ( yes "" | git mergetool file3 >/dev/null 2>&1 ) && + git mergetool file3 >/dev/null 2>&1 && test "$(cat file3)" = "master new sub" ) '
@@ -189,10 +189,10 @@ test_expect_success 'mergetool on file in parent dir' ' ( cd subdir && test_expect_code 1 git merge master >/dev/null 2>&1 && - ( yes "" | git mergetool file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) && - ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) && - ( yes "" | git mergetool ../both >/dev/null 2>&1 ) && + git mergetool file3 >/dev/null 2>&1 && + git mergetool ../file1 >/dev/null 2>&1 && + git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 && + git mergetool ../both >/dev/null 2>&1 && ( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool ../submod >/dev/null 2>&1 ) &&
@@ -302,7 +302,7 @@ test_expect_success 'mergetool takes partial path' ' git submodule update -N && test_expect_code 1 git merge master && - ( yes "" | git mergetool subdir ) && + git mergetool subdir && test "$(cat subdir/file3)" = "master new sub" '
@@ -370,8 +370,8 @@ test_expect_success 'deleted vs modified submodule' ' git checkout -b test$test_count.a test$test_count && test_expect_code 1 git merge master && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && + git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod ) && rmdir submod && mv submod-movedaside submod &&
@@ -387,8 +387,8 @@ test_expect_success 'deleted vs modified submodule' ' git submodule update -N && test_expect_code 1 git merge master && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && + git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod ) && test ! -e submod &&
@@ -401,8 +401,8 @@ test_expect_success 'deleted vs modified submodule' ' git submodule update -N && test_expect_code 1 git merge test$test_count && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && + git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod ) && test ! -e submod &&
@@ -417,8 +417,8 @@ test_expect_success 'deleted vs modified submodule' ' git submodule update -N && test_expect_code 1 git merge test$test_count && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && + git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod ) && test "$(cat submod/bar)" = "master submodule" &&
@@ -441,8 +441,8 @@ test_expect_success 'file vs modified submodule' ' git checkout -b test$test_count.a branch1 && test_expect_code 1 git merge master && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && + git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod ) && rmdir submod && mv submod-movedaside submod &&
@@ -457,8 +457,8 @@ test_expect_success 'file vs modified submodule' ' git checkout -b test$test_count.b test$test_count && test_expect_code 1 git merge master && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && + git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod ) && git submodule update -N &&
@@ -473,8 +473,8 @@ test_expect_success 'file vs modified submodule' ' git submodule update -N && test_expect_code 1 git merge test$test_count && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && + git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod ) && test -d submod.orig &&
@@ -489,8 +489,8 @@ test_expect_success 'file vs modified submodule' ' git submodule update -N && test_expect_code 1 git merge test$test_count && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both>/dev/null 2>&1 ) && + git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 && + git mergetool both>/dev/null 2>&1 && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod ) && test "$(cat submod/bar)" = "master submodule" &&
Signature · 1 line
2.12.0.5.gfbc750a84
Quoted 3 lines · Denton Liu
In these tests, there are many situations where
'echo "" | git mergetool' is used. This replaces all of those occurrences with 'git mergetool -y' for simplicity and readability.
"-y where _possible_" is not necessarily a good thing to do in tests. We do want to make sure that both "yes" from the input and "-y" from the command line work. Changes to "-y" done only for the tests that are not about accepting the interactive input from the end-user is a very good idea, but "replaces all of those" makes me worried.
t/t7610-mergetool.sh test_expect_success 'custom mergetool' ' · line 137
Quoted 8 lines
t/t7610-mergetool.sh +4
-4- ( yes "" | git mergetool both >/dev/null 2>&1 ) && - ( yes "" | git mergetool file1 file1 ) && - ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) && - ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && + git mergetool -y both >/dev/null 2>&1 && + git mergetool -y file1 file1 && + git mergetool -y file2 "spaced name" >/dev/null 2>&1 && + git mergetool -y subdir/file3 >/dev/null 2>&1 &&
So these replace "the user interactively keeps typing <ENTER>" with "-y", which sounds good. These are obviously more about what the code actually does.
t/t7610-mergetool.sh test_expect_success 'mergetool crlf' ' · line 161
Quoted 10 lines
t/t7610-mergetool.sh +5
-5- ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && - ( yes "" | git mergetool file2 >/dev/null 2>&1 ) && - ( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && - ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && + git mergetool file1 >/dev/null 2>&1 && + git mergetool file2 >/dev/null 2>&1 && + git mergetool "spaced name" >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && + git mergetool subdir/file3 >/dev/null 2>&1 &&
The reason for the lack of "-y" in the rewrite, in contrast to what was done in the previous hunk we saw, is not quite obvious.
t/t7610-mergetool.sh test_expect_success 'mergetool in subdir' ' · line 180
Quoted 6 lines
t/t7610-mergetool.sh +1
-1@@ -177,7 +177,7 @@ test_expect_success 'mergetool in subdir' ' ( cd subdir && test_expect_code 1 git merge master >/dev/null 2>&1 && - ( yes "" | git mergetool file3 >/dev/null 2>&1 ) && + git mergetool file3 >/dev/null 2>&1 &&
Likewise, and likewise for the remainder of the patch where the updated command line does not say "-y".
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Denton Liu
In these tests, there are many situations where
'echo "" | git mergetool' is used. This replaces all of those occurrences with 'git mergetool -y' for simplicity and readability.
Quoted 6 lines
"-y where _possible_" is not necessarily a good thing to do in tests. We do want to make sure that both "yes" from the input and "-y" from the command line work. Changes to "-y" done only for the tests that are not about accepting the interactive input from the end-user is a very good idea, but "replaces all of those" makes me worried.
The 'custom mergetool' test case seems like a good place to introduce an interactive test. Would the following patch to my patch work?
t/t7610-mergetool.sh +2 -2
@@ -135,8 +135,8 @@ test_expect_success 'custom mergetool' ' test_expect_code 1 git merge master >/dev/null 2>&1 && git mergetool -y both >/dev/null 2>&1 && git mergetool -y file1 file1 && - git mergetool -y file2 "spaced name" >/dev/null 2>&1 && - git mergetool -y subdir/file3 >/dev/null 2>&1 && + ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) && + ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0
-5- ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && - ( yes "" | git mergetool file2 >/dev/null 2>&1 ) && - ( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && - ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ git mergetool file1 >/dev/null 2>&1 && + git mergetool file2 >/dev/null 2>&1 && + git mergetool "spaced name" >/dev/null 2>&1 && + git mergetool both >/dev/null 2>&1 && + git mergetool subdir/file3 >/dev/null 2>&1 &&The reason for the lack of "-y" in the rewrite, in contrast to what was done in the previous hunk we saw, is not quite obvious.
Sorry, it was my mistake. I had forgotten to replace the '-y'. I have corrected this for a future revision.