cargo_hackerman/
mergetool.rs1use crate::toml::restore;
2use cargo_metadata::camino::Utf8PathBuf;
3use std::path::Path;
4
5fn restore_path(path: &Path) -> anyhow::Result<()> {
6 match path.to_str() {
7 Some(d) => restore(&Utf8PathBuf::from(d))?,
8 None => crate::toml::restore_path(path)?,
9 };
10 Ok(())
11}
12
13pub fn merge(base: &Path, local: &Path, remote: &Path, _merged: &Path) -> anyhow::Result<()> {
14 restore_path(local)?;
15 restore_path(base)?;
16 restore_path(remote)?;
17
18 let output = std::process::Command::new("git")
19 .arg("merge-file")
20 .args(["-L", "a/Cargo.toml"])
21 .args(["-L", "base/Cargo.toml"])
22 .args(["-L", "b/Cargo.toml"])
23 .args([local, base, remote])
24 .arg("-p")
25 .output()?;
26
27 let merged_bytes = output.stdout;
28 let code = output.status;
29
30 std::fs::write(local, merged_bytes)?;
31
32 std::process::exit(code.code().unwrap_or(-1));
33}