Skip to content

Commit f950026

Browse files
newrengitster
authored andcommitted
fast-rebase: write conflict state to working tree, index, and HEAD
Previously, when fast-rebase hit a conflict, it simply aborted and left HEAD, the index, and the working tree where they were before the operation started. While fast-rebase does not support restarting from a conflicted state, write the conflicted state out anyway as it gives us a way to see what the conflicts are and write tests that check for them. This will be important in the upcoming commits, because sequencer.c is only superficially integrated with merge-ort.c; in particular, it calls merge_switch_to_result() after EACH merge instead of only calling it at the end of all the sequence of merges (or when a conflict is hit). This not only causes needless updates to the working copy and index, but also causes all intermediate data to be freed and tossed, preventing caching information from one merge to the next. However, integrating sequencer.c more deeply with merge-ort.c is a big task, and making this small extension to fast-rebase.c provides us with a simple way to test the edge and corner cases that we want to make sure continue working. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent caba91c commit f950026

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

t/helper/test-fast-rebase.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ int cmd__fast_rebase(int argc, const char **argv)
9191
struct commit *last_commit = NULL, *last_picked_commit = NULL;
9292
struct object_id head;
9393
struct lock_file lock = LOCK_INIT;
94-
int clean = 1;
9594
struct strvec rev_walk_args = STRVEC_INIT;
9695
struct rev_info revs;
9796
struct commit *commit;
@@ -176,11 +175,10 @@ int cmd__fast_rebase(int argc, const char **argv)
176175
free((char*)merge_opt.ancestor);
177176
merge_opt.ancestor = NULL;
178177
if (!result.clean)
179-
die("Aborting: Hit a conflict and restarting is not implemented.");
178+
break;
180179
last_picked_commit = commit;
181180
last_commit = create_commit(result.tree, commit, last_commit);
182181
}
183-
fprintf(stderr, "\nDone.\n");
184182
/* TODO: There should be some kind of rev_info_free(&revs) call... */
185183
memset(&revs, 0, sizeof(revs));
186184

@@ -189,24 +187,39 @@ int cmd__fast_rebase(int argc, const char **argv)
189187
if (result.clean < 0)
190188
exit(128);
191189

192-
strbuf_addf(&reflog_msg, "finish rebase %s onto %s",
193-
oid_to_hex(&last_picked_commit->object.oid),
194-
oid_to_hex(&last_commit->object.oid));
195-
if (update_ref(reflog_msg.buf, branch_name.buf,
196-
&last_commit->object.oid,
197-
&last_picked_commit->object.oid,
198-
REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
199-
error(_("could not update %s"), argv[4]);
200-
die("Failed to update %s", argv[4]);
190+
if (result.clean) {
191+
fprintf(stderr, "\nDone.\n");
192+
strbuf_addf(&reflog_msg, "finish rebase %s onto %s",
193+
oid_to_hex(&last_picked_commit->object.oid),
194+
oid_to_hex(&last_commit->object.oid));
195+
if (update_ref(reflog_msg.buf, branch_name.buf,
196+
&last_commit->object.oid,
197+
&last_picked_commit->object.oid,
198+
REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
199+
error(_("could not update %s"), argv[4]);
200+
die("Failed to update %s", argv[4]);
201+
}
202+
if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0)
203+
die(_("unable to update HEAD"));
204+
strbuf_release(&reflog_msg);
205+
strbuf_release(&branch_name);
206+
207+
prime_cache_tree(the_repository, the_repository->index,
208+
result.tree);
209+
} else {
210+
fprintf(stderr, "\nAborting: Hit a conflict.\n");
211+
strbuf_addf(&reflog_msg, "rebase progress up to %s",
212+
oid_to_hex(&last_picked_commit->object.oid));
213+
if (update_ref(reflog_msg.buf, "HEAD",
214+
&last_commit->object.oid,
215+
&head,
216+
REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
217+
error(_("could not update %s"), argv[4]);
218+
die("Failed to update %s", argv[4]);
219+
}
201220
}
202-
if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0)
203-
die(_("unable to update HEAD"));
204-
strbuf_release(&reflog_msg);
205-
strbuf_release(&branch_name);
206-
207-
prime_cache_tree(the_repository, the_repository->index, result.tree);
208221
if (write_locked_index(&the_index, &lock,
209222
COMMIT_LOCK | SKIP_IF_UNCHANGED))
210223
die(_("unable to write %s"), get_index_file());
211-
return (clean == 0);
224+
return (result.clean == 0);
212225
}

0 commit comments

Comments
 (0)