A3: offer git's prepared merge message in the commit box

git.mergeMessage reads MERGE_MSG without its comment lines while a merge
is in progress. The Changes window fills an empty box with it once per
merge when conflicts show up, and again on vcs.commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-31 14:25:11 +01:00
parent 95fd9b926f
commit 983319d8a3
7 changed files with 183 additions and 2 deletions

View file

@ -19,6 +19,10 @@
* - **Amend:** checking Amend with an empty box fills it with the last
* commit's message (`git.lastMessage`); clearing Amend again empties a
* box that still holds exactly that text.
* - **Merge message:** while a merge waits on conflicts, an empty box
* (without Amend) offers the message git prepared (`git.mergeMessage`),
* once per merge: when the status first shows conflicted files, and
* again on `vcs.commit` if the box is empty then.
* - **Untrusted input:** the status comes from the engine and, through it,
* from git; malformed entries are dropped and the count capped
* ({@link MAX_FILES}).
@ -236,6 +240,44 @@ export const useChangesStore = defineStore("changes", () => {
void onAmend(on);
});
/** Whether the prepared merge message was offered for the merge in progress. */
let mergeOffered = false;
/**
* Fills an empty box (without Amend) with the message git prepared for
* the merge in progress. A failed call or no merge leaves the box as it
* is; no merge also ends the current offer.
*/
async function offerMergeMessage(): Promise<void> {
if (amend.value || message.value.trim() !== "") {
return;
}
const result = await runWaiting("git.mergeMessage");
if (!result.ok) {
return;
}
const value = result.value;
const text =
typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.message === "string"
? value.message
: null;
if (text === null) {
mergeOffered = false;
return;
}
mergeOffered = true;
if (!amend.value && message.value.trim() === "") {
message.value = text;
}
}
watch(status, (s) => {
const conflicted = (s?.files ?? []).some((f) => f.index === "conflicted" || f.worktree === "conflicted");
if (conflicted && !mergeOffered) {
void offerMergeMessage();
}
});
/**
* Runs a mutating git command, toasting its failure.
*
@ -343,6 +385,7 @@ export const useChangesStore = defineStore("changes", () => {
params: { hash: hash.slice(0, SHORT_HASH), summary },
});
prefilled = null;
mergeOffered = false;
message.value = "";
amend.value = false;
await refresh();
@ -383,6 +426,9 @@ export const useChangesStore = defineStore("changes", () => {
open();
focusPending.value = true;
focusRequest.value += 1;
if (phase.value === "ready") {
void offerMergeMessage();
}
}
/** Hides the tool window; the status and the message stay. */