built-in add -p: implement the "checkout" patch modes

This patch teaches the built-in `git add -p` machinery all the tricks it
needs to know in order to act as the work horse for `git checkout -p`.

Apart from the minor changes (slightly reworded messages, different
`diff` and `apply --check` invocations), it requires a new function to
actually apply the changes, as `git checkout -p` is a bit special in
that respect: when the desired changes do not apply to the index, but
apply to the work tree, Git does not fail straight away, but asks the
user whether to apply the changes to the worktree at least.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin
2019-12-21 21:57:14 +00:00
committed by Junio C Hamano
parent 6610e4628a
commit 52628f94fc
3 changed files with 137 additions and 7 deletions

View File

@ -206,9 +206,10 @@ int run_add_interactive(const char *revision, const char *patch_mode,
mode = ADD_P_STASH;
else if (!strcmp(patch_mode, "--patch=reset"))
mode = ADD_P_RESET;
else if (!strcmp(patch_mode, "--patch=checkout"))
mode = ADD_P_CHECKOUT;
else
die("'%s' not yet supported in the built-in add -p",
patch_mode);
die("'%s' not supported", patch_mode);
return !!run_add_p(the_repository, mode, revision, pathspec);
}