summaryrefslogtreecommitdiff
path: root/tests/patch
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2020-03-26 14:16:41 +0100
committerPatrick Steinhardt <ps@pks.im>2020-03-26 14:21:35 +0100
commit5f47cb48d388279f92d339a5a791040254ee4d1c (patch)
tree5a2b1f7a3a96f12f19044ef52df88883c99d44d8 /tests/patch
parentca782c913b7052712c7a6163c102a01733202ebf (diff)
downloadlibgit2-5f47cb48d388279f92d339a5a791040254ee4d1c.tar.gz
patch: correctly handle mode changes for renames
When generating a patch for a renamed file whose mode bits have changed in addition to the rename, then we currently fail to parse the generated patch. Furthermore, when generating a diff we output mode bits after the similarity metric, which is different to how upstream git handles it. Fix both issues by adding another state transition that allows similarity indices after mode changes and by printing mode changes before the similarity index.
Diffstat (limited to 'tests/patch')
-rw-r--r--tests/patch/patch_common.h8
-rw-r--r--tests/patch/print.c6
2 files changed, 14 insertions, 0 deletions
diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h
index 731524767..1e03889fc 100644
--- a/tests/patch/patch_common.h
+++ b/tests/patch/patch_common.h
@@ -579,6 +579,14 @@
"rename from file.txt\n" \
"rename to newfile.txt\n"
+#define PATCH_RENAME_EXACT_WITH_MODE \
+ "diff --git a/RENAMED.md b/README.md\n" \
+ "old mode 100644\n" \
+ "new mode 100755\n" \
+ "similarity index 100%\n" \
+ "rename from RENAMED.md\n" \
+ "rename to README.md\n"
+
#define PATCH_RENAME_SIMILAR \
"diff --git a/file.txt b/newfile.txt\n" \
"similarity index 77%\n" \
diff --git a/tests/patch/print.c b/tests/patch/print.c
index c4ff479e9..b0a933943 100644
--- a/tests/patch/print.c
+++ b/tests/patch/print.c
@@ -107,6 +107,12 @@ void test_patch_print__rename_exact(void)
strlen(PATCH_RENAME_EXACT));
}
+void test_patch_print__rename_exact_with_mode(void)
+{
+ patch_print_from_patchfile(PATCH_RENAME_EXACT_WITH_MODE,
+ strlen(PATCH_RENAME_EXACT_WITH_MODE));
+}
+
void test_patch_print__rename_similar(void)
{
patch_print_from_patchfile(PATCH_RENAME_SIMILAR,