]> git.ipfire.org Git - thirdparty/git.git/blobdiff - apply.c
Merge branch 'cp/apply-core-filemode'
[thirdparty/git.git] / apply.c
diff --git a/apply.c b/apply.c
index 7608e3301ca0727dcfec0a579ed46390afa41ab0..355e2b0f2f0cb848a41a739d797ccec4d044d6b1 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -2219,7 +2219,8 @@ static void reverse_patches(struct patch *p)
                struct fragment *frag = p->fragments;
 
                SWAP(p->new_name, p->old_name);
-               SWAP(p->new_mode, p->old_mode);
+               if (p->new_mode)
+                       SWAP(p->new_mode, p->old_mode);
                SWAP(p->is_new, p->is_delete);
                SWAP(p->lines_added, p->lines_deleted);
                SWAP(p->old_oid_prefix, p->new_oid_prefix);
@@ -3777,8 +3778,17 @@ static int check_preimage(struct apply_state *state,
                return error_errno("%s", old_name);
        }
 
-       if (!state->cached && !previous)
-               st_mode = ce_mode_from_stat(*ce, st->st_mode);
+       if (!state->cached && !previous) {
+               if (*ce && !(*ce)->ce_mode)
+                       BUG("ce_mode == 0 for path '%s'", old_name);
+
+               if (trust_executable_bit)
+                       st_mode = ce_mode_from_stat(*ce, st->st_mode);
+               else if (*ce)
+                       st_mode = (*ce)->ce_mode;
+               else
+                       st_mode = patch->old_mode;
+       }
 
        if (patch->is_new < 0)
                patch->is_new = 0;