Skip to content

Commit 5291828

Browse files
newrengitster
authored andcommitted
merge-ort: write $GIT_DIR/AUTO_MERGE whenever we hit a conflict
There are a variety of questions users might ask while resolving conflicts: * What changes have been made since the previous (first) parent? * What changes are staged? * What is still unstaged? (or what is still conflicted?) * What changes did I make to resolve conflicts so far? The first three of these have simple answers: * git diff HEAD * git diff --cached * git diff There was no way to answer the final question previously. Adding one is trivial in merge-ort, since it works by creating a tree representing what should be written to the working copy complete with conflict markers. Simply write that tree to .git/AUTO_MERGE, allowing users to answer the fourth question with * git diff AUTO_MERGE I avoided using a name like "MERGE_AUTO", because that would be merge-specific (much like MERGE_HEAD, REBASE_HEAD, REVERT_HEAD, CHERRY_PICK_HEAD) and I wanted a name that didn't change depending on which type of operation the merge was part of. Ensure that paths which clean out other temporary operation-specific files (e.g. CHERRY_PICK_HEAD, MERGE_MSG, rebase-merge/ state directory) also clean out this AUTO_MERGE file. Signed-off-by: Elijah Newren <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa2faac commit 5291828

File tree

6 files changed

+20
-0
lines changed

6 files changed

+20
-0
lines changed

branch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ void remove_merge_branch_state(struct repository *r)
344344
unlink(git_path_merge_rr(r));
345345
unlink(git_path_merge_msg(r));
346346
unlink(git_path_merge_mode(r));
347+
unlink(git_path_auto_merge(r));
347348
save_autostash(git_path_merge_autostash(r));
348349
}
349350

builtin/rebase.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ static int finish_rebase(struct rebase_options *opts)
737737
int ret = 0;
738738

739739
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
740+
unlink(git_path_auto_merge(the_repository));
740741
apply_autostash(state_dir_path("autostash", opts));
741742
close_object_store(the_repository->objects);
742743
/*

merge-ort.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,6 +3496,9 @@ void merge_switch_to_result(struct merge_options *opt,
34963496
{
34973497
assert(opt->priv == NULL);
34983498
if (result->clean >= 0 && update_worktree_and_index) {
3499+
const char *filename;
3500+
FILE *fp;
3501+
34993502
trace2_region_enter("merge", "checkout", opt->repo);
35003503
if (checkout(opt, head, result->tree)) {
35013504
/* failure to function */
@@ -3514,6 +3517,13 @@ void merge_switch_to_result(struct merge_options *opt,
35143517
}
35153518
opt->priv = NULL;
35163519
trace2_region_leave("merge", "record_conflicted", opt->repo);
3520+
3521+
trace2_region_enter("merge", "write_auto_merge", opt->repo);
3522+
filename = git_path_auto_merge(opt->repo);
3523+
fp = xfopen(filename, "w");
3524+
fprintf(fp, "%s\n", oid_to_hex(&result->tree->object.oid));
3525+
fclose(fp);
3526+
trace2_region_leave("merge", "write_auto_merge", opt->repo);
35173527
}
35183528

35193529
if (display_update_msgs) {

path.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,5 +1534,6 @@ REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR")
15341534
REPO_GIT_PATH_FUNC(merge_mode, "MERGE_MODE")
15351535
REPO_GIT_PATH_FUNC(merge_head, "MERGE_HEAD")
15361536
REPO_GIT_PATH_FUNC(merge_autostash, "MERGE_AUTOSTASH")
1537+
REPO_GIT_PATH_FUNC(auto_merge, "AUTO_MERGE")
15371538
REPO_GIT_PATH_FUNC(fetch_head, "FETCH_HEAD")
15381539
REPO_GIT_PATH_FUNC(shallow, "shallow")

path.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ struct path_cache {
176176
const char *merge_mode;
177177
const char *merge_head;
178178
const char *merge_autostash;
179+
const char *auto_merge;
179180
const char *fetch_head;
180181
const char *shallow;
181182
};
@@ -191,6 +192,7 @@ const char *git_path_merge_rr(struct repository *r);
191192
const char *git_path_merge_mode(struct repository *r);
192193
const char *git_path_merge_head(struct repository *r);
193194
const char *git_path_merge_autostash(struct repository *r);
195+
const char *git_path_auto_merge(struct repository *r);
194196
const char *git_path_fetch_head(struct repository *r);
195197
const char *git_path_shallow(struct repository *r);
196198

sequencer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,7 @@ static int do_pick_commit(struct repository *r,
20962096
refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
20972097
NULL, 0);
20982098
unlink(git_path_merge_msg(r));
2099+
unlink(git_path_auto_merge(r));
20992100
fprintf(stderr,
21002101
_("dropping %s %s -- patch contents already upstream\n"),
21012102
oid_to_hex(&commit->object.oid), msg.subject);
@@ -2451,6 +2452,8 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose)
24512452
need_cleanup = 1;
24522453
}
24532454

2455+
unlink(git_path_auto_merge(r));
2456+
24542457
if (!need_cleanup)
24552458
return;
24562459

@@ -4111,6 +4114,7 @@ static int pick_commits(struct repository *r,
41114114
unlink(rebase_path_stopped_sha());
41124115
unlink(rebase_path_amend());
41134116
unlink(git_path_merge_head(r));
4117+
unlink(git_path_auto_merge(r));
41144118
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
41154119

41164120
if (item->command == TODO_BREAK) {
@@ -4505,6 +4509,7 @@ static int commit_staged_changes(struct repository *r,
45054509
return error(_("could not commit staged changes."));
45064510
unlink(rebase_path_amend());
45074511
unlink(git_path_merge_head(r));
4512+
unlink(git_path_auto_merge(r));
45084513
if (final_fixup) {
45094514
unlink(rebase_path_fixup_msg());
45104515
unlink(rebase_path_squash_msg());

0 commit comments

Comments
 (0)