From fc156726e691d4f4625ef21da3e5e086db2d39db Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Tue, 11 Sep 2018 14:00:33 +1200 Subject: [PATCH] models: add a get_checkout_branch() function In a bunch of places we needed to get the branch we were supposed to be checking out (which is actual_branch if that is set, otherwise the normal branch name). Add a function to do that. Additionally, instead of showing the normal branch name next to the "last update" date, use the result of this new function. Signed-off-by: Paul Eggleton --- layerindex/models.py | 15 +++++++++------ layerindex/utils.py | 4 +--- templates/layerindex/detail.html | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/layerindex/models.py b/layerindex/models.py index 379fdb6..6255c60 100644 --- a/layerindex/models.py +++ b/layerindex/models.py @@ -205,7 +205,7 @@ class LayerRecipeExtraURL(models.Model): url = url.replace('%pn%', recipe.pn) url = url.replace('%pv%', recipe.pv) url = url.replace('%branch%', recipe.layerbranch.branch.name) - url = url.replace('%actual_branch%', recipe.layerbranch.actual_branch) + url = url.replace('%actual_branch%', recipe.layerbranch.get_checkout_branch()) return url def __str__(self): @@ -311,11 +311,7 @@ class LayerBranch(models.Model): def commit_url(self, commit_hash): url = self.layer.vcs_web_commit_url url = url.replace('%hash%', commit_hash) - if self.actual_branch: - branchname = self.actual_branch - else: - branchname = self.branch.name - url = url.replace('%branch%', branchname) + url = url.replace('%branch%', self.get_checkout_branch()) return url def test_tree_url(self): @@ -324,6 +320,13 @@ class LayerBranch(models.Model): def test_file_url(self): return self.file_url('conf/layer.conf') + def get_checkout_branch(self): + """Get the branch that we actually need to check out in the repo""" + if self.actual_branch: + return self.actual_branch + else: + return self.branch.name + def get_usage_url(self): usage_url = self.layer.usage_url if usage_url.startswith('http'): diff --git a/layerindex/utils.py b/layerindex/utils.py index 1fee4e7..63759f2 100644 --- a/layerindex/utils.py +++ b/layerindex/utils.py @@ -243,9 +243,7 @@ def checkout_repo(repodir, commit, logger, force=False): runcmd("git checkout %s" % commit, repodir, logger=logger) def checkout_layer_branch(layerbranch, repodir, logger=None): - branchname = layerbranch.branch.name - if layerbranch.actual_branch: - branchname = layerbranch.actual_branch + branchname = layerbranch.get_checkout_branch() checkout_repo(repodir, 'origin/%s' % branchname, logger) def is_layer_valid(layerdir): diff --git a/templates/layerindex/detail.html b/templates/layerindex/detail.html index 73c3030..299c3a2 100644 --- a/templates/layerindex/detail.html +++ b/templates/layerindex/detail.html @@ -113,7 +113,7 @@ {% if layerbranch.vcs_last_commit %}

- Last commit: {{ layerbranch.vcs_last_commit|timesince }} ago ({{ layerbranch.branch.name }} branch) + Last commit: {{ layerbranch.vcs_last_commit|timesince }} ago ({{ layerbranch.get_checkout_branch }} branch)

{% endif %}