Skip to content

fix: friendly error when bruin CLI cannot find a git repository#759

Open
DjamilaBaroudi wants to merge 1 commit into
mainfrom
fix/friendly-no-git-error
Open

fix: friendly error when bruin CLI cannot find a git repository#759
DjamilaBaroudi wants to merge 1 commit into
mainfrom
fix/friendly-no-git-error

Conversation

@DjamilaBaroudi
Copy link
Copy Markdown
Collaborator

Summary

  • Detect no git repository found / failed to find the git repository root in bruin CLI output and replace with a single actionable message: "Bruin requires a git repository. Run git init at your project root, then reload the window."
  • New helper friendlifyBruinError + constant FRIENDLY_NO_GIT_REPO_MESSAGE in src/utilities/helperUtils.ts.
  • Wired into validate (bruinValidate.ts), connections list (bruinConnections.ts), and render parseError (bruinRender.ts).
  • 6 unit tests covering both patterns, case-insensitivity, pass-through, Error inputs, and null/undefined.

Context

Related to BRU-2675. The ticket's "incorrect workspace root folder" framing turned out to be a red herring — bruin CLI walks up from the file path (not cwd/workspace) to find .git, so the workspace root location does not matter. The real cause was a missing git repo in the user's project, and the CLI errors surfaced today are unfriendly. This PR doesn't change the CLI requirement; it just makes the failure actionable.

Render currently keeps showing the generic "failed to mutate the asset" because the CLI itself drops the underlying cause for the render subcommand — that's a separate upstream fix in bruin-data/bruin. Once fixed there, this PR's helper will cover render automatically with no further extension changes.

Test plan

  • tsc -p ./ --noEmit clean
  • eslint clean on all touched files
  • Helper unit tests pass (7 assertions verified against compiled output)
  • Manual: open a folder with no .git ancestor, click Validate → expect friendly message instead of no git repository found
  • Manual: open Settings → Connections in same folder → expect friendly message instead of failed to find the git repository root
  • Manual: open a folder with .git → confirm normal flows still work (no regressions)

🤖 Generated with Claude Code

Detect "no git repository found" and "failed to find the git
repository root" in CLI output and replace them with a single
actionable message guiding users to run `git init` at their project
root. Wired into validate, connections list, and render error paths.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 28, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/test/extension.test.ts:1106-1111
**Second pattern test doesn't isolate pattern 2**

The string `"Failed to find the git repository root: no git repository found"` also satisfies the first pattern (`/no git repository found/i`), so this test would pass even if the second entry in `NO_GIT_REPO_PATTERNS` were removed. A string like `"Failed to find the git repository root"` (without the `: no git repository found` suffix) would uniquely exercise the second pattern.

```suggestion
    test("maps 'failed to find the git repository root' to the friendly message", () => {
      assert.strictEqual(
        friendlifyBruinError("Failed to find the git repository root"),
        FRIENDLY_NO_GIT_REPO_MESSAGE
      );
    });
```

Reviews (1): Last reviewed commit: "fix: surface friendly error when bruin C..." | Re-trigger Greptile

Comment on lines +1106 to +1111
test("maps 'failed to find the git repository root' to the friendly message", () => {
assert.strictEqual(
friendlifyBruinError("Failed to find the git repository root: no git repository found"),
FRIENDLY_NO_GIT_REPO_MESSAGE
);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Second pattern test doesn't isolate pattern 2

The string "Failed to find the git repository root: no git repository found" also satisfies the first pattern (/no git repository found/i), so this test would pass even if the second entry in NO_GIT_REPO_PATTERNS were removed. A string like "Failed to find the git repository root" (without the : no git repository found suffix) would uniquely exercise the second pattern.

Suggested change
test("maps 'failed to find the git repository root' to the friendly message", () => {
assert.strictEqual(
friendlifyBruinError("Failed to find the git repository root: no git repository found"),
FRIENDLY_NO_GIT_REPO_MESSAGE
);
});
test("maps 'failed to find the git repository root' to the friendly message", () => {
assert.strictEqual(
friendlifyBruinError("Failed to find the git repository root"),
FRIENDLY_NO_GIT_REPO_MESSAGE
);
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/test/extension.test.ts
Line: 1106-1111

Comment:
**Second pattern test doesn't isolate pattern 2**

The string `"Failed to find the git repository root: no git repository found"` also satisfies the first pattern (`/no git repository found/i`), so this test would pass even if the second entry in `NO_GIT_REPO_PATTERNS` were removed. A string like `"Failed to find the git repository root"` (without the `: no git repository found` suffix) would uniquely exercise the second pattern.

```suggestion
    test("maps 'failed to find the git repository root' to the friendly message", () => {
      assert.strictEqual(
        friendlifyBruinError("Failed to find the git repository root"),
        FRIENDLY_NO_GIT_REPO_MESSAGE
      );
    });
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant