am: let command-line options override saved options
When resuming, git-am mistakenly ignores command-line options.
For instance, when a patch fails to apply with "git am patch",
subsequently running "git am --3way" would not cause git-am to fall
back on attempting a threeway merge. This occurs because by default
the --3way option is saved as "false", and the saved am options are
loaded after the command-line options are parsed, thus overwriting
the command-line options when resuming.
Fix this by moving the am_load() function call before parse_options(),
so that command-line options will override the saved am options.
The purpose of supporting this use case is to enable users to "wiggle"
that one conflicting patch. As such, it is expected that the
command-line options do not affect subsequent applied patches. Implement
this by calling am_load() once we apply the conflicting patch
successfully.
Noticed-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff --git a/builtin/am.c b/builtin/am.c
index 1399c8d..f81b74d 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1779,7 +1779,6 @@
if (resume) {
validate_resume_state(state);
- resume = 0;
} else {
int skip;
@@ -1841,6 +1840,10 @@
next:
am_next(state);
+
+ if (resume)
+ am_load(state);
+ resume = 0;
}
if (!is_empty_file(am_path(state, "rewritten"))) {
@@ -1895,6 +1898,7 @@
next:
am_next(state);
+ am_load(state);
am_run(state, 0);
}
@@ -2022,6 +2026,7 @@
die(_("failed to clean index"));
am_next(state);
+ am_load(state);
am_run(state, 0);
}
@@ -2132,6 +2137,7 @@
int keep_cr = -1;
int patch_format = PATCH_FORMAT_UNKNOWN;
enum resume_mode resume = RESUME_FALSE;
+ int in_progress;
const char * const usage[] = {
N_("git am [options] [(<mbox>|<Maildir>)...]"),
@@ -2227,6 +2233,10 @@
am_state_init(&state, git_path("rebase-apply"));
+ in_progress = am_in_progress(&state);
+ if (in_progress)
+ am_load(&state);
+
argc = parse_options(argc, argv, prefix, options, usage, 0);
if (binary >= 0)
@@ -2239,7 +2249,7 @@
if (read_index_preload(&the_index, NULL) < 0)
die(_("failed to read the index"));
- if (am_in_progress(&state)) {
+ if (in_progress) {
/*
* Catch user error to feed us patches when there is a session
* in progress:
@@ -2257,8 +2267,6 @@
if (resume == RESUME_FALSE)
resume = RESUME_APPLY;
-
- am_load(&state);
} else {
struct argv_array paths = ARGV_ARRAY_INIT;
int i;