| 1526 | } |
| 1527 | |
| 1528 | fn commit_file(repository: &GitRepository, path: &str, bytes: &[u8], message: &str) -> Oid { |
| 1529 | let root = repository.workdir().expect("worktree"); |
| 1530 | fs::write(root.join(path), bytes).expect("write file"); |
| 1531 | let mut index = repository.index().expect("index"); |
| 1532 | index.add_path(Path::new(path)).expect("add path"); |
| 1533 | index.write().expect("write index"); |
| 1534 | let tree_oid = index.write_tree().expect("write tree"); |
| 1535 | let tree = repository.find_tree(tree_oid).expect("find tree"); |
| 1536 | let signature = Signature::now("Atomic Test", "atomic@example.com").expect("signature"); |
| 1537 | let parents = repository |
| 1538 | .head() |
| 1539 | .ok() |
| 1540 | .and_then(|head| head.target()) |
| 1541 | .map(|oid| repository.find_commit(oid).expect("parent")); |
| 1542 | match parents.as_ref() { |
| 1543 | Some(parent) => repository |
| 1544 | .commit( |
| 1545 | Some("HEAD"), |
| 1546 | &signature, |
| 1547 | &signature, |
| 1548 | message, |
| 1549 | &tree, |
| 1550 | &[parent], |
| 1551 | ) |
| 1552 | .expect("commit"), |
| 1553 | None => repository |
| 1554 | .commit(Some("HEAD"), &signature, &signature, message, &tree, &[]) |
| 1555 | .expect("initial commit"), |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | fn repository_observation(root: &Path) -> Box<GitRepositoryObservation> { |
| 1560 | match observe_git(root).expect("observe") { |