summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-11-04 19:01:57 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2018-11-05 15:53:59 +0000
commitbd682f3ee4bc6593470d65f69a0e734fd0ae88eb (patch)
tree807b9e3a7866be28acd4a66f59dd33981093331d
parenta3c1070c6e9f021f1fbd651bb273caaeefa726e2 (diff)
downloadlibgit2-bd682f3ee4bc6593470d65f69a0e734fd0ae88eb.tar.gz
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.
-rw-r--r--tests/apply/apply_helpers.h25
-rw-r--r--tests/apply/both.c11
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/apply/apply_helpers.h b/tests/apply/apply_helpers.h
index 982e731a3..90c1942ab 100644
--- a/tests/apply/apply_helpers.h
+++ b/tests/apply/apply_helpers.h
@@ -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;
diff --git a/tests/apply/both.c b/tests/apply/both.c
index 7ad5bd809..91b9b42b5 100644
--- a/tests/apply/both.c
+++ b/tests/apply/both.c
@@ -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);
+}