Last active
May 31, 2022 05:38
-
-
Save AmaiSaeta/048b6fd11623097e3c8b7dc762cbd29c to your computer and use it in GitHub Desktop.
スクリプトファイル(shebangが書かれているファイル)にGitリポジトリ上の実行パーミッションが付与されていない場合にcommitをエラーにするpre-commit hook(主にGit for Windows向け)
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/bash | |
exist_non_exec_perm_exec_file=0 | |
git diff --cached --name-only --diff-filter=AM | while read path | |
do | |
if head -1 "$path" | grep '^#!' > /dev/null && | |
git ls-files -s "$path" | grep '^100644' > /dev/null | |
then | |
echo $(tput smso)\*\*WARNING\*\*$(tput rmso) $path maybe need \"execution\" permission. Run \`git update-index --add --chmod=x $path\` >&2 | |
exist_non_exec_perm_exec_file=1 | |
fi | |
done | |
if [[ $exist_non_exec_perm_exec_file -eq 1 ]] | |
then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment