Skip to content

Commit

Permalink
Merge pull request #33 from 3YOURMIND/do-not-check-git-folder
Browse files Browse the repository at this point in the history
Do not check if .git folder exists
  • Loading branch information
flixx authored Jan 7, 2019
2 parents 92a686f + ab5536c commit 32dc956
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 30 deletions.
14 changes: 4 additions & 10 deletions django_migration_linter/migration_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -136,12 +136,6 @@ def print_errors(errors):
def lint_all_migrations(self, git_commit_id=None):
# Collect migrations
if git_commit_id:
if not 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()
Expand Down Expand Up @@ -180,7 +174,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
)
Expand All @@ -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)
Expand All @@ -222,7 +216,7 @@ def _gather_migrations_git(self, git_commit_id):
output = []
for line in map(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

Expand Down
5 changes: 0 additions & 5 deletions django_migration_linter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 1 addition & 15 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 32dc956

Please sign in to comment.