mirror of
https://github.com/NixOS/nix.git
synced 2025-11-16 07:22:43 +01:00
Merge pull request #14492 from NixOS/fix-14429
fetchGit: Drop `git+` from the `url` attribute
This commit is contained in:
commit
709a73e7ae
6 changed files with 80 additions and 15 deletions
|
|
@ -330,10 +330,13 @@ struct ParsedUrlScheme
|
|||
|
||||
ParsedUrlScheme parseUrlScheme(std::string_view scheme);
|
||||
|
||||
/* Detects scp-style uris (e.g. git@github.com:NixOS/nix) and fixes
|
||||
them by removing the `:` and assuming a scheme of `ssh://`. Also
|
||||
changes absolute paths into file:// URLs. */
|
||||
ParsedURL fixGitURL(const std::string & url);
|
||||
/**
|
||||
* Detects scp-style uris (e.g. `git@github.com:NixOS/nix`) and fixes
|
||||
* them by removing the `:` and assuming a scheme of `ssh://`. Also
|
||||
* drops `git+` from the scheme (e.g. `git+https://` to `https://`)
|
||||
* and changes absolute paths into `file://` URLs.
|
||||
*/
|
||||
ParsedURL fixGitURL(std::string url);
|
||||
|
||||
/**
|
||||
* Whether a string is valid as RFC 3986 scheme name.
|
||||
|
|
|
|||
|
|
@ -409,21 +409,23 @@ ParsedUrlScheme parseUrlScheme(std::string_view scheme)
|
|||
};
|
||||
}
|
||||
|
||||
ParsedURL fixGitURL(const std::string & url)
|
||||
ParsedURL fixGitURL(std::string url)
|
||||
{
|
||||
std::regex scpRegex("([^/]*)@(.*):(.*)");
|
||||
if (!hasPrefix(url, "/") && std::regex_match(url, scpRegex))
|
||||
return parseURL(std::regex_replace(url, scpRegex, "ssh://$1@$2/$3"));
|
||||
if (hasPrefix(url, "file:"))
|
||||
return parseURL(url);
|
||||
if (url.find("://") == std::string::npos) {
|
||||
url = std::regex_replace(url, scpRegex, "ssh://$1@$2/$3");
|
||||
if (!hasPrefix(url, "file:") && !hasPrefix(url, "git+file:") && url.find("://") == std::string::npos)
|
||||
return ParsedURL{
|
||||
.scheme = "file",
|
||||
.authority = ParsedURL::Authority{},
|
||||
.path = splitString<std::vector<std::string>>(url, "/"),
|
||||
};
|
||||
}
|
||||
return parseURL(url);
|
||||
auto parsed = parseURL(url);
|
||||
// Drop the superfluous "git+" from the scheme.
|
||||
auto scheme = parseUrlScheme(parsed.scheme);
|
||||
if (scheme.application == "git")
|
||||
parsed.scheme = scheme.transport;
|
||||
return parsed;
|
||||
}
|
||||
|
||||
// https://www.rfc-editor.org/rfc/rfc3986#section-3.1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue