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:
parent
95fd9b926f
commit
983319d8a3
7 changed files with 183 additions and 2 deletions
|
|
@ -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. */
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ let listeners: ((event: { payload: unknown }) => void)[];
|
|||
let gitStatus: unknown;
|
||||
/** Errors to throw, by command id. */
|
||||
let failures: Record<string, { code: string; message: string }>;
|
||||
/** What `git.mergeMessage` answers. */
|
||||
let mergeMessage: string | null;
|
||||
/** What `file.saveAll` answers. */
|
||||
let saveAll: unknown;
|
||||
/** Pinia of the current test. */
|
||||
|
|
@ -118,6 +120,7 @@ beforeEach(() => {
|
|||
mounted = [];
|
||||
failures = {};
|
||||
gitStatus = sampleStatus();
|
||||
mergeMessage = null;
|
||||
saveAll = { saved: [], failed: [], skipped: [] };
|
||||
Element.prototype.scrollIntoView = () => undefined;
|
||||
invoke.mockReset();
|
||||
|
|
@ -145,6 +148,8 @@ beforeEach(() => {
|
|||
return Promise.resolve(gitStatus);
|
||||
case "git.lastMessage":
|
||||
return Promise.resolve({ message: "Last subject\n\nLast body" });
|
||||
case "git.mergeMessage":
|
||||
return Promise.resolve({ message: mergeMessage });
|
||||
case "git.commit":
|
||||
return Promise.resolve({ commit: "fedcba9876543210", summary: String(args.params.message).split("\n")[0] });
|
||||
case "file.saveAll":
|
||||
|
|
@ -338,6 +343,32 @@ describe("the Changes store", () => {
|
|||
expect(callsOf("git.lastMessage")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("offers git's prepared merge message once while a merge has conflicts", async () => {
|
||||
const changes = useChangesStore(pinia);
|
||||
await changes.refresh();
|
||||
expect(callsOf("git.mergeMessage")).toHaveLength(0);
|
||||
mergeMessage = "Merge branch 'feature'";
|
||||
gitStatus = {
|
||||
...sampleStatus(),
|
||||
files: [{ path: "a.php", index: "conflicted", worktree: "conflicted" }],
|
||||
};
|
||||
await changes.refresh();
|
||||
await flushPromises();
|
||||
expect(callsOf("git.mergeMessage")).toHaveLength(1);
|
||||
expect(changes.message).toBe("Merge branch 'feature'");
|
||||
changes.message = "";
|
||||
await emit({ kind: "gitChanged", available: true, repo: null, filesChanged: true });
|
||||
expect(callsOf("git.mergeMessage")).toHaveLength(1);
|
||||
expect(changes.message).toBe("");
|
||||
changes.focusMessage();
|
||||
await flushPromises();
|
||||
expect(changes.message).toBe("Merge branch 'feature'");
|
||||
changes.message = "mine";
|
||||
changes.focusMessage();
|
||||
await flushPromises();
|
||||
expect(changes.message).toBe("mine");
|
||||
});
|
||||
|
||||
it("keeps the message when git refuses the commit", async () => {
|
||||
const changes = useChangesStore(pinia);
|
||||
await changes.refresh();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue