{"record":{"id":"d8f18303b85ba1bd","repo":"GitoxideLabs/gitoxide","slug":"adding-files-requires-a-worktree-directory-that-co","errorCode":null,"errorMessage":"Adding files requires a worktree directory that contains them","messagePattern":"Adding files requires a worktree directory that contains them","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"gitoxide-core/src/repository/archive.rs","lineNumber":34,"sourceCode":"    rev_spec: Option<&str>,\n    mut progress: impl NestedProgress,\n    Options {\n        format,\n        prefix,\n        add_paths,\n        files,\n    }: Options,\n) -> anyhow::Result<()> {\n    let format = format.map_or_else(|| format_from_ext(destination_path), Ok)?;\n    let object = repo.rev_parse_single(rev_spec.unwrap_or(\"HEAD\"))?.object()?;\n    let (modification_date, tree) = fetch_rev_info(object)?;\n\n    let start = std::time::Instant::now();\n    let (mut stream, index) = repo.worktree_stream(tree)?;\n    if !add_paths.is_empty() {\n        let root = gix::path::realpath(\n            repo.workdir()\n                .ok_or_else(|| anyhow!(\"Adding files requires a worktree directory that contains them\"))?,\n        )?;\n        for path in add_paths {\n            stream.add_entry_from_path(&root, &gix::path::realpath(&path)?, repo.object_hash())?;\n        }\n    }\n    for (path, content) in files {\n        stream.add_entry(gix::worktree::stream::AdditionalEntry {\n            id: gix::hash::Kind::Sha1.null(),\n            mode: gix::object::tree::EntryKind::Blob.into(),\n            relative_path: path.into(),\n            source: gix::worktree::stream::entry::Source::Memory(content.into()),\n        });\n    }\n\n    let mut entries = progress.add_child(\"entries\");\n    entries.init(Some(index.entries().len()), gix::progress::count(\"entries\"));\n    let mut bytes = progress.add_child(\"written\");\n    bytes.init(None, gix::progress::bytes());","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gitoxide-core/src/repository/archive.rs#L16-L52","documentation":"Thrown by `stream` in gitoxide-core's archive command when `--add` paths were supplied but the repository is bare (no worktree). Adding files to the archive stream requires resolving paths against a real working directory via `repo.workdir()`, which is `None` for bare repositories.","triggerScenarios":"Calling `gix archive ... --add <path>` (via `stream`) inside or against a bare repository, or a repository opened with `--bare`/`open::Kind::Bare` so `repo.workdir()` returns `None`.","commonSituations":"Running the archive command on a server-side bare clone that only exists for hosting; CI checkout configured as bare to save space.","solutions":["Run the command in a non-bare clone that has a working tree","Drop the `--add` flags and only stream from a tree/commit, which does not need a workdir","Convert the bare repo: `git worktree add <dir> <ref>` and run against the worktree, or `git clone` a normal checkout"],"exampleFix":"// before (bare repo)\ngix repo archive HEAD --add extra.txt\n// after\ngix repo archive HEAD  # stream tree contents only, no --add","handlingStrategy":"validation","validationCode":"if add_paths.is_empty() {\n    // safe: no workdir needed\n} else if repo.workdir().is_none() {\n    return Err(\"--add requires a non-bare repository with a worktree\".into());\n}","typeGuard":"fn supports_add_paths(repo: &gix::Repository) -> bool {\n    repo.workdir().is_some()\n}","tryCatchPattern":null,"preventionTips":["Check `git rev-parse --is-bare-repository` before combining archive/merge commands with worktree-dependent flags","Only use `--add` in full checkouts"],"tags":["archive","worktree","bare-repository","cli","gitoxide"],"backgroundTag":"unsupported-operation","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}