(repository: &GitRepository, path: &str, content: &[u8], message: &str)
| 178 | } |
| 179 | |
| 180 | fn commit_file(repository: &GitRepository, path: &str, content: &[u8], message: &str) -> Oid { |
| 181 | let worktree = repository.workdir().expect("Git worktree"); |
| 182 | fs::write(worktree.join(path), content).expect("write committed file"); |
| 183 | let mut index = repository.index().expect("Git index"); |
| 184 | index.add_path(Path::new(path)).expect("stage file"); |
| 185 | index.write().expect("write index"); |
| 186 | let tree_oid = index.write_tree().expect("write tree"); |
| 187 | let tree = repository.find_tree(tree_oid).expect("find tree"); |
| 188 | let signature = Signature::now("CB-10A Tests", "cb10a@example.com").expect("signature"); |
| 189 | let parent = repository |
| 190 | .head() |
| 191 | .ok() |
| 192 | .and_then(|head| head.target()) |
| 193 | .and_then(|oid| repository.find_commit(oid).ok()); |
| 194 | match parent.as_ref() { |
| 195 | Some(parent) => repository |
| 196 | .commit( |
| 197 | Some("HEAD"), |
| 198 | &signature, |
| 199 | &signature, |
| 200 | message, |
| 201 | &tree, |
| 202 | &[parent], |
| 203 | ) |
| 204 | .expect("commit with parent"), |
| 205 | None => repository |
| 206 | .commit(Some("HEAD"), &signature, &signature, message, &tree, &[]) |
| 207 | .expect("initial commit"), |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | fn view_merkle(fixture: &Colocated) -> String { |
| 212 | let output = fixture.atomic(&["view", "show", "main"]); |
no test coverage detected