Skip to content

Commit 8387fbb

Browse files
authored
Update checking if running on the current branch (#144)
* Update checking if running on the current branch * Update makemigrations.py
1 parent a28c34c commit 8387fbb

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

migration_fixer/management/commands/makemigrations.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ def handle(self, *app_labels, **options):
104104
if self.verbosity >= 2:
105105
self.stdout.write("Retrieving the current branch...")
106106

107-
current_branch = self.repo.active_branch.name
108-
109107
if self.repo.is_dirty(): # pragma: no cover
110108
raise CommandError(
111109
self.style.ERROR(
@@ -114,13 +112,17 @@ def handle(self, *app_labels, **options):
114112
)
115113
)
116114

115+
default_branch_commit = self.repo.commit(self.default_branch)
116+
117+
current_commit = self.repo.head.commit
118+
117119
if not self.skip_default_branch_update:
118120
if self.verbosity >= 2:
119121
self.stdout.write(
120122
f"Fetching git remote {self.remote} changes on: {self.default_branch}"
121123
)
122124

123-
if current_branch == self.default_branch: # pragma: no cover
125+
if current_commit == default_branch_commit: # pragma: no cover
124126
remote = self.repo.remotes[self.remote]
125127
remote.pull(
126128
self.default_branch,
@@ -146,10 +148,6 @@ def handle(self, *app_labels, **options):
146148
f"Retrieving the last commit sha on: {self.default_branch}"
147149
)
148150

149-
default_branch_commit = self.repo.commit(self.default_branch)
150-
151-
current_commit = self.repo.commit(current_branch)
152-
153151
# Load the current graph state. Pass in None for the connection so
154152
# the loader doesn't try to resolve replaced migrations from DB.
155153
loader = MigrationLoader(None, ignore_no_migrations=True)

0 commit comments

Comments
 (0)