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

@ -1,5 +1,5 @@
//! Merge commands (M4.8): `git.merge`, `git.mergeAbort`,
//! `git.conflictVersions` and `git.markResolved`, on top of
//! `git.conflictVersions`, `git.markResolved` and `git.mergeMessage`, on top of
//! `lutra_vcs::Repo`'s merge calls.
//!
//! Each runs through [`super::git::start_with`]: a pending outcome, git and
@ -25,6 +25,7 @@ pub fn register(registry: &mut Registry) -> Result<(), EngineError> {
registry.register(Box::new(MergeAbort))?;
registry.register(Box::new(ConflictVersionsCommand))?;
registry.register(Box::new(MarkResolved))?;
registry.register(Box::new(MergeMessage))?;
Ok(())
}
@ -112,6 +113,36 @@ impl Command for MergeAbort {
}
}
/// `git.mergeMessage`.
struct MergeMessage;
impl Command for MergeMessage {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "git.mergeMessage",
label: "Git: Prepared Merge Message",
menu_path: None,
default_shortcut: None,
params: "none; returns { message: string | null }: the message git prepared for the merge in progress (MERGE_MSG without its # comment lines), null when no merge is in progress; for prefilling the commit box",
}
}
fn enabled(&self, state: &State) -> bool {
state.has_project()
}
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let command = self.spec().id;
let _: serde_json::Map<String, Value> = parse(command, params)?;
start_with(
state,
command,
false,
Box::new(|repo| Ok(json!({ "message": repo.merge_message()? }))),
)
}
}
/// Params of `git.conflictVersions`.
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
@ -217,4 +248,5 @@ pub(crate) const COMMAND_IDS: &[&str] = &[
"git.markResolved",
"git.merge",
"git.mergeAbort",
"git.mergeMessage",
];