diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index 7ecbf98..00a44eb 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -152,8 +152,10 @@ class MigrationLinter(object): def _gather_migrations_git(self, git_commit_id): migrations = [] # Get changes since specified commit - git_diff_command = 'cd {0} && git diff --name-status {1}'.format( - self.django_path, git_commit_id) + git_diff_command = ( + 'cd {0} && ' + 'git diff --name-only --diff-filter=A {1}').format( + self.django_path, git_commit_id) log.info('Executing {0}'.format(git_diff_command)) diff_process = Popen( git_diff_command, shell=True, stdout=PIPE, stderr=PIPE) @@ -161,10 +163,9 @@ class MigrationLinter(object): utils.clean_bytes_to_str, diff_process.stdout.readlines()): # Only gather lines that include added migrations if re.search( - '^A.*\/{0}\/.*\.py'.format(self.MIGRATION_FOLDER_NAME), + '\/{0}\/.*\.py'.format(self.MIGRATION_FOLDER_NAME), line) and \ '__init__' not in line: - line = line.split()[-1] # Remove the status letter app_name, migration_name = self._split_migration_path(line) migrations.append((app_name, migration_name)) diff_process.wait() diff --git a/tests/functional/test_cmd_line_call.py b/tests/functional/test_cmd_line_call.py index ac62575..a3afd33 100644 --- a/tests/functional/test_cmd_line_call.py +++ b/tests/functional/test_cmd_line_call.py @@ -116,6 +116,21 @@ class CallLinterFromCommandLineTest(unittest.TestCase): self.assertTrue(lines[2].endswith('IGNORE')) def test_call_linter_cmd_line_git_id(self): + cmd = '{0} {1} d7125d5f4f0cc9623f670a66c54f131acc50032d'.format( + self.linter_exec, + fixtures.MULTI_COMMIT_PROJECT) + fixtures.prepare_git_project(fixtures.MULTI_COMMIT_PROJECT) + + process = Popen( + cmd, shell=True, stdout=PIPE, stderr=PIPE) + process.wait() + self.assertEqual(process.returncode, 0) + lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) + self.assertEqual(len(lines), 3) + self.assertTrue(lines[0].endswith('OK')) + self.assertTrue(lines[1].startswith('*** Summary')) + + def test_call_linter_with_deleted_migrations(self): cmd = '{0} {1} 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba'.format( self.linter_exec, fixtures.DELETED_MIGRATION_PROJECT) diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/COMMIT_EDITMSG b/tests/test_project_fixtures/test_deleted_migration_project/git/COMMIT_EDITMSG index 974dd96..e513fa5 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/git/COMMIT_EDITMSG +++ b/tests/test_project_fixtures/test_deleted_migration_project/git/COMMIT_EDITMSG @@ -1 +1,16 @@ Delete file and insert new + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit. +# +# Date: Thu Jan 18 23:27:37 2018 +0100 +# +# On branch master +# Changes to be committed: +# deleted: test_app/migrations/0002_new_not_null_field.py +# new file: test_app/migrations/0003_new_nullable_field.py +# modified: test_app/models.py +# +# Untracked files: +# git/ +# diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/index b/tests/test_project_fixtures/test_deleted_migration_project/git/index index b3e362d..a41e52a 100644 Binary files a/tests/test_project_fixtures/test_deleted_migration_project/git/index and b/tests/test_project_fixtures/test_deleted_migration_project/git/index differ diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/logs/HEAD b/tests/test_project_fixtures/test_deleted_migration_project/git/logs/HEAD index 236e554..5377828 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/git/logs/HEAD +++ b/tests/test_project_fixtures/test_deleted_migration_project/git/logs/HEAD @@ -1,3 +1,4 @@ 0000000000000000000000000000000000000000 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e David-Wobrock 1516314144 +0100 commit (initial): Project init 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba David-Wobrock 1516314322 +0100 commit: Add backward incompatible migration 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba be2fae887ee7ecd2d1e6371af1a865c17414bde9 David-Wobrock 1516314457 +0100 commit: Delete file and insert new +be2fae887ee7ecd2d1e6371af1a865c17414bde9 4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 David-Wobrock 1516459290 +0100 commit (amend): Delete file and insert new diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/logs/refs/heads/master b/tests/test_project_fixtures/test_deleted_migration_project/git/logs/refs/heads/master index 236e554..5377828 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/git/logs/refs/heads/master +++ b/tests/test_project_fixtures/test_deleted_migration_project/git/logs/refs/heads/master @@ -1,3 +1,4 @@ 0000000000000000000000000000000000000000 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e David-Wobrock 1516314144 +0100 commit (initial): Project init 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba David-Wobrock 1516314322 +0100 commit: Add backward incompatible migration 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba be2fae887ee7ecd2d1e6371af1a865c17414bde9 David-Wobrock 1516314457 +0100 commit: Delete file and insert new +be2fae887ee7ecd2d1e6371af1a865c17414bde9 4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 David-Wobrock 1516459290 +0100 commit (amend): Delete file and insert new diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/20/6a76068032bb321ca63f561a230675d2645182 b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/20/6a76068032bb321ca63f561a230675d2645182 new file mode 100644 index 0000000..40a0fd7 Binary files /dev/null and b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/20/6a76068032bb321ca63f561a230675d2645182 differ diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/39/0459eae1e9c3eecaac732d51867c8b8ed5102f b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/39/0459eae1e9c3eecaac732d51867c8b8ed5102f new file mode 100644 index 0000000..21bfffe Binary files /dev/null and b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/39/0459eae1e9c3eecaac732d51867c8b8ed5102f differ diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/330bb1c7154afb23f170218d170dae079c437f b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/330bb1c7154afb23f170218d170dae079c437f new file mode 100644 index 0000000..d261e11 --- /dev/null +++ b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/330bb1c7154afb23f170218d170dae079c437f @@ -0,0 +1,2 @@ +x�ޱ +Â0E]íW¼± RAÈ …‚ƒ›{Hš×´ò’H’¢ŸocÄÉñ^Îá^E^A]ïW}ðôU:ã™V0Ú› ¬×H±(:’1±\2;çº:k7‰~DÒÀß0;¹„C›Û2ü&¬fïÂù$þ“ZIñcuƒ /M*B‘0¦ßÑf&–E+‚Й4ðÝv_ž<4Si \ No newline at end of file diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/dc4ba9e7695893423be1b54f3101d6ccbd11c7 b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/dc4ba9e7695893423be1b54f3101d6ccbd11c7 new file mode 100644 index 0000000..4b41432 Binary files /dev/null and b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/dc4ba9e7695893423be1b54f3101d6ccbd11c7 differ diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/87/39ba2b3bc1f8efddd5806ec429405150505b81 b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/87/39ba2b3bc1f8efddd5806ec429405150505b81 new file mode 100644 index 0000000..3454df2 Binary files /dev/null and b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/87/39ba2b3bc1f8efddd5806ec429405150505b81 differ diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/fb/cc4dab70fb36389f806bb72fd5056f5034f572 b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/fb/cc4dab70fb36389f806bb72fd5056f5034f572 new file mode 100644 index 0000000..5807b0b Binary files /dev/null and b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/fb/cc4dab70fb36389f806bb72fd5056f5034f572 differ diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/refs/heads/master b/tests/test_project_fixtures/test_deleted_migration_project/git/refs/heads/master index 953a67e..c422dbc 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/git/refs/heads/master +++ b/tests/test_project_fixtures/test_deleted_migration_project/git/refs/heads/master @@ -1 +1 @@ -be2fae887ee7ecd2d1e6371af1a865c17414bde9 +4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 diff --git a/tests/test_project_fixtures/test_deleted_migration_project/test_app/migrations/0003_new_nullable_field.py b/tests/test_project_fixtures/test_deleted_migration_project/test_app/migrations/0003_new_nullable_field.py index b30169e..fbcc4da 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/test_app/migrations/0003_new_nullable_field.py +++ b/tests/test_project_fixtures/test_deleted_migration_project/test_app/migrations/0003_new_nullable_field.py @@ -1,18 +1,15 @@ -# Generated by Django 2.0.1 on 2018-01-18 22:26 - -from django.db import migrations, models +from django.db import migrations +from django.db import models class Migration(migrations.Migration): - dependencies = [ - ('test_app', '0001_initial'), - ] + dependencies = [('test_app', '0001_initial'),] operations = [ migrations.AddField( model_name='a', - name='new_nullable_field', - field=models.IntegerField(null=True), + name='new_char_nullable_test_field', + field=models.CharField(max_length=30, null=True), ), ] diff --git a/tests/test_project_fixtures/test_deleted_migration_project/test_app/models.py b/tests/test_project_fixtures/test_deleted_migration_project/test_app/models.py index 928f993..4b330bb 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/test_app/models.py +++ b/tests/test_project_fixtures/test_deleted_migration_project/test_app/models.py @@ -3,4 +3,4 @@ from django.db import models class A(models.Model): null_field = models.IntegerField(null=True) new_not_null_field = models.IntegerField(null=False) - new_nullable_field = models.IntegerField(null=True) + new_char_nullable_test_field = models.CharField(max_length=30, null=True)