rust-lang/cargo · error
couldn't find repository name
Error message
couldn't find repository name
What it means
GitHub fast path expects exactly two path segments (`user/repo`). After successfully reading the username segment, the next `pieces.next()` returned `None`, meaning the URL path had only one segment (e.g. `https://github.com/user` with no repository).
Solutions
- Append the repository name to the URL: `https://github.com/<user>/<repo>`.
- Verify the URL by opening it in a browser before committing.
- Add a CI lint that rejects git URLs without at least two path segments.
Example fix
# before
[dependencies]
x = { git = "https://github.com/rust-lang" }
# after
[dependencies]
x = { git = "https://github.com/rust-lang/cargo" } Defensive patterns
Strategy: validation
Validate before calling
fn require_two_segments(u: &url::Url) -> Result<(&str, &str), anyhow::Error> {
let mut s = u.path_segments().ok_or_else(|| anyhow::"no path"))?;
let user = s.next().filter(|x| !x.is_empty()).ok_or_else(|| anyhow!("no user"))?;
let repo = s.next().filter(|x| !x.is_empty()).ok_or_else(|| anyhow!("no repo"))?;
Ok((user, repo))
} Type guard
fn url_has_user_and_repo(u: &url::Url) -> bool {
u.path_segments().map_or(false, |mut s| s.next().is_some() && s.next().is_some())
} Try / catch
let repository = match pieces.next() { Some(r) if !r.is_empty() => r, _ => return Ok(FastPathRev::Indeterminate) }; Prevention
- Copy the repository root URL, not the user/org profile URL.
- CI lint: GitHub git URLs must have exactly two path segments.
- Open the URL in a browser to confirm it lands on a repo.
When it happens
Trigger: A git dependency URL of the form `https://github.com/<user>` (or with `.git` omitted and only one path component) reaching the GitHub fast path.
Common situations: Copy-paste of a GitHub profile URL instead of a repo URL; trailing slash manipulation that dropped the repo segment; misconfigured registry pointing at a user root.
Related errors
- couldn't find username
- no path segments on url
- too many segments on URL
- attempting to update a git repository, but
- can't checkout from ' ': you are in the offline mode ( )
AI-assisted analysis of rust-lang/cargo@495c385d08 (2026-08-11).
Data as JSON: /api/errors/beaec307325387d9.
Report an issue: GitHub.
Appendix: source
Thrown at src/sources/git/utils.rs:1819
rev
} else {
debug!("can't use github fast path with `rev = \"{}\"`", rev);
return Ok(FastPathRev::Indeterminate);
}
}
};
// This expects GitHub urls in the form `github.com/user/repo` and nothing
// else
let mut pieces = url
.path_segments()
.ok_or_else(|| anyhow!("no path segments on url"))?;
let username = pieces
.next()
.ok_or_else(|| anyhow!("couldn't find username"))?;
let repository = pieces
.next()
.ok_or_else(|| anyhow!("couldn't find repository name"))?;
if pieces.next().is_some() {
anyhow::bail!("too many segments on URL");
}
// Trim off the `.git` from the repository, if present, since that's
// optional for GitHub and won't work when we try to use the API as well.
let repository = repository.strip_suffix(".git").unwrap_or(repository);
let url = format!(
"https://api.github.com/repos/{}/{}/commits/{}",
username, repository, github_branch_name,
);
debug!("attempting GitHub fast path for {}", url);
let mut request =
Request::get(url).header(http::header::ACCEPT, "application/vnd.github.3.sha");
if let Some(local_object) = local_object {
request = request.header(http::header::IF_NONE_MATCH, &format!("\"{local_object}\""));
}View on GitHub (pinned to 495c385d08)