Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
1open Irmin
2open Private
3
4let test_commit_fields () =
5 let tree_hash = Hash.sha1 "tree content" in
6 let c =
7 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice"
8 ~message:"Initial commit" ()
9 in
10 Alcotest.(check string) "author" "Alice" (Commit.Git.author c);
11 Alcotest.(check string) "message" "Initial commit" (Commit.Git.message c);
12 Alcotest.(check (list (Alcotest.testable Hash.pp Hash.equal)))
13 "no parents" [] (Commit.Git.parents c);
14 Alcotest.(check bool)
15 "tree matches" true
16 (Hash.equal tree_hash (Commit.Git.tree c))
17
18let test_commit_committer () =
19 let tree_hash = Hash.sha1 "tree" in
20 let c =
21 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice" ~committer:"Bob"
22 ~message:"test" ()
23 in
24 Alcotest.(check string) "committer" "Bob" (Commit.Git.committer c)
25
26let test_commit_parents () =
27 let tree_hash = Hash.sha1 "tree" in
28 let parent1 = Hash.sha1 "parent1" in
29 let parent2 = Hash.sha1 "parent2" in
30 let c =
31 Commit.Git.v ~tree:tree_hash ~parents:[ parent1; parent2 ] ~author:"test"
32 ~message:"merge" ()
33 in
34 Alcotest.(check int) "two parents" 2 (List.length (Commit.Git.parents c))
35
36let test_commit_roundtrip () =
37 let tree_hash = Hash.sha1 "tree content" in
38 let c =
39 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice"
40 ~message:"test commit" ()
41 in
42 let bytes = Commit.Git.to_bytes c in
43 match Commit.Git.of_bytes bytes with
44 | Ok c' ->
45 Alcotest.(check string) "author roundtrip" "Alice" (Commit.Git.author c');
46 Alcotest.(check string)
47 "message roundtrip" "test commit" (Commit.Git.message c')
48 | Error (`Msg msg) -> Alcotest.fail msg
49
50let test_commit_hash () =
51 let tree_hash = Hash.sha1 "tree" in
52 let c1 =
53 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice" ~message:"same"
54 ~timestamp:1000L ()
55 in
56 let c2 =
57 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice" ~message:"same"
58 ~timestamp:1000L ()
59 in
60 Alcotest.(check bool)
61 "same content same hash" true
62 (Hash.equal (Commit.Git.hash c1) (Commit.Git.hash c2))
63
64let suite =
65 ( "commit",
66 [
67 Alcotest.test_case "fields" `Quick test_commit_fields;
68 Alcotest.test_case "committer" `Quick test_commit_committer;
69 Alcotest.test_case "parents" `Quick test_commit_parents;
70 Alcotest.test_case "roundtrip" `Quick test_commit_roundtrip;
71 Alcotest.test_case "hash" `Quick test_commit_hash;
72 ] )