Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.95 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # A hook script called by "git commit" with no arguments. The hook should
  4. # exit with non-zero status after issuing an appropriate message if it wants
  5. # to stop the commit.
  6.  
  7. SELF_DIR=`git rev-parse --show-toplevel`
  8. DATABASE=$SELF_DIR/.permissions
  9.  
  10. # Clear the permissions database file
  11. > $DATABASE
  12.  
  13. IFS_OLD=$IFS; IFS=$'\n'
  14. echo -n "Backing-up file permissions ... "
  15.  
  16. DIRS=()
  17.  
  18. for FILE in `git ls-files`
  19. do
  20.    # Save the permissions of all files in the index
  21.    echo $FILE";"`stat -c "%a;%U;%G" $FILE` >> $DATABASE
  22.    FILE_DIR=$(dirname "$FILE")
  23.    if ! [[ " ${DIRS[@]} " =~ " ${FILE_DIR} " ]]; then
  24.       DIRS+=("$FILE_DIR");
  25.    fi
  26. done
  27.  
  28. echo -n "and directory permissions ... "
  29. for DIR in "${DIRS[@]}"
  30. do
  31.    # Save the permissions of all directories in the index
  32.    echo $DIR";"`stat -c "%a;%U;%G" $DIR` >> $DATABASE
  33. done
  34.  
  35. IFS=$IFS_OLD
  36.  
  37. # Add the permissions database file to the index
  38. git add $DATABASE
  39.  
  40. echo "OK"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement