summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2014-12-15 19:00:29 -0500
committerMonty Taylor <mordred@inaugust.com>2014-12-16 14:59:18 -0500
commite73e67acdd84e3c0fe7f5a8cabb62d514c5a9d06 (patch)
tree9606c86db185cf075f669d40771fcd2afca6abe6
parentb3678714aabd9c82a4ad389036e160a0819fd45c (diff)
downloadpbr-e73e67acdd84e3c0fe7f5a8cabb62d514c5a9d06.tar.gz
Stop including git sha in version strings0.10.3
We include it in pbr.json now. Including it is contentious in the world of python, and it's up for debate as to whether or not it provides value. Change-Id: Ie2ca34f59e9b42a3126c95edf36640fef32feed8
-rw-r--r--pbr/packaging.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py
index 4f5897c..5bd3b06 100644
--- a/pbr/packaging.py
+++ b/pbr/packaging.py
@@ -843,21 +843,30 @@ def _get_version_from_git(pre_version):
if the current revision has no tag.
"""
- git_dir = _get_git_directory()
- if git_dir and _git_is_installed():
+ git_dir = _run_git_functions()
+ if git_dir:
if pre_version:
try:
return _run_git_command(
['describe', '--exact-match'], git_dir,
throw_on_error=True).replace('-', '.')
except Exception:
- sha = _run_git_command(
- ['log', '-n1', '--pretty=format:%h'], git_dir)
- return "%s.dev%s+g%s" % (pre_version, _get_revno(git_dir), sha)
+ return "%s.dev%s" % (pre_version, _get_revno(git_dir))
else:
- return _run_git_command(
- ['describe', '--always'],
- git_dir).replace('-', '.').replace('.g', '+g')
+ # git describe always is going to return one of three things
+ # - a short-sha if there are no tags
+ # - a tag, if there's one on the current revision
+ # - a string of the form $last_tag-$revs_since_last_tag-g$short_sha
+ raw_version = _run_git_command(['describe', '--always'], git_dir)
+ # First, if there are no -'s or .'s, then it's just a short sha.
+ # Create a synthetic version for it.
+ if '-' not in raw_version and '.' not in raw_version:
+ return "0.0.0.%s" % _get_revno(git_dir)
+ # Now, we want to strip the short-sha prefix
+ stripped_version = raw_version.split('-g')[0]
+ # Finally, if we convert - to ., we'll get the version we want
+ return stripped_version.replace('-', '.')
+
# If we don't know the version, return an empty string so at least
# the downstream users of the value always have the same type of
# object to work with.