watanabe1115 / CodeFormatter

0 stars 2 forks source link

pre-commit sample #1

Open watanabe1115 opened 6 years ago

watanabe1115 commented 6 years ago
#!/bin/sh
if git rev-parse --verify HEAD >/dev/null 2>&1
then
    against=HEAD
else
    # Initial commit: diff against an empty tree object
    against=3d26c7f3e7205ae0ce44a28040f56b59ceb52818
fi
# Redirect output to stderr.
exec 1>&2

IS_ERROR=0
# コミットされるファイルのうち、.csで終わるもの
for FILE in `git diff-index --name-status $against -- | grep -E '^[AUM].*\.cs$'| cut -c3-`; do
    # CodeFormmaterで整形
    if mono bin/CodeFormatter.exe -s bin/CodeFormatterSetting.xml -o $FILE; then
        git add $FILE
    else
        IS_ERROR=1
    fi
done
exit $IS_ERROR
mob-takashiwatanabe commented 6 years ago
#!/bin/sh
if git rev-parse --verify HEAD >/dev/null 2>&1
then
    against=HEAD
else
    # Initial commit: diff against an empty tree object
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Redirect output to stderr.
exec 1>&2

IS_ERROR=0
# コミットされるファイルのうち、.csで終わるもの
for FILE in `git diff --name-only --cached | grep ".cs"`; do
    # CodeFormmaterで整形
    if mono CodeFormatter/Bin/CodeFormatter.exe --settings CodeFormatter/Bin/CodeFormatterSettings.xml $FILE; then
        git add $FILE
    else
        IS_ERROR=1
    fi
done
exit $IS_ERROR