Skip to content

Commit 7c5585f

Browse files
newrengitster
authored andcommitted
Tighten and correct a few testcases for merging and cherry-picking
t3501 had a testcase originally added in 05f2dfb (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 30fd3a5 (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 <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2512f15 commit 7c5585f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

t/t3501-revert-cherry-pick.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ test_expect_success 'cherry-pick "-" works with arguments' '
141141
test_cmp expect actual
142142
'
143143

144-
test_expect_success 'cherry-pick works with dirty renamed file' '
144+
test_expect_failure 'cherry-pick works with dirty renamed file' '
145145
test_commit to-rename &&
146146
git checkout -b unrelated &&
147147
test_commit unrelated &&
@@ -150,7 +150,10 @@ test_expect_success 'cherry-pick works with dirty renamed file' '
150150
test_tick &&
151151
git commit -m renamed &&
152152
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
154157
'
155158

156159
test_done

t/t7607-merge-overwrite.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ test_expect_failure 'will not overwrite unstaged changes in renamed file' '
9797
git mv c1.c other.c &&
9898
git commit -m rename &&
9999
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) &&
101104
test_cmp important other.c
102105
'
103106

0 commit comments

Comments
 (0)