Git hook
Pre commit hook
#!/bin/sh
# setup-pre-commit.sh
# Path to the pre-commit hook
HOOK_PATH=".git/hooks/pre-commit"
# Pre-commit hook script
HOOK_SCRIPT="#!/bin/sh\n\n# Increment version in package.json using jq\nVERSION=\$(jq -r '.version' package.json)\nNEW_VERSION=\$(echo \$VERSION | awk -F. -v OFS=. '{\$NF = \$NF + 1 ; print}')\n\n# Update the version in package.json\njq \".version = \\\"\$NEW_VERSION\\\"\" package.json > temp.json && mv temp.json package.json\n\n# Add the package.json to the commit\ngit add package.json\n\n# Exit successfully\nexit 0"
# Create the pre-commit hook
echo "$HOOK_SCRIPT" > "$HOOK_PATH"
# Make the pre-commit hook executable
chmod +x "$HOOK_PATH"
echo "Pre-commit hook set up successfully."Git Hooks
Link hook file

Last updated
