From f217f0e86dc7bacc5dc127982eaadca758b558ce Mon Sep 17 00:00:00 2001 From: Eyvind Bernhardsen Date: Fri, 2 Jul 2010 21:20:47 +0200 Subject: Avoid conflicts when merging branches with mixed normalization Currently, merging across changes in line ending normalization is painful since files containing CRLF will conflict with normalized files, even if the only difference between the two versions is the line endings. Additionally, any "real" merge conflicts that exist are obscured because every line in the file has a conflict. Assume you start out with a repo that has a lot of text files with CRLF checked in (A): o---C / \ A---B---D B: Add "* text=auto" to .gitattributes and normalize all files to LF-only C: Modify some of the text files D: Try to merge C You will get a ridiculous number of LF/CRLF conflicts when trying to merge C into D, since the repository contents for C are "wrong" wrt the new .gitattributes file. Fix ll-merge so that the "base", "theirs" and "ours" stages are passed through convert_to_worktree() and convert_to_git() before a three-way merge. This ensures that all three stages are normalized in the same way, removing from consideration differences that are only due to normalization. This feature is optional for now since it changes a low-level mechanism and is not necessary for the majority of users. The "merge.renormalize" config variable enables it. Signed-off-by: Eyvind Bernhardsen Signed-off-by: Junio C Hamano --- t/t6038-merge-text-auto.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 t/t6038-merge-text-auto.sh (limited to 't/t6038-merge-text-auto.sh') diff --git a/t/t6038-merge-text-auto.sh b/t/t6038-merge-text-auto.sh new file mode 100755 index 0000000000..127baf8560 --- /dev/null +++ b/t/t6038-merge-text-auto.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +test_description='CRLF merge conflict across text=auto change' + +. ./test-lib.sh + +test_expect_success setup ' + git config merge.renormalize true && + git config core.autocrlf false && + echo first line | append_cr >file && + echo first line >control_file && + echo only line >inert_file && + git add file control_file inert_file && + git commit -m "Initial" && + git tag initial && + git branch side && + echo "* text=auto" >.gitattributes && + touch file && + git add .gitattributes file && + git commit -m "normalize file" && + echo same line | append_cr >>file && + echo same line >>control_file && + git add file control_file && + git commit -m "add line from a" && + git tag a && + git rm .gitattributes && + rm file && + git checkout file && + git commit -m "remove .gitattributes" && + git tag c && + git checkout side && + echo same line | append_cr >>file && + echo same line >>control_file && + git add file control_file && + git commit -m "add line from b" && + git tag b && + git checkout master +' + +test_expect_success 'Check merging after setting text=auto' ' + git reset --hard a && + git merge b && + cat file | remove_cr >file.temp && + test_cmp file file.temp +' + +test_expect_success 'Check merging addition of text=auto' ' + git reset --hard b && + git merge a && + cat file | remove_cr >file.temp && + test_cmp file file.temp +' + +test_expect_failure 'Test delete/normalize conflict' ' + git checkout side && + git reset --hard initial && + git rm file && + git commit -m "remove file" && + git checkout master && + git reset --hard a^ && + git merge side +' + +test_done -- cgit v1.2.3 From 331a1838b26c3032bec27b66307a9de9b3b11509 Mon Sep 17 00:00:00 2001 From: Eyvind Bernhardsen Date: Fri, 2 Jul 2010 21:20:48 +0200 Subject: Try normalizing files to avoid delete/modify conflicts when merging If a file is modified due to normalization on one branch, and deleted on another, a merge of the two branches will result in a delete/modify conflict for that file even if it is otherwise unchanged. Try to avoid the conflict by normalizing and comparing the "base" file and the modified file when their sha1s differ. If they compare equal, the file is considered unmodified and is deleted. Signed-off-by: Eyvind Bernhardsen Signed-off-by: Junio C Hamano --- t/t6038-merge-text-auto.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t6038-merge-text-auto.sh') diff --git a/t/t6038-merge-text-auto.sh b/t/t6038-merge-text-auto.sh index 127baf8560..d1ab86ebd7 100755 --- a/t/t6038-merge-text-auto.sh +++ b/t/t6038-merge-text-auto.sh @@ -51,7 +51,7 @@ test_expect_success 'Check merging addition of text=auto' ' test_cmp file file.temp ' -test_expect_failure 'Test delete/normalize conflict' ' +test_expect_success 'Test delete/normalize conflict' ' git checkout side && git reset --hard initial && git rm file && -- cgit v1.2.3 From 18acb30ee458a4a413d987215af41b4a76643f5d Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Thu, 5 Aug 2010 06:09:33 -0500 Subject: t6038 (merge.renormalize): style nitpicks Some tweaks to simplify adding and running tests. - Use test_tick for predictable, sort of realistic commit dates; - Use test_cmp as "test_cmp expected actual" --- some crazy content that was not expected should cause the test to fail; - Remove and re-add all files at the start of each test so the worktree is easier to think about; - Avoid using cat where not necessary for clarity. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t6038-merge-text-auto.sh | 52 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 't/t6038-merge-text-auto.sh') diff --git a/t/t6038-merge-text-auto.sh b/t/t6038-merge-text-auto.sh index d1ab86ebd7..e21b5d27d7 100755 --- a/t/t6038-merge-text-auto.sh +++ b/t/t6038-merge-text-auto.sh @@ -1,58 +1,94 @@ #!/bin/sh -test_description='CRLF merge conflict across text=auto change' +test_description='CRLF merge conflict across text=auto change + +* [master] remove .gitattributes + ! [side] add line from b +-- + + [side] add line from b +* [master] remove .gitattributes +* [master^] add line from a +* [master~2] normalize file +*+ [side^] Initial +' . ./test-lib.sh test_expect_success setup ' git config merge.renormalize true && git config core.autocrlf false && + echo first line | append_cr >file && echo first line >control_file && echo only line >inert_file && + git add file control_file inert_file && + test_tick && git commit -m "Initial" && git tag initial && git branch side && + echo "* text=auto" >.gitattributes && touch file && git add .gitattributes file && + test_tick && git commit -m "normalize file" && + echo same line | append_cr >>file && echo same line >>control_file && git add file control_file && + test_tick && git commit -m "add line from a" && git tag a && + git rm .gitattributes && rm file && git checkout file && + test_tick && git commit -m "remove .gitattributes" && git tag c && + git checkout side && echo same line | append_cr >>file && echo same line >>control_file && git add file control_file && + test_tick && git commit -m "add line from b" && git tag b && + git checkout master ' -test_expect_success 'Check merging after setting text=auto' ' +test_expect_success 'Merge after setting text=auto' ' + cat <<-\EOF >expected && + first line + same line + EOF + + git rm -fr . && + rm -f .gitattributes && git reset --hard a && git merge b && - cat file | remove_cr >file.temp && - test_cmp file file.temp + test_cmp expected file ' -test_expect_success 'Check merging addition of text=auto' ' +test_expect_success 'Merge addition of text=auto' ' + cat <<-\EOF >expected && + first line + same line + EOF + + git rm -fr . && + rm -f .gitattributes && git reset --hard b && git merge a && - cat file | remove_cr >file.temp && - test_cmp file file.temp + test_cmp expected file ' test_expect_success 'Test delete/normalize conflict' ' - git checkout side && + git checkout -f side && + git rm -fr . && + rm -f .gitattributes && git reset --hard initial && git rm file && git commit -m "remove file" && -- cgit v1.2.3 From d347cee4deda2e740f3c9e0046a86b46debdaeb8 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Thu, 5 Aug 2010 06:11:12 -0500 Subject: t6038 (merge.renormalize): try checkout -m and cherry-pick MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit checkout -m and cherry-pick have not been wired up to respect merge.renormalize, but a naïve user would not know that. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t6038-merge-text-auto.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 't/t6038-merge-text-auto.sh') diff --git a/t/t6038-merge-text-auto.sh b/t/t6038-merge-text-auto.sh index e21b5d27d7..a7ea4b626b 100755 --- a/t/t6038-merge-text-auto.sh +++ b/t/t6038-merge-text-auto.sh @@ -85,6 +85,47 @@ test_expect_success 'Merge addition of text=auto' ' test_cmp expected file ' +test_expect_failure 'checkout -m after setting text=auto' ' + cat <<-\EOF >expected && + first line + same line + EOF + + git rm -fr . && + rm -f .gitattributes && + git reset --hard initial && + git checkout a -- . && + git checkout -m b && + test_cmp expected file +' + +test_expect_failure 'checkout -m addition of text=auto' ' + cat <<-\EOF >expected && + first line + same line + EOF + + git rm -fr . && + rm -f .gitattributes file && + git reset --hard initial && + git checkout b -- . && + git checkout -m a && + test_cmp expected file +' + +test_expect_failure 'cherry-pick patch from after text=auto was added' ' + append_cr <<-\EOF >expected && + first line + same line + EOF + + git rm -fr . && + git reset --hard b && + test_must_fail git cherry-pick a >err 2>&1 && + grep "[Nn]othing added" err && + test_cmp expected file +' + test_expect_success 'Test delete/normalize conflict' ' git checkout -f side && git rm -fr . && -- cgit v1.2.3 From beeeb45493332f38de2a3b58120c5bebb5863577 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Thu, 5 Aug 2010 06:13:04 -0500 Subject: t6038 (merge.renormalize): check that it can be turned off An unusual sort of person (not me) may even enjoy the conflicts from line-ending changes. But more importantly, it is useful to document that behavior so we can more easily notice if it changes in an uncontrolled way while no one is watching. Cc: Eyvind Bernhardsen Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t6038-merge-text-auto.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 't/t6038-merge-text-auto.sh') diff --git a/t/t6038-merge-text-auto.sh b/t/t6038-merge-text-auto.sh index a7ea4b626b..52d0dc4bb8 100755 --- a/t/t6038-merge-text-auto.sh +++ b/t/t6038-merge-text-auto.sh @@ -15,7 +15,6 @@ test_description='CRLF merge conflict across text=auto change . ./test-lib.sh test_expect_success setup ' - git config merge.renormalize true && git config core.autocrlf false && echo first line | append_cr >file && @@ -59,12 +58,19 @@ test_expect_success setup ' git checkout master ' +test_expect_success 'set up fuzz_conflict() helper' ' + fuzz_conflict() { + sed -e "s/^\([<>=]......\) .*/\1/" "$@" + } +' + test_expect_success 'Merge after setting text=auto' ' cat <<-\EOF >expected && first line same line EOF + git config merge.renormalize true && git rm -fr . && rm -f .gitattributes && git reset --hard a && @@ -78,6 +84,7 @@ test_expect_success 'Merge addition of text=auto' ' same line EOF + git config merge.renormalize true && git rm -fr . && rm -f .gitattributes && git reset --hard b && @@ -85,12 +92,51 @@ test_expect_success 'Merge addition of text=auto' ' test_cmp expected file ' +test_expect_success 'Detect CRLF/LF conflict after setting text=auto' ' + q_to_cr <<-\EOF >expected && + <<<<<<< + first line + same line + ======= + first lineQ + same lineQ + >>>>>>> + EOF + + git config merge.renormalize false && + rm -f .gitattributes && + git reset --hard a && + test_must_fail git merge b && + fuzz_conflict file >file.fuzzy && + test_cmp expected file.fuzzy +' + +test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' ' + q_to_cr <<-\EOF >expected && + <<<<<<< + first lineQ + same lineQ + ======= + first line + same line + >>>>>>> + EOF + + git config merge.renormalize false && + rm -f .gitattributes && + git reset --hard b && + test_must_fail git merge a && + fuzz_conflict file >file.fuzzy && + test_cmp expected file.fuzzy +' + test_expect_failure 'checkout -m after setting text=auto' ' cat <<-\EOF >expected && first line same line EOF + git config merge.renormalize true && git rm -fr . && rm -f .gitattributes && git reset --hard initial && @@ -105,6 +151,7 @@ test_expect_failure 'checkout -m addition of text=auto' ' same line EOF + git config merge.renormalize true && git rm -fr . && rm -f .gitattributes file && git reset --hard initial && @@ -119,6 +166,7 @@ test_expect_failure 'cherry-pick patch from after text=auto was added' ' same line EOF + git config merge.renormalize true && git rm -fr . && git reset --hard b && test_must_fail git cherry-pick a >err 2>&1 && -- cgit v1.2.3 From ca02ad3447efdbd4cb2aa9ba0ee3fc6124035274 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Fri, 17 Sep 2010 09:16:01 -0400 Subject: Side-step sed line-ending "corruption" leading to t6038 failure. By default, MSYS sed throws away CR from CRLF line-endings. Tests t6038.5 and t6038.6 employ sed to normalize conflict output of git-merge for validation purposes. These tests expect CRLF line-endings to be present in the normalized output of git-merge, and thus fail when sed undesirably removes CR. Fix by employing sed's -b/--binary switch to suppress its default behavior of dropping CR characters. Acked-by: Johannes Sixt Signed-off-by: Eric Sunshine Signed-off-by: Pat Thoyts --- t/t6038-merge-text-auto.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 't/t6038-merge-text-auto.sh') diff --git a/t/t6038-merge-text-auto.sh b/t/t6038-merge-text-auto.sh index 52d0dc4bb8..460bf741b5 100755 --- a/t/t6038-merge-text-auto.sh +++ b/t/t6038-merge-text-auto.sh @@ -14,6 +14,8 @@ test_description='CRLF merge conflict across text=auto change . ./test-lib.sh +test_have_prereq MINGW && SED_OPTIONS=-b + test_expect_success setup ' git config core.autocrlf false && @@ -60,7 +62,7 @@ test_expect_success setup ' test_expect_success 'set up fuzz_conflict() helper' ' fuzz_conflict() { - sed -e "s/^\([<>=]......\) .*/\1/" "$@" + sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@" } ' -- cgit v1.2.3 From a31d066524e55351b385e34f9494f36e9f960a6c Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Tue, 14 Dec 2010 18:32:12 +0000 Subject: t6038-*.sh: Pass the -b (--binary) option to sed on cygwin The tests using the fuzz_conflict helper function (tests 5-6) fail on cygwin in the same way they used to on MinGW, prior to commit ca02ad3. The solution is also the same; passing the -b (--binary) option to sed, using the SED_OPTIONS variable. We introduce a new prerequisite SED_STRIPS_CR to use in the conditional initialisation of SED_OPTIONS, rather than MINGW. The new prerequisite is set in test-lib.sh for both MinGW and Cygwin. Signed-off-by: Ramsay Jones Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- t/t6038-merge-text-auto.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t6038-merge-text-auto.sh') diff --git a/t/t6038-merge-text-auto.sh b/t/t6038-merge-text-auto.sh index 460bf741b5..d9c2d386dd 100755 --- a/t/t6038-merge-text-auto.sh +++ b/t/t6038-merge-text-auto.sh @@ -14,7 +14,7 @@ test_description='CRLF merge conflict across text=auto change . ./test-lib.sh -test_have_prereq MINGW && SED_OPTIONS=-b +test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b test_expect_success setup ' git config core.autocrlf false && -- cgit v1.2.3