Merge pull request #10184 from jbradberry/explicit-pre-commit-script

Break out the pre-commit hook into an explicit script

SUMMARY

This means that

we don't have to be always updating the underlying .git/hooks/pre-commit file
updates to the logic will just work automatically
the logic of the conditional invocation of black has been fixed so that AWX_IGNORE_BLACK=1 should work correctly now


ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME


API

AWX VERSION



  
    
    

    
    

  


ADDITIONAL INFORMATION

Reviewed-by: Rebeccah Hunter <rhunter@redhat.com>
Reviewed-by: Alan Rominger <arominge@redhat.com>
Reviewed-by: Jeff Bradberry <None>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-05-12 16:37:27 +00:00 committed by GitHub
commit a73cb0280c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -272,7 +272,7 @@ black: reports
@(set -o pipefail && $@ $(BLACK_ARGS) awx awxkit awx_collection | tee reports/$@.report)
.git/hooks/pre-commit:
@echo "[ -z \$$AWX_IGNORE_BLACK ] && (black --check \`git diff --cached --name-only --diff-filter=AM | grep -E '\.py$\'\` || (echo 'To fix this, run \`make black\` to auto-format your code prior to commit, or set AWX_IGNORE_BLACK=1' && exit 1))" > .git/hooks/pre-commit
@echo "./pre-commit.sh" > .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
genschema: reports

8
pre-commit.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/bash
if [ -z $AWX_IGNORE_BLACK ]
then
black --check $(git diff --cached --name-only --diff-filter=AM | grep -E '\.py') || \
(echo 'To fix this, run `make black` to auto-format your code prior to commit, or set AWX_IGNORE_BLACK=1' && \
exit 1)
fi