{"record":{"id":"2e186385e0df6ecd","repo":"gitbutlerapp/gitbutler","slug":"no-git-repository-found","errorCode":null,"errorMessage":"No git repository found.","messagePattern":"No git repository found\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/setup.rs","lineNumber":693,"sourceCode":"                \"{}\",\n                t.hint\n                    .paint(\"Initializing new repository and creating an empty first commit...\")\n            )?;\n            let repo = gix::init(current_dir)?;\n\n            create_empty_initial_commit(&repo)?;\n\n            writeln!(\n                &mut progress as &mut dyn FmtWrite,\n                \"{}\",\n                t.success\n                    .paint(\"Initialized a new repository and created an empty first commit.\\n\")\n            )?;\n            return Ok(repo);\n        }\n    }\n\n    Err(anyhow::anyhow!(\"No git repository found.\"))\n}\n\nfn create_empty_initial_commit(repo: &gix::Repository) -> anyhow::Result<()> {\n    // In an unborn repo, this returns the well-known empty-tree id.\n    // (It works even if the empty tree object isn’t physically in the ODB.)\n    let empty_tree = repo.head_tree_id_or_empty().expect(\"repo access failed\"); // -> Id<'_>\n    let empty_tree = empty_tree.detach(); // -> ObjectId (optional; commit() accepts Into<ObjectId> anyway)\n\n    // No parents for the first commit. Update HEAD (writes through to refs/heads/main).\n    repo.commit(\n        \"HEAD\",\n        \"Initial empty commit\\n\",\n        empty_tree,\n        std::iter::empty::<gix::hash::ObjectId>(),\n    )?;\n\n    Ok(())\n}","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/setup.rs#L675-L711","documentation":"This error is raised by `setup_new_repo` in the `but` CLI after it failed to find an existing git repository and failed to initialize a new one (e.g. because the directory was not eligible for init or no path was usable). It is a terminal fallback: every code path that could produce a usable repository returns earlier, so reaching this line means no repository could be located or created.","triggerScenarios":"Running `but` commands in a directory that is not inside any git repository (no `.git` anywhere up the tree) when the auto-init path also fails, or calling `find_or_initialize_repo` with a working directory that does not permit repository creation.","commonSituations":"Running `but status` or similar in a plain folder, a typo'd `--dir`/cwd outside the repo, running in a container where the project was not volume-mounted, or running before `git init` when initialization was skipped.","solutions":["cd into (or point the command at) a directory that is inside a git repository, or run `git init` first","verify with `git rev-parse --show-toplevel` that the current directory belongs to a repo","check that the intended workspace directory exists and is writable before invoking the command"],"exampleFix":"// before (shell)\nbut status   # run in ~/projects/plain-folder\n// after\ncd ~/projects/my-repo && but status","handlingStrategy":"validation","validationCode":"if !std::path::Path::new(dir).join(\".git\").exists() {\n    // walk up parents or run `git rev-parse --show-toplevel` first\n    eprintln!(\"Not inside a git repository: {dir}\");\n}","typeGuard":null,"tryCatchPattern":"match find_or_initialize_repo(ctx) {\n    Err(e) if e.to_string().contains(\"No git repository found\") => {\n        eprintln!(\"Run from inside a repo, or `git init` first.\");\n    }\n    other => other?,\n}","preventionTips":["always launch `but` from within a git work tree","script a `git rev-parse --show-toplevel` precheck","ensure the target directory is mounted/exists in containers"],"tags":["git","cli","repository"],"backgroundTag":"resource-not-found","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"}