Skip to content

Commit 0de3a73

Browse files
committed
Merge branch 'js/rebase-r-and-merge-head'
Bugfix for the recently graduated "git rebase --rebase-merges". * js/rebase-r-and-merge-head: status: rebase and merge can be in progress at the same time built-in rebase --skip/--abort: clean up stale .git/<name> files rebase -i: include MERGE_HEAD into files to clean up rebase -r: do not write MERGE_HEAD unless needed rebase -r: demonstrate bug with conflicting merges
2 parents bda53f4 + 982288e commit 0de3a73

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

builtin/rebase.c

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "revision.h"
2424
#include "commit-reach.h"
2525
#include "rerere.h"
26+
#include "branch.h"
2627

2728
static char const * const builtin_rebase_usage[] = {
2829
N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] "
@@ -1021,6 +1022,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10211022
if (reset_head(NULL, "reset", NULL, RESET_HEAD_HARD,
10221023
NULL, NULL) < 0)
10231024
die(_("could not discard worktree changes"));
1025+
remove_branch_state();
10241026
if (read_basic_state(&options))
10251027
exit(1);
10261028
goto run_rebase;
@@ -1039,6 +1041,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10391041
NULL, NULL) < 0)
10401042
die(_("could not move back to %s"),
10411043
oid_to_hex(&options.orig_head));
1044+
remove_branch_state();
10421045
ret = finish_rebase(&options);
10431046
goto cleanup;
10441047
}

sequencer.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -3244,10 +3244,6 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
32443244
}
32453245

32463246
merge_commit = to_merge->item;
3247-
write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
3248-
git_path_merge_head(the_repository), 0);
3249-
write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
3250-
32513247
bases = get_merge_bases(head_commit, merge_commit);
32523248
if (bases && oideq(&merge_commit->object.oid,
32533249
&bases->item->object.oid)) {
@@ -3256,6 +3252,10 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
32563252
goto leave_merge;
32573253
}
32583254

3255+
write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
3256+
git_path_merge_head(the_repository), 0);
3257+
write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
3258+
32593259
for (j = bases; j; j = j->next)
32603260
commit_list_insert(j->item, &reversed);
32613261
free_commit_list(bases);
@@ -3512,6 +3512,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
35123512
unlink(rebase_path_author_script());
35133513
unlink(rebase_path_stopped_sha());
35143514
unlink(rebase_path_amend());
3515+
unlink(git_path_merge_head(the_repository));
35153516
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
35163517

35173518
if (item->command == TODO_BREAK)
@@ -3882,6 +3883,7 @@ static int commit_staged_changes(struct replay_opts *opts,
38823883
opts, flags))
38833884
return error(_("could not commit staged changes."));
38843885
unlink(rebase_path_amend());
3886+
unlink(git_path_merge_head(the_repository));
38853887
if (final_fixup) {
38863888
unlink(rebase_path_fixup_msg());
38873889
unlink(rebase_path_squash_msg());

t/t3430-rebase-merges.sh

+16
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,20 @@ test_expect_success 'with --autosquash and --exec' '
396396
grep "G: +G" actual
397397
'
398398

399+
test_expect_success '--continue after resolving conflicts after a merge' '
400+
git checkout -b already-has-g E &&
401+
git cherry-pick E..G &&
402+
test_commit H2 &&
403+
404+
git checkout -b conflicts-in-merge H &&
405+
test_commit H2 H2.t conflicts H2-conflict &&
406+
test_must_fail git rebase -r already-has-g &&
407+
grep conflicts H2.t &&
408+
echo resolved >H2.t &&
409+
git add -u &&
410+
git rebase --continue &&
411+
test_must_fail git rev-parse --verify HEAD^2 &&
412+
test_path_is_missing .git/MERGE_HEAD
413+
'
414+
399415
test_done

wt-status.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,7 @@ void wt_status_get_state(struct wt_status_state *state,
15591559
struct object_id oid;
15601560

15611561
if (!stat(git_path_merge_head(the_repository), &st)) {
1562+
wt_status_check_rebase(NULL, state);
15621563
state->merge_in_progress = 1;
15631564
} else if (wt_status_check_rebase(NULL, state)) {
15641565
; /* all set */
@@ -1583,9 +1584,13 @@ static void wt_longstatus_print_state(struct wt_status *s)
15831584
const char *state_color = color(WT_STATUS_HEADER, s);
15841585
struct wt_status_state *state = &s->state;
15851586

1586-
if (state->merge_in_progress)
1587+
if (state->merge_in_progress) {
1588+
if (state->rebase_interactive_in_progress) {
1589+
show_rebase_information(s, state_color);
1590+
fputs("\n", s->fp);
1591+
}
15871592
show_merge_in_progress(s, state_color);
1588-
else if (state->am_in_progress)
1593+
} else if (state->am_in_progress)
15891594
show_am_in_progress(s, state_color);
15901595
else if (state->rebase_in_progress || state->rebase_interactive_in_progress)
15911596
show_rebase_in_progress(s, state_color);

0 commit comments

Comments
 (0)