Last active
June 15, 2018 15:43
-
-
Save drmercer/65672f41210c2538ba4188eb8e750e44 to your computer and use it in GitHub Desktop.
A pair of git hooks for emulating receive.denyCurrentBranch=updateInstead on older git versions (MIT)
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
These two git hooks could be placed in your (remote) repository's `hooks` directory to emulate the behavior of | |
receive.denyCurrentBranch=updateInstead on older versions of git that don't support that option for that setting. | |
Make sure both are executable, and don't put any file extensions on them. | |
These hooks are licensed under the MIT license (found in the `~LICENSE` file). |
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
#!/bin/sh | |
# | |
# A post-receive hook that simply updates the working directory | |
# | |
# Clear pesky variables: | |
unset GIT_DIR | |
unset GIT_WORK_TREE | |
cd .. # Change to repo root | |
# Update the working directory: | |
git reset --hard HEAD |
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
#!/bin/sh | |
# | |
# A pre-receive hook for emulating receive.denyCurrentBranch=updateInstead on older | |
# git versions. I have used it on version 1.7.1. | |
# | |
# This script aborts the receive if there are local unsaved changes in the repository. | |
# | |
# Remove pesky environment variables | |
unset GIT_DIR | |
unset GIT_WORK_TREE | |
cd .. # Change dir to the repo root | |
# Check that the denyCurrentBranch setting is 'ignore' | |
dcb=$(git config --get receive.denyCurrentBranch) | |
if [ "$dcb" != "ignore" ]; then | |
echo 'WARNING: Your receive.denyCurrentBranch config value is not set to "ignore".' | |
fi | |
# Check for unsaved local changes | |
if ! git diff-index --quiet HEAD -- ; then | |
echo "There are unsaved changes in the remote worktree." | |
exit 1 | |
else | |
exit 0 | |
fi |
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
The MIT License | |
Copyright (c) 2016 Dan Mercer | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the "Software"), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
the Software, and to permit persons to whom the Software is furnished to do so, | |
subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS | |
IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | |
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | |
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | |
THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment