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

Function commit_index_tree

atomic-cli/src/commands/git/hooks.rs:896–908  ·  view source on GitHub ↗

The tree of the index Git is committing from, when the pre-commit hook was handed one through `GIT_INDEX_FILE`. Advisory like the rest of the capture: any failure keeps the primary index observation, and a wrong tree can only make the capture fail verification against the committed tree later — it never widens trust.

(root: &Path)

Source from the content-addressed store, hash-verified

894/// index observation, and a wrong tree can only make the capture fail
895/// verification against the committed tree later — it never widens trust.
896fn commit_index_tree(root: &Path) -> Option<String> {
897 let named = std::env::var_os("GIT_INDEX_FILE")?;
898 let path = PathBuf::from(named);
899 // Git runs hooks from the worktree root and may pass a relative path.
900 let path = if path.is_absolute() {
901 path
902 } else {
903 root.join(path)
904 };
905 let git = git2::Repository::open(root).ok()?;
906 let mut index = git2::Index::open(&path).ok()?;
907 index.write_tree_to(&git).ok().map(|tree| tree.to_string())
908}
909
910pub(crate) fn record_pre_commit(root: &Path) -> CliResult<()> {
911 let root = canonical_root(root)?;

Callers 1

record_pre_commitFunction · 0.85

Calls 2

openFunction · 0.50
okMethod · 0.45

Tested by

no test coverage detected