|
1 |
| -use crate::{fixture_path, hex_to_id}; |
2 |
| -use git_commitgraph::{Graph, GraphPosition}; |
3 |
| - |
4 |
| -const ROOT: &[u8] = b"09e3185550fdb352031df65f0e81e74df3b9a556"; |
5 |
| -const ROOT_INDEX: GraphPosition = GraphPosition(0); |
6 |
| -const COMMIT1: &[u8] = b"33316871b4ab988ea87ba60aaf0138ddb4fb0d21"; |
7 |
| -const COMMIT1_INDEX: GraphPosition = GraphPosition(2); |
8 |
| -const COMMIT2: &[u8] = b"cbfe147d1826a0d2701f7c80dbe0e2cfba385b15"; |
9 |
| -const COMMIT2_INDEX: GraphPosition = GraphPosition(6); |
10 |
| -const COMMIT3: &[u8] = b"9dab5d610702ceca4bd889a5ef2662cacfd53178"; |
11 |
| -const COMMIT3_INDEX: GraphPosition = GraphPosition(5); |
12 |
| -const COMMIT4: &[u8] = b"2ec748404455c0b0451b186851a815da13918ebb"; |
13 |
| -const COMMIT4_INDEX: GraphPosition = GraphPosition(1); |
14 |
| -const THREE_PARENTS: &[u8] = b"7070cd0b59cd46a0f0fa0c50ca9148390ae1e7c7"; |
15 |
| -const THREE_PARENTS_INDEX: GraphPosition = GraphPosition(4); |
16 |
| -const FOUR_PARENTS: &[u8] = b"5ca46a72d91817add3a7218f3eaf8b2b6c1caa13"; |
17 |
| -const FOUR_PARENTS_INDEX: GraphPosition = GraphPosition(3); |
| 1 | +use crate::{check_common, create_repo, inspect_refs}; |
| 2 | +use git_commitgraph::Graph; |
18 | 3 |
|
19 | 4 | #[test]
|
20 |
| -fn v1() -> Result<(), Box<dyn std::error::Error>> { |
21 |
| - let root_id = hex_to_id(ROOT); |
22 |
| - let commit1_id = hex_to_id(COMMIT1); |
23 |
| - let commit2_id = hex_to_id(COMMIT2); |
24 |
| - let commit3_id = hex_to_id(COMMIT3); |
25 |
| - let commit4_id = hex_to_id(COMMIT4); |
26 |
| - let three_parents_id = hex_to_id(THREE_PARENTS); |
27 |
| - let four_parents_id = hex_to_id(FOUR_PARENTS); |
28 |
| - |
29 |
| - let cg = Graph::from_info_dir(fixture_path("v1/octopus_merges/info"))?; |
30 |
| - assert_eq!(cg.num_commits(), 7); |
31 |
| - assert_eq!(cg.id_at(ROOT_INDEX), root_id.to_borrowed()); |
32 |
| - assert_eq!(cg.id_at(COMMIT1_INDEX), commit1_id.to_borrowed()); |
33 |
| - assert_eq!(cg.id_at(COMMIT2_INDEX), commit2_id.to_borrowed()); |
34 |
| - assert_eq!(cg.id_at(COMMIT3_INDEX), commit3_id.to_borrowed()); |
35 |
| - assert_eq!(cg.id_at(COMMIT4_INDEX), commit4_id.to_borrowed()); |
36 |
| - assert_eq!(cg.id_at(THREE_PARENTS_INDEX), three_parents_id.to_borrowed()); |
37 |
| - assert_eq!(cg.id_at(FOUR_PARENTS_INDEX), four_parents_id.to_borrowed()); |
38 |
| - assert_eq!( |
39 |
| - cg.iter_ids().collect::<Vec<_>>(), |
40 |
| - vec![ |
41 |
| - root_id.to_borrowed(), |
42 |
| - commit4_id.to_borrowed(), |
43 |
| - commit1_id.to_borrowed(), |
44 |
| - four_parents_id.to_borrowed(), |
45 |
| - three_parents_id.to_borrowed(), |
46 |
| - commit3_id.to_borrowed(), |
47 |
| - commit2_id.to_borrowed(), |
48 |
| - ] |
49 |
| - ); |
50 |
| - |
51 |
| - let root = cg.commit_at(ROOT_INDEX); |
52 |
| - assert_eq!(root.generation(), 1); |
53 |
| - assert_eq!(root.id(), root_id.to_borrowed()); |
54 |
| - assert_eq!(root.parent1()?, None); |
55 |
| - assert_eq!( |
56 |
| - root.root_tree_id(), |
57 |
| - hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(), |
58 |
| - ); |
59 |
| - assert_eq!(root.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, vec![]); |
60 |
| - |
61 |
| - let commit1 = cg.commit_at(COMMIT1_INDEX); |
62 |
| - assert_eq!(commit1.generation(), 2); |
63 |
| - assert_eq!(commit1.id(), commit1_id.to_borrowed()); |
64 |
| - assert_eq!(commit1.parent1()?, Some(ROOT_INDEX)); |
65 |
| - assert_eq!( |
66 |
| - commit1.root_tree_id(), |
67 |
| - hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(), |
68 |
| - ); |
69 |
| - assert_eq!( |
70 |
| - commit1.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, |
71 |
| - vec![ROOT_INDEX], |
72 |
| - ); |
73 |
| - |
74 |
| - let commit2 = cg.commit_at(COMMIT2_INDEX); |
75 |
| - assert_eq!(commit2.generation(), 2); |
76 |
| - assert_eq!(commit2.id(), commit2_id.to_borrowed()); |
77 |
| - assert_eq!(commit2.parent1()?, Some(ROOT_INDEX)); |
78 |
| - assert_eq!( |
79 |
| - commit2.root_tree_id(), |
80 |
| - hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(), |
81 |
| - ); |
82 |
| - assert_eq!( |
83 |
| - commit2.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, |
84 |
| - vec![ROOT_INDEX], |
85 |
| - ); |
86 |
| - |
87 |
| - let commit3 = cg.commit_at(COMMIT3_INDEX); |
88 |
| - assert_eq!(commit3.generation(), 2); |
89 |
| - assert_eq!(commit3.id(), commit3_id.to_borrowed()); |
90 |
| - assert_eq!(commit3.parent1()?, Some(ROOT_INDEX)); |
91 |
| - assert_eq!( |
92 |
| - commit3.root_tree_id(), |
93 |
| - hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(), |
94 |
| - ); |
95 |
| - assert_eq!( |
96 |
| - commit3.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, |
97 |
| - vec![ROOT_INDEX], |
98 |
| - ); |
99 |
| - |
100 |
| - let commit4 = cg.commit_at(COMMIT4_INDEX); |
101 |
| - assert_eq!(commit4.generation(), 2); |
102 |
| - assert_eq!(commit4.id(), commit4_id.to_borrowed()); |
103 |
| - assert_eq!(commit4.parent1()?, Some(ROOT_INDEX)); |
104 |
| - assert_eq!( |
105 |
| - commit4.root_tree_id(), |
106 |
| - hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(), |
107 |
| - ); |
108 |
| - assert_eq!( |
109 |
| - commit4.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, |
110 |
| - vec![ROOT_INDEX], |
111 |
| - ); |
112 |
| - |
113 |
| - let three_parents = cg.commit_at(THREE_PARENTS_INDEX); |
114 |
| - assert_eq!(three_parents.generation(), 3); |
115 |
| - assert_eq!(three_parents.id(), three_parents_id.to_borrowed()); |
116 |
| - assert_eq!(three_parents.parent1()?, Some(COMMIT1_INDEX)); |
117 |
| - assert_eq!( |
118 |
| - three_parents.root_tree_id(), |
119 |
| - hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(), |
120 |
| - ); |
121 |
| - assert_eq!( |
122 |
| - three_parents.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, |
123 |
| - vec![COMMIT1_INDEX, COMMIT2_INDEX, COMMIT3_INDEX], |
124 |
| - ); |
125 |
| - |
126 |
| - let four_parents = cg.commit_at(FOUR_PARENTS_INDEX); |
127 |
| - assert_eq!(four_parents.generation(), 3); |
128 |
| - assert_eq!(four_parents.id(), four_parents_id.to_borrowed()); |
129 |
| - assert_eq!(four_parents.parent1()?, Some(COMMIT2_INDEX)); |
130 |
| - assert_eq!( |
131 |
| - four_parents.root_tree_id(), |
132 |
| - hex_to_id(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").to_borrowed(), |
133 |
| - ); |
134 |
| - assert_eq!( |
135 |
| - four_parents.iter_parent_indices().collect::<Result<Vec<_>, _>>()?, |
136 |
| - vec![COMMIT2_INDEX, COMMIT1_INDEX, COMMIT3_INDEX, COMMIT4_INDEX], |
137 |
| - ); |
| 5 | +fn test() -> Result<(), Box<dyn std::error::Error>> { |
| 6 | + let repo_dir = create_repo("octopus_merges.sh"); |
| 7 | + let refs = inspect_refs( |
| 8 | + repo_dir.path(), |
| 9 | + &[ |
| 10 | + "root", |
| 11 | + "parent1", |
| 12 | + "parent2", |
| 13 | + "parent3", |
| 14 | + "parent4", |
| 15 | + "three_parents", |
| 16 | + "four_parents", |
| 17 | + ], |
| 18 | + ); |
| 19 | + let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?; |
| 20 | + check_common(&cg, &refs); |
| 21 | + |
| 22 | + assert_eq!(cg.commit_at(refs["root"].pos()).generation(), 1); |
| 23 | + assert_eq!(cg.commit_at(refs["parent1"].pos()).generation(), 2); |
| 24 | + assert_eq!(cg.commit_at(refs["parent2"].pos()).generation(), 2); |
| 25 | + assert_eq!(cg.commit_at(refs["parent3"].pos()).generation(), 2); |
| 26 | + assert_eq!(cg.commit_at(refs["parent4"].pos()).generation(), 2); |
| 27 | + assert_eq!(cg.commit_at(refs["three_parents"].pos()).generation(), 3); |
| 28 | + assert_eq!(cg.commit_at(refs["four_parents"].pos()).generation(), 3); |
138 | 29 |
|
139 | 30 | Ok(())
|
140 | 31 | }
|
0 commit comments