mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-11 07:38:49 +00:00
feat: add git hook installation script and update Makefile
- Introduced a new script `install-hooks.sh` to automate the installation of git hooks from the `.githooks` directory to the `.git/hooks` directory. - Updated the Makefile to include a new `install-hooks` target for easy execution of the hook installation process. - Modified the pre-push hook to correctly reference the repository root directory.
This commit is contained in:
parent
6e59b17c6a
commit
909be0f18f
@ -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"
|
||||
|
||||
7
Makefile
7
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..."
|
||||
|
||||
45
scripts/install-hooks.sh
Executable file
45
scripts/install-hooks.sh
Executable file
@ -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)"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user