diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 0000000..1a6d156 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,33 @@ +#!/bin/sh + +# Target repository URL (replace this with the target repository URL) +TARGET_REPO="git@github.com:Tengs-Penkwe/FarmDSL.git" + +# Check if we're already in the process of pushing to the target repo +if [ "$PUSHING_TO_TARGET" = "true" ]; then + # echo "Already pushing to target repository. Skipping to avoid loop." + exit 0 +else + echo "\nAlso pushing to the GitHub repo to use the CI tools it provides\n" +fi + +# Get the name of the current branch +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + +# Set an environment variable to prevent recursive triggering +export PUSHING_TO_TARGET=true + +# Push the current branch to the same branch in the target repository +git push "$TARGET_REPO" "$CURRENT_BRANCH" -f + +# Unset the environment variable after the push +unset PUSHING_TO_TARGET + +# Check if the push was successful +if [ $? -eq 0 ]; then + echo "\nPush to GitHub repository succeeded.\n" +else + echo "\nPush to GitHub repository failed.\n" >&2 + exit 1 +fi + diff --git a/package.json b/package.json index 5dd7ce2..26a2302 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "typescript": "^4.9.4" }, "scripts": { + "postinstall": "git config core.hooksPath .githooks", "cover": "nyc --reporter text --reporter html yarn run test", "build": "tsc && yarn lint", "lint": "eslint src --ext .ts",