osmith submitted this change.
obs: srcpkg: support having no git tags
Instead of failing when a project has no git-version-gen script, and no
git tags, use 0.0.0 as version. This is needed for the new osmo-epdg
project, which doesn't have tags yet.
Change-Id: I2f0f409feb96611095dfa511a33ea730e5bbf3e4
---
M scripts/obs/lib/srcpkg.py
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/scripts/obs/lib/srcpkg.py b/scripts/obs/lib/srcpkg.py
index 324bc66..9476d82 100644
--- a/scripts/obs/lib/srcpkg.py
+++ b/scripts/obs/lib/srcpkg.py
@@ -42,11 +42,24 @@
pattern = lib.git.get_latest_tag_pattern(project)
pattern = pattern.replace("^", "", 1)
pattern = pattern.replace("$", "", -1)
- ret = lib.run_cmd(["git", "describe",
+ result = lib.run_cmd(["git", "describe",
"--abbrev=4",
"--tags",
f"--match={pattern}",
- "HEAD"], cwd=repo_path).output.rstrip()
+ "HEAD"], cwd=repo_path, check=False)
+
+ if result.returncode == 128:
+ print(f"{project}: has no git tags, using 0.0.0 as version")
+ commit = lib.run_cmd(["git", "rev-parse", "HEAD"],
+ cwd=repo_path).output[0:4]
+ count = lib.run_cmd(["git", "rev-list", "--count", "HEAD"],
+ cwd=repo_path).output.rstrip()
+ return f"0.0.0.{count}-{commit}"
+
+ if result.returncode != 0:
+ lib.exit_error_cmd(result, "command failed unexpectedly")
+
+ ret = result.output.rstrip()
# Like git-version-gen:
# * Change the first '-' to '.'
To view, visit change 34669. To unsubscribe, or for help writing mail filters, visit settings.