# Review and verify one local Git commit

Use this with a trusted Git installation and a complete local repository with an existing HEAD and ordinary history (no legacy grafts). Run from the repository root. The reviewer keeps the approval record outside the agent's editable workspace. Choose one ordinary commit with one parent for this procedure.

## Capture the proposal

After staging the intended edits, run this block in a POSIX shell. It records the current index as a Git tree object and presents the comparison against the captured base commit. Review every changed path. Inspect binary files and submodule revisions separately when the patch cannot show enough detail. If a command fails or an unexpected path appears, stop the review.

```sh
(
  set -eu
  export GIT_NO_REPLACE_OBJECTS=1
  base=$(git rev-parse --verify 'HEAD^{commit}')
  tree=$(git write-tree)
  git --no-pager diff --no-relative --ignore-submodules=none --no-ext-diff --no-textconv "$base" "$tree" --
  printf '\nbase=%s\ntree=%s\n' "$base" "$tree"
)
```

If you approve, record the repository, intended branch, permitted action, full base and tree IDs, and your decision in your own review record. For example, permit one local commit on the named branch and require a separate decision before a push. A different staged change or base calls for a fresh review. If your review covers a particular commit message, signature or author, check those fields separately.

## Check the resulting commit

Copy the following block to a reviewer-controlled file named `verify-reviewed-commit.sh` outside the project. Run `sh /path/to/verify-reviewed-commit.sh BASE_ID TREE_ID COMMIT_ID` from the repository, replacing the arguments with the two full IDs from your saved approval and the full candidate commit ID. The verifier reads Git objects and returns zero only for a matching tree and sole parent. A nonzero exit means stop. Keep any Git errors alongside the result.

```sh
#!/bin/sh
set -eu
export GIT_NO_REPLACE_OBJECTS=1
if [ "$#" -ne 3 ]; then
  echo 'Usage: verify-reviewed-commit.sh BASE_ID TREE_ID COMMIT_ID' >&2
  exit 2
fi
base=$1
tree=$2
commit=$3
for id in "$base" "$tree" "$commit"; do
  case "$id" in ''|*[!0-9a-f]*) echo 'Use full lowercase object IDs' >&2; exit 2;; esac
  case "${#id}" in 40|64) ;; *) echo 'Use full object IDs' >&2; exit 2;; esac
done
resolved=$(git rev-parse --verify "${commit}^{commit}")
if [ "$resolved" != "$commit" ]; then
  echo 'Candidate must be the full ID of a commit' >&2
  exit 2
fi
actual_tree=$(git rev-parse --verify "${commit}^{tree}")
parents=$(git --no-pager show -s --no-notes --no-show-signature --format=%P "$commit" --)
if [ "$actual_tree" != "$tree" ] || [ "$parents" != "$base" ]; then
  printf 'MISMATCH\nactual tree=%s\nactual parents=%s\n' "$actual_tree" "$parents" >&2
  exit 1
fi
printf 'MATCH commit=%s\n' "$commit"
```

A match covers the candidate's tracked snapshot and parentage. Check the intended repository, branch and remote destination before authorizing any push. A later amend, rebase or change of candidate requires verification of the new commit ID. A mismatch calls for inspection and a decision from the reviewer. Preserve the saved approval and both snapshots while investigating.

## Run tests against the verified commit

A matching tree and parent do not establish that tests passed on that snapshot. Use this optional step when tests are part of your review. Only run code and setup commands you trust; a linked worktree shares repository data and your user permissions. It is not a security sandbox.

From the original repository root, replace `COMMIT_ID` with the full candidate ID that passed the verifier. Choose an unused sibling directory. Stop if this command fails; do not reuse a pre-existing checkout.

```sh
GIT_NO_REPLACE_OBJECTS=1 git worktree add --detach ../review-check COMMIT_ID
```

Run the project's documented setup and test procedure inside that checkout. This block shows the command used by the guide's dependency-free Python fixture; replace the Python line with your project's trusted test command. The subshell exits with that command's status, and it stops if changing directory or reading HEAD fails. Record its output and exit status before running another command.

```sh
(
  set -eu
  cd ../review-check
  export GIT_NO_REPLACE_OBJECTS=1
  git rev-parse --verify 'HEAD^{commit}'
  python3 -B -m unittest -v
)
```

Confirm that the printed HEAD equals the verified candidate ID. Record the runtime, setup, test command, output and exit status with that ID. The old checkout's untracked configuration, ignored dependencies and unstaged edits are not copied by this operation. Use the project's documented dependency versions. Keep other agents out of the test checkout; inspect any changes made by setup or tests. A clean status cannot establish that the tests were meaningful or that external services were identical.

After saving the result, inspect the checkout for changes, including ignored outputs:

```sh
git -C ../review-check status --short --untracked-files=all --ignored
```

Preserve anything you need before cleanup. From the original repository root, remove only this disposable checkout when you are finished. Do not add `--force` if removal refuses; inspect the remaining files first. Ignored outputs can be discarded by removal even when ordinary status looks clean.

```sh
git worktree remove ../review-check
```

These commands do not authorize a push. If a fix changes the candidate, obtain a fresh review record and repeat verification and testing for its new full ID.

## Instruction for a coding agent

> Prepare the requested change and stage only the agreed paths. Show me the base commit, staged tree ID and the diff between them. Wait for my decision. If I approve one local commit, return the full resulting commit ID. Compare it with the base and tree in my saved decision and report the verifier's exit status. If tests are required, run the agreed test procedure in a fresh detached checkout of that verified ID. Return the ID, environment, commands, output and exit status together. Stop before pushing. If verification or testing fails, preserve the evidence and wait for review; any fix needs a fresh proposal.

A reviewer can run the same check independently. Keep any authority to publish under the repository's usual controls.
