Skip to content

Commit 4f264c7

Browse files
authored
Merge pull request #5 from tannewt/fix_no_releases
Determine version even when no tags exist in the repo.
2 parents 0684d8c + 5ebe5d4 commit 4f264c7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

circuitpython_build_tools/build.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@ def version_string(path=None, *, valid_semver=False):
3838
if tag.returncode == 0:
3939
version = tag.stdout.strip().decode("utf-8", "strict")
4040
else:
41-
describe = subprocess.run("git describe --tags", shell=True, stdout=subprocess.PIPE, cwd=path)
42-
tag, additional_commits, commitish = describe.stdout.strip().decode("utf-8", "strict").rsplit("-", maxsplit=2)
43-
commitish = commitish[1:]
41+
describe = subprocess.run("git describe --tags --always", shell=True, stdout=subprocess.PIPE, cwd=path)
42+
describe = describe.stdout.strip().decode("utf-8", "strict").rsplit("-", maxsplit=2)
43+
if len(describe) == 3:
44+
tag, additional_commits, commitish = describe.stdout.strip().decode("utf-8", "strict").rsplit("-", maxsplit=2)
45+
commitish = commitish[1:]
46+
else:
47+
tag = "0.0.0"
48+
commit_count = subprocess.run("git rev-list --count HEAD", shell=True, stdout=subprocess.PIPE, cwd=path)
49+
additional_commits = commit_count.stdout.strip().decode("utf-8", "strict")
50+
commitish = describe[0]
4451
if valid_semver:
4552
version_info = semver.parse_version_info(tag)
4653
if not version_info.prerelease:

0 commit comments

Comments
 (0)