Created
January 21, 2022 12:14
-
-
Save SamStudio8/d38d70c9d181860a2ec0726e517f4fe8 to your computer and use it in GitHub Desktop.
Django unchecked migration pre-commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import subprocess | |
p = subprocess.Popen("git ls-files --others --exclude-standard", shell=True, stdout=subprocess.PIPE) | |
out, err = p.communicate() | |
migrations = [] | |
for unchecked_rp in out.decode('UTF-8').split('\n'): | |
if "migrations" in unchecked_rp: | |
# Look for a Migration class just to be sure? | |
with open(unchecked_rp) as maybe_migration_fh: | |
for line in maybe_migration_fh: | |
if "class Migration" in line: | |
migrations.append(unchecked_rp) | |
break | |
if len(migrations) > 0: | |
sys.stderr.write("Unchecked migrations detected: \n") | |
for migration_name in migrations: | |
sys.stderr.write(f" * {migration_name}\n") | |
sys.stderr.write("Commit all these files to permit a commit.\n") | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment