{"record":{"id":"e21b17b8ae30fa3c","repo":"rust-lang/cargo","slug":"multiple-packages-found-at-src-to-disa","errorCode":null,"errorMessage":"multiple packages found at `{src}`:\n    {}\nTo disambiguate, run `cargo add --git {src} <package>`","messagePattern":"multiple packages found at `(.+?)`:\n    (.+?)\nTo disambiguate, run `cargo add --git (.+?) <package>`","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":1076,"sourceCode":"}\n\nfn infer_package_for_git_source(\n    mut packages: Vec<Package>,\n    src: &dyn std::fmt::Display,\n) -> CargoResult<Package> {\n    let package = match packages.len() {\n        0 => unreachable!(\n            \"this function should only be called with packages from `GitSource::read_packages` \\\n            and that call should error for us when there are no packages\"\n        ),\n        1 => packages.pop().expect(\"match ensured element is present\"),\n        _ => {\n            let mut names: Vec<_> = packages\n                .iter()\n                .map(|p| p.name().as_str().to_owned())\n                .collect();\n            names.sort_unstable();\n            anyhow::bail!(\n                \"multiple packages found at `{src}`:\\n    {}\\nTo disambiguate, run `cargo add --git {src} <package>`\",\n                names\n                    .iter()\n                    .map(|s| s.to_string())\n                    .coalesce(|x, y| if x.len() + y.len() < 78 {\n                        Ok(format!(\"{x}, {y}\"))\n                    } else {\n                        Err((x, y))\n                    })\n                    .into_iter()\n                    .format(\"\\n    \"),\n            );\n        }\n    };\n    Ok(package)\n}\n\nfn populate_dependency(mut dependency: Dependency, arg: &DepOp) -> Dependency {","sourceCodeStart":1058,"sourceCodeEnd":1094,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/ops/cargo_add/mod.rs#L1058-L1094","documentation":"Thrown by infer_package_for_git_source when `cargo add --git <url>` resolves a repository that contains two or more packages and the user did not name which one to add. Unlike error 61, this is expected user-input ambiguity, so cargo prints the sorted package list and the exact disambiguation command.","triggerScenarios":"Running `cargo add --git https://github.com/org/repo` against a repo with multiple workspace members; a git source whose root Cargo.toml is virtual; adding from a fork that added extra crates.","commonSituations":"Adding a crate that lives in a multi-crate monorepo (e.g., most larger Rust projects) without specifying the member; vendoring from a fork; CI scripts that add by URL only.","solutions":["Re-run with the package name appended, exactly as the error's `cargo add --git {src} <package>` hint shows.","Pick the correct name from the printed sorted list (it is the `name = \"...\"` in each member's Cargo.toml).","If only one crate is intended, refactor the source repo to a single package so the disambiguation is unnecessary."],"exampleFix":"# before\ncargo add --git https://github.com/org/repo\n# after (name from the printed list)\ncargo add --git https://github.com/org/repo mycrate","handlingStrategy":"validation","validationCode":"// Enumerate packages in a git repo before adding.\n// `git ls-remote` won't list packages; instead clone shallowly and scan:\nfn packages_in_repo(url: &str) -> Vec<String> { /* clone --depth 1, walk Cargo.toml */ vec![] }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always append the package name when adding from a multi-package git repo.","Read the repo's workspace members list before scripting `cargo add --git`.","Treat the disambiguation hint in the error as authoritative."],"tags":["cargo-add","git-source","ambiguous-match","user-input"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}