Tighten and correct a few testcases for merging and cherry-picking

t3501 had a testcase originally added in 05f2dfb965 (cherry-pick: demonstrate a segmentation fault, 2016-11-26) to ensure cherry-pick wouldn't segfault when working with a dirty file involved in a rename. While the segfault was fixed, there was another problem this test demonstrated: namely, that git would overwrite a dirty file involved in a rename. Further, the test encoded a "successful merge" and overwriting of this file as correct behavior. Modify the test so that it would still catch the segfault, but to require the correct behavior. Mark it as test_expect_failure for now too, since this second bug is not yet fixed. t7607 had a test added in 30fd3a5425 (merge overwrites unstaged changes in renamed file, 2012-04-15) specific to looking for a merge overwriting a dirty file involved in a rename, but it too actually encoded what I would term incorrect behavior: it expected the merge to succeed. Fix that, and add a few more checks to make sure that the merge really does produce the expected results. Reviewed-By: Stefan Beller <sbeller@google.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Jan 5, 2018 at 12:19 UTC 7c5585ff488638a3754368f090ad6b6576c6714b
2 files changed +9 -3
t/t3501-revert-cherry-pick.sh
+5 -2
@@ -141,7 +141,7 @@ test_expect_success 'cherry-pick "-" works with arguments' '
141 test_cmp expect actual
142 '
143
144 -test_expect_success 'cherry-pick works with dirty renamed file' '
144 +test_expect_failure 'cherry-pick works with dirty renamed file' '
145 test_commit to-rename &&
146 git checkout -b unrelated &&
147 test_commit unrelated &&
@@ -150,7 +150,10 @@ test_expect_success 'cherry-pick works with dirty renamed file' '
150 test_tick &&
151 git commit -m renamed &&
152 echo modified >renamed &&
153 - git cherry-pick refs/heads/unrelated
153 + test_must_fail git cherry-pick refs/heads/unrelated >out &&
154 + test_i18ngrep "Refusing to lose dirty file at renamed" out &&
155 + test $(git rev-parse :0:renamed) = $(git rev-parse HEAD^:to-rename.t) &&
156 + grep -q "^modified$" renamed
157 '
158
159 test_done
t/t7607-merge-overwrite.sh
+4 -1
@@ -97,7 +97,10 @@ test_expect_failure 'will not overwrite unstaged changes in renamed file' '
97 git mv c1.c other.c &&
98 git commit -m rename &&
99 cp important other.c &&
100 - git merge c1a &&
100 + test_must_fail git merge c1a >out &&
101 + test_i18ngrep "Refusing to lose dirty file at other.c" out &&
102 + test_path_is_file other.c~HEAD &&
103 + test $(git hash-object other.c~HEAD) = $(git rev-parse c1a:c1.c) &&
104 test_cmp important other.c
105 '
106