#! /usr/bin/env python3

# Note that this file should work in both Python 2 and 3.

from __future__ import print_function
from subprocess import Popen, PIPE

dirty = Popen(["git", "diff-index", "--quiet", "HEAD"], stdout=PIPE).wait() != 0

commit_process = Popen(["git", "describe", "--tags", "--abbrev=0"], stdout=PIPE)
(version, err) = commit_process.communicate()

print("STABLE_GIT_VERSION %s%s" % (
    version.decode("utf-8").replace("\n", ""),
    "-dirty" if dirty else "")
)


#! /usr/bin/env python3

# Note that this file should work in both Python 2 and 3.

from __future__ import print_function
from subprocess import Popen, PIPE

dirty = Popen(["git", "diff-index", "--quiet", "HEAD"], stdout=PIPE).wait() != 0

commit_process = Popen(["git", "describe", "--always", "--tags", "--abbrev=0"], stdout=PIPE)
(version, err) = commit_process.communicate()

print("STABLE_GIT_VERSION %s%s" % (
    version.decode("utf-8").replace("\n", ""),
    "-dirty" if dirty else "")
)


Make git describe --always return a value
Make git describe --always return a value

This means that the latest commit will be stamped if there are no tags.