{"record":{"id":"85f7c9fdb7f3d099","repo":"rust-lang/cargo","slug":"files-in-the-working-directory-contain-changes","errorCode":null,"errorMessage":"{} files in the working directory contain changes that were not yet committed into git:\n\n{}\n\nto proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag","messagePattern":"(.+?) files in the working directory contain changes that were not yet committed into git:\n\n(.+?)\n\nto proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_package/vcs.rs","lineNumber":264,"sourceCode":"        .chain(dirty_files_outside_pkg_root(ws, pkg, repo, src_files)?.iter())\n        .map(|path| {\n            pathdiff::diff_paths(path, cwd)\n                .as_ref()\n                .unwrap_or(path)\n                .display()\n                .to_string()\n        })\n        .collect();\n    let dirty = !dirty_src_files.is_empty();\n    if !dirty || opts.allow_dirty {\n        let maybe_head_id = repo.head()?.try_peel_to_id()?;\n        Ok(maybe_head_id.map(|id| GitVcsInfo {\n            sha1: id.to_string(),\n            dirty,\n        }))\n    } else {\n        dirty_src_files.sort_unstable();\n        anyhow::bail!(\n            \"{} files in the working directory contain changes that were \\\n             not yet committed into git:\\n\\n{}\\n\\n\\\n             to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag\",\n            dirty_src_files.len(),\n            dirty_src_files.join(\"\\n\")\n        )\n    }\n}\n\n/// Helper to collect dirty statuses for a single repo.\n/// `relative_package_root` is `Some` if the root is a sub-directory of the workdir.\n/// Writes dirty files outside `relative_package_root` into `dirty_files_outside_package_root`,\n/// and all *everything else* into `dirty_files`.\n#[must_use]\nfn collect_statuses(\n    repo: &gix::Repository,\n    workdir: &Path,\n    relative_package_root: Option<&Path>,","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/ops/cargo_package/vcs.rs#L246-L282","documentation":"Thrown during `cargo package` or `cargo publish` when the working directory of a git repository contains source files with uncommitted modifications. Cargo refuses to package dirty trees to ensure reproducible published artifacts. The `--allow-dirty` flag overrides this guard.","triggerScenarios":"Running `cargo package` (without `--allow-dirty`) when `git status` shows modified, staged-but-uncommitted, or untracked source files within the package. The check uses `gix` status to enumerate dirty files and compares them against the source file set.","commonSituations":"Forgetting to `git commit` before publishing; having generated files (e.g. from a code generator) that are tracked but locally modified; working on changes and wanting to test packaging mid-development.","solutions":["Commit or stash the uncommitted changes, then re-run `cargo package`.","Pass `--allow-dirty` to include uncommitted changes: `cargo package --allow-dirty`.","Add generated or irrelevant files to `.gitignore` so they are not tracked."],"exampleFix":"# Option 1: commit first\ngit add -A && git commit -m \"prep for publish\"\n\n# Option 2: allow dirty\ncargo package --allow-dirty","handlingStrategy":"validation","validationCode":"// Pre-check git status for dirty files before packaging\nfn check_git_clean(repo_root: &Path) -> Result<(), String> {\n    let output = std::process::Command::new(\"git\")\n        .args([\"status\", \"--porcelain\"])\n        .current_dir(repo_root)\n        .output().map_err(|e| e.to_string())?;\n    if !output.stdout.is_empty() {\n        return Err(format!(\"uncommitted changes:\\n{}\", String::from_utf8_lossy(&output.stdout)));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always commit changes before running `cargo publish`.","Use `--allow-dirty` only for local testing, never for real publishes.","Add a git pre-commit or CI check that runs `cargo publish --dry-run`."],"tags":["cargo-package","git","vcs","dirty","uncommitted"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}