diff options
author | Linus Heckemann <git@sphalerite.org> | 2024-05-30 23:20:42 +0200 |
---|---|---|
committer | Linus Heckemann <git@sphalerite.org> | 2024-05-30 21:53:51 +0000 |
commit | 3df013597d7a2b5e400839e6625c05bd47de4dca (patch) | |
tree | c2165caf7b2ba73e0b75858dffc0f9b5f4089700 /src | |
parent | 2f104bbe3baf1e43a3fd78dc04f3f8ed48183554 (diff) |
libfetchers: handle nonexistent refs in GitLab repos more gracefully
Before:
$ nix flake lock --override-input nixpkgs gitlab:simple-nixos-mailserver/nixos-mailserver/nonexistent
fetching git input 'git+file:///home/linus/projects/lix'
fetching gitlab input 'gitlab:simple-nixos-mailserver/nixos-mailserver/nonexistent'
error: [json.exception.type_error.302] type must be string, but is null
After:
$ outputs/out/bin/nix flake lock --override-input nixpkgs gitlab:simple-nixos-mailserver/nixos-mailserver/nonexistent
fetching git input 'git+file:///home/linus/projects/lix'
fetching gitlab input 'gitlab:simple-nixos-mailserver/nixos-mailserver/nonexistent'
error:
… while updating the lock file of flake 'git+file:///home/linus/projects/lix?ref=refs/heads/fix-gitlab-nonexistent&rev=915f16a619a36237a099b9aa9afed6d14ff613b4'
… while updating the flake input 'nixpkgs'
… while fetching the input 'gitlab:simple-nixos-mailserver/nixos-mailserver/nonexistent'
error: No commits returned by GitLab API -- does the ref really exist?
Change-Id: Id9bc79d98348500e152ed519bb3ac79a3d15c38d
Diffstat (limited to 'src')
-rw-r--r-- | src/libfetchers/github.cc | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 6f997885d..3129e0d73 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -322,9 +322,15 @@ struct GitLabInputScheme : GitArchiveInputScheme readFile( store->toRealPath( downloadFile(store, url, "source", false, headers).storePath))); - auto rev = Hash::parseAny(std::string(json[0]["id"]), htSHA1); - debug("HEAD revision for '%s' is %s", url, rev.gitRev()); - return rev; + if (json.is_array() && json.size() == 1 && json[0]["id"] != nullptr) { + auto rev = Hash::parseAny(std::string(json[0]["id"]), htSHA1); + debug("HEAD revision for '%s' is %s", url, rev.gitRev()); + return rev; + } else if (json.is_array() && json.size() == 0) { + throw Error("No commits returned by GitLab API -- does the ref really exist?"); + } else { + throw Error("Didn't know what to do with response from GitLab: %s", json); + } } DownloadUrl getDownloadUrl(const Input & input) const override |