summaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
authorJerry Zhang <jerry@skydio.com>2021-12-13 22:03:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-12-13 22:30:25 (GMT)
commit324eb77ee76277be99bdc54ef0b74ff30f5f567b (patch)
treed9eecb504b5d4c671fe2cde24a7110b53de5b632 /apply.c
parentc21b8ae857d0d58b67ca77384ccc1880d834c2d5 (diff)
downloadgit-324eb77ee76277be99bdc54ef0b74ff30f5f567b.zip
git-324eb77ee76277be99bdc54ef0b74ff30f5f567b.tar.gz
git-324eb77ee76277be99bdc54ef0b74ff30f5f567b.tar.bz2
git-apply: add --allow-empty flag
Some users or scripts will pipe "git diff" output to "git apply" when replaying diffs or commits. In these cases, they will rely on the return value of "git apply" to know whether the diff was applied successfully. However, for empty commits, "git apply" will fail. This complicates scripts since they have to either buffer the diff and check its length, or run diff again with "exit-code", essentially doing the diff twice. Add the "--allow-empty" flag to "git apply" which allows it to handle both empty diffs and empty commits created by "git format-patch --always" by doing nothing and returning 0. Add tests for both with and without --allow-empty. Signed-off-by: Jerry Zhang <jerry@skydio.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/apply.c b/apply.c
index 0392f42..fed1952 100644
--- a/apply.c
+++ b/apply.c
@@ -4752,8 +4752,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;
}
@@ -5081,6 +5083,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()
};