Using --git-commit-id option does not find uncommitted migrations
Opened this issue · 4 comments
- Create a new migration with
manage.py makemigrations
that adds a new non-null column (which would fail the migration) - Don't commit it
- Run
lintmigrations --git-commit-id $some-sha
- Migration is not detected as erroneous
I know that this is likely a limitation of what information we can get (heh) from the git process:
django-migration-linter/django_migration_linter/migration_linter.py
Lines 360 to 362 in 8e56562
Is there a different command we could use to also consider untracked and staged files in this calculation? Another use case this would come up is if you want to include this migration linter as a pre-commit hook which would operate off of the files in the stage (index).
This also might be a duplicate of #168 but it's a slightly different focus.
Yes, that's not easy to add I think 🤔 At least, git does not provide these options as far as I know.
I think staged files are taken into account, but not untracked ones.
Maybe some workaround can be enough here? By using the lintmigrations
command directly onto the untracked migration file? lintmigrations app_name migration_name
I had the same issue, but because cd {}
was cd'ing into my settings directory. Adding these settings fixed it for me:
MIGRATION_LINTER_OPTIONS = {
'project_root_path': str(REPO_PATH),
}
I think there's a fairly easy workaround here, since staged files are taken into account, you just need to git add
the migration files and lintmigrations will check them. pre-commit should work off staged files so it should work there.
@David-Wobrock would this be fixed by just appending the output of git ls-files --others --exclude-standard
to the output of git_diff_command
?