diff options
author | Jürg Billeter <j@bitron.ch> | 2018-02-25 11:36:05 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-09-27 14:12:34 +0100 |
commit | 900e890069427aff929c0529f34a02d891503ace (patch) | |
tree | 090c887c3daab36f633d828622e48bbeb6901611 | |
parent | 44da8175253c78b03dcfefd4693f804c45c72d11 (diff) | |
download | buildstream-900e890069427aff929c0529f34a02d891503ace.tar.gz |
git.py: Make `ref` human readable
Use `git describe` to prefix `ref` with closest tag, if available.
-rw-r--r-- | buildstream/plugins/sources/git.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/buildstream/plugins/sources/git.py b/buildstream/plugins/sources/git.py index cc6d35cd0..77db9534a 100644 --- a/buildstream/plugins/sources/git.py +++ b/buildstream/plugins/sources/git.py @@ -43,6 +43,12 @@ git - stage files from a git repository # will be used to update the 'ref' when refreshing the pipeline. track: master + # Optionally specify the ref format used for tracking. + # The default is 'sha1' for the raw commit hash. + # If you specify 'git-describe', the commit hash will be prefixed + # with the closest tag. + ref-format: sha1 + # Specify the commit ref, this must be specified in order to # checkout sources and build, but can be automatically updated # if the 'track' attribute was specified. @@ -205,7 +211,18 @@ class GitMirror(SourceFetcher): [self.source.host_git, 'rev-parse', tracking], fail="Unable to find commit for specified branch name '{}'".format(tracking), cwd=self.mirror) - return output.rstrip('\n') + ref = output.rstrip('\n') + + if self.source.ref_format == 'git-describe': + # Prefix the ref with the closest tag, if available, + # to make the ref human readable + exit_code, output = self.source.check_output( + [self.source.host_git, 'describe', '--tags', '--abbrev=40', '--long', ref], + cwd=self.mirror) + if exit_code == 0: + ref = output.rstrip('\n') + + return ref def stage(self, directory, track=None): fullpath = os.path.join(directory, self.path) @@ -341,13 +358,18 @@ 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', 'ref', 'submodules', 'checkout-submodules', 'ref-format'] 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.tracking = self.node_get_member(node, str, 'track', None) + self.ref_format = self.node_get_member(node, str, 'ref-format', 'sha1') + if self.ref_format not in ['sha1', 'git-describe']: + provenance = self.node_provenance(node, member_name='ref-format') + raise SourceError("{}: Unexpected value for ref-format: {}".format(provenance, self.ref_format)) + # At this point we now know if the source has a ref and/or a track. # If it is missing both then we will be unable to track or build. if self.mirror.ref is None and self.tracking is None: |