Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # A hook script called by "git commit" with no arguments. The hook should
- # exit with non-zero status after issuing an appropriate message if it wants
- # to stop the commit.
- SELF_DIR=`git rev-parse --show-toplevel`
- DATABASE=$SELF_DIR/.permissions
- # Clear the permissions database file
- > $DATABASE
- IFS_OLD=$IFS; IFS=$'\n'
- echo -n "Backing-up file permissions ... "
- DIRS=()
- for FILE in `git ls-files`
- do
- # Save the permissions of all files in the index
- echo $FILE";"`stat -c "%a;%U;%G" $FILE` >> $DATABASE
- FILE_DIR=$(dirname "$FILE")
- if ! [[ " ${DIRS[@]} " =~ " ${FILE_DIR} " ]]; then
- DIRS+=("$FILE_DIR");
- fi
- done
- echo -n "and directory permissions ... "
- for DIR in "${DIRS[@]}"
- do
- # Save the permissions of all directories in the index
- echo $DIR";"`stat -c "%a;%U;%G" $DIR` >> $DATABASE
- done
- IFS=$IFS_OLD
- # Add the permissions database file to the index
- git add $DATABASE
- echo "OK"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement