Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
phillipuniverse opened this issue Feb 25, 2022 · 4 comments
Open

Comments

@phillipuniverse
Copy link
Contributor

  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).

@phillipuniverse
Copy link
Contributor Author

This also might be a duplicate of #168 but it's a slightly different focus.

@David-Wobrock
Copy link
Collaborator

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

@sondrelg
Copy link
Contributor

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),
}

@lieryan
Copy link
Contributor

lieryan commented Jan 11, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants