From 547dc9985ca6d401284b7ee0018721e8aa3324d3 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Wed, 24 Jun 2026 14:24:52 -0700 Subject: [PATCH] repo: Normalize GNUPGHOME path for MSYS GPG on Windows Convert GNUPGHOME to a POSIX path using cygpath on Windows so MSYS GPG can read it correctly. Bug: 510840000 Change-Id: I7d25564dd6521f6e887ff45548f42984e709ef5e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/601121 Tested-by: Gavin Mak Reviewed-by: Brian Gan Commit-Queue: Gavin Mak --- repo | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/repo b/repo index ed9524eb6..dd9934ff9 100755 --- a/repo +++ b/repo @@ -747,6 +747,28 @@ def SetGitTrace2ParentSid(env=None): _setenv(KEY, value, env=env) +def _NormalizeGpgHomePath(path: str) -> str: + """Convert path for GPG on Windows if running in MSYS/MinGW. + + If GPG is MSYS-based (common in Git Bash/Cygwin), it expects POSIX-like paths + (e.g. /c/Users/... instead of C:\\Users\\...). Native Windows Python uses + Windows-style paths, which MSYS GPG will incorrectly treat as relative paths. + We use cygpath to query the active MSYS/Cygwin mount configuration and resolve + the correct POSIX path. + """ + if platform.system() == "Windows": + try: + out = subprocess.check_output( + ["cygpath", "-u", path], + stderr=subprocess.DEVNULL, + universal_newlines=True, + ) + return out.strip() + except (OSError, subprocess.CalledProcessError): + pass + return path + + def _setenv(key, value, env=None): """Set |key| in the OS environment |env| to |value|.""" if env is None: @@ -1079,7 +1101,7 @@ def verify_rev(cwd, remote_ref, rev, quiet): print(file=sys.stderr) env = os.environ.copy() - _setenv("GNUPGHOME", gpg_dir, env) + _setenv("GNUPGHOME", _NormalizeGpgHomePath(gpg_dir), env) run_git("tag", "-v", cur, cwd=cwd, env=env) return "%s^0" % cur