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>
This commit is contained in:

committed by
Junio C Hamano

parent
c21b8ae857
commit
324eb77ee7
@ -16,7 +16,7 @@ SYNOPSIS
|
||||
[--ignore-space-change | --ignore-whitespace]
|
||||
[--whitespace=(nowarn|warn|fix|error|error-all)]
|
||||
[--exclude=<path>] [--include=<path>] [--directory=<root>]
|
||||
[--verbose | --quiet] [--unsafe-paths] [<patch>...]
|
||||
[--verbose | --quiet] [--unsafe-paths] [--allow-empty] [<patch>...]
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
@ -256,6 +256,10 @@ When `git apply` is used as a "better GNU patch", the user can pass
|
||||
the `--unsafe-paths` option to override this safety check. This option
|
||||
has no effect when `--index` or `--cached` is in use.
|
||||
|
||||
--allow-empty::
|
||||
Don't return error for patches containing no diff. This includes
|
||||
empty patches and patches with commit text only.
|
||||
|
||||
CONFIGURATION
|
||||
-------------
|
||||
|
||||
|
Reference in New Issue
Block a user