(repository: &GitRepository, path: &str, content: &[u8], message: &str)
| 41 | } |
| 42 | |
| 43 | fn commit_file(repository: &GitRepository, path: &str, content: &[u8], message: &str) -> Oid { |
| 44 | let worktree = repository.workdir().expect("Git worktree"); |
| 45 | fs::write(worktree.join(path), content).expect("write committed file"); |
| 46 | let mut index = repository.index().expect("Git index"); |
| 47 | index.add_path(Path::new(path)).expect("stage file"); |
| 48 | index.write().expect("write index"); |
| 49 | let tree_oid = index.write_tree().expect("write tree"); |
| 50 | let tree = repository.find_tree(tree_oid).expect("find tree"); |
| 51 | let signature = Signature::now("Atomic Test", "atomic@example.com").expect("signature"); |
| 52 | let parents = repository |
| 53 | .head() |
| 54 | .ok() |
| 55 | .and_then(|head| head.target()) |
| 56 | .and_then(|oid| repository.find_commit(oid).ok()); |
| 57 | match parents.as_ref() { |
| 58 | Some(parent) => repository |
| 59 | .commit( |
| 60 | Some("HEAD"), |
| 61 | &signature, |
| 62 | &signature, |
| 63 | message, |
| 64 | &tree, |
| 65 | &[parent], |
| 66 | ) |
| 67 | .expect("commit with parent"), |
| 68 | None => repository |
| 69 | .commit(Some("HEAD"), &signature, &signature, message, &tree, &[]) |
| 70 | .expect("initial commit"), |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | fn init_git(root: &Path) -> GitRepository { |
| 75 | let repository = GitRepository::init(root).expect("init Git"); |
no test coverage detected