Test separated ots hooks
This commit is contained in:
parent
094cd53864
commit
6dc8399238
11 changed files with 386 additions and 13 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
# Git OpenTimestamp Hooks Installer
|
||||
# Copies self-contained hooks to git repository
|
||||
# Detects available tools and installs matching hooks
|
||||
|
||||
set -e
|
||||
|
||||
|
|
@ -9,21 +9,50 @@ 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
|
||||
|
||||
HOOKS_DIR="$(git rev-parse --git-dir)/hooks"
|
||||
MODE=""
|
||||
|
||||
echo "Installing OpenTimestamp hooks to: $HOOKS_DIR"
|
||||
# Detect available tools
|
||||
if command -v ots &> /dev/null; then
|
||||
MODE="ots"
|
||||
echo "Detected: ots CLI"
|
||||
elif command -v node &> /dev/null && node -e "require('@opentimestamps/ots')" &> /dev/null 2>&1; then
|
||||
MODE="node"
|
||||
echo "Detected: @opentimestamps/ots (Node.js)"
|
||||
echo "Note: Node version creates local proofs only (no calendar submission)"
|
||||
echo ""
|
||||
|
||||
# Install node package locally if not already present
|
||||
if [ ! -d "node_modules/@opentimestamps" ]; then
|
||||
echo "Installing @opentimestamps/ots locally..."
|
||||
npm install @opentimestamps/ots
|
||||
echo "✓ Package installed"
|
||||
fi
|
||||
else
|
||||
echo "Error: Neither ots CLI nor @opentimestamps/ots found" >&2
|
||||
echo "Install one of:" >&2
|
||||
echo " pipx install opentimestamps-client (recommended)" >&2
|
||||
echo " npm install @opentimestamps/ots (local proofs only)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copy hooks
|
||||
cp "$SCRIPT_DIR/post-commit" "$HOOKS_DIR/post-commit"
|
||||
cp "$SCRIPT_DIR/pre-commit" "$HOOKS_DIR/pre-commit"
|
||||
echo ""
|
||||
echo "Installing $MODE hooks to: $HOOKS_DIR"
|
||||
|
||||
# Copy appropriate hooks
|
||||
if [ "$MODE" = "ots" ]; then
|
||||
cp "$SCRIPT_DIR/post-commit-ots" "$HOOKS_DIR/post-commit"
|
||||
cp "$SCRIPT_DIR/pre-commit-ots" "$HOOKS_DIR/pre-commit"
|
||||
else
|
||||
cp "$SCRIPT_DIR/post-commit-node" "$HOOKS_DIR/post-commit"
|
||||
cp "$SCRIPT_DIR/pre-commit-node" "$HOOKS_DIR/pre-commit"
|
||||
fi
|
||||
|
||||
# Make executable
|
||||
chmod +x "$HOOKS_DIR/post-commit" "$HOOKS_DIR/pre-commit"
|
||||
|
||||
echo "✓ Post-commit hook installed"
|
||||
|
|
@ -32,19 +61,33 @@ echo "✓ Pre-commit backfill hook installed"
|
|||
# Setup .gitignore
|
||||
GITIGNORE=".gitignore"
|
||||
if [ ! -f "$GITIGNORE" ]; then
|
||||
echo ".ots/.attestation-cache" > "$GITIGNORE"
|
||||
cat > "$GITIGNORE" << 'EOF'
|
||||
.ots/.attestation-cache
|
||||
node_modules/
|
||||
EOF
|
||||
echo "✓ Created .gitignore"
|
||||
elif ! grep -q ".ots/.attestation-cache" "$GITIGNORE"; then
|
||||
echo "" >> "$GITIGNORE"
|
||||
echo ".ots/.attestation-cache" >> "$GITIGNORE"
|
||||
if [ "$MODE" = "node" ] && ! grep -q "node_modules/" "$GITIGNORE"; then
|
||||
echo "node_modules/" >> "$GITIGNORE"
|
||||
fi
|
||||
echo "✓ Updated .gitignore"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Mode: $MODE"
|
||||
if [ "$MODE" = "ots" ]; then
|
||||
echo " - Full Bitcoin attestation via calendars"
|
||||
echo " - Proofs submitted to remote calendars"
|
||||
else
|
||||
echo " - Local proofs only (no calendar submission)"
|
||||
echo " - For full attestation, use: pipx install opentimestamps-client"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Make a test commit to verify hooks work"
|
||||
echo "2. Commit the .ots/ directory: git add .ots/"
|
||||
echo "3. Commit with message: git commit -m 'Add OpenTimestamp proofs'"
|
||||
echo "1. Make a test commit"
|
||||
echo "2. Commit proofs: git add .ots/ && git commit -m 'Add OpenTimestamp proofs'"
|
||||
echo ""
|
||||
echo "To uninstall:"
|
||||
echo " rm $HOOKS_DIR/post-commit $HOOKS_DIR/pre-commit"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue