| 2227 | use git2::Oid; |
| 2228 | |
| 2229 | fn commit_file(git: &GitRepository, root: &Path, content: &[u8]) -> Oid { |
| 2230 | std::fs::write(root.join("tracked.txt"), content).unwrap(); |
| 2231 | let mut index = git.index().unwrap(); |
| 2232 | index.add_path(Path::new("tracked.txt")).unwrap(); |
| 2233 | index.write().unwrap(); |
| 2234 | let tree_oid = index.write_tree().unwrap(); |
| 2235 | let tree = git.find_tree(tree_oid).unwrap(); |
| 2236 | let signature = git2::Signature::now("Atomic Test", "test@atomic.invalid").unwrap(); |
| 2237 | let parents = git |
| 2238 | .head() |
| 2239 | .ok() |
| 2240 | .and_then(|head| head.target()) |
| 2241 | .map(|oid| git.find_commit(oid).unwrap()); |
| 2242 | match parents.as_ref() { |
| 2243 | Some(parent) => git |
| 2244 | .commit( |
| 2245 | Some("HEAD"), |
| 2246 | &signature, |
| 2247 | &signature, |
| 2248 | "checkpoint", |
| 2249 | &tree, |
| 2250 | &[parent], |
| 2251 | ) |
| 2252 | .unwrap(), |
| 2253 | None => git |
| 2254 | .commit( |
| 2255 | Some("HEAD"), |
| 2256 | &signature, |
| 2257 | &signature, |
| 2258 | "checkpoint", |
| 2259 | &tree, |
| 2260 | &[], |
| 2261 | ) |
| 2262 | .unwrap(), |
| 2263 | } |
| 2264 | } |
| 2265 | |
| 2266 | /// Atomic + colocated Git with the retained shadow exclude marker, no |
| 2267 | /// shim checkpoint and no shim opt-in: a native, unenrolled repo. |