use crate::auto_push_dirty_paths::listed;
use crate::policy_events::{PolicyEvent, render_policy_events};
pub const CORE_ID: &str = "merge-isolation";
pub const OVERLAP_CODE: &str = "paths-in-use";
pub const CONFLICT_CODE: &str = "merge-conflict";
pub const APPLY_REFUSED_CODE: &str = "not-applied";
fn render(code: &'static str, message: String) -> String {
return render_policy_events(
1,
&[PolicyEvent::CoreFinding {
core_id: CORE_ID,
code,
message,
}],
);
}
pub fn overlap_finding(reference: &str, paths: &[Vec<u8>]) -> String {
return render(
OVERLAP_CODE,
format!(
"git merge {reference} was not run: the merge changes {}, which this checkout holds staged or modified \
(probably another session's work in progress). Writing the merge there would overwrite that work, so \
nothing was changed. Valid ways forward: wait until the session that owns those files has committed or \
restored them, then merge again; or merge in a clean linked worktree \
(`git worktree add -b merge-work ../merge-work <branch>`, then `git merge {reference}` there, and bring \
the result back with `git merge --ff-only merge-work` here once those paths are free); or, when the \
files are yours, commit them (`git commit -- <path>`) or set them aside (`git stash push -- <path>`) and \
run the merge again.",
listed(paths)
),
);
}
pub fn conflict_finding(reference: &str, paths: &[String]) -> String {
return render(
CONFLICT_CODE,
format!(
"git merge {reference} was not run: merging it into the current branch conflicts in {}. Conflicts have \
to be resolved in a worktree, and this checkout holds staged changes that are not yours, so nothing was \
changed. Valid ways forward: merge in a clean linked worktree (`git worktree add -b merge-work \
../merge-work <this branch>`, then `git merge {reference}` there, resolve, commit, and bring the result \
back with `git merge --ff-only merge-work` here); or resolve in a clean checkout of the repository; or \
rebase or adjust {reference} so that it no longer conflicts.",
paths.join(", ")
),
);
}
pub fn not_applied_finding(reference: &str, detail: &str) -> String {
return render(
APPLY_REFUSED_CODE,
format!(
"git merge {reference} was not applied: Git refused to move the checkout to the merge ({detail}). The \
branch, the index and the worktree are as they were. Valid ways forward: remove or move the files Git \
names and merge again; or merge in a clean linked worktree and bring the result back with \
`git merge --ff-only`."
),
);
}
#[cfg(test)]
#[path = "merge_isolation_report_tests.rs"]
mod tests;