Unverified Commit 1c7fb212 by Edward Thomson Committed by GitHub

Merge pull request #5466 from pks-t/pks/patch-modechange-with-rename

patch: correctly handle mode changes for renames
parents 85533f37 5f47cb48
...@@ -428,6 +428,9 @@ int git_diff_delta__format_file_header( ...@@ -428,6 +428,9 @@ int git_diff_delta__format_file_header(
git_buf_printf(out, "diff --git %s %s\n", git_buf_printf(out, "diff --git %s %s\n",
old_path.ptr, new_path.ptr); old_path.ptr, new_path.ptr);
if (unchanged && delta->old_file.mode != delta->new_file.mode)
diff_print_modes(out, delta);
if (delta->status == GIT_DELTA_RENAMED || if (delta->status == GIT_DELTA_RENAMED ||
(delta->status == GIT_DELTA_COPIED && unchanged)) { (delta->status == GIT_DELTA_COPIED && unchanged)) {
if ((error = diff_delta_format_similarity_header(out, delta)) < 0) if ((error = diff_delta_format_similarity_header(out, delta)) < 0)
...@@ -444,9 +447,6 @@ int git_diff_delta__format_file_header( ...@@ -444,9 +447,6 @@ int git_diff_delta__format_file_header(
"--- %s\n+++ %s\n", old_path.ptr, new_path.ptr); "--- %s\n+++ %s\n", old_path.ptr, new_path.ptr);
} }
if (unchanged && delta->old_file.mode != delta->new_file.mode)
diff_print_modes(out, delta);
if (git_buf_oom(out)) if (git_buf_oom(out))
error = -1; error = -1;
......
...@@ -411,6 +411,7 @@ static const parse_header_transition transitions[] = { ...@@ -411,6 +411,7 @@ static const parse_header_transition transitions[] = {
{ "GIT binary patch" , STATE_INDEX, STATE_END, NULL }, { "GIT binary patch" , STATE_INDEX, STATE_END, NULL },
{ "Binary files " , STATE_INDEX, STATE_END, NULL }, { "Binary files " , STATE_INDEX, STATE_END, NULL },
{ "similarity index " , STATE_END, STATE_SIMILARITY, parse_header_similarity },
{ "similarity index " , STATE_DIFF, STATE_SIMILARITY, parse_header_similarity }, { "similarity index " , STATE_DIFF, STATE_SIMILARITY, parse_header_similarity },
{ "dissimilarity index ", STATE_DIFF, STATE_SIMILARITY, parse_header_dissimilarity }, { "dissimilarity index ", STATE_DIFF, STATE_SIMILARITY, parse_header_dissimilarity },
{ "rename from " , STATE_SIMILARITY, STATE_RENAME, parse_header_renamefrom }, { "rename from " , STATE_SIMILARITY, STATE_RENAME, parse_header_renamefrom },
......
...@@ -579,6 +579,14 @@ ...@@ -579,6 +579,14 @@
"rename from file.txt\n" \ "rename from file.txt\n" \
"rename to newfile.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 \ #define PATCH_RENAME_SIMILAR \
"diff --git a/file.txt b/newfile.txt\n" \ "diff --git a/file.txt b/newfile.txt\n" \
"similarity index 77%\n" \ "similarity index 77%\n" \
......
...@@ -107,6 +107,12 @@ void test_patch_print__rename_exact(void) ...@@ -107,6 +107,12 @@ void test_patch_print__rename_exact(void)
strlen(PATCH_RENAME_EXACT)); 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) void test_patch_print__rename_similar(void)
{ {
patch_print_from_patchfile(PATCH_RENAME_SIMILAR, patch_print_from_patchfile(PATCH_RENAME_SIMILAR,
......
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