Skip to content

Commit

Permalink
Adds pre-commit check for DONOTSUBMIT
Browse files Browse the repository at this point in the history
  • Loading branch information
abaire authored and mborgerson committed Feb 24, 2022
1 parent 159b706 commit ad9065a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,32 @@ EOF
# the staged ones. Depending on typical workflows it might be better to do
# something more complicated here, or to just have the hook fail instead of
# perform an in-place fix.
files_to_format="$(echo "${changed_python_filenames}" | grep -v '3rdparty')"
local files_to_format="$(echo "${changed_python_filenames}" | grep -v '3rdparty')"
if [[ -n "${files_to_format}" ]]; then
echo "${files_to_format}" | xargs black
echo "${files_to_format}" | xargs git add
fi
}

function check_no_donotsubmit {
local filenames="$1"

if [[ -z "${filenames}" ]]; then
return
fi

set +e
output="$(grep -H -ni 'DONOTSUBMIT' -- "$1" 2>/dev/null)"
found=$?
set -e

if [[ $found -eq 0 ]]; then
echo "${output}"
echo "DONOTSUBMIT tag found, aborting"
exit 1
fi
}


if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
Expand All @@ -62,4 +81,6 @@ changed_python_filenames="$(echo "${added_and_modified_filenames}" | \
git config --local core.whitespace -blank-at-eof

run_black
check_no_donotsubmit "${changed_python_filenames}"
check_no_diffmarkers_or_whitespace_errors "${against}"

0 comments on commit ad9065a

Please sign in to comment.