diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-03-21 11:23:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-21 11:23:56 +0100 |
commit | 7ed81701ee5da8c49f31bf0bbe3bca3645cf37bc (patch) | |
tree | 4a0029f6d76414950881508a548b9b1ae793317d | |
parent | 8ad485ea893862029e02cb560a15fd276753b04f (diff) | |
parent | 31544b93ffa985661541309ec2360dfb7b527a80 (diff) |
Merge pull request #6290 from Misterio77/fix-sourcehut-tags-refs
Fix sourcehut tags refs resolving
-rw-r--r-- | src/libfetchers/github.cc | 10 | ||||
-rw-r--r-- | tests/sourcehut-flakes.nix | 2 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index a1430f087..58b6e7c04 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -390,7 +390,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme ref_uri = line.substr(ref_index+5, line.length()-1); } else - ref_uri = fmt("refs/heads/%s", ref); + ref_uri = fmt("refs/(heads|tags)/%s", ref); auto file = store->toRealPath( downloadFile(store, fmt("%s/info/refs", base_url), "source", false, headers).storePath); @@ -399,9 +399,11 @@ struct SourceHutInputScheme : GitArchiveInputScheme std::string line; std::string id; while(getline(is, line)) { - auto index = line.find(ref_uri); - if (index != std::string::npos) { - id = line.substr(0, index-1); + // Append $ to avoid partial name matches + std::regex pattern(fmt("%s$", ref_uri)); + + if (std::regex_search(line, pattern)) { + id = line.substr(0, line.find('\t')); break; } } diff --git a/tests/sourcehut-flakes.nix b/tests/sourcehut-flakes.nix index d1d89d149..6a1930904 100644 --- a/tests/sourcehut-flakes.nix +++ b/tests/sourcehut-flakes.nix @@ -59,7 +59,7 @@ let echo 'ref: refs/heads/master' > $out/HEAD mkdir -p $out/info - echo '${nixpkgs.rev} refs/heads/master' > $out/info/refs + echo -e '${nixpkgs.rev}\trefs/heads/master' > $out/info/refs ''; in |