Skip to content

Instantly share code, notes, and snippets.

@ilyaguy
Last active March 6, 2018 15:43
Show Gist options
  • Save ilyaguy/afd5bf31cc3633011545b8c1190bafda to your computer and use it in GitHub Desktop.
Save ilyaguy/afd5bf31cc3633011545b8c1190bafda to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
#
NAME=$(git branch | grep '*' | sed -e 's/\* //' -e 's#^.*/##')
DESCRIPTION=$(git config branch."$NAME".description)
echo "$NAME"': '"$(cat $1)" > "$1"
if [ -n "$DESCRIPTION" ]
then
echo "" >> "$1"
echo $DESCRIPTION >> "$1"
fi
#!/bin/sh
#
# Author: Bo-Yi Wu <appleboy.tw@gmail.com>
root_dir="$(pwd)/"
commit_list=$(git diff-index --cached --name-only --diff-filter=ACMR HEAD)
error_buffer=""
php_debug=""
js_errors=""
js_file=""
for file in $commit_list
do
extension=$(echo "$file" | awk -F . '{print $NF}')
case $extension in
php)
errors=$(php -l $root_dir$file 2>&1 | grep "Parse error")
if [ -n "$errors" ]; then
echo "Syntax errors found in file: $file \n"
error_buffer="$error_buffer \n$errors"
fi
if [ "$SKIP_DEBUG" != 1 ]; then
errors=$(grep -in -e 'print_r\|var_dump\|var_export' $root_dir$file 2>&1)
if [ -n "$errors" ]; then
echo "Debug messages found in file: $file "
php_debug="$php_debug \n$file\n$errors"
fi
fi
;;
coffee|js)
if [ "$SKIP_DEBUG" != 1 ]; then
js_errors=$(grep -i -e 'console\.' $root_dir$file 2>&1)
if [ -n "$js_errors" ]; then
echo "Debug messages found in file: $file "
if [ -n "$js_file" ]; then
js_file="$js_file, $file"
else
js_file="$file"
fi
fi
fi
;;
esac
done
if [ -n "$error_buffer" ] || [ -n "$php_debug" ] || [ -n "$js_errors" ]; then
echo
echo "These errors were found in try-to-commit files: "
if [ -n "$error_buffer" ]; then
echo $error_buffer
echo
fi
if [ -n "$php_debug" ]; then
echo "$php_debug \n\nfiles found debug message"
echo "Please remove 'print_r', 'var_dump', 'var_export' from source code."
echo
fi
if [ -n "$js_file" ]; then
echo "$js_file files found debug message"
echo "Please remove 'console.[log|info|xxxx] debug message' from source code."
echo
fi
echo "Can't commit, fix errors first."
exit 1
else
echo "Commited successfully."
fi
#!/bin/bash
if [ "$INSIDE_EMACS" = "" ]
then
echo "Clean shell"
exec < /dev/tty
read -p "А не сделал ли я хуйню? [Y/n]:" response
exec <&-
if [[ $response == "N" || $response == "n" ]]
then
exit 0
fi
exit 1
else
echo "Inside emacs!"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment