fake_git_repo.rs

 1use fs::{FakeFs, Fs};
 2use gpui::BackgroundExecutor;
 3use serde_json::json;
 4use std::path::Path;
 5use util::path;
 6
 7#[gpui::test]
 8async fn test_checkpoints(executor: BackgroundExecutor) {
 9    let fs = FakeFs::new(executor);
10    fs.insert_tree(
11        path!("/"),
12        json!({
13            "bar": {
14                "baz": "qux"
15            },
16            "foo": {
17                ".git": {},
18                "a": "lorem",
19                "b": "ipsum",
20            },
21        }),
22    )
23    .await;
24    fs.with_git_state(Path::new("/foo/.git"), true, |_git| {})
25        .unwrap();
26    let repository = fs
27        .open_repo(Path::new("/foo/.git"), Some("git".as_ref()))
28        .unwrap();
29
30    let checkpoint_1 = repository.checkpoint().await.unwrap();
31    fs.write(Path::new("/foo/b"), b"IPSUM").await.unwrap();
32    fs.write(Path::new("/foo/c"), b"dolor").await.unwrap();
33    let checkpoint_2 = repository.checkpoint().await.unwrap();
34    let checkpoint_3 = repository.checkpoint().await.unwrap();
35
36    assert!(
37        repository
38            .compare_checkpoints(checkpoint_2.clone(), checkpoint_3.clone())
39            .await
40            .unwrap()
41    );
42    assert!(
43        !repository
44            .compare_checkpoints(checkpoint_1.clone(), checkpoint_2.clone())
45            .await
46            .unwrap()
47    );
48
49    repository.restore_checkpoint(checkpoint_1).await.unwrap();
50    assert_eq!(
51        fs.files_with_contents(Path::new("")),
52        [
53            (Path::new(path!("/bar/baz")).into(), b"qux".into()),
54            (Path::new(path!("/foo/a")).into(), b"lorem".into()),
55            (Path::new(path!("/foo/b")).into(), b"ipsum".into())
56        ]
57    );
58}