mirror of
https://github.com/mandiant/capa.git
synced 2025-12-21 23:00:29 -08:00
The comment claims that: > doesn't matter if `#!/usr/bin/env bash` gets repeated later on in a hooks file However it is a convetion that there is only one comment like that and the `setup-hooks.sh` script already takes care of adding it if the file didn't exist. Alternatively, we could leave the extra comment and remove the related code in `setup-hooks.sh`. Currently two comments are added even if the file didn't exist.
60 lines
2.0 KiB
Plaintext
Executable File
60 lines
2.0 KiB
Plaintext
Executable File
# Copyright (C) 2020 FireEye, Inc. All Rights Reserved.
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at: [package root]/LICENSE.txt
|
|
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
# Use a console with emojis support for a better experience
|
|
|
|
# Stash uncommited changes
|
|
MSG="post-commit-$(date +%s)";
|
|
git stash push -kum "$MSG" &>/dev/null ;
|
|
STASH_LIST=$(git stash list);
|
|
if [[ "$STASH_LIST" == *"$MSG"* ]]; then
|
|
echo "Uncommited changes stashed with message '$MSG', if you abort before they are restored run \`git stash pop\`";
|
|
fi
|
|
|
|
python_3() {
|
|
case "$(uname -s)" in
|
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
|
py -3 -m $1 > $2 2>&1;;
|
|
*)
|
|
python3 -m $1 > $2 2>&1;;
|
|
esac
|
|
}
|
|
|
|
# Run isort and print state (it doesn't block the commit)
|
|
python_3 'isort --profile black --length-sort --line-width 120 -c .' 'isort-output.log';
|
|
if [ $? == 0 ]; then
|
|
echo 'isort succeeded!! 💖';
|
|
else
|
|
echo 'isort failed 😭';
|
|
echo 'Check isort-output.log for details';
|
|
fi
|
|
|
|
# Run black and print state (it doesn't block the commit)
|
|
python_3 'black -l 120 --check .' 'black-output.log';
|
|
if [ $? == 0 ]; then
|
|
echo 'black succeeded!! 💝';
|
|
else
|
|
echo 'black failed 😭';
|
|
echo 'Check black-output.log for details';
|
|
fi
|
|
|
|
# Run rule linter and print state (it doesn't block the commit)
|
|
python ./scripts/lint.py ./rules/ > rule-linter-output.log 2>&1;
|
|
if [ $? == 0 ]; then
|
|
echo 'Rule linter succeeded!! 💘';
|
|
else
|
|
echo 'Rule linter failed 😭';
|
|
echo 'Check rule-linter-output.log for details';
|
|
fi
|
|
|
|
# Restore stashed changes
|
|
if [[ "$STASH_LIST" == *"$MSG"* ]]; then
|
|
git stash pop --index &>/dev/null ;
|
|
echo "Stashed changes '$MSG' restored";
|
|
fi
|