]> git.ipfire.org Git - thirdparty/git.git/commit - apply.h
git-apply: add --allow-empty flag
authorJerry Zhang <jerry@skydio.com>
Mon, 13 Dec 2021 22:03:27 +0000 (14:03 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2021 22:30:25 +0000 (14:30 -0800)
commit324eb77ee76277be99bdc54ef0b74ff30f5f567b
treed9eecb504b5d4c671fe2cde24a7110b53de5b632
parentc21b8ae857d0d58b67ca77384ccc1880d834c2d5
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>
Documentation/git-apply.txt
apply.c
apply.h
t/t4126-apply-empty.sh