1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Set the origin instead of hacking in the URL resolving

This commit is contained in:
Bouke van der Bijl 2024-03-15 09:30:58 +01:00
parent 1f73de2629
commit 1a76ca4161
3 changed files with 14 additions and 15 deletions

View file

@ -198,6 +198,12 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
return git_repository_is_shallow(*this);
}
void setRemote(const std::string & name, const std::string & url) override
{
if (git_remote_set_url(*this, name.c_str(), url.c_str()))
throw Error("setting remote '%s' URL to '%s': %s", name, url, git_error_last()->message);
}
Hash resolveRef(std::string ref) override
{
Object object;
@ -302,9 +308,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
std::vector<std::tuple<Submodule, Hash>> getSubmodules(const Hash & rev, bool exportIgnore) override;
std::string resolveSubmoduleUrl(
const std::string & url,
const std::string & base) override
std::string resolveSubmoduleUrl(const std::string & url) override
{
git_buf buf = GIT_BUF_INIT;
if (git_submodule_resolve_url(&buf, *this, url.c_str()))
@ -312,14 +316,6 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
Finally cleanup = [&]() { git_buf_dispose(&buf); };
std::string res(buf.ptr);
// Git has a default protocol of 'ssh' for URLs without a protocol:
// https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_the_ssh_protocol
// This code matches what git_submodule_resolve_url does inside of itself to see if the URL is already absolute.
// Inside libgit2 it just checks whether there's any ':' in the URL to default to the ssh:// protocol.
if (!hasPrefix(res, "/") && res.find(":") == res.npos)
res = parseURL(base + "/" + res).canonicalise().to_string();
return res;
}