Skip to content

Commit b497c51

Browse files
committed
fix: Handle apps without git repository gracefully in chat headers
- Return '<no-git-repo>' instead of throwing error when no .git directory exists - Update ChatHeader and BackendChatHeader to display info message for uninitialized git repos - Prevent 'Not a git repository' error when switching to fullstack/backend/frontend modes
1 parent 0ff9b74 commit b497c51

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/components/backend-chat/BackendChatHeader.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function BackendChatHeader({
109109
// REMINDER: KEEP UP TO DATE WITH app_handlers.ts
110110
const versionPostfix = versions.length === 100_000 ? `+` : "";
111111

112-
const isNotMainBranch = branchInfo && branchInfo.branch !== "main";
112+
const isNotMainBranch = branchInfo && branchInfo.branch !== "main" && branchInfo.branch !== "<no-git-repo>";
113113

114114
const currentBranchName = branchInfo?.branch;
115115

@@ -160,7 +160,27 @@ export function BackendChatHeader({
160160
</TooltipProvider>
161161
</>
162162
)}
163-
{currentBranchName && currentBranchName !== "<no-branch>" && (
163+
{currentBranchName === "<no-git-repo>" && (
164+
<>
165+
<TooltipProvider>
166+
<Tooltip>
167+
<TooltipTrigger asChild>
168+
<span className="flex items-center gap-1">
169+
<strong>Info:</strong>
170+
<span>Version control not initialized</span>
171+
<Info size={14} />
172+
</span>
173+
</TooltipTrigger>
174+
<TooltipContent>
175+
<p>
176+
This app does not have git version control initialized yet.
177+
</p>
178+
</TooltipContent>
179+
</Tooltip>
180+
</TooltipProvider>
181+
</>
182+
)}
183+
{currentBranchName && currentBranchName !== "<no-branch>" && currentBranchName !== "<no-git-repo>" && (
164184
<span>
165185
You are on branch: <strong>{currentBranchName}</strong>.
166186
</span>

src/components/chat/ChatHeader.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function ChatHeader({
108108
// REMINDER: KEEP UP TO DATE WITH app_handlers.ts
109109
const versionPostfix = versions.length === 100_000 ? `+` : "";
110110

111-
const isNotMainBranch = branchInfo && branchInfo.branch !== "main";
111+
const isNotMainBranch = branchInfo && branchInfo.branch !== "main" && branchInfo.branch !== "<no-git-repo>";
112112

113113
const currentBranchName = branchInfo?.branch;
114114

@@ -153,6 +153,26 @@ export function ChatHeader({
153153
</TooltipProvider>
154154
</>
155155
)}
156+
{currentBranchName === "<no-git-repo>" && (
157+
<>
158+
<TooltipProvider>
159+
<Tooltip>
160+
<TooltipTrigger asChild>
161+
<span className="flex items-center gap-1">
162+
<strong>Info:</strong>
163+
<span>Version control not initialized</span>
164+
<Info size={14} />
165+
</span>
166+
</TooltipTrigger>
167+
<TooltipContent>
168+
<p>
169+
This app does not have git version control initialized yet.
170+
</p>
171+
</TooltipContent>
172+
</Tooltip>
173+
</TooltipProvider>
174+
</>
175+
)}
156176
{currentBranchName && currentBranchName !== "<no-branch>" && (
157177
<span>
158178
You are on branch: <strong>{currentBranchName}</strong>.

src/ipc/handlers/version_handlers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ export function registerVersionHandlers() {
129129

130130
// Return appropriate result if the app is not a git repo
131131
if (!fs.existsSync(path.join(appPath, ".git"))) {
132-
throw new Error("Not a git repository");
132+
return {
133+
branch: "<no-git-repo>",
134+
};
133135
}
134136

135137
try {

0 commit comments

Comments
 (0)