Skip to content

Commit

Permalink
Merge ce42ee0 into 1c93a41
Browse files Browse the repository at this point in the history
  • Loading branch information
lorinkoz committed Jun 14, 2020
2 parents 1c93a41 + ce42ee0 commit 81cbed7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.rst
Expand Up @@ -89,6 +89,13 @@ forget to apply them again at the end::
python manage.py unmigrate --fake
python manage.py migrate --fake

No more master
--------------

This package (still) uses ``master`` as the name of the default branch. If that
is no longer the case for your repositories, you can define ``MAIN_BRANCH`` in
your Django settings.

Do you see potential?
---------------------

Expand Down
6 changes: 4 additions & 2 deletions django_unmigrate/core.py
Expand Up @@ -9,6 +9,8 @@
from git import Repo
from git.exc import GitCommandError

from .settings import MAIN_BRANCH


class GitError(Exception):
message = ""
Expand All @@ -20,15 +22,15 @@ def __str__(self):
return self.message


def get_targets(database="default", ref="master"):
def get_targets(database="default", ref=MAIN_BRANCH):
"""
Produce target migrations from ``database`` and ``ref``.
"""
added_targets = get_added_migrations(ref)
return get_parents_from_targets(added_targets, database)


def get_added_migrations(ref="master"):
def get_added_migrations(ref=MAIN_BRANCH):
"""
Detect the added migrations when compared to ``ref``, and return them as
target tuples: ``(app_name, migration_name)``
Expand Down
3 changes: 2 additions & 1 deletion django_unmigrate/management/commands/unmigrate.py
Expand Up @@ -4,14 +4,15 @@
from django.db import DEFAULT_DB_ALIAS

from django_unmigrate.core import get_targets, GitError
from django_unmigrate.settings import MAIN_BRANCH


class Command(BaseCommand):
help = "Unapplies migrations that were added in relation to the passed Git ref."

def add_arguments(self, parser):
parser.add_argument(
"ref", nargs="?", default="master", help="Git ref to compare existing migrations.",
"ref", nargs="?", default=MAIN_BRANCH, help="Git ref to compare existing migrations.",
)
parser.add_argument(
"--database",
Expand Down
4 changes: 4 additions & 0 deletions django_unmigrate/settings.py
@@ -0,0 +1,4 @@
from django.conf import settings


MAIN_BRANCH = getattr(settings, "MAIN_BRANCH", "master")

0 comments on commit 81cbed7

Please sign in to comment.