-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The pre-commit.protect-master should protect more than just master #8
Open
lillialexis
wants to merge
4
commits into
master
Choose a base branch
from
FEI-5966
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+34
−10
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,43 @@ | ||
#!/bin/sh | ||
|
||
# A simple pre-commit hook that makes it illegal to commit to master | ||
# on the repo. An exception is made for the automated process | ||
# which is the only thing allowed to merge into master. | ||
# A simple pre-commit hook that makes it illegal to commit to master (and other | ||
# deploy/target branches) on the repo. An exception is made for the automated process | ||
# which is the only thing allowed to merge into master/etc. | ||
# | ||
# For emergencies, you can override this hook by using 'git commit -n'. | ||
|
||
# IF YOU UPDATE THESE VARS, be sure to update pre-push.protect-master as well. | ||
# If you want to whitelist other users, just add another "-e <email>". | ||
SUPERUSERS="-e [email protected]" | ||
|
||
if git config --get user.email | grep -x $SUPERUSERS >/dev/null; then | ||
|
||
# Exit if user email matches a SUPERUSER | ||
if git config --get user.email | grep -x "$SUPERUSERS" >/dev/null; then | ||
exit 0 | ||
fi | ||
|
||
if [ "`git rev-parse --abbrev-ref HEAD`" = "master" ]; then | ||
echo "FATAL ERROR: You cannot commit directly to the master branch." | ||
echo "Commit to a deploy branch instead:" | ||
echo " https://khanacademy.org/r/git-at-ka" | ||
exit 1 | ||
fi | ||
# Get the current branch name | ||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
# Get the known deploy branches from the git config (comma-separated list) | ||
KNOWN_DEPLOY_BRANCHES=$(git config --get ka.olc.targetBranches) | ||
|
||
# Check if the current branch is protected | ||
case "$CURRENT_BRANCH" in | ||
master|main|next|deploy*) | ||
echo "FATAL ERROR: You cannot commit directly to the $CURRENT_BRANCH branch." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Check if the current branch matches any known deploy branches | ||
IFS=',' | ||
for branch in $KNOWN_DEPLOY_BRANCHES; do | ||
if [ "$CURRENT_BRANCH" = "$branch" ]; then | ||
echo "FATAL ERROR: You cannot commit directly to the $CURRENT_BRANCH branch." | ||
echo "Make a pull-request or audit and land it to this branch instead" | ||
exit 1 | ||
fi | ||
done | ||
|
||
exit 0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this link went nowhere...