Skip to content

Instantly share code, notes, and snippets.

@sanukin39
Created July 29, 2017 11:22
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 sanukin39/2a5aaafee2008100e5e14c528a86bd68 to your computer and use it in GitHub Desktop.
Save sanukin39/2a5aaafee2008100e5e14c528a86bd68 to your computer and use it in GitHub Desktop.
git pre-commit for unity and it check forgot to add the meta file
#!/bin/sh
#
# git pre-commit for Unity
# It check Forgot to add the meta file
# An alert is issued when a file has been added but no meta file has been added
#
# To enable this hook, rename this file to "pre-commit".
addfiles=`git diff --cached --name-status | awk '$2 != "A" { print $2 }'`
for file in $addfiles
do
if [[ ! "$file" =~ .meta$ ]]; then
metaFileName=$file.meta
hasMeta=false
for item in ${addfiles[@]}; do
if [ $item == $metaFileName ]; then
hasMeta=true
fi
done
if ! $hasMeta ; then
cat <<EOF
The following file was added, but the meta file for the file was not added
Check your git workspace!!
${file}
EOF
exit 1
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment