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

Function commit_file

atomic-cli/src/commands/git/shadow.rs:2417–2452  ·  view source on GitHub ↗
(git: &GitRepository, root: &Path, content: &[u8])

Source from the content-addressed store, hash-verified

2415 use git2::Oid;
2416
2417 fn commit_file(git: &GitRepository, root: &Path, content: &[u8]) -> Oid {
2418 std::fs::write(root.join("tracked.txt"), content).unwrap();
2419 let mut index = git.index().unwrap();
2420 index.add_path(Path::new("tracked.txt")).unwrap();
2421 index.write().unwrap();
2422 let tree_oid = index.write_tree().unwrap();
2423 let tree = git.find_tree(tree_oid).unwrap();
2424 let signature = git2::Signature::now("Atomic Test", "test@atomic.invalid").unwrap();
2425 let parents = git
2426 .head()
2427 .ok()
2428 .and_then(|head| head.target())
2429 .map(|oid| git.find_commit(oid).unwrap());
2430 match parents.as_ref() {
2431 Some(parent) => git
2432 .commit(
2433 Some("HEAD"),
2434 &signature,
2435 &signature,
2436 "checkpoint",
2437 &tree,
2438 &[parent],
2439 )
2440 .unwrap(),
2441 None => git
2442 .commit(
2443 Some("HEAD"),
2444 &signature,
2445 &signature,
2446 "checkpoint",
2447 &tree,
2448 &[],
2449 )
2450 .unwrap(),
2451 }
2452 }
2453
2454 /// Atomic + colocated Git with the retained shadow exclude marker, no
2455 /// shim checkpoint and no shim opt-in: a native, unenrolled repo.

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