Skip to content

Commit e5b32bf

Browse files
avargitster
authored andcommitted
rebase: don't override --no-reschedule-failed-exec with config
Fix a bug in how --no-reschedule-failed-exec interacts with rebase.rescheduleFailedExec=true being set in the config. Before this change the --no-reschedule-failed-exec config option would be overridden by the config. This bug happened because of the particulars of how "rebase" works v.s. most other git commands when it comes to parsing options and config: When we read the config and parse the CLI options we correctly prefer the --no-reschedule-failed-exec option over rebase.rescheduleFailedExec=true in the config. So far so good. However the --reschedule-failed-exec option doesn't take effect when the rebase starts (we'd just create a ".git/rebase-merge/reschedule-failed-exec" file if it was true). It only takes effect when the exec command fails, at which point we'll reschedule the failed "exec" command. Since we only wrote out the positive ".git/rebase-merge/reschedule-failed-exec" under --reschedule-failed-exec, but nothing with --no-reschedule-failed-exec we'll forget that we asked not to reschedule failed "exec", and would happily re-read the config and see that rebase.rescheduleFailedExec=true is set. So the config will effectively override the user having explicitly disabled the option on the command-line. Even more confusingly: Since rebase accepts different options based on its state there wasn't even a way to get around this with "rebase --continue --no-reschedule-failed-exec" (but you could of course set the config with "rebase -c ..."). I think the least bad way out of this is to declare that for such options and config whatever we decide at the beginning of the rebase goes. So we'll now always create either a "reschedule-failed-exec" or a "no-reschedule-failed-exec file at the start, not just the former if we decided we wanted the feature. With this new worldview you can no longer change the setting once a rebase has started except by manually removing the state files discussed above. I think making it work like that is the the least confusing thing we can do. In the future we might want to learn to change the setting in the middle by combining "--edit-todo" with "--[no-]reschedule-failed-exec", we currently don't support combining those options, or any other way to change the state in the middle of the rebase short of manually editing the files in ".git/rebase-merge/*". The bug being fixed here originally came about because of a combination of the behavior of the code added in d421afa (rebase: introduce --reschedule-failed-exec, 2018-12-10) and the addition of the config variable in 969de3f (rebase: add a config option to default to --reschedule-failed-exec, 2018-12-10). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cd663df commit e5b32bf

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

Documentation/git-rebase.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,14 @@ See also INCOMPATIBLE OPTIONS below.
622622
--no-reschedule-failed-exec::
623623
Automatically reschedule `exec` commands that failed. This only makes
624624
sense in interactive mode (or when an `--exec` option was provided).
625+
+
626+
Even though this option applies once a rebase is started, it's set for
627+
the whole rebase at the start based on either the
628+
`rebase.rescheduleFailedExec` configuration (see linkgit:git-config[1]
629+
or "CONFIGURATION" below) or whether this option is
630+
provided. Otherwise an explicit `--no-reschedule-failed-exec` at the
631+
start would be overridden by the presence of
632+
`rebase.rescheduleFailedExec=true` configuration.
625633

626634
INCOMPATIBLE OPTIONS
627635
--------------------

sequencer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static GIT_PATH_FUNC(rebase_path_strategy, "rebase-merge/strategy")
164164
static GIT_PATH_FUNC(rebase_path_strategy_opts, "rebase-merge/strategy_opts")
165165
static GIT_PATH_FUNC(rebase_path_allow_rerere_autoupdate, "rebase-merge/allow_rerere_autoupdate")
166166
static GIT_PATH_FUNC(rebase_path_reschedule_failed_exec, "rebase-merge/reschedule-failed-exec")
167+
static GIT_PATH_FUNC(rebase_path_no_reschedule_failed_exec, "rebase-merge/no-reschedule-failed-exec")
167168
static GIT_PATH_FUNC(rebase_path_drop_redundant_commits, "rebase-merge/drop_redundant_commits")
168169
static GIT_PATH_FUNC(rebase_path_keep_redundant_commits, "rebase-merge/keep_redundant_commits")
169170

@@ -2672,6 +2673,8 @@ static int read_populate_opts(struct replay_opts *opts)
26722673

26732674
if (file_exists(rebase_path_reschedule_failed_exec()))
26742675
opts->reschedule_failed_exec = 1;
2676+
else if (file_exists(rebase_path_no_reschedule_failed_exec()))
2677+
opts->reschedule_failed_exec = 0;
26752678

26762679
if (file_exists(rebase_path_drop_redundant_commits()))
26772680
opts->drop_redundant_commits = 1;
@@ -2772,6 +2775,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
27722775
write_file(rebase_path_ignore_date(), "%s", "");
27732776
if (opts->reschedule_failed_exec)
27742777
write_file(rebase_path_reschedule_failed_exec(), "%s", "");
2778+
else
2779+
write_file(rebase_path_no_reschedule_failed_exec(), "%s", "");
27752780

27762781
return 0;
27772782
}

t/t3418-rebase-continue.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,27 @@ test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' '
290290
git rebase HEAD^
291291
'
292292

293+
test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
294+
test_when_finished "git rebase --abort" &&
295+
test_config rebase.rescheduleFailedExec true &&
296+
test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
297+
test_must_fail git rebase --continue 2>err &&
298+
! grep "has been rescheduled" err
299+
'
300+
301+
test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
302+
test_when_finished "git rebase --abort" &&
303+
test_must_fail git rebase -x false HEAD~2 &&
304+
test_config rebase.rescheduleFailedExec true &&
305+
test_must_fail git rebase --continue 2>err &&
306+
! grep "has been rescheduled" err
307+
'
308+
309+
test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' '
310+
test_when_finished "git rebase --abort" &&
311+
test_must_fail git rebase -x false HEAD~2 &&
312+
test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
313+
test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
314+
'
315+
293316
test_done

0 commit comments

Comments
 (0)