diff --git a/.githooks/pre-push b/.githooks/pre-push index 49663ef..db60b84 100644 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -10,7 +10,8 @@ NOCOLOR='\033[0m' # Get the directory where this hook is located HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(cd "$HOOK_DIR/.." && pwd)" +# Go up from .git/hooks/ to repo root +REPO_ROOT="$(cd "$HOOK_DIR/../.." && pwd)" CHANGELOG_SCRIPT="$REPO_ROOT/scripts/update_changelog.sh" PREVIEW_FILE="$REPO_ROOT/.changelog_preview.tmp" VERSION_FILE="$REPO_ROOT/.changelog_version.tmp" diff --git a/Makefile b/Makefile index 7ee10c2..5e82c49 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ test-e2e: # Network - Distributed P2P Database System # Makefile for development and build tasks -.PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports +.PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports install-hooks VERSION := 0.53.13 COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) @@ -37,6 +37,11 @@ build: deps go build -ldflags "$(LDFLAGS) -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildVersion=$(VERSION)' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildCommit=$(COMMIT)' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildTime=$(DATE)'" -o bin/gateway ./cmd/gateway @echo "Build complete! Run ./bin/network-cli version" +# Install git hooks +install-hooks: + @echo "Installing git hooks..." + @bash scripts/install-hooks.sh + # Clean build artifacts clean: @echo "Cleaning build artifacts..." diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh new file mode 100755 index 0000000..51a7156 --- /dev/null +++ b/scripts/install-hooks.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Install git hooks from .githooks/ to .git/hooks/ +# This ensures the pre-push hook runs automatically + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" +GITHOOKS_DIR="$REPO_ROOT/.githooks" +GIT_HOOKS_DIR="$REPO_ROOT/.git/hooks" + +if [ ! -d "$GITHOOKS_DIR" ]; then + echo "Error: .githooks directory not found at $GITHOOKS_DIR" + exit 1 +fi + +if [ ! -d "$GIT_HOOKS_DIR" ]; then + echo "Error: .git/hooks directory not found at $GIT_HOOKS_DIR" + echo "Are you in a git repository?" + exit 1 +fi + +echo "Installing git hooks..." + +# Copy all hooks from .githooks/ to .git/hooks/ +for hook in "$GITHOOKS_DIR"/*; do + if [ -f "$hook" ]; then + hook_name=$(basename "$hook") + dest="$GIT_HOOKS_DIR/$hook_name" + + echo " Installing $hook_name..." + cp "$hook" "$dest" + chmod +x "$dest" + + # Make sure the hook can find the repo root + # The hooks already use relative paths, so this should work + fi +done + +echo "✓ Git hooks installed successfully!" +echo "" +echo "The following hooks are now active:" +ls -1 "$GIT_HOOKS_DIR"/* 2>/dev/null | xargs -n1 basename || echo " (none)" +