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

Detect if this is a merge or rebase in rebase_migration command #260

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def handle(self, *args: Any, app_label: str, **options: Any) -> None:
if not max_migration_txt.exists():
raise CommandError(f"{app_label} does not have a max_migration.txt.")

migration_names = find_migration_names(
migration_names = self.find_migration_names(
max_migration_txt.read_text().splitlines()
)
if migration_names is None:
Expand Down Expand Up @@ -175,16 +175,17 @@ def handle(self, *args: Any, app_label: str, **options: Any) -> None:
+ " updated its dependencies, and updated max_migration.txt."
)


def find_migration_names(max_migration_lines: list[str]) -> tuple[str, str] | None:
lines = max_migration_lines
if len(lines) <= 1:
return None
if not lines[0].startswith("<<<<<<<"):
return None
if not lines[-1].startswith(">>>>>>>"):
return None
return lines[1].strip(), lines[-2].strip()
def find_migration_names(
self, max_migration_lines: list[str]
) -> tuple[str, str] | None:
lines = max_migration_lines
if len(lines) <= 1:
return None
if not lines[0].startswith("<<<<<<<"):
return None
if not lines[-1].startswith(">>>>>>>"):
return None
return lines[1].strip(), lines[-2].strip()


def migration_applied(app_label: str, migration_name: str) -> bool:
Expand Down
14 changes: 9 additions & 5 deletions tests/test_rebase_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,19 +427,23 @@ class Migration(migrations.Migration):

class FindMigrationNamesTests(SimpleTestCase):
def test_none_when_no_lines(self):
result = module.find_migration_names([])
result = module.Command().find_migration_names([])
assert result is None

def test_none_when_no_first_marker(self):
result = module.find_migration_names(["not_a_marker", "0002_author_nicknames"])
result = module.Command().find_migration_names(
["not_a_marker", "0002_author_nicknames"]
)
assert result is None

def test_none_when_no_second_marker(self):
result = module.find_migration_names(["<<<<<<<", "0002_author_nicknames"])
result = module.Command().find_migration_names(
["<<<<<<<", "0002_author_nicknames"]
)
assert result is None

def test_works_with_two_way_merge(self):
result = module.find_migration_names(
result = module.Command().find_migration_names(
[
"<<<<<<<",
"0002_author_nicknames",
Expand All @@ -451,7 +455,7 @@ def test_works_with_two_way_merge(self):
assert result == ("0002_author_nicknames", "0002_longer_titles")

def test_works_with_three_way_merge(self):
result = module.find_migration_names(
result = module.Command().find_migration_names(
[
"<<<<<<<",
"0002_author_nicknames",
Expand Down