Skip to content

Instantly share code, notes, and snippets.

@dctabuyz
Last active January 19, 2018 14:52
Show Gist options
  • Save dctabuyz/ffda085e08f15b01da155f5338a4daa8 to your computer and use it in GitHub Desktop.
Save dctabuyz/ffda085e08f15b01da155f5338a4daa8 to your computer and use it in GitHub Desktop.
pre-receive hook: protect windows git users
#!/bin/sh
# https://msdn.microsoft.com/ru-ru/library/windows/desktop/aa365247(v=vs.85).aspx
# the following reserved characters:
# < (less than)
# > (greater than)
# : (colon)
# " (double quote)
# / (forward slash)
# \ (backslash)
# | (vertical bar or pipe)
# ? (question mark)
# * (asterisk)
# Integer value zero, sometimes referred to as the ASCII NUL character.
# Characters whose integer representations are in the range from 1 through 31,
# except for alternate data streams where these characters are allowed.
# For more information about file streams, see File Streams.
# Any other character that the target file system does not allow.
# CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9,
# LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.
# Also avoid these names followed immediately by an extension;
# for example, NUL.txt is not recommended. For more information, see Namespaces.
FORBIDDEN='<>:"/\|?*'
while read oldsha newsha refname someparam ;
do
branch=`echo ${refname} | cut -b 12-`
t=`echo ${branch} | tr A-Z a-z`
for reserved in con prn aux nul com1 com2 com3 com4 com5 com6 com7 com8 com9 lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9
do
if [ "${t}x" = "${reserved}x" ] ;
then
echo "it is not a good idea to use '${branch}' as name for branch. please rename your branch. thank you."
exit 1
fi
done
t=`echo ${branch} | tr -d ${FORBIDDEN}`
if [ "${t}x" = "${branch}x" ] ;
then
exit 0
fi
echo "symbols '${FORBIDDEN}' are not allowed in branch name. please rename your branch. thank you."
done
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment