Skip to content

Instantly share code, notes, and snippets.

@AmaiSaeta
Last active May 31, 2022 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmaiSaeta/048b6fd11623097e3c8b7dc762cbd29c to your computer and use it in GitHub Desktop.
Save AmaiSaeta/048b6fd11623097e3c8b7dc762cbd29c to your computer and use it in GitHub Desktop.
スクリプトファイル(shebangが書かれているファイル)にGitリポジトリ上の実行パーミッションが付与されていない場合にcommitをエラーにするpre-commit hook(主にGit for Windows向け)
#!/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