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)
| 894 | /// index observation, and a wrong tree can only make the capture fail |
| 895 | /// verification against the committed tree later — it never widens trust. |
| 896 | fn 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 | |
| 910 | pub(crate) fn record_pre_commit(root: &Path) -> CliResult<()> { |
| 911 | let root = canonical_root(root)?; |
no test coverage detected