3YOURMIND/django-migration-linter

Using --git-commit-id option does not find uncommitted migrations

Opened this issue · 4 comments

  1. Create a new migration with manage.py makemigrations that adds a new non-null column (which would fail the migration)
  2. Don't commit it
  3. Run lintmigrations --git-commit-id $some-sha
  4. 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:

git_diff_command = (
"cd {0} && git diff --relative --name-only --diff-filter=AR {1}"
).format(self.django_path, git_commit_id)

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.

Hi @phillipuniverse

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?