mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
Merge branch 'tr/am--no-verify'
Conditionally skip the pre-applypatch and applypatch-msg hooks when applying patches with 'git am'. * tr/am--no-verify: am: allow passing --no-verify flag
This commit is contained in:
commit
b242e89dff
|
@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
[verse]
|
[verse]
|
||||||
'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]
|
'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] [--no-verify]
|
||||||
[--[no-]3way] [--interactive] [--committer-date-is-author-date]
|
[--[no-]3way] [--interactive] [--committer-date-is-author-date]
|
||||||
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
|
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
|
||||||
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
|
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
|
||||||
|
@ -138,6 +138,12 @@ include::rerere-options.txt[]
|
||||||
--interactive::
|
--interactive::
|
||||||
Run interactively.
|
Run interactively.
|
||||||
|
|
||||||
|
-n::
|
||||||
|
--no-verify::
|
||||||
|
By default, the pre-applypatch and applypatch-msg hooks are run.
|
||||||
|
When any of `--no-verify` or `-n` is given, these are bypassed.
|
||||||
|
See also linkgit:githooks[5].
|
||||||
|
|
||||||
--committer-date-is-author-date::
|
--committer-date-is-author-date::
|
||||||
By default the command records the date from the e-mail
|
By default the command records the date from the e-mail
|
||||||
message as the commit author date, and uses the time of
|
message as the commit author date, and uses the time of
|
||||||
|
|
11
builtin/am.c
11
builtin/am.c
|
@ -117,6 +117,7 @@ struct am_state {
|
||||||
|
|
||||||
/* various operating modes and command line options */
|
/* various operating modes and command line options */
|
||||||
int interactive;
|
int interactive;
|
||||||
|
int no_verify;
|
||||||
int threeway;
|
int threeway;
|
||||||
int quiet;
|
int quiet;
|
||||||
int signoff; /* enum signoff_type */
|
int signoff; /* enum signoff_type */
|
||||||
|
@ -472,10 +473,12 @@ static void am_destroy(const struct am_state *state)
|
||||||
*/
|
*/
|
||||||
static int run_applypatch_msg_hook(struct am_state *state)
|
static int run_applypatch_msg_hook(struct am_state *state)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
assert(state->msg);
|
assert(state->msg);
|
||||||
ret = run_hooks_l("applypatch-msg", am_path(state, "final-commit"), NULL);
|
|
||||||
|
if (!state->no_verify)
|
||||||
|
ret = run_hooks_l("applypatch-msg", am_path(state, "final-commit"), NULL);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
FREE_AND_NULL(state->msg);
|
FREE_AND_NULL(state->msg);
|
||||||
|
@ -1650,7 +1653,7 @@ static void do_commit(const struct am_state *state)
|
||||||
const char *reflog_msg, *author, *committer = NULL;
|
const char *reflog_msg, *author, *committer = NULL;
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
|
|
||||||
if (run_hooks("pre-applypatch"))
|
if (!state->no_verify && run_hooks("pre-applypatch"))
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
if (write_cache_as_tree(&tree, 0, NULL))
|
if (write_cache_as_tree(&tree, 0, NULL))
|
||||||
|
@ -2340,6 +2343,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
OPT_BOOL('i', "interactive", &state.interactive,
|
OPT_BOOL('i', "interactive", &state.interactive,
|
||||||
N_("run interactively")),
|
N_("run interactively")),
|
||||||
|
OPT_BOOL('n', "no-verify", &state.no_verify,
|
||||||
|
N_("bypass pre-applypatch and applypatch-msg hooks")),
|
||||||
OPT_HIDDEN_BOOL('b', "binary", &binary,
|
OPT_HIDDEN_BOOL('b', "binary", &binary,
|
||||||
N_("historical option -- no-op")),
|
N_("historical option -- no-op")),
|
||||||
OPT_BOOL('3', "3way", &state.threeway,
|
OPT_BOOL('3', "3way", &state.threeway,
|
||||||
|
|
|
@ -345,6 +345,21 @@ test_expect_success 'am with failing applypatch-msg hook' '
|
||||||
test_cmp_rev first HEAD
|
test_cmp_rev first HEAD
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'am with failing applypatch-msg hook (no verify)' '
|
||||||
|
rm -fr .git/rebase-apply &&
|
||||||
|
git reset --hard &&
|
||||||
|
git checkout first &&
|
||||||
|
test_hook applypatch-msg <<-\EOF &&
|
||||||
|
echo hook-message >"$1"
|
||||||
|
exit 1
|
||||||
|
EOF
|
||||||
|
git am --no-verify patch1 &&
|
||||||
|
test_path_is_missing .git/rebase-apply &&
|
||||||
|
git diff --exit-code second &&
|
||||||
|
git log -1 --format=format:%B >actual &&
|
||||||
|
test_cmp msg actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'am with pre-applypatch hook' '
|
test_expect_success 'am with pre-applypatch hook' '
|
||||||
rm -fr .git/rebase-apply &&
|
rm -fr .git/rebase-apply &&
|
||||||
git reset --hard &&
|
git reset --hard &&
|
||||||
|
@ -374,6 +389,23 @@ test_expect_success 'am with failing pre-applypatch hook' '
|
||||||
test_cmp_rev first HEAD
|
test_cmp_rev first HEAD
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'am with failing pre-applypatch hook (no verify)' '
|
||||||
|
rm -fr .git/rebase-apply &&
|
||||||
|
git reset --hard &&
|
||||||
|
git checkout first &&
|
||||||
|
touch empty-file &&
|
||||||
|
test_hook pre-applypatch <<-\EOF &&
|
||||||
|
rm empty-file
|
||||||
|
exit 1
|
||||||
|
EOF
|
||||||
|
git am --no-verify patch1 &&
|
||||||
|
test_path_is_missing .git/rebase-apply &&
|
||||||
|
test_path_is_file empty-file &&
|
||||||
|
git diff --exit-code second &&
|
||||||
|
git log -1 --format=format:%B >actual &&
|
||||||
|
test_cmp msg actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'am with post-applypatch hook' '
|
test_expect_success 'am with post-applypatch hook' '
|
||||||
rm -fr .git/rebase-apply &&
|
rm -fr .git/rebase-apply &&
|
||||||
git reset --hard &&
|
git reset --hard &&
|
||||||
|
|
Loading…
Reference in a new issue