Commit bd682f3e by Edward Thomson

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.
parent a3c1070c
......@@ -319,6 +319,31 @@
" Put into a pot three quarts of water, three onions cut small, one\n" \
" spoonful of black pepper pounded, and two of salt, with two or three\n"
#define DIFF_RENAME_AFTER_MODIFY \
"diff --git a/veal.txt b/veal.txt\n" \
"index 292cb60..61c686b 100644\n" \
"--- a/veal.txt\n" \
"+++ b/veal.txt\n" \
"@@ -1,4 +1,4 @@\n" \
"-VEAL SOUP!\n" \
"+VEAL SOUP\n" \
"\n" \
" Put into a pot three quarts of water, three onions cut small, one\n" \
" spoonful of black pepper pounded, and two of salt, with two or three\n" \
"diff --git a/veal.txt b/beef.txt\n" \
"similarity index 96%\n" \
"rename from veal.txt\n" \
"rename to beef.txt\n" \
"index 94d2c01..292cb60 100644\n" \
"--- a/veal.txt\n" \
"+++ b/beef.txt\n" \
"@@ -15,4 +15,4 @@ will curdle in the soup. For a change you may put a dozen ripe tomatos\n" \
" in, first taking off their skins, by letting them stand a few minutes in\n" \
" hot water, when they may be easily peeled. When made in this way you\n" \
" must thicken it with the flour only. Any part of the veal may be used,\n" \
"-but the shin or knuckle is the nicest.\n" \
"+but the shin or knuckle is the nicest!\n"
struct iterator_compare_data {
struct merge_index_entry *expected;
size_t cnt;
......
......@@ -650,3 +650,14 @@ void test_apply_both__rename_and_modify_deltas(void)
git_diff_free(diff);
}
void test_apply_both__cant_rename_after_modify(void)
{
git_diff *diff;
cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_AFTER_MODIFY,
strlen(DIFF_RENAME_AFTER_MODIFY)));
cl_git_fail(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
git_diff_free(diff);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment