From 574af4b7fefc35b822815f80a9eb460589b103c5 Mon Sep 17 00:00:00 2001 From: David-Wobrock Date: Fri, 4 Jan 2019 21:39:58 +0100 Subject: [PATCH 1/3] Do not check if .git folder exists git commands will fail anyway if not present --- django_migration_linter/migration_linter.py | 10 ++-------- django_migration_linter/utils.py | 5 ----- tests/unit/test_utils.py | 16 +--------------- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index e00b6a07..999843f5 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -134,12 +134,6 @@ def print_errors(errors): def lint_all_migrations(self, git_commit_id=None): # Collect migrations if git_commit_id: - if not utils.is_git_project(self.django_path): - raise ValueError( - ( - "The given project {0} does not seem " "to be versioned by git." - ).format(self.django_path) - ) migrations = self._gather_migrations_git(git_commit_id) else: migrations = self._gather_all_migrations() @@ -178,7 +172,7 @@ def get_sql(self, app_name, migration_name): it allows to seperate the instances correctly. """ sqlmigrate_command = ( - "cd {0} && " "{1} manage.py sqlmigrate {2} {3} " "--database {4}" + "cd {0} && {1} manage.py sqlmigrate {2} {3} " "--database {4}" ).format( self.django_path, self.python_exe, app_name, migration_name, self.database ) @@ -205,7 +199,7 @@ def _gather_migrations_git(self, git_commit_id): migrations = [] # Get changes since specified commit git_diff_command = ( - "cd {0} && " "git diff --name-only --diff-filter=A {1}" + "cd {0} && git diff --name-only --diff-filter=A {1}" ).format(self.django_path, git_commit_id) logger.info("Executing {0}".format(git_diff_command)) diff_process = Popen(git_diff_command, shell=True, stdout=PIPE, stderr=PIPE) diff --git a/django_migration_linter/utils.py b/django_migration_linter/utils.py index 1efc5d7d..5d34d1b7 100644 --- a/django_migration_linter/utils.py +++ b/django_migration_linter/utils.py @@ -25,11 +25,6 @@ def is_django_project(path): return os.path.isfile(django_manage_file) -def is_git_project(path): - git_directory = os.path.join(path, ".git") - return os.path.isdir(git_directory) - - def is_directory(path): return os.path.isdir(path) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 28fb3632..b997288d 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -16,25 +16,11 @@ import unittest from tests import fixtures -from django_migration_linter.utils import is_django_project, is_git_project, is_directory, find_project_settings_module, \ +from django_migration_linter.utils import is_django_project, is_directory, find_project_settings_module, \ split_path, split_migration_path class UtilityFunctionTest(unittest.TestCase): - def tearDown(self, *args, **kwargs): - fixtures.clear_all_git_projects() - super( - UtilityFunctionTest, - self).tearDown(*args, **kwargs) - - def test_detect_not_git_project(self): - self.assertFalse(is_git_project(fixtures.NOT_GIT_DJANGO_PROJECT)) - - def test_detect_git_project(self): - project_path = fixtures.MULTI_COMMIT_PROJECT - fixtures.prepare_git_project(project_path) - self.assertTrue(is_git_project(project_path)) - def test_detect_django_project(self): self.assertTrue(is_django_project(fixtures.ADD_NOT_NULL_COLUMN_PROJECT)) From a159e296771d3d45d0012cff2dc95c958cd3717d Mon Sep 17 00:00:00 2001 From: Felix Date: Sat, 5 Jan 2019 19:35:12 +0100 Subject: [PATCH 2/3] Print a better git error to the console --- django_migration_linter/migration_linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index 999843f5..a392881d 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -217,7 +217,7 @@ def _gather_migrations_git(self, git_commit_id): output = [] for line in map(utils.clean_bytes_to_str, diff_process.stderr.readlines()): output.append(line) - logger.info("Error while git diff command:\n{}".format("".join(output))) + logger.error("Error while git diff command:\n{}".format("".join(output))) raise Exception("Error while executing git diff command") return migrations From ab5536c8e73ce749597ac0428df6042ba358fac8 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 7 Jan 2019 12:25:57 +0100 Subject: [PATCH 3/3] Remove is_git_project from import --- django_migration_linter/migration_linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index 26a0ffb6..032d9100 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -22,7 +22,7 @@ from .cache import Cache from .constants import DEFAULT_CACHE_PATH, MIGRATION_FOLDER_NAME from .migration import Migration -from .utils import is_directory, is_django_project, is_git_project, clean_bytes_to_str +from .utils import is_directory, is_django_project, clean_bytes_to_str from .sql_analyser import analyse_sql_statements logger = logging.getLogger(__name__)