{"record":{"id":"aeeecb98c8f1113e","repo":"rust-lang/cargo","slug":"too-many-segments-on-url","errorCode":null,"errorMessage":"too many segments on URL","messagePattern":"too many segments on URL","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sources/git/utils.rs","lineNumber":1821,"sourceCode":"                debug!(\"can't use github fast path with `rev = \\\"{}\\\"`\", rev);\n                return Ok(FastPathRev::Indeterminate);\n            }\n        }\n    };\n\n    // This expects GitHub urls in the form `github.com/user/repo` and nothing\n    // else\n    let mut pieces = url\n        .path_segments()\n        .ok_or_else(|| anyhow!(\"no path segments on url\"))?;\n    let username = pieces\n        .next()\n        .ok_or_else(|| anyhow!(\"couldn't find username\"))?;\n    let repository = pieces\n        .next()\n        .ok_or_else(|| anyhow!(\"couldn't find repository name\"))?;\n    if pieces.next().is_some() {\n        anyhow::bail!(\"too many segments on URL\");\n    }\n\n    // Trim off the `.git` from the repository, if present, since that's\n    // optional for GitHub and won't work when we try to use the API as well.\n    let repository = repository.strip_suffix(\".git\").unwrap_or(repository);\n\n    let url = format!(\n        \"https://api.github.com/repos/{}/{}/commits/{}\",\n        username, repository, github_branch_name,\n    );\n    debug!(\"attempting GitHub fast path for {}\", url);\n    let mut request =\n        Request::get(url).header(http::header::ACCEPT, \"application/vnd.github.3.sha\");\n    if let Some(local_object) = local_object {\n        request = request.header(http::header::IF_NONE_MATCH, &format!(\"\\\"{local_object}\\\"\"));\n    }\n    let response = gctx\n        .http_async()?","sourceCodeStart":1803,"sourceCodeEnd":1839,"githubUrl":"https://github.com/rust-lang/cargo/blob/495c385d0875c4ba51eb72ea0448a2d4c018b8d4/src/sources/git/utils.rs#L1803-L1839","documentation":"GitHub fast path requires exactly `user/repo` (two segments). A third `pieces.next()` returned `Some`, so the URL has extra path components beyond the repository (e.g. `https://github.com/user/repo/extra` or `https://github.com/user/repo/tree/main`). GitHub API URL construction would be ambiguous, so Cargo bails.","triggerScenarios":"A git dependency URL with more than two path segments reaches the fast path. Commonly a URL to a subdirectory, branch, or file on GitHub pasted into `Cargo.toml` instead of the repo root.","commonSituations":"Pasting a deep GitHub URL (to a subfolder, tag page, or `tree/<branch>` view) as the `git` value; trailing `/something` left after editing.","solutions":["Trim the URL to the repo root: `https://github.com/<user>/<repo>` (optionally with `.git`).","Move subdir/branch info into the `path` / `branch` / `rev` keys of the dependency instead of the URL.","Validate that the git URL path has exactly two segments before commit."],"exampleFix":"# before\n[dependencies]\nx = { git = \"https://github.com/user/repo/tree/main/sub\" }\n\n# after\n[dependencies]\nx = { git = \"https://github.com/user/repo\", branch = \"main\", path = \"sub\" }","handlingStrategy":"validation","validationCode":"fn require_exactly_two_segments(u: &url::Url) -> Result<(&str, &str), anyhow::Error> {\n    let mut s = u.path_segments().ok_or_else(|| anyhow!(\"no path\"))?;\n    let user = s.next().ok_or_else(|| anyhow!(\"no user\"))?;\n    let repo = s.next().ok_or_else(|| anyhow!(\"no repo\"))?;\n    if s.next().is_some() { anyhow::bail!(\"too many segments\"); }\n    Ok((user, repo))\n}","typeGuard":"fn url_has_exactly_two_segments(u: &url::Url) -> bool {\n    u.path_segments().map_or(false, |mut s| s.next().is_some() && s.next().is_some() && s.next().is_none())\n}","tryCatchPattern":"if pieces.next().is_some() { return Ok(FastPathRev::Indeterminate); } // skip fast path gracefully","preventionTips":["Trim deep GitHub URLs to the repo root before using as `git`.","Put subdir/branch info in `path`/`branch` keys, not the URL.","CI lint against more than two path segments on git dependency URLs."],"tags":["cargo","git","url-parsing","github-fast-path","configuration"],"backgroundTag":null,"analyzedSha":"495c385d0875c4ba51eb72ea0448a2d4c018b8d4","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}