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'