{"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":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/setup.rs","lineNumber":650,"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":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but/src/command/legacy/setup.rs#L632-L668","documentation":"End state of `setup_new_repo`: the current directory is not inside a git repository, so setup offers an interactive prompt ('Would you like to initialize a new one? [y/N]'). The error is returned when the user answers anything other than `y`, or when there is no interactive terminal at all (`prepare_for_terminal_input` yields None), in which case the prompt never appears.","triggerScenarios":"Running `but setup` in a plain directory and declining the init prompt (answering N, n, empty enter, or any non-'y' input); running setup non-interactively (piped stdin, CI) where the prompt cannot be shown at all.","commonSituations":"Forgot to `cd` into the clone before running the tool; CI or cron pipelines with no TTY; expecting setup to find a repo that was never cloned; a clone step silently failed earlier in the script.","solutions":["cd into the actual repository clone (or pass its path) and rerun setup","If you genuinely want a new repo there, run setup interactively and answer `y`, or just `git init` and make an initial commit yourself first","In scripts, ensure the clone step succeeded and run `git init` before invoking setup non-interactively"],"exampleFix":"# before: ran in the wrong folder, prompt declined / no TTY\nmkdir -p ~/work && cd ~/work && but setup\n\n# after: enter the repo first\ncd ~/work/project && but setup","handlingStrategy":"validation","validationCode":"if gix::discover(std::env::current_dir()?).is_err() {\n    if !std::io::stdin().is_terminal() {\n        anyhow::bail!(\"not inside a git repository and no TTY to prompt; run 'git init' first\");\n    }\n    // else let setup offer the init prompt\n}","typeGuard":null,"tryCatchPattern":"match run_setup(&mut ctx, &mut out) {\n    Ok(_) => {}\n    Err(err) if err.to_string() == \"No git repository found.\" => {\n        // guidance: cd into the clone, or git init, or answer 'y' when prompted\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["cd into the clone (or pass its path) before running setup","In non-interactive pipelines, run `git init` and an initial commit explicitly beforehand","Fail the pipeline early if the clone step did not produce a `.git`"],"tags":["rust","cli","setup","git","repo-discovery","interactive-prompt"],"backgroundTag":"not-a-git-repository","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}