зеркало из https://github.com/microsoft/git.git
am: let --signoff override --no-signoff
After resolving a conflicting patch, a user may wish to sign off the patch to declare that the patch has been modified. As such, the user will expect that running "git am --signoff --continue" will append the signoff to the commit message. However, the --signoff option is only taken into account during the mail-parsing stage. If the --signoff option is set, then the signoff will be appended to the commit message. Since the mail-parsing stage comes before the patch application stage, the --signoff option, if provided on the command-line when resuming, will have no effect at all. We cannot move the append_signoff() call to the patch application stage as the applypatch-msg hook and interactive mode, which run before patch application, may expect the signoff to be there. Fix this by taking note if the user explictly set the --signoff option on the command-line, and append the signoff to the commit message when resuming if so. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
852a171018
Коммит
b5e823594c
28
builtin/am.c
28
builtin/am.c
|
@ -98,6 +98,12 @@ enum scissors_type {
|
|||
SCISSORS_TRUE /* pass --scissors to git-mailinfo */
|
||||
};
|
||||
|
||||
enum signoff_type {
|
||||
SIGNOFF_FALSE = 0,
|
||||
SIGNOFF_TRUE = 1,
|
||||
SIGNOFF_EXPLICIT /* --signoff was set on the command-line */
|
||||
};
|
||||
|
||||
struct am_state {
|
||||
/* state directory path */
|
||||
char *dir;
|
||||
|
@ -123,7 +129,7 @@ struct am_state {
|
|||
int interactive;
|
||||
int threeway;
|
||||
int quiet;
|
||||
int signoff;
|
||||
int signoff; /* enum signoff_type */
|
||||
int utf8;
|
||||
int keep; /* enum keep_type */
|
||||
int message_id;
|
||||
|
@ -1185,6 +1191,18 @@ static void NORETURN die_user_resolve(const struct am_state *state)
|
|||
exit(128);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends signoff to the "msg" field of the am_state.
|
||||
*/
|
||||
static void am_append_signoff(struct am_state *state)
|
||||
{
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
|
||||
strbuf_attach(&sb, state->msg, state->msg_len, state->msg_len);
|
||||
append_signoff(&sb, 0, 0);
|
||||
state->msg = strbuf_detach(&sb, &state->msg_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses `mail` using git-mailinfo, extracting its patch and authorship info.
|
||||
* state->msg will be set to the patch message. state->author_name,
|
||||
|
@ -2153,8 +2171,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
|
|||
OPT_BOOL('3', "3way", &state.threeway,
|
||||
N_("allow fall back on 3way merging if needed")),
|
||||
OPT__QUIET(&state.quiet, N_("be quiet")),
|
||||
OPT_BOOL('s', "signoff", &state.signoff,
|
||||
N_("add a Signed-off-by line to the commit message")),
|
||||
OPT_SET_INT('s', "signoff", &state.signoff,
|
||||
N_("add a Signed-off-by line to the commit message"),
|
||||
SIGNOFF_EXPLICIT),
|
||||
OPT_BOOL('u', "utf8", &state.utf8,
|
||||
N_("recode into utf8 (default)")),
|
||||
OPT_SET_INT('k', "keep", &state.keep,
|
||||
|
@ -2267,6 +2286,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
|
|||
|
||||
if (resume == RESUME_FALSE)
|
||||
resume = RESUME_APPLY;
|
||||
|
||||
if (state.signoff == SIGNOFF_EXPLICIT)
|
||||
am_append_signoff(&state);
|
||||
} else {
|
||||
struct argv_array paths = ARGV_ARRAY_INIT;
|
||||
int i;
|
||||
|
|
|
@ -64,6 +64,26 @@ test_expect_success '--no-quiet overrides --quiet' '
|
|||
test_i18ncmp expected out
|
||||
'
|
||||
|
||||
test_expect_success '--signoff overrides --no-signoff' '
|
||||
rm -fr .git/rebase-apply &&
|
||||
git reset --hard &&
|
||||
git checkout first &&
|
||||
|
||||
test_must_fail git am --no-signoff side[12].eml &&
|
||||
test_path_is_dir .git/rebase-apply &&
|
||||
echo side1 >file &&
|
||||
git add file &&
|
||||
git am --signoff --continue &&
|
||||
|
||||
# Applied side1 will be signed off
|
||||
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
|
||||
git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
|
||||
test_cmp expected actual &&
|
||||
|
||||
# Applied side2 will not be signed off
|
||||
test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
|
||||
'
|
||||
|
||||
test_expect_success TTY '--reject overrides --no-reject' '
|
||||
rm -fr .git/rebase-apply &&
|
||||
git reset --hard &&
|
||||
|
|
Загрузка…
Ссылка в новой задаче