{"id":"4ef530fca75b75f6","repo":"rust-lang/cargo","slug":"more-than-one-of-hg-git-pijul-fossil-config","errorCode":null,"errorMessage":"more than one of .hg, .git, .pijul, .fossil configurations found and the ignore file can't be filled in as a result. specify --vcs to override detection","messagePattern":"more than one of \\.hg, \\.git, \\.pijul, \\.fossil configurations found and the ignore file can't be filled in as a result\\. specify --vcs to override detection","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_new.rs","lineNumber":581,"sourceCode":"        if path.join(\".hg\").exists() {\n            version_control = Some(VersionControl::Hg);\n            num_detected_vcses += 1;\n        }\n\n        if path.join(\".pijul\").exists() {\n            version_control = Some(VersionControl::Pijul);\n            num_detected_vcses += 1;\n        }\n\n        if path.join(\".fossil\").exists() {\n            version_control = Some(VersionControl::Fossil);\n            num_detected_vcses += 1;\n        }\n\n        // if none exists, maybe create git, like in `cargo new`\n\n        if num_detected_vcses > 1 {\n            anyhow::bail!(\n                \"more than one of .hg, .git, .pijul, .fossil configurations \\\n                 found and the ignore file can't be filled in as \\\n                 a result. specify --vcs to override detection\"\n            );\n        }\n    }\n\n    let mkopts = MkOptions {\n        version_control,\n        path,\n        name,\n        source_files: src_paths_types,\n        edition: opts.edition.as_deref(),\n        registry: opts.registry.as_deref(),\n    };\n\n    mk(gctx, &mkopts).with_context(|| {\n        format!(","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_new.rs#L563-L599","documentation":"During `cargo init`, if --vcs was not passed Cargo auto-detects the existing VCS by checking for .git/.hg/.pijul/.fossil. When MORE than one of those directories is present, it cannot decide which ignore-file format (.gitignore vs .hgignore vs .gitignore-fossil vs .ignore) to write, so it bails at cargo_new.rs:580-586 asking the user to disambiguate with --vcs.","triggerScenarios":"`cargo init` in a directory that contains both a `.git/` and a `.hg/` (or .pijul/, .fossil/) - e.g. a repo migrated from Mercurial to Git where the old .hg was left in place, or a directory bind-mounted from another VCS workspace.","commonSituations":"Half-finished VCS migrations (git repo that still contains .hg); CI checkouts that leave auxiliary VCS metadata; users experimenting with Pijul/Fossil alongside Git; tooling that creates a .git skeleton regardless of the real VCS.","solutions":["Pass --vcs explicitly to override detection: `cargo init --vcs git`","Remove the stale VCS directory you no longer use (e.g. `rm -rf .hg`) then re-run","Pass `--vcs none` to skip ignore-file generation entirely"],"exampleFix":"# before (.git and .hg both present)\ncargo init\n# after (option A)\ncargo init --vcs git\n# after (option B)\nrm -rf .hg && cargo init","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn count_vcs_dirs(dir: &Path) -> usize {\n    [\".git\", \".hg\", \".pijul\", \".fossil\"].iter().filter(|d| dir.join(d).exists()).count()\n}\n\nif count_vcs_dirs(dir) > 1 && vcs_arg.is_none() { /* force user to pass --vcs */ }","typeGuard":"import { existsSync } from 'fs';\nimport { join } from 'path';\nfunction detectSingleVcs(dir: string): string | null {\n  const found = ['.git','.hg','.pijul','.fossil'].filter(d => existsSync(join(dir, d)));\n  return found.length === 1 ? found[0] : null;\n}","tryCatchPattern":null,"preventionTips":["Always pass --vcs when running `cargo init` in mixed-VCS directories","Clean up stale VCS metadata (e.g. remove leftover .hg after git migration)","In CI, pin the VCS explicitly to avoid environment-dependent detection"],"tags":["cargo-init","vcs","detection","ambiguity"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}