git-ots/hooks/post-commit-ots
Otto b1e305d831 Replace legacy scripts with separated ots/node hooks
- Remove deprecated scripts/ directory (6 files)
- Add hooks/post-commit-ots (ots CLI version)
- Add hooks/pre-commit-ots (ots CLI backfill)
- Add hooks/post-commit-node (Node.js version, local proofs only)
- Add hooks/pre-commit-node (Node.js backfill, no upgrade)
- Update hooks/install.sh to auto-detect and install matching hooks
- Update documentation (SKILL.md, README.md, AGENTS.md)
- Add node_modules/ to .gitignore for Node.js mode

Breaking change: Scripts removed, use new hooks/ directory.
2026-03-08 00:38:43 +01:00

41 lines
1 KiB
Bash
Executable file

#!/bin/bash
# Git OpenTimestamp Post-Commit Hook (ots CLI version)
# Requires: opentimestamps-client (pipx install opentimestamps-client)
set -e
OUTPUT_DIR=".ots"
OUTPUT_FILE="$OUTPUT_DIR/proof.ots"
mkdir -p "$OUTPUT_DIR"
COMMIT_HASH=$(git rev-parse HEAD)
# Generate proof using ots CLI
temp_file=$(mktemp)
temp_ots="${temp_file}.ots"
python3 -c "import sys; sys.stdout.buffer.write(bytes.fromhex('$COMMIT_HASH'))" > "$temp_file"
ots stamp "$temp_file" 2>/dev/null
if [ -f "$temp_ots" ]; then
mv "$temp_ots" "$OUTPUT_FILE"
rm -f "$temp_file"
echo "[ots] Generated proof: ${COMMIT_HASH:0:8}"
else
rm -f "$temp_file"
echo "[ots] Warning: Failed to generate proof" >&2
exit 0
fi
# Save previous commit for chaining
PREV_COMMIT=$(git rev-parse HEAD^1 2>/dev/null || echo "")
if [ -n "$PREV_COMMIT" ]; then
echo "$PREV_COMMIT" > "$OUTPUT_DIR/prev-commit.txt"
fi
# Create individual proof file
INDIVIDUAL_PROOF="$OUTPUT_DIR/${COMMIT_HASH}.ots"
cp "$OUTPUT_FILE" "$INDIVIDUAL_PROOF"
echo "[ots] Proof generated successfully"