]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-ort: write $GIT_DIR/AUTO_MERGE whenever we hit a conflict
authorElijah Newren <newren@gmail.com>
Sat, 20 Mar 2021 00:03:52 +0000 (00:03 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 Mar 2021 19:35:40 +0000 (12:35 -0700)
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 <newren@gmail.com>
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
branch.c
builtin/rebase.c
merge-ort.c
path.c
path.h
sequencer.c

index 9c9dae1eae321c6878607a3b624a187fcb176380..b71a2de29dbed9ca37423f956f0b54f3fdc279d9 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -344,6 +344,7 @@ void remove_merge_branch_state(struct repository *r)
        unlink(git_path_merge_rr(r));
        unlink(git_path_merge_msg(r));
        unlink(git_path_merge_mode(r));
+       unlink(git_path_auto_merge(r));
        save_autostash(git_path_merge_autostash(r));
 }
 
index 840dbd7eb7772e47f408f05468f21df153e9cc20..6c252d62758c5ad3765a67dfee0db23c37510e80 100644 (file)
@@ -737,6 +737,7 @@ static int finish_rebase(struct rebase_options *opts)
        int ret = 0;
 
        delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
+       unlink(git_path_auto_merge(the_repository));
        apply_autostash(state_dir_path("autostash", opts));
        close_object_store(the_repository->objects);
        /*
index 303e894142743e5fb2b2ed4938c21e2c29f15192..e8f1a435f99ae01fce7a3d7b0ab392d3ee0004d2 100644 (file)
@@ -3496,6 +3496,9 @@ void merge_switch_to_result(struct merge_options *opt,
 {
        assert(opt->priv == NULL);
        if (result->clean >= 0 && update_worktree_and_index) {
+               const char *filename;
+               FILE *fp;
+
                trace2_region_enter("merge", "checkout", opt->repo);
                if (checkout(opt, head, result->tree)) {
                        /* failure to function */
@@ -3514,6 +3517,13 @@ void merge_switch_to_result(struct merge_options *opt,
                }
                opt->priv = NULL;
                trace2_region_leave("merge", "record_conflicted", opt->repo);
+
+               trace2_region_enter("merge", "write_auto_merge", opt->repo);
+               filename = git_path_auto_merge(opt->repo);
+               fp = xfopen(filename, "w");
+               fprintf(fp, "%s\n", oid_to_hex(&result->tree->object.oid));
+               fclose(fp);
+               trace2_region_leave("merge", "write_auto_merge", opt->repo);
        }
 
        if (display_update_msgs) {
diff --git a/path.c b/path.c
index 7b385e5eb282276f5d2e0becde48d5e09434d6b1..9e883eb52446d39573a0291109e4b57d28d56bc9 100644 (file)
--- a/path.c
+++ b/path.c
@@ -1534,5 +1534,6 @@ REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR")
 REPO_GIT_PATH_FUNC(merge_mode, "MERGE_MODE")
 REPO_GIT_PATH_FUNC(merge_head, "MERGE_HEAD")
 REPO_GIT_PATH_FUNC(merge_autostash, "MERGE_AUTOSTASH")
+REPO_GIT_PATH_FUNC(auto_merge, "AUTO_MERGE")
 REPO_GIT_PATH_FUNC(fetch_head, "FETCH_HEAD")
 REPO_GIT_PATH_FUNC(shallow, "shallow")
diff --git a/path.h b/path.h
index e7e77da6aaa5cf8e4652141ecf785ee18effeaca..251c78d980000af0a40f1388ece5c9d68b354982 100644 (file)
--- a/path.h
+++ b/path.h
@@ -176,6 +176,7 @@ struct path_cache {
        const char *merge_mode;
        const char *merge_head;
        const char *merge_autostash;
+       const char *auto_merge;
        const char *fetch_head;
        const char *shallow;
 };
@@ -191,6 +192,7 @@ const char *git_path_merge_rr(struct repository *r);
 const char *git_path_merge_mode(struct repository *r);
 const char *git_path_merge_head(struct repository *r);
 const char *git_path_merge_autostash(struct repository *r);
+const char *git_path_auto_merge(struct repository *r);
 const char *git_path_fetch_head(struct repository *r);
 const char *git_path_shallow(struct repository *r);
 
index d2332d3e1787126f50f3e5f01652c00911c8eda9..472cdd8c620de8f137c06d788ffcaed0816a4ea8 100644 (file)
@@ -2096,6 +2096,7 @@ static int do_pick_commit(struct repository *r,
                refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
                                NULL, 0);
                unlink(git_path_merge_msg(r));
+               unlink(git_path_auto_merge(r));
                fprintf(stderr,
                        _("dropping %s %s -- patch contents already upstream\n"),
                        oid_to_hex(&commit->object.oid), msg.subject);
@@ -2451,6 +2452,8 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose)
                need_cleanup = 1;
        }
 
+       unlink(git_path_auto_merge(r));
+
        if (!need_cleanup)
                return;
 
@@ -4111,6 +4114,7 @@ static int pick_commits(struct repository *r,
                        unlink(rebase_path_stopped_sha());
                        unlink(rebase_path_amend());
                        unlink(git_path_merge_head(r));
+                       unlink(git_path_auto_merge(r));
                        delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
 
                        if (item->command == TODO_BREAK) {
@@ -4505,6 +4509,7 @@ static int commit_staged_changes(struct repository *r,
                return error(_("could not commit staged changes."));
        unlink(rebase_path_amend());
        unlink(git_path_merge_head(r));
+       unlink(git_path_auto_merge(r));
        if (final_fixup) {
                unlink(rebase_path_fixup_msg());
                unlink(rebase_path_squash_msg());