[PATCH v4 0/3] checkout -m: recreate conflict labels
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Oct 13, 2026, 15:47 UTC
- Message-ID
- <cover.1791906474.git.phillip.wood@dunelm.org.uk>
- In-Reply-To
- <cover.1790761727.git.phillip.wood@dunelm.org.uk>
When "git checkout -m <path>" recreates a merge conflict, it uses the labels "base", "ours", "theirs", rather than the labels used by the original merge. This short series teaches the ort machinery to write the labels to ".git/MERGE_LABELS" when it switches to a merge result containing conflicts, so that "git checkout -m" can then read that file and use the same labels.
Changes since V3:
- added patch 2 to cache merge config settings and conflict labels
Changes since V2:
- only write ".git/MERGE_LABELS" when there are conflicts and added a check to an existing "checkout -m <branch>" test - change write_merge_labels() to take an array of labels - use a local variable to store the internal merge state when writing labels - use strbuf_detach() rather than xmemdupz() when reading labels - add a comment to say we ignore trailing cruft when reading the labels file
Changes since V1:
- use strbuf_getline() rather than strbuf_read_file() to read labels so that the newline handling of the reading and writing sides match.
NB ".git/MERGE_LABELS" is still undocumented - I'm hoping to find time to add some documentation for all the MERGE_* files in a future series. Johannes suggested using an index extension to store the labels, but as we already have MERGE_MODE, MERGE_RR and MERGE_MSG I think it is easier just to add another file.
base-commit: 3bc0341126508f78f5869cbfc0005e987efdf0c7 Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fconflict-labels%2Fv4 View-Changes-At: https://github.com/phillipwood/git/compare/3bc034112...eda10c234 Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/conflict-labels/v4
Junio C Hamano (1): checkout -m <path>: cache merge settings
Phillip Wood (2): remove_branch_state: convert boolean argument to flags merge: remember conflict labels
branch.c | 17 ++++++++---- branch.h | 4 ++- builtin/checkout.c | 66 ++++++++++++++++++++++++++++++++++++++-------- builtin/commit.c | 1 + merge-ort.c | 20 ++++++++++++++ merge.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ merge.h | 3 +++ path.c | 1 + path.h | 1 + repository.c | 1 + repository.h | 1 + sequencer.c | 1 + t/t7201-co.sh | 22 ++++++++++++++++ 13 files changed, 187 insertions(+), 17 deletions(-)
Range-diff against v3:
1: 86ef0f848a = 1: 86ef0f848a remove_branch_state: convert boolean argument to flags
-: ---------- > 2: 36f3808d2f checkout -m <path>: cache merge settings
2: 182edb2e88 ! 3: eda10c2340 merge: remember conflict labels
@@ builtin/checkout.c
#include "lockfile.h"
#include "mem-pool.h"
#include "object-file.h"
-@@ builtin/checkout.c: static int checkout_merged(int pos, const struct checkout *state,
- struct cache_entry *ce = the_repository->index->cache[pos];
- const char *path = ce->name;
- mmfile_t ancestor, ours, theirs;
+@@ builtin/checkout.c: static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
+ struct checkout_merged_data {
+ int conflict_style;
+ int renormalize;
+ char *base_label, *ours_label, *theirs_label;
- enum ll_merge_result merge_status;
- int status;
- struct object_id oid;
-@@ builtin/checkout.c: static int checkout_merged(int pos, const struct checkout *state,
+ };
+
++static void checkout_merged_release(struct checkout_merged_data *data)
++{
++ free(data->base_label);
++ free(data->ours_label);
++ free(data->theirs_label);
++}
++
+ static void checkout_merged_prepare(struct checkout_merged_data *data)
+ {
+ int renormalize = 0;
repo_config_get_bool(the_repository, "merge.renormalize", &renormalize);
- ll_opts.renormalize = renormalize;
-+ if (read_merge_labels(the_repository, &base_label, &ours_label,
-+ &theirs_label)) {
-+ base_label = xstrdup("base");
-+ ours_label = xstrdup("ours");
-+ theirs_label = xstrdup("theirs");
+ data->renormalize = renormalize;
++ if (read_merge_labels(the_repository, &data->base_label, &data->ours_label,
++ &data->theirs_label)) {
++ data->base_label = xstrdup("base");
++ data->ours_label = xstrdup("ours");
++ data->theirs_label = xstrdup("theirs");
+ }
- ll_opts.conflict_style = conflict_style;
+ }
+
+ static int checkout_merged(int pos, const struct checkout *state,
+@@ builtin/checkout.c: static int checkout_merged(int pos, const struct checkout *state,
+
+ ll_opts.renormalize = data->renormalize;
+ ll_opts.conflict_style = data->conflict_style;
- merge_status = ll_merge(&result_buf, path, &ancestor, "base",
- &ours, "ours", &theirs, "theirs",
-+ merge_status = ll_merge(&result_buf, path, &ancestor, base_label,
-+ &ours, ours_label, &theirs, theirs_label,
++ merge_status = ll_merge(&result_buf, path, &ancestor, data->base_label,
++ &ours, data->ours_label, &theirs, data->theirs_label,
state->istate, &ll_opts);
-+ free(base_label);
-+ free(ours_label);
-+ free(theirs_label);
free(ancestor.ptr);
free(ours.ptr);
- free(theirs.ptr);
+@@ builtin/checkout.c: static int checkout_worktree(const struct checkout_opts *opts,
+ pos = skip_same_name(ce, pos) - 1;
+ }
+ }
++
++ if (opts->merge)
++ checkout_merged_release(&checkout_merged_data);
++
+ if (pc_workers > 1)
+ errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
+ NULL, NULL);
@@ builtin/checkout.c: static void report_tracking(struct branch_info *new_branch_info)
static void update_refs_for_switch(const struct checkout_opts *opts,-- 2.56.0.134.g299a3c16181