From 28967020f142564e98f8844f3db9f8837f461e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Azevedo?= Date: Sat, 8 Aug 2026 08:20:38 -0400 Subject: [PATCH] Resolve the archive folder when GitHub does not name it - github install ... version(v1.2.3) fails with r(170) on any repository whose tags carry a leading "v". The archive downloads fine, but GitHub names the folder inside it after the tag with the "v" removed, so v18.7.0 unpacks into -18.7.0 while the code cds to -v18.7.0 and stops. The same mismatch affects the -force- path on repositories that have renamed their default branch: archive/master.zip is served for them, but it unpacks into -main rather than -master. Rather than guess, try the plausible names in order. The expected name is tried first, so archives that already resolved are unaffected -- verified against haghish/markdoc 5.0.2, which still resolves on the first candidate. Directory discovery was considered and rejected: this command unpacks into the user's working directory and leaves the folder behind, so a second install in the same directory leaves several -* folders and makes discovery ambiguous. An earlier draft used it and failed exactly that way in testing. Verified in Stata 17, in a directory holding four unpacked archives at once: yaml v2.0.1 -> yaml-2.0.1 (v stripped) yaml master -> yaml-main (default branch renamed) markdoc 5.0.2 -> markdoc-5.0.2 (unchanged, first candidate) wbopendata v18.7.0 -> wbopendata-18.7.0 (v stripped) yaml v9.9.9 -> clean error listing what was tried Note for anyone testing this: -confirm file "dir/."- is not a usable directory test here; it returns 601 whether or not the directory exists. capture cd is used instead, which the surrounding code already relies on. --- github.ado | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/github.ado b/github.ado index 1be1f40..7419303 100644 --- a/github.ado +++ b/github.ado @@ -523,9 +523,46 @@ prog define github quietly copy "`path'" "`packagename'-`version'.zip", replace quietly unzipfile "`packagename'-`version'.zip", replace - local dir "`packagename'-`version'" local wd : pwd - qui cd "`dir'" + + // The archive's root folder is named by GitHub, and does not always + // equal "-": + // + // * a tag written v1.2.3 unpacks into -1.2.3 (GitHub drops + // the leading "v"), so -version(v1.2.3)- used to stop with r(170) + // on repositories that tag with that prefix; + // * archive/master.zip on a repository whose default branch is main + // unpacks into -main, not -master. + // + // Candidates are tried in order, so the expected name still wins and + // nothing changes for archives that already matched. Directory + // discovery is deliberately NOT used: this command unpacks into the + // user's working directory and leaves the folder there, so a second + // install in the same directory would leave several -* + // folders and make discovery ambiguous. + local candidates "`packagename'-`version'" + if regexm("`version'", "^v[0-9]") { + local stripped = regexr("`version'", "^v", "") + local candidates "`candidates' `packagename'-`stripped'" + } + if "`version'" == "master" local candidates "`candidates' `packagename'-main" + if "`version'" == "main" local candidates "`candidates' `packagename'-master" + + local found 0 + foreach c of local candidates { + if !`found' { + capture cd "`c'" + if _rc == 0 { + local found 1 + local dir "`c'" + } + } + } + if !`found' { + di as err "cannot locate the folder unpacked from `packagename'-`version'.zip" + di as txt "looked for: `candidates'" + exit 601 + } local pkg : pwd // check that the package does not include PKG and TOC before `force'