function stripDotGit(path) {
    return path.replace(/\.git$/i, "");
}
function stripLeadingSlash(path) {
    return path.replace(/^\/+/, "");
}
function stripTrailingSlash(path) {
    return path.replace(/\/+$/, "");
}
function parseHttpLike(remoteUrl) {
    const url = new URL(remoteUrl);
    const host = url.hostname.toLowerCase();
    const repoPath = stripDotGit(stripTrailingSlash(stripLeadingSlash(url.pathname)));
    if (!repoPath)
        throw new Error("Invalid git remote URL (missing path)");
    return { host, repoPath };
}
function parseScpLike(remoteUrl) {
    const m = /^([^@]+)@([^:]+):(.+)$/.exec(remoteUrl);
    if (!m || !m[2] || !m[3])
        throw new Error("Invalid SCP-like git remote URL");
    const host = String(m[2]).toLowerCase();
    const repoPath = stripDotGit(stripTrailingSlash(stripLeadingSlash(String(m[3]))));
    if (!repoPath)
        throw new Error("Invalid git remote URL (missing path)");
    return { host, repoPath };
}
export function parseGitRemote(remoteUrl) {
    const trimmed = remoteUrl.trim();
    if (!trimmed)
        throw new Error("Remote URL is empty");
    if (/^(https?|ssh):\/\//i.test(trimmed)) {
        return parseHttpLike(trimmed);
    }
    if (/^[^@]+@[^:]+:.+/.test(trimmed)) {
        return parseScpLike(trimmed);
    }
    return parseHttpLike(trimmed);
}
//# sourceMappingURL=gitRemote.js.map