]> git.ipfire.org Git - thirdparty/git.git/blobdiff - apply.c
Merge branch 'rs/apply-symlinks-use-strset'
[thirdparty/git.git] / apply.c
diff --git a/apply.c b/apply.c
index 99f76b59378851042ac87edf03b354dfeb6a551c..f66d48ba2f3070822fa9f78bd6d90e41427bc075 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -135,10 +135,10 @@ int check_apply_state(struct apply_state *state, int force_apply)
        int is_not_gitdir = !startup_info->have_repository;
 
        if (state->apply_with_reject && state->threeway)
-               return error(_("--reject and --3way cannot be used together."));
+               return error(_("options '%s' and '%s' cannot be used together"), "--reject", "--3way");
        if (state->threeway) {
                if (is_not_gitdir)
-                       return error(_("--3way outside a repository"));
+                       return error(_("'%s' outside a repository"), "--3way");
                state->check_index = 1;
        }
        if (state->apply_with_reject) {
@@ -149,10 +149,10 @@ int check_apply_state(struct apply_state *state, int force_apply)
        if (!force_apply && (state->diffstat || state->numstat || state->summary || state->check || state->fake_ancestor))
                state->apply = 0;
        if (state->check_index && is_not_gitdir)
-               return error(_("--index outside a repository"));
+               return error(_("'%s' outside a repository"), "--index");
        if (state->cached) {
                if (is_not_gitdir)
-                       return error(_("--cached outside a repository"));
+                       return error(_("'%s' outside a repository"), "--cached");
                state->check_index = 1;
        }
        if (state->ita_only && (state->check_index || is_not_gitdir))
@@ -3584,7 +3584,9 @@ static int try_threeway(struct apply_state *state,
 
        /* No point falling back to 3-way merge in these cases */
        if (patch->is_delete ||
-           S_ISGITLINK(patch->old_mode) || S_ISGITLINK(patch->new_mode))
+           S_ISGITLINK(patch->old_mode) || S_ISGITLINK(patch->new_mode) ||
+           (patch->is_new && !patch->direct_to_threeway) ||
+           (patch->is_rename && !patch->lines_added && !patch->lines_deleted))
                return -1;
 
        /* Preimage the patch was prepared for */
@@ -4726,8 +4728,10 @@ static int apply_patch(struct apply_state *state,
        }
 
        if (!list && !skipped_patch) {
-               error(_("unrecognized input"));
-               res = -128;
+               if (!state->allow_empty) {
+                       error(_("No valid patches in input (allow with \"--allow-empty\")"));
+                       res = -128;
+               }
                goto end;
        }
 
@@ -5045,7 +5049,7 @@ int apply_parse_options(int argc, const char **argv,
                        N_("leave the rejected hunks in corresponding *.rej files")),
                OPT_BOOL(0, "allow-overlap", &state->allow_overlap,
                        N_("allow overlapping hunks")),
-               OPT__VERBOSE(&state->apply_verbosity, N_("be verbose")),
+               OPT__VERBOSITY(&state->apply_verbosity),
                OPT_BIT(0, "inaccurate-eof", options,
                        N_("tolerate incorrectly detected missing new-line at the end of file"),
                        APPLY_OPT_INACCURATE_EOF),
@@ -5055,6 +5059,8 @@ int apply_parse_options(int argc, const char **argv,
                OPT_CALLBACK(0, "directory", state, N_("root"),
                        N_("prepend <root> to all filenames"),
                        apply_option_parse_directory),
+               OPT_BOOL(0, "allow-empty", &state->allow_empty,
+                       N_("don't return error for empty patches")),
                OPT_END()
        };