Skip to content

Commit bd682f3

Browse files
committed
apply: test that we can't rename a file after modifying it
Multiple deltas can exist in a diff, and can be applied in-order. However if there exists a delta that renames a file, it must be first, so that other deltas can reference the resulting target file. git enforces this (`error: already exists in index`), so ensure that we do, too.
1 parent a3c1070 commit bd682f3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/apply/apply_helpers.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,31 @@
319319
" Put into a pot three quarts of water, three onions cut small, one\n" \
320320
" spoonful of black pepper pounded, and two of salt, with two or three\n"
321321

322+
#define DIFF_RENAME_AFTER_MODIFY \
323+
"diff --git a/veal.txt b/veal.txt\n" \
324+
"index 292cb60..61c686b 100644\n" \
325+
"--- a/veal.txt\n" \
326+
"+++ b/veal.txt\n" \
327+
"@@ -1,4 +1,4 @@\n" \
328+
"-VEAL SOUP!\n" \
329+
"+VEAL SOUP\n" \
330+
"\n" \
331+
" Put into a pot three quarts of water, three onions cut small, one\n" \
332+
" spoonful of black pepper pounded, and two of salt, with two or three\n" \
333+
"diff --git a/veal.txt b/beef.txt\n" \
334+
"similarity index 96%\n" \
335+
"rename from veal.txt\n" \
336+
"rename to beef.txt\n" \
337+
"index 94d2c01..292cb60 100644\n" \
338+
"--- a/veal.txt\n" \
339+
"+++ b/beef.txt\n" \
340+
"@@ -15,4 +15,4 @@ will curdle in the soup. For a change you may put a dozen ripe tomatos\n" \
341+
" in, first taking off their skins, by letting them stand a few minutes in\n" \
342+
" hot water, when they may be easily peeled. When made in this way you\n" \
343+
" must thicken it with the flour only. Any part of the veal may be used,\n" \
344+
"-but the shin or knuckle is the nicest.\n" \
345+
"+but the shin or knuckle is the nicest!\n"
346+
322347
struct iterator_compare_data {
323348
struct merge_index_entry *expected;
324349
size_t cnt;

tests/apply/both.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,14 @@ void test_apply_both__rename_and_modify_deltas(void)
650650

651651
git_diff_free(diff);
652652
}
653+
654+
void test_apply_both__cant_rename_after_modify(void)
655+
{
656+
git_diff *diff;
657+
658+
cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_AFTER_MODIFY,
659+
strlen(DIFF_RENAME_AFTER_MODIFY)));
660+
cl_git_fail(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
661+
662+
git_diff_free(diff);
663+
}

0 commit comments

Comments
 (0)