Test commit with pre-commit backfill
This commit is contained in:
parent
c0685dabfb
commit
810d26b7af
6 changed files with 150 additions and 6 deletions
|
|
@ -1 +1 @@
|
||||||
4a6f5ed0c12315b0bc8a0fa5815ada1bd20e5963
|
46aded7b9582bbed673843e2cf8a3f8fa742ad91
|
||||||
|
|
|
||||||
BIN
.ots/proof.ots
BIN
.ots/proof.ots
Binary file not shown.
97
backfill-proofs.sh
Executable file
97
backfill-proofs.sh
Executable file
|
|
@ -0,0 +1,97 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# backfill-proofs.sh - Generate/upgrade OpenTimestamp proofs for all commits
|
||||||
|
# Usage: backfill-proofs.sh [repository-path]
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
REPO_PATH="${1:-.}"
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
cd "$REPO_PATH"
|
||||||
|
|
||||||
|
# Verify we're in a git repository
|
||||||
|
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
||||||
|
echo "Error: not a git repository" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find the generate-proof.sh script
|
||||||
|
GENERATE_SCRIPT=""
|
||||||
|
|
||||||
|
# Check if generate-proof.sh is in the same directory as this script
|
||||||
|
if [ -f "$SCRIPT_DIR/generate-proof.sh" ]; then
|
||||||
|
GENERATE_SCRIPT="$SCRIPT_DIR/generate-proof.sh"
|
||||||
|
# Check in repository root
|
||||||
|
elif [ -f "generate-proof.sh" ]; then
|
||||||
|
GENERATE_SCRIPT="./generate-proof.sh"
|
||||||
|
# Check if skill is installed globally
|
||||||
|
elif [ -f "$HOME/.openclaw/workspace/skills/git-ots-hook/scripts/generate-proof.sh" ]; then
|
||||||
|
GENERATE_SCRIPT="$HOME/.openclaw/workspace/skills/git-ots-hook/scripts/generate-proof.sh"
|
||||||
|
else
|
||||||
|
echo "Error: generate-proof.sh not found" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod +x "$GENERATE_SCRIPT"
|
||||||
|
|
||||||
|
# Ensure .ots directory exists
|
||||||
|
mkdir -p .ots
|
||||||
|
|
||||||
|
echo "[ots-backfill] Scanning commit history..."
|
||||||
|
|
||||||
|
# Get all commit hashes (oldest to newest)
|
||||||
|
COMMITS=$(git rev-list --reverse HEAD)
|
||||||
|
TOTAL=$(echo "$COMMITS" | wc -l)
|
||||||
|
CURRENT=0
|
||||||
|
|
||||||
|
# Track if any proofs were updated
|
||||||
|
UPDATED=0
|
||||||
|
|
||||||
|
for COMMIT in $COMMITS; do
|
||||||
|
CURRENT=$((CURRENT + 1))
|
||||||
|
echo "[ots-backfill] Processing commit $CURRENT/$TOTAL: ${COMMIT:0:8}"
|
||||||
|
|
||||||
|
# Check if proof exists for this commit
|
||||||
|
PROOF_FILE=".ots/${COMMIT}.ots"
|
||||||
|
|
||||||
|
if [ -f "$PROOF_FILE" ]; then
|
||||||
|
# Try to upgrade existing proof
|
||||||
|
echo " Upgrading existing proof..."
|
||||||
|
if ots upgrade "$PROOF_FILE" 2>/dev/null; then
|
||||||
|
echo " ✓ Upgraded to attested"
|
||||||
|
UPDATED=$((UPDATED + 1))
|
||||||
|
else
|
||||||
|
echo " - Still pending (no upgrade available)"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Generate new proof for this commit
|
||||||
|
echo " Generating new proof..."
|
||||||
|
"$GENERATE_SCRIPT" "$COMMIT" "$PROOF_FILE" >/dev/null 2>&1
|
||||||
|
echo " ✓ Generated proof"
|
||||||
|
UPDATED=$((UPDATED + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Create/update latest proof symlink
|
||||||
|
LATEST_COMMIT=$(git rev-parse HEAD)
|
||||||
|
if [ -f ".ots/${LATEST_COMMIT}.ots" ]; then
|
||||||
|
cp ".ots/${LATEST_COMMIT}.ots" ".ots/proof.ots"
|
||||||
|
echo "[ots-backfill] Updated .ots/proof.ots for latest commit"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Save previous commit chain info
|
||||||
|
echo "[ots-backfill] Saving commit chain..."
|
||||||
|
git rev-list HEAD | while read COMMIT; do
|
||||||
|
PREV=$(git rev-parse ${COMMIT}^1 2>/dev/null || echo "")
|
||||||
|
if [ -n "$PREV" ]; then
|
||||||
|
echo "$COMMIT:$PREV" >> ".ots/commit-chain.txt"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "[ots-backfill] Complete! Processed $TOTAL commits, updated $UPDATED proofs"
|
||||||
|
echo ""
|
||||||
|
echo "Proofs stored in: .ots/"
|
||||||
|
echo " - Individual proofs: .ots/<commit-hash>.ots"
|
||||||
|
echo " - Latest proof: .ots/proof.ots"
|
||||||
|
echo " - Commit chain: .ots/commit-chain.txt"
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# install-ots-hook.sh - Install OpenTimestamp post-commit hook
|
# install-ots-hook.sh - Install OpenTimestamp post-commit hook
|
||||||
# Usage: install-ots-hook.sh [repository-path]
|
# Usage: install-ots-hook.sh [repository-path] [backfill]
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
REPO_PATH="${1:-.}"
|
REPO_PATH="${1:-.}"
|
||||||
|
ENABLE_BACKFILL="${2:-}" # Second arg: "backfill" to enable pre-commit backfill hook
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
cd "$REPO_PATH"
|
cd "$REPO_PATH"
|
||||||
|
|
@ -18,7 +19,7 @@ fi
|
||||||
HOOKS_DIR="$(git rev-parse --git-dir)/hooks"
|
HOOKS_DIR="$(git rev-parse --git-dir)/hooks"
|
||||||
POST_COMMIT_HOOK="$HOOKS_DIR/post-commit"
|
POST_COMMIT_HOOK="$HOOKS_DIR/post-commit"
|
||||||
|
|
||||||
echo "Installing OpenTimestamp hook in: $REPO_PATH"
|
echo "Installing OpenTimestamp hooks in: $REPO_PATH"
|
||||||
|
|
||||||
# Create the post-commit hook
|
# Create the post-commit hook
|
||||||
cat > "$POST_COMMIT_HOOK" << 'HOOK_SCRIPT'
|
cat > "$POST_COMMIT_HOOK" << 'HOOK_SCRIPT'
|
||||||
|
|
@ -66,10 +67,23 @@ HOOK_SCRIPT
|
||||||
chmod +x "$POST_COMMIT_HOOK"
|
chmod +x "$POST_COMMIT_HOOK"
|
||||||
|
|
||||||
echo "✓ Post-commit hook installed successfully"
|
echo "✓ Post-commit hook installed successfully"
|
||||||
|
|
||||||
|
# Optionally install pre-commit backfill hook
|
||||||
|
if [ "$ENABLE_BACKFILL" = "backfill" ]; then
|
||||||
|
PRE_COMMIT_HOOK="$HOOKS_DIR/pre-commit"
|
||||||
|
cp "$SCRIPT_DIR/pre-commit-backfill" "$PRE_COMMIT_HOOK"
|
||||||
|
chmod +x "$PRE_COMMIT_HOOK"
|
||||||
|
echo "✓ Pre-commit backfill hook installed (will backfill proofs before each commit)"
|
||||||
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Next steps:"
|
echo "Next steps:"
|
||||||
echo "1. Ensure generate-proof.sh is accessible (copy to repo root or install skill globally)"
|
echo "1. Ensure scripts are accessible (copy to repo root or install skill globally)"
|
||||||
echo "2. Verify ots CLI or @opentimestamps/ots is installed"
|
echo "2. Verify ots CLI or @opentimestamps/ots is installed"
|
||||||
echo "3. Make a test commit to verify the hook works"
|
echo "3. Make a test commit to verify the hooks work"
|
||||||
echo ""
|
echo ""
|
||||||
echo "To uninstall, run: rm $POST_COMMIT_HOOK"
|
echo "To uninstall:"
|
||||||
|
echo " rm $POST_COMMIT_HOOK"
|
||||||
|
if [ "$ENABLE_BACKFILL" = "backfill" ]; then
|
||||||
|
echo " rm $PRE_COMMIT_HOOK"
|
||||||
|
fi
|
||||||
|
|
|
||||||
32
pre-commit-backfill
Executable file
32
pre-commit-backfill
Executable file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Pre-commit hook: backfill proofs for all commits before creating new commit
|
||||||
|
# This ensures all historical commits have attested proofs
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Get the directory where this hook is installed
|
||||||
|
HOOKS_DIR="$(git rev-parse --git-dir)/hooks"
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
# Find the backfill-proofs.sh script
|
||||||
|
BACKFILL_SCRIPT=""
|
||||||
|
|
||||||
|
if [ -f "$SCRIPT_DIR/backfill-proofs.sh" ]; then
|
||||||
|
BACKFILL_SCRIPT="$SCRIPT_DIR/backfill-proofs.sh"
|
||||||
|
elif [ -f ".git/hooks/backfill-proofs.sh" ]; then
|
||||||
|
BACKFILL_SCRIPT=".git/hooks/backfill-proofs.sh"
|
||||||
|
elif [ -f "backfill-proofs.sh" ]; then
|
||||||
|
BACKFILL_SCRIPT="./backfill-proofs.sh"
|
||||||
|
elif [ -f "$HOME/.openclaw/workspace/skills/git-ots-hook/scripts/backfill-proofs.sh" ]; then
|
||||||
|
BACKFILL_SCRIPT="$HOME/.openclaw/workspace/skills/git-ots-hook/scripts/backfill-proofs.sh"
|
||||||
|
else
|
||||||
|
# Silently skip if backfill script not found
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod +x "$BACKFILL_SCRIPT"
|
||||||
|
|
||||||
|
echo "[ots] Backfilling proofs before commit..."
|
||||||
|
"$BACKFILL_SCRIPT" .
|
||||||
|
|
||||||
|
echo "[ots] Ready to commit"
|
||||||
1
test4.txt
Normal file
1
test4.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# Test pre-commit backfill
|
||||||
Loading…
Add table
Add a link
Reference in a new issue