From: Lev Stipakov Date: Mon, 19 Dec 2022 15:56:38 +0000 (+0200) Subject: git-version.py: proper support for tags X-Git-Tag: v2.7_alpha1~632 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91ab3d022e2652a46e6d6f25ab62f7c903e583c1;p=thirdparty%2Fopenvpn.git git-version.py: proper support for tags Git magic to get branch name git rev-parse --symbolic-full-name HEAD doesn't work when we're on tag, which is the case when we build releases. First, try to get tag name with git describe --exact-match and if this fails, get branch name as before. Use subprocess.Popen() to suppress stdout/stderr output. Github: Fixes OpenVPN/openvpn#199 Signed-off-by: Lev Stipakov Acked-by: Frank Lichtenheld Message-Id: <20221219155638.497-1-lstipakov@gmail.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25773.html Signed-off-by: Gert Doering --- diff --git a/build/msvc/msvc-generate/git-version.py b/build/msvc/msvc-generate/git-version.py index 814dc86a8..00458955a 100644 --- a/build/msvc/msvc-generate/git-version.py +++ b/build/msvc/msvc-generate/git-version.py @@ -24,15 +24,25 @@ import os import sys +import subprocess + +def run_command(args): + sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + o, _ = sp.communicate() + return o.decode("utf-8")[:-1] def get_branch_commit_id(): - commit_id = os.popen("git rev-parse --short=16 HEAD").read()[:-1] + commit_id = run_command(["git", "rev-parse", "--short=16", "HEAD"]) if not commit_id: raise - l = os.popen("git rev-parse --symbolic-full-name HEAD").read().split("/")[2:] - if not l: - l = ["none\n"] - branch = "/" .join(l)[:-1] + branch = run_command(["git", "describe", "--exact-match"]) + if not branch: + # this returns an array like ["master"] or ["release", "2.6"] + branch = run_command(["git", "rev-parse", "--symbolic-full-name", "HEAD"]).split("/")[2:] + if not branch: + branch = ["none"] + branch = "/" .join(branch) # handle cases like release/2.6 + return branch, commit_id def main():