From 90c5875d1fd73bbc462e1d4472318e7373e84502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Sun, 25 Feb 2018 16:38:25 +0100 Subject: git.py: Support tracking annotated tags in a branch --- buildstream/plugins/sources/git.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/buildstream/plugins/sources/git.py b/buildstream/plugins/sources/git.py index 947ba0856..38bb6f6d3 100644 --- a/buildstream/plugins/sources/git.py +++ b/buildstream/plugins/sources/git.py @@ -186,7 +186,14 @@ class GitMirror(SourceFetcher): raise SourceError("{}: expected ref '{}' was not found in git repository: '{}'" .format(self.source, self.ref, self.url)) - def latest_commit(self, tracking): + def latest_commit(self, tracking, *, track_tags): + if track_tags: + _, output = self.source.check_output( + [self.source.host_git, 'describe', '--abbrev=0', tracking], + fail="Unable to find annotated tag for specified branch name '{}'".format(tracking), + cwd=self.mirror) + tracking = output.rstrip('\n') + _, output = self.source.check_output( [self.source.host_git, 'rev-parse', tracking], fail="Unable to find commit for specified branch name '{}'".format(tracking), @@ -304,11 +311,12 @@ class GitSource(Source): def configure(self, node): ref = self.node_get_member(node, str, 'ref', None) - config_keys = ['url', 'track', 'ref', 'submodules', 'checkout-submodules'] + config_keys = ['url', 'track', 'track-tags', 'ref', 'submodules', 'checkout-submodules'] self.node_validate(node, config_keys + Source.COMMON_CONFIG_KEYS) self.original_url = self.node_get_member(node, str, 'url') self.mirror = GitMirror(self, '', self.original_url, ref, primary=True) + self.track_tags = self.node_get_member(node, bool, 'track-tags', False) self.tracking = self.node_get_member(node, str, 'track', None) # At this point we now know if the source has a ref and/or a track. @@ -396,7 +404,7 @@ class GitSource(Source): self.mirror._fetch() # Update self.mirror.ref and node.ref from the self.tracking branch - ret = self.mirror.latest_commit(self.tracking) + ret = self.mirror.latest_commit(self.tracking, track_tags=self.track_tags) return ret -- cgit v1.2.1