use irmin::*;
fn main() -> Result<(), Error> {
let config = Config::<Json>::mem(None)?;
let repo = Repo::new(config)?;
let mut store = Store::new(&repo)?;
let path = repo.path(&["foo", "bar"])?;
let a = json!({
"x": 1i32,
"y": 2i32,
"z": 3i32,
});
store.set(
&path,
a.as_object().unwrap(),
Info::new(&repo, "example", "initial commit")?,
)?;
let head = store.head()?.unwrap();
let mut branch1 = Store::of_branch(&repo, "branch1")?;
branch1.set_head(&head);
let mut branch2 = Store::of_branch(&repo, "branch2")?;
branch2.set_head(&head);
let b = json!({
"x": 0i32,
"y": 2i32,
"z": 3i32,
});
branch1.set(
&path,
b.as_object().unwrap(),
Info::new(&repo, "example", "initial commit")?,
)?;
let c = json!({
"x": 1i32,
"y": 0i32,
"z": 3i32,
});
branch2.set(
&path,
c.as_object().unwrap(),
Info::new(&repo, "example", "initial commit")?,
)?;
assert!(store.merge(&branch1, repo.info("example", "merge branch1")?)?);
assert!(store.merge(&branch2, repo.info("example", "merge branch2")?)?);
let v = store.find(&path)?.unwrap();
assert!(
&v == json!({
"x": 0,
"y": 0,
"z": 3,
})
.as_object()
.unwrap()
);
Ok(())
}