Commit cea9e6e6 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

fix ahead / behind

parent dcfb8812
...@@ -327,15 +327,11 @@ class Repo(TimeStampedModel): ...@@ -327,15 +327,11 @@ class Repo(TimeStampedModel):
def main_branch(self): def main_branch(self):
return self.project.branch_set.get(name=f'{self.git_remote()}/{self.default_branch}') return self.project.branch_set.get(name=f'{self.git_remote()}/{self.default_branch}')
def diff(self): def ahead(self):
branch = self.main_branch() return self.main_branch().ahead
if branch.ahead and branch.behind:
return f'+{branch.ahead} / -{branch.behind}' def behind(self):
if branch.ahead: return self.main_branch().behind
return f'+{branch.ahead}'
if branch.behind:
return f'-{branch.behind}'
return ''
class Commit(NamedModel, TimeStampedModel): class Commit(NamedModel, TimeStampedModel):
...@@ -356,10 +352,12 @@ class Branch(TimeStampedModel): ...@@ -356,10 +352,12 @@ class Branch(TimeStampedModel):
unique_together = ('project', 'name') unique_together = ('project', 'name')
def get_ahead(self, branch='master'): def get_ahead(self, branch='master'):
return len(self.project.git().git.rev_list(f'{branch}..{self}').split('\n')) commits = self.project.git().git.rev_list(f'{branch}..{self}')
return len(commits.split('\n')) if commits else 0
def get_behind(self, branch='master'): def get_behind(self, branch='master'):
return len(self.project.git().git.rev_list(f'{self}..{branch}').split('\n')) commits = self.project.git().git.rev_list(f'{self}..{branch}')
return len(commits.split('\n')) if commits else 0
def remote(self): def remote(self):
# TODO: ForeignKey to Repo # TODO: ForeignKey to Repo
......
...@@ -41,7 +41,8 @@ class ProjectTable(StrippedTable): ...@@ -41,7 +41,8 @@ class ProjectTable(StrippedTable):
class RepoTable(StrippedTable): class RepoTable(StrippedTable):
diff = tables.Column(accessor='diff', orderable=False) ahead = tables.Column(accessor='ahead', orderable=False)
behind = tables.Column(accessor='behind', orderable=False)
class Meta: class Meta:
model = models.Repo model = models.Repo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment