spiegel-keyman/resources/git-hooks/pre-commit
Eberhard Beilharz 44116b70dd
chore(common): detect ssh remotes in git hooks
Sometime ago we lost the ability to detect git remotes that use ssh
(git@github.com:keymanapp/keyman.git) and we only detect remotes that
use https (https://github.com/keymanapp/keyman.git). This change restores
this ability.

Also add some empty lines between the different parts of the error message.

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
2024-09-17 11:38:41 +02:00

41 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# for github.com/keymanapp repositories only!
#
GIT_ORIGIN="$(git remote get-url origin)"
if [[ ! "$GIT_ORIGIN" =~ github\.com(/|:)keymanapp ]]; then
# Not a Keyman repository. We have no opinion.
echo "DEBUG: Not a Keyman repository. We don't care"
exit 0
fi
#
# We want to make sure that .sh files are executable; however, .inc.sh need not
# be as they are always source-included in scripts.
#
SH_NON_EXECUTABLE=`git ls-files --stage | grep "\\.sh$" | grep -v "\\.inc\\.sh$" | grep -v 755 | cut -f 2 -`
if [ ! -z "$SH_NON_EXECUTABLE" ]; then
echo "ERROR: The following scripts are not marked as executable:"
echo
echo "$SH_NON_EXECUTABLE"
echo
echo "You can mark them as executable with:"
echo " git add --chmod=+x"
exit 1
fi
#
# Prevent accidental commits to master, beta, stable-x.y, or staging (for websites)
#
branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$branch" =~ ^(master|beta|stable-\d+\.\d+|staging)$ ]]; then
echo "ERROR: You cannot commit to $branch for this repo. Create a branch and open a pull request\n"
exit 2
fi
exit 0