From 8993f104661f1cafc359da0fff3ddec91785ae42 Mon Sep 17 00:00:00 2001 From: Chris Keele Date: Sat, 10 Apr 2021 15:49:06 -0700 Subject: [PATCH 1/2] Check for diff3-style merge conflict artifacts. --- pre_commit_hooks/check_merge_conflict.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pre_commit_hooks/check_merge_conflict.py b/pre_commit_hooks/check_merge_conflict.py index c20a8af7..2e52e06d 100644 --- a/pre_commit_hooks/check_merge_conflict.py +++ b/pre_commit_hooks/check_merge_conflict.py @@ -7,6 +7,7 @@ CONFLICT_PATTERNS = [ b'<<<<<<< ', b'======= ', + b'||||||| ', b'=======\n', b'>>>>>>> ', ] From 0c6a81a69f43717f79028f9938ca0d9d68ba8eeb Mon Sep 17 00:00:00 2001 From: Chris Keele Date: Sun, 11 Apr 2021 02:44:34 -0700 Subject: [PATCH 2/2] Add negative test cases for various git artifacts. --- pre_commit_hooks/check_merge_conflict.py | 3 ++- tests/check_merge_conflict_test.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pre_commit_hooks/check_merge_conflict.py b/pre_commit_hooks/check_merge_conflict.py index 2e52e06d..3921a37d 100644 --- a/pre_commit_hooks/check_merge_conflict.py +++ b/pre_commit_hooks/check_merge_conflict.py @@ -7,8 +7,9 @@ CONFLICT_PATTERNS = [ b'<<<<<<< ', b'======= ', - b'||||||| ', b'=======\n', + b'||||||| ', + b'|||||||\n', b'>>>>>>> ', ] diff --git a/tests/check_merge_conflict_test.py b/tests/check_merge_conflict_test.py index fccf41ff..ae6149dd 100644 --- a/tests/check_merge_conflict_test.py +++ b/tests/check_merge_conflict_test.py @@ -129,8 +129,32 @@ def test_does_not_care_when_not_in_a_merge(tmpdir): f.write_binary(b'problem\n=======\n') assert main([str(f.realpath())]) == 0 + f = tmpdir.join('README.md') + f.write_binary(b'problem\n======= \n') + assert main([str(f.realpath())]) == 0 + + f = tmpdir.join('README.md') + f.write_binary(b'problem\n|||||||\n') + assert main([str(f.realpath()), '--assume-in-merge']) == 0 + + f = tmpdir.join('README.md') + f.write_binary(b'problem\n||||||| \n') + assert main([str(f.realpath()), '--assume-in-merge']) == 0 + def test_care_when_assumed_merge(tmpdir): f = tmpdir.join('README.md') f.write_binary(b'problem\n=======\n') assert main([str(f.realpath()), '--assume-in-merge']) == 1 + + f = tmpdir.join('README.md') + f.write_binary(b'problem\n======= \n') + assert main([str(f.realpath()), '--assume-in-merge']) == 1 + + f = tmpdir.join('README.md') + f.write_binary(b'problem\n|||||||\n') + assert main([str(f.realpath()), '--assume-in-merge']) == 1 + + f = tmpdir.join('README.md') + f.write_binary(b'problem\n||||||| \n') + assert main([str(f.realpath()), '--assume-in-merge']) == 1