{"record":{"id":"b4b778c712ac56be","repo":"gitbutlerapp/gitbutler","slug":"repoownership","errorCode":"RepoOwnership","errorMessage":"The git directory is considered unsafe as it's not owned by the current user. Use `git config --global --add safe.directory '{}'` to allow it","messagePattern":"The git directory is considered unsafe as it's not owned by the current user\\. Use `git config --global --add safe\\.directory '(.+?)'` to allow it","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/but-api/src/legacy/projects.rs","lineNumber":194,"sourceCode":"\n/// Prepare an already-known project for activation in the UI or server.\n///\n/// This repairs missing target metadata in freshly selected storage locations.\npub fn prepare_project_for_activation(ctx: &mut Context) -> Result<()> {\n    assure_repo_ownership(&*ctx.repo.get()?)?;\n    let _guard = ctx.exclusive_worktree_access();\n    gitbutler_branch_actions::base::bootstrap_default_target_if_missing(ctx)?;\n    Ok(())\n}\n\n// TODO(gix): remove this once there is no `git2` as `gix` provides safety by not trusting Git configuration instead.\nfn assure_repo_ownership(repo: &gix::Repository) -> Result<()> {\n    if repo.git_dir_trust() == gix::sec::Trust::Full {\n        return Ok(());\n    }\n\n    let path = repo.workdir().unwrap_or(repo.git_dir());\n    Err(anyhow!(\n        \"The git directory is considered unsafe as it's not owned by the current user. Use `git config --global --add safe.directory '{}'` to allow it\",\n        path.display()\n    )\n    .context(Code::RepoOwnership))\n}\n\n#[but_api]\n#[instrument(err(Debug))]\npub fn is_gerrit(ctx: &but_ctx::Context) -> Result<bool> {\n    let repo = ctx.repo.get()?;\n    Ok(\n        gitbutler_project::gerrit::is_used_by_default_remote(&repo).unwrap_or_else(|err| {\n            tracing::debug!(?err, \"Gerrit detection failed\");\n            false\n        }),\n    )\n}\n","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/legacy/projects.rs#L176-L212","documentation":"`assure_repo_ownership` checks `repo.git_dir_trust()`; when gix reports the repository as not fully trusted (directory owned by a different user, like git's `safe.directory` protection), the project cannot be activated and this `RepoOwnership`-coded error is returned, telling the user to add the path to `safe.directory`. This mirrors git's own dubious-ownership safety mechanism to prevent privilege issues when a repo is owned by another account.","triggerScenarios":"Opening/activating a project whose `.git` (or workdir) is owned by a different OS user than the process running GitButler — e.g. repos under root-owned paths, WSL/Windows permission mismatches, containers mounting host repos, or shared network drives.","commonSituations":"Running the app as a different user than the one who cloned; Docker/container volumes; NFS/SMB shares; WSL accessing /mnt/c repos; repos copied with `sudo`.","solutions":["Run the suggested command: `git config --global --add safe.directory '<path shown in the error>'`.","Or fix ownership: `sudo chown -R $(whoami) <repo path>`.","In WSL, move the repo into the Linux filesystem (~/) or configure safe.directory as above.","If in a container, run as the same UID as the mounted repo's owner or whitelist the path in safe.directory."],"exampleFix":"// before\n// RepoOwnership error when opening /home/alice/repo as bob\ngit config --global --add safe.directory '/home/alice/repo';\n// or\nsudo chown -R bob:bob /home/alice/repo","handlingStrategy":"validation","validationCode":"# shell: check ownership before launching GitButler against a repo\nstat -c '%U' \"$REPO/.git\"   # compare with current user\n# or pre-add safe.directory:\ngit config --global --add safe.directory \"$(realpath \"$REPO\")\"","typeGuard":null,"tryCatchPattern":"match prepare_project_for_activation(...) {\n    Err(e) if e.to_string().contains(\"not owned by the current user\") => {\n        // surface the exact `git config --global --add safe.directory '<path>'` command to the user\n        show_fix_hint(&e.to_string());\n    }\n    other => other?,\n}","preventionTips":["Own the repo with the same user that runs the tool (chown after sudo operations)","Avoid working on host-mounted/network-share repos across user boundaries","In WSL, keep repos in the Linux filesystem; whitelist cross-ownership paths in safe.directory","Run containers as the same UID as the mounted repo's owner"],"tags":["git","permissions","ownership","security"],"backgroundTag":"permission-denied","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}