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
|
|
@ -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",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -147,11 +147,21 @@ fn merge_conflict_versions_resolve_and_abort() {
|
|||
);
|
||||
assert_eq!(host.git_changes(), 0);
|
||||
|
||||
let prepared = host.run("git.mergeMessage", Value::Null).unwrap();
|
||||
let text = prepared["message"].as_str().unwrap();
|
||||
assert!(text.starts_with("Merge branch 'feature'"), "{text}");
|
||||
assert!(!text.contains('#'), "{text}");
|
||||
assert_eq!(host.git_changes(), 0);
|
||||
|
||||
let again = host.run("git.merge", json!({"branch": "feature"}));
|
||||
assert!(matches!(again, Err(EngineError::Failed(m)) if m.contains("in progress")));
|
||||
|
||||
host.run("git.mergeAbort", Value::Null).unwrap();
|
||||
assert_eq!(host.git_changes(), 1);
|
||||
assert_eq!(
|
||||
host.run("git.mergeMessage", Value::Null).unwrap(),
|
||||
json!({"message": null})
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(root.join("a.php")).unwrap(),
|
||||
"<?php\nmain\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue