Merge branch 'da/mergetool-tests'

The clean-up of this test script was long overdue and is a very
welcome change.

* da/mergetool-tests:
  test-lib-functions: adjust style to match CodingGuidelines
  t7610-mergetool: use test_config to isolate tests
  t7610-mergetool: add missing && and remove commented-out code
  t7610-mergetool: use tabs instead of a mix of tabs and spaces
This commit is contained in:
Junio C Hamano 2014-10-21 13:28:14 -07:00
commit 64bff25f78
2 changed files with 442 additions and 444 deletions

View File

@ -14,512 +14,504 @@ Testing basic merge tool invocation'
# running mergetool # running mergetool
test_expect_success 'setup' ' test_expect_success 'setup' '
git config rerere.enabled true && git config rerere.enabled true &&
echo master >file1 && echo master >file1 &&
echo master spaced >"spaced name" && echo master spaced >"spaced name" &&
echo master file11 >file11 && echo master file11 >file11 &&
echo master file12 >file12 && echo master file12 >file12 &&
echo master file13 >file13 && echo master file13 >file13 &&
echo master file14 >file14 && echo master file14 >file14 &&
mkdir subdir && mkdir subdir &&
echo master sub >subdir/file3 && echo master sub >subdir/file3 &&
test_create_repo submod && test_create_repo submod &&
( (
cd submod && cd submod &&
: >foo && : >foo &&
git add foo && git add foo &&
git commit -m "Add foo" git commit -m "Add foo"
) && ) &&
git submodule add git://example.com/submod submod && git submodule add git://example.com/submod submod &&
git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod && git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod &&
git commit -m "add initial versions" && git commit -m "add initial versions" &&
git checkout -b branch1 master && git checkout -b branch1 master &&
git submodule update -N && git submodule update -N &&
echo branch1 change >file1 && echo branch1 change >file1 &&
echo branch1 newfile >file2 && echo branch1 newfile >file2 &&
echo branch1 spaced >"spaced name" && echo branch1 spaced >"spaced name" &&
echo branch1 both added >both && echo branch1 both added >both &&
echo branch1 change file11 >file11 && echo branch1 change file11 >file11 &&
echo branch1 change file13 >file13 && echo branch1 change file13 >file13 &&
echo branch1 sub >subdir/file3 && echo branch1 sub >subdir/file3 &&
( (
cd submod && cd submod &&
echo branch1 submodule >bar && echo branch1 submodule >bar &&
git add bar && git add bar &&
git commit -m "Add bar on branch1" && git commit -m "Add bar on branch1" &&
git checkout -b submod-branch1 git checkout -b submod-branch1
) && ) &&
git add file1 "spaced name" file11 file13 file2 subdir/file3 submod && git add file1 "spaced name" file11 file13 file2 subdir/file3 submod &&
git add both && git add both &&
git rm file12 && git rm file12 &&
git commit -m "branch1 changes" && git commit -m "branch1 changes" &&
git checkout -b stash1 master && git checkout -b stash1 master &&
echo stash1 change file11 >file11 && echo stash1 change file11 >file11 &&
git add file11 && git add file11 &&
git commit -m "stash1 changes" && git commit -m "stash1 changes" &&
git checkout -b stash2 master && git checkout -b stash2 master &&
echo stash2 change file11 >file11 && echo stash2 change file11 >file11 &&
git add file11 && git add file11 &&
git commit -m "stash2 changes" && git commit -m "stash2 changes" &&
git checkout master && git checkout master &&
git submodule update -N && git submodule update -N &&
echo master updated >file1 && echo master updated >file1 &&
echo master new >file2 && echo master new >file2 &&
echo master updated spaced >"spaced name" && echo master updated spaced >"spaced name" &&
echo master both added >both && echo master both added >both &&
echo master updated file12 >file12 && echo master updated file12 >file12 &&
echo master updated file14 >file14 && echo master updated file14 >file14 &&
echo master new sub >subdir/file3 && echo master new sub >subdir/file3 &&
( (
cd submod && cd submod &&
echo master submodule >bar && echo master submodule >bar &&
git add bar && git add bar &&
git commit -m "Add bar on master" && git commit -m "Add bar on master" &&
git checkout -b submod-master git checkout -b submod-master
) && ) &&
git add file1 "spaced name" file12 file14 file2 subdir/file3 submod && git add file1 "spaced name" file12 file14 file2 subdir/file3 submod &&
git add both && git add both &&
git rm file11 && git rm file11 &&
git commit -m "master updates" && git commit -m "master updates" &&
git config merge.tool mytool && git config merge.tool mytool &&
git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
git config mergetool.mytool.trustExitCode true && git config mergetool.mytool.trustExitCode true &&
git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" && git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" &&
git config mergetool.mybase.trustExitCode true git config mergetool.mybase.trustExitCode true
' '
test_expect_success 'custom mergetool' ' test_expect_success 'custom mergetool' '
git checkout -b test1 branch1 && git checkout -b test1 branch1 &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge master >/dev/null 2>&1 && test_must_fail git merge master >/dev/null 2>&1 &&
( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "" | git mergetool file1 file1 ) && ( yes "" | git mergetool file1 file1 ) &&
( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) && ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) &&
( yes "" | git mergetool subdir/file3 >/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 file11 >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
( yes "l" | git mergetool submod >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
test "$(cat file1)" = "master updated" && test "$(cat file1)" = "master updated" &&
test "$(cat file2)" = "master new" && test "$(cat file2)" = "master new" &&
test "$(cat subdir/file3)" = "master new sub" && test "$(cat subdir/file3)" = "master new sub" &&
test "$(cat submod/bar)" = "branch1 submodule" && test "$(cat submod/bar)" = "branch1 submodule" &&
git commit -m "branch1 resolved with mergetool" git commit -m "branch1 resolved with mergetool"
' '
test_expect_success 'mergetool crlf' ' test_expect_success 'mergetool crlf' '
git config core.autocrlf true && test_config core.autocrlf true &&
git checkout -b test2 branch1 && git checkout -b test2 branch1 &&
test_must_fail git merge master >/dev/null 2>&1 && test_must_fail git merge master >/dev/null 2>&1 &&
( yes "" | git mergetool file1 >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
( yes "" | git mergetool file2 >/dev/null 2>&1 ) && ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) && ( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) &&
( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "" | git mergetool subdir/file3 >/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 file11 >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
( yes "r" | git mergetool submod >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod >/dev/null 2>&1 ) &&
test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" && test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" && test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" && test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
git submodule update -N && git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" && test "$(cat submod/bar)" = "master submodule" &&
git commit -m "branch1 resolved with mergetool - autocrlf" && git commit -m "branch1 resolved with mergetool - autocrlf" &&
git config core.autocrlf false && git config core.autocrlf false &&
git reset --hard git reset --hard
' '
test_expect_success 'mergetool in subdir' ' test_expect_success 'mergetool in subdir' '
git checkout -b test3 branch1 && git checkout -b test3 branch1 &&
git submodule update -N && git submodule update -N &&
( (
cd subdir && cd subdir &&
test_must_fail git merge master >/dev/null 2>&1 && test_must_fail git merge master >/dev/null 2>&1 &&
( yes "" | git mergetool file3 >/dev/null 2>&1 ) && ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
test "$(cat file3)" = "master new sub" test "$(cat file3)" = "master new sub"
) )
' '
test_expect_success 'mergetool on file in parent dir' ' test_expect_success 'mergetool on file in parent dir' '
( (
cd subdir && cd subdir &&
( yes "" | git mergetool ../file1 >/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 ../file2 ../spaced\ name >/dev/null 2>&1 ) &&
( yes "" | git mergetool ../both >/dev/null 2>&1 ) && ( yes "" | git mergetool ../both >/dev/null 2>&1 ) &&
( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) &&
( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) &&
( yes "l" | git mergetool ../submod >/dev/null 2>&1 ) && ( yes "l" | git mergetool ../submod >/dev/null 2>&1 ) &&
test "$(cat ../file1)" = "master updated" && test "$(cat ../file1)" = "master updated" &&
test "$(cat ../file2)" = "master new" && test "$(cat ../file2)" = "master new" &&
test "$(cat ../submod/bar)" = "branch1 submodule" && test "$(cat ../submod/bar)" = "branch1 submodule" &&
git commit -m "branch1 resolved with mergetool - subdir" git commit -m "branch1 resolved with mergetool - subdir"
) )
' '
test_expect_success 'mergetool skips autoresolved' ' test_expect_success 'mergetool skips autoresolved' '
git checkout -b test4 branch1 && git checkout -b test4 branch1 &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge master && test_must_fail git merge master &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
( yes "l" | git mergetool submod >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git reset --hard git reset --hard
' '
test_expect_success 'mergetool merges all from subdir' ' test_expect_success 'mergetool merges all from subdir' '
( (
cd subdir && cd subdir &&
git config rerere.enabled false && git config rerere.enabled false &&
test_must_fail git merge master && test_must_fail git merge master &&
( yes "r" | git mergetool ../submod ) && ( yes "r" | git mergetool ../submod ) &&
( yes "d" "d" | git mergetool --no-prompt ) && ( yes "d" "d" | git mergetool --no-prompt ) &&
test "$(cat ../file1)" = "master updated" && test "$(cat ../file1)" = "master updated" &&
test "$(cat ../file2)" = "master new" && test "$(cat ../file2)" = "master new" &&
test "$(cat file3)" = "master new sub" && test "$(cat file3)" = "master new sub" &&
( cd .. && git submodule update -N ) && ( cd .. && git submodule update -N ) &&
test "$(cat ../submod/bar)" = "master submodule" && test "$(cat ../submod/bar)" = "master submodule" &&
git commit -m "branch2 resolved by mergetool from subdir" git commit -m "branch2 resolved by mergetool from subdir"
) )
' '
test_expect_success 'mergetool skips resolved paths when rerere is active' ' test_expect_success 'mergetool skips resolved paths when rerere is active' '
git config rerere.enabled true && git config rerere.enabled true &&
rm -rf .git/rr-cache && rm -rf .git/rr-cache &&
git checkout -b test5 branch1 git checkout -b test5 branch1 &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge master >/dev/null 2>&1 && test_must_fail git merge master >/dev/null 2>&1 &&
( yes "l" | git mergetool --no-prompt submod >/dev/null 2>&1 ) && ( yes "l" | git mergetool --no-prompt submod >/dev/null 2>&1 ) &&
( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) && ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) &&
git submodule update -N && git submodule update -N &&
output="$(yes "n" | git mergetool --no-prompt)" && output="$(yes "n" | git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git reset --hard git reset --hard
' '
test_expect_success 'conflicted stash sets up rerere' ' test_expect_success 'conflicted stash sets up rerere' '
git config rerere.enabled true && git config rerere.enabled true &&
git checkout stash1 && git checkout stash1 &&
echo "Conflicting stash content" >file11 && echo "Conflicting stash content" >file11 &&
git stash && git stash &&
git checkout --detach stash2 && git checkout --detach stash2 &&
test_must_fail git stash apply && test_must_fail git stash apply &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
conflicts="$(git rerere remaining)" && conflicts="$(git rerere remaining)" &&
test "$conflicts" = "file11" && test "$conflicts" = "file11" &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" != "No files need merging" && test "$output" != "No files need merging" &&
git commit -am "save the stash resolution" && git commit -am "save the stash resolution" &&
git reset --hard stash2 && git reset --hard stash2 &&
test_must_fail git stash apply && test_must_fail git stash apply &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
conflicts="$(git rerere remaining)" && conflicts="$(git rerere remaining)" &&
test -z "$conflicts" && test -z "$conflicts" &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" test "$output" = "No files need merging"
' '
test_expect_success 'mergetool takes partial path' ' test_expect_success 'mergetool takes partial path' '
git reset --hard git reset --hard &&
git config rerere.enabled false && git config rerere.enabled false &&
git checkout -b test12 branch1 && git checkout -b test12 branch1 &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge master && test_must_fail git merge master &&
#should not need these lines ( yes "" | git mergetool subdir ) &&
#( 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 ) &&
#( yes "" | git mergetool file1 file2 >/dev/null 2>&1 ) &&
( yes "" | git mergetool subdir ) && test "$(cat subdir/file3)" = "master new sub" &&
git reset --hard
test "$(cat subdir/file3)" = "master new sub" &&
git reset --hard
' '
test_expect_success 'deleted vs modified submodule' ' test_expect_success 'deleted vs modified submodule' '
git checkout -b test6 branch1 && git checkout -b test6 branch1 &&
git submodule update -N && git submodule update -N &&
mv submod submod-movedaside && mv submod submod-movedaside &&
git rm --cached submod && git rm --cached submod &&
git commit -m "Submodule deleted from branch" && git commit -m "Submodule deleted from branch" &&
git checkout -b test6.a test6 && git checkout -b test6.a test6 &&
test_must_fail git merge master && test_must_fail git merge master &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
( yes "r" | git mergetool submod ) && ( yes "r" | git mergetool submod ) &&
rmdir submod && mv submod-movedaside submod && rmdir submod && mv submod-movedaside submod &&
test "$(cat submod/bar)" = "branch1 submodule" && test "$(cat submod/bar)" = "branch1 submodule" &&
git submodule update -N && git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" && test "$(cat submod/bar)" = "master submodule" &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping module" && git commit -m "Merge resolved by keeping module" &&
mv submod submod-movedaside && mv submod submod-movedaside &&
git checkout -b test6.b test6 && git checkout -b test6.b test6 &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge master && test_must_fail git merge master &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
( yes "l" | git mergetool submod ) && ( yes "l" | git mergetool submod ) &&
test ! -e submod && test ! -e submod &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git commit -m "Merge resolved by deleting module" && git commit -m "Merge resolved by deleting module" &&
mv submod-movedaside submod && mv submod-movedaside submod &&
git checkout -b test6.c master && git checkout -b test6.c master &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge test6 && test_must_fail git merge test6 &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
( yes "r" | git mergetool submod ) && ( yes "r" | git mergetool submod ) &&
test ! -e submod && test ! -e submod &&
test -d submod.orig && test -d submod.orig &&
git submodule update -N && git submodule update -N &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git commit -m "Merge resolved by deleting module" && git commit -m "Merge resolved by deleting module" &&
mv submod.orig submod && mv submod.orig submod &&
git checkout -b test6.d master && git checkout -b test6.d master &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge test6 && test_must_fail git merge test6 &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
( yes "l" | git mergetool submod ) && ( yes "l" | git mergetool submod ) &&
test "$(cat submod/bar)" = "master submodule" && test "$(cat submod/bar)" = "master submodule" &&
git submodule update -N && git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" && test "$(cat submod/bar)" = "master submodule" &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping module" && git commit -m "Merge resolved by keeping module" &&
git reset --hard HEAD git reset --hard HEAD
' '
test_expect_success 'file vs modified submodule' ' test_expect_success 'file vs modified submodule' '
git checkout -b test7 branch1 && git checkout -b test7 branch1 &&
git submodule update -N && git submodule update -N &&
mv submod submod-movedaside && mv submod submod-movedaside &&
git rm --cached submod && git rm --cached submod &&
echo not a submodule >submod && echo not a submodule >submod &&
git add submod && git add submod &&
git commit -m "Submodule path becomes file" && git commit -m "Submodule path becomes file" &&
git checkout -b test7.a branch1 && git checkout -b test7.a branch1 &&
test_must_fail git merge master && test_must_fail git merge master &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
( yes "r" | git mergetool submod ) && ( yes "r" | git mergetool submod ) &&
rmdir submod && mv submod-movedaside submod && rmdir submod && mv submod-movedaside submod &&
test "$(cat submod/bar)" = "branch1 submodule" && test "$(cat submod/bar)" = "branch1 submodule" &&
git submodule update -N && git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" && test "$(cat submod/bar)" = "master submodule" &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping module" && git commit -m "Merge resolved by keeping module" &&
mv submod submod-movedaside && mv submod submod-movedaside &&
git checkout -b test7.b test7 && git checkout -b test7.b test7 &&
test_must_fail git merge master && test_must_fail git merge master &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
( yes "l" | git mergetool submod ) && ( yes "l" | git mergetool submod ) &&
git submodule update -N && git submodule update -N &&
test "$(cat submod)" = "not a submodule" && test "$(cat submod)" = "not a submodule" &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping file" && git commit -m "Merge resolved by keeping file" &&
git checkout -b test7.c master && git checkout -b test7.c master &&
rmdir submod && mv submod-movedaside submod && rmdir submod && mv submod-movedaside submod &&
test ! -e submod.orig && test ! -e submod.orig &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge test7 && test_must_fail git merge test7 &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
( yes "r" | git mergetool submod ) && ( yes "r" | git mergetool submod ) &&
test -d submod.orig && test -d submod.orig &&
git submodule update -N && git submodule update -N &&
test "$(cat submod)" = "not a submodule" && test "$(cat submod)" = "not a submodule" &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping file" && git commit -m "Merge resolved by keeping file" &&
git checkout -b test7.d master && git checkout -b test7.d master &&
rmdir submod && mv submod.orig submod && rmdir submod && mv submod.orig submod &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge test7 && test_must_fail git merge test7 &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
( yes "" | git mergetool both>/dev/null 2>&1 ) && ( yes "" | git mergetool both>/dev/null 2>&1 ) &&
( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
( yes "l" | git mergetool submod ) && ( yes "l" | git mergetool submod ) &&
test "$(cat submod/bar)" = "master submodule" && test "$(cat submod/bar)" = "master submodule" &&
git submodule update -N && git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" && test "$(cat submod/bar)" = "master submodule" &&
output="$(git mergetool --no-prompt)" && output="$(git mergetool --no-prompt)" &&
test "$output" = "No files need merging" && test "$output" = "No files need merging" &&
git commit -m "Merge resolved by keeping module" git commit -m "Merge resolved by keeping module"
' '
test_expect_success 'submodule in subdirectory' ' test_expect_success 'submodule in subdirectory' '
git checkout -b test10 branch1 && git checkout -b test10 branch1 &&
git submodule update -N && git submodule update -N &&
(
cd subdir &&
test_create_repo subdir_module &&
( (
cd subdir_module && cd subdir &&
: >file15 && test_create_repo subdir_module &&
git add file15 && (
git commit -m "add initial versions" cd subdir_module &&
) : >file15 &&
) && git add file15 &&
git submodule add git://example.com/subsubmodule subdir/subdir_module && git commit -m "add initial versions"
git add subdir/subdir_module && )
git commit -m "add submodule in subdirectory" && ) &&
git submodule add git://example.com/subsubmodule subdir/subdir_module &&
git add subdir/subdir_module &&
git commit -m "add submodule in subdirectory" &&
git checkout -b test10.a test10 && git checkout -b test10.a test10 &&
git submodule update -N && git submodule update -N &&
( (
cd subdir/subdir_module && cd subdir/subdir_module &&
git checkout -b super10.a && git checkout -b super10.a &&
echo test10.a >file15 && echo test10.a >file15 &&
git add file15 && git add file15 &&
git commit -m "on branch 10.a" git commit -m "on branch 10.a"
) && ) &&
git add subdir/subdir_module && git add subdir/subdir_module &&
git commit -m "change submodule in subdirectory on test10.a" && git commit -m "change submodule in subdirectory on test10.a" &&
git checkout -b test10.b test10 && git checkout -b test10.b test10 &&
git submodule update -N && git submodule update -N &&
( (
cd subdir/subdir_module && cd subdir/subdir_module &&
git checkout -b super10.b && git checkout -b super10.b &&
echo test10.b >file15 && echo test10.b >file15 &&
git add file15 && git add file15 &&
git commit -m "on branch 10.b" git commit -m "on branch 10.b"
) && ) &&
git add subdir/subdir_module && git add subdir/subdir_module &&
git commit -m "change submodule in subdirectory on test10.b" && git commit -m "change submodule in subdirectory on test10.b" &&
test_must_fail git merge test10.a >/dev/null 2>&1 && test_must_fail git merge test10.a >/dev/null 2>&1 &&
( (
cd subdir && cd subdir &&
( yes "l" | git mergetool subdir_module ) ( yes "l" | git mergetool subdir_module )
) && ) &&
test "$(cat subdir/subdir_module/file15)" = "test10.b" && test "$(cat subdir/subdir_module/file15)" = "test10.b" &&
git submodule update -N && git submodule update -N &&
test "$(cat subdir/subdir_module/file15)" = "test10.b" && test "$(cat subdir/subdir_module/file15)" = "test10.b" &&
git reset --hard && git reset --hard &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge test10.a >/dev/null 2>&1 && test_must_fail git merge test10.a >/dev/null 2>&1 &&
( yes "r" | git mergetool subdir/subdir_module ) && ( yes "r" | git mergetool subdir/subdir_module ) &&
test "$(cat subdir/subdir_module/file15)" = "test10.b" && test "$(cat subdir/subdir_module/file15)" = "test10.b" &&
git submodule update -N && git submodule update -N &&
test "$(cat subdir/subdir_module/file15)" = "test10.a" && test "$(cat subdir/subdir_module/file15)" = "test10.a" &&
git commit -m "branch1 resolved with mergetool" && git commit -m "branch1 resolved with mergetool" &&
rm -rf subdir/subdir_module rm -rf subdir/subdir_module
' '
test_expect_success 'directory vs modified submodule' ' test_expect_success 'directory vs modified submodule' '
git checkout -b test11 branch1 && git checkout -b test11 branch1 &&
mv submod submod-movedaside && mv submod submod-movedaside &&
git rm --cached submod && git rm --cached submod &&
mkdir submod && mkdir submod &&
echo not a submodule >submod/file16 && echo not a submodule >submod/file16 &&
git add submod/file16 && git add submod/file16 &&
git commit -m "Submodule path becomes directory" && git commit -m "Submodule path becomes directory" &&
test_must_fail git merge master && test_must_fail git merge master &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "l" | git mergetool submod ) && ( yes "l" | git mergetool submod ) &&
test "$(cat submod/file16)" = "not a submodule" && test "$(cat submod/file16)" = "not a submodule" &&
rm -rf submod.orig && rm -rf submod.orig &&
git reset --hard >/dev/null 2>&1 && git reset --hard >/dev/null 2>&1 &&
test_must_fail git merge master && test_must_fail git merge master &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
test ! -e submod.orig && test ! -e submod.orig &&
( yes "r" | git mergetool submod ) && ( yes "r" | git mergetool submod ) &&
test -d submod.orig && test -d submod.orig &&
test "$(cat submod.orig/file16)" = "not a submodule" && test "$(cat submod.orig/file16)" = "not a submodule" &&
rm -r submod.orig && rm -r submod.orig &&
mv submod-movedaside/.git submod && mv submod-movedaside/.git submod &&
( cd submod && git clean -f && git reset --hard ) && ( cd submod && git clean -f && git reset --hard ) &&
git submodule update -N && git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" && test "$(cat submod/bar)" = "master submodule" &&
git reset --hard >/dev/null 2>&1 && rm -rf submod-movedaside && git reset --hard >/dev/null 2>&1 && rm -rf submod-movedaside &&
git checkout -b test11.c master && git checkout -b test11.c master &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge test11 && test_must_fail git merge test11 &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
( yes "l" | git mergetool submod ) && ( yes "l" | git mergetool submod ) &&
git submodule update -N && git submodule update -N &&
test "$(cat submod/bar)" = "master submodule" && test "$(cat submod/bar)" = "master submodule" &&
git reset --hard >/dev/null 2>&1 && git reset --hard >/dev/null 2>&1 &&
git submodule update -N && git submodule update -N &&
test_must_fail git merge test11 && test_must_fail git merge test11 &&
test -n "$(git ls-files -u)" && test -n "$(git ls-files -u)" &&
test ! -e submod.orig && test ! -e submod.orig &&
( yes "r" | git mergetool submod ) && ( yes "r" | git mergetool submod ) &&
test "$(cat submod/file16)" = "not a submodule" && test "$(cat submod/file16)" = "not a submodule" &&
git reset --hard master >/dev/null 2>&1 && git reset --hard master >/dev/null 2>&1 &&
( cd submod && git clean -f && git reset --hard ) && ( cd submod && git clean -f && git reset --hard ) &&
git submodule update -N git submodule update -N
' '
test_expect_success 'file with no base' ' test_expect_success 'file with no base' '
git checkout -b test13 branch1 && git checkout -b test13 branch1 &&
test_must_fail git merge master && test_must_fail git merge master &&
git mergetool --no-prompt --tool mybase -- both && git mergetool --no-prompt --tool mybase -- both &&
>expected && >expected &&
test_cmp both expected && test_cmp both expected &&
git reset --hard master >/dev/null 2>&1 git reset --hard master >/dev/null 2>&1
' '
test_expect_success 'custom commands override built-ins' ' test_expect_success 'custom commands override built-ins' '
git checkout -b test14 branch1 && git checkout -b test14 branch1 &&
git config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
git config mergetool.defaults.trustExitCode true && test_config mergetool.defaults.trustExitCode true &&
test_must_fail git merge master && test_must_fail git merge master &&
git mergetool --no-prompt --tool defaults -- both && git mergetool --no-prompt --tool defaults -- both &&
echo master both added >expected && echo master both added >expected &&
test_cmp both expected && test_cmp both expected &&
git config --unset mergetool.defaults.cmd && git reset --hard master >/dev/null 2>&1
git config --unset mergetool.defaults.trustExitCode &&
git reset --hard master >/dev/null 2>&1
' '
test_done test_done

View File

@ -413,7 +413,7 @@ test_external () {
# test_run_, but keep its stdout on our stdout even in # test_run_, but keep its stdout on our stdout even in
# non-verbose mode. # non-verbose mode.
"$@" 2>&4 "$@" 2>&4
if [ "$?" = 0 ] if test "$?" = 0
then then
if test $test_external_has_tap -eq 0; then if test $test_external_has_tap -eq 0; then
test_ok_ "$descr" test_ok_ "$descr"
@ -440,11 +440,12 @@ test_external_without_stderr () {
tmp=${TMPDIR:-/tmp} tmp=${TMPDIR:-/tmp}
stderr="$tmp/git-external-stderr.$$.tmp" stderr="$tmp/git-external-stderr.$$.tmp"
test_external "$@" 4> "$stderr" test_external "$@" 4> "$stderr"
[ -f "$stderr" ] || error "Internal error: $stderr disappeared." test -f "$stderr" || error "Internal error: $stderr disappeared."
descr="no stderr: $1" descr="no stderr: $1"
shift shift
say >&3 "# expecting no stderr from previous command" say >&3 "# expecting no stderr from previous command"
if [ ! -s "$stderr" ]; then if test ! -s "$stderr"
then
rm "$stderr" rm "$stderr"
if test $test_external_has_tap -eq 0; then if test $test_external_has_tap -eq 0; then
@ -454,8 +455,9 @@ test_external_without_stderr () {
test_success=$(($test_success + 1)) test_success=$(($test_success + 1))
fi fi
else else
if [ "$verbose" = t ]; then if test "$verbose" = t
output=`echo; echo "# Stderr is:"; cat "$stderr"` then
output=$(echo; echo "# Stderr is:"; cat "$stderr")
else else
output= output=
fi fi
@ -474,7 +476,7 @@ test_external_without_stderr () {
# The commands test the existence or non-existence of $1. $2 can be # The commands test the existence or non-existence of $1. $2 can be
# given to provide a more precise diagnosis. # given to provide a more precise diagnosis.
test_path_is_file () { test_path_is_file () {
if ! [ -f "$1" ] if ! test -f "$1"
then then
echo "File $1 doesn't exist. $*" echo "File $1 doesn't exist. $*"
false false
@ -482,7 +484,7 @@ test_path_is_file () {
} }
test_path_is_dir () { test_path_is_dir () {
if ! [ -d "$1" ] if ! test -d "$1"
then then
echo "Directory $1 doesn't exist. $*" echo "Directory $1 doesn't exist. $*"
false false
@ -501,11 +503,12 @@ test_dir_is_empty () {
} }
test_path_is_missing () { test_path_is_missing () {
if [ -e "$1" ] if test -e "$1"
then then
echo "Path exists:" echo "Path exists:"
ls -ld "$1" ls -ld "$1"
if [ $# -ge 1 ]; then if test $# -ge 1
then
echo "$*" echo "$*"
fi fi
false false
@ -666,9 +669,12 @@ test_cmp_rev () {
# similar to GNU seq(1), but the latter might not be available # similar to GNU seq(1), but the latter might not be available
# everywhere (and does not do letters). It may be used like: # everywhere (and does not do letters). It may be used like:
# #
# for i in `test_seq 100`; do # for i in $(test_seq 100)
# for j in `test_seq 10 20`; do # do
# for k in `test_seq a z`; do # for j in $(test_seq 10 20)
# do
# for k in $(test_seq a z)
# do
# echo $i-$j-$k # echo $i-$j-$k
# done # done
# done # done