MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / commit_file

Function commit_file

atomic-cli/src/commands/agent/hooks.rs:782–810  ·  view source on GitHub ↗
(repository: &GitRepository, root: &Path, content: &[u8], message: &str)

Source from the content-addressed store, hash-verified

780 use crate::commands::git::checkpoint::{self, VerifiedCheckpointInput};
781
782 fn commit_file(repository: &GitRepository, root: &Path, content: &[u8], message: &str) -> Oid {
783 fs::write(root.join("tracked.txt"), content).unwrap();
784 let mut index = repository.index().unwrap();
785 index.add_path(Path::new("tracked.txt")).unwrap();
786 index.write().unwrap();
787 let tree_oid = index.write_tree().unwrap();
788 let tree = repository.find_tree(tree_oid).unwrap();
789 let signature = Signature::now("Atomic Test", "test@atomic.invalid").unwrap();
790 let parents = repository
791 .head()
792 .ok()
793 .and_then(|head| head.target())
794 .map(|oid| repository.find_commit(oid).unwrap());
795 match parents.as_ref() {
796 Some(parent) => repository
797 .commit(
798 Some("HEAD"),
799 &signature,
800 &signature,
801 message,
802 &tree,
803 &[parent],
804 )
805 .unwrap(),
806 None => repository
807 .commit(Some("HEAD"), &signature, &signature, message, &tree, &[])
808 .unwrap(),
809 }
810 }
811
812 fn initialized_colocated_repository(root: &Path) -> (GitRepository, Oid) {
813 atomic_repository::Repository::init(root).unwrap();

Calls 9

as_refMethod · 0.80
writeFunction · 0.50
unwrapMethod · 0.45
indexMethod · 0.45
add_pathMethod · 0.45
writeMethod · 0.45
okMethod · 0.45
headMethod · 0.45
commitMethod · 0.45