Compare commits

...

2 commits

4 changed files with 23 additions and 2 deletions

7
Cargo.lock generated
View file

@ -2078,6 +2078,7 @@ dependencies = [
"serde_yaml",
"sha1",
"sha2",
"similar",
"tempfile",
"tokio",
"toml",
@ -3294,6 +3295,12 @@ version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]]
name = "similar"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e"
[[package]]
name = "siphasher"
version = "0.3.11"

View file

@ -16,7 +16,8 @@ This is a rather unorganised list of TODOs just so I can somewhat keep track of
merge (with conflict overrides on a file content level) should result in an install dir with A and B, where a.json and b.json are in A, and a.json is the result of merging a.json into the installed a.json (overwriting any existing key's values with the modpack's values), and the original files in folder B untouched (x.json and y.json)
merge (retaining original/modified values) merge should result in an install dir with A and B, where a.json and b.json are in A, and a.json is the result of merging a.json into the installed a.json (retaining the existing values from the file in the install dir), and the original files in folder B untouched (x.json and y.json)
- [ ] Test the merge apply policies when I am not half asleep.
- [ ] Test the merge apply policies when I am not half asleep
- [ ] Show package version somewhere in `mmm`
### Nice to haves

View file

@ -17,6 +17,7 @@ serde_json = "1.0.128"
serde_yaml = "0.9.34"
sha1 = "0.10.6"
sha2 = "0.10.8"
similar = "2.6.0"
tempfile = "3.12.0"
tokio = { version = "1.39.2", features = ["full"] }
toml = { version = "0.8.19", features = ["preserve_order"] }

View file

@ -6,6 +6,7 @@ use crate::{
};
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use similar::{ChangeTag, TextDiff};
use std::{
collections::{BTreeMap, BTreeSet},
path::{Path, PathBuf},
@ -298,9 +299,20 @@ impl ModpackMeta {
)
.with_context(|| format!("Failed to merge file {src:?} -> {dst:?}"))?;
std::fs::write(dst, merged_contents).with_context(|| {
std::fs::write(dst, &merged_contents).with_context(|| {
format!("Failed to write merged contents of {src:?} -> {dst:?}")
})?;
println!("Successfully merged {src:?} -> {dst:?}. See diff below:");
let diff = TextDiff::from_lines(&dst_val, &merged_contents);
for change in diff.iter_all_changes() {
let sign = match change.tag() {
ChangeTag::Delete => "-",
ChangeTag::Insert => "+",
ChangeTag::Equal => " ",
};
print!("{}{}", sign, change);
}
} else {
println!("Syncing file {} -> {}", src.display(), dst.display());
std::fs::copy(src, dst)?;