Add warning banner if user is not on main branch (#91)

This commit is contained in:
Will Chen
2025-05-06 11:06:27 -07:00
committed by GitHub
parent 1fcb58a141
commit 43ec6a4563
5 changed files with 216 additions and 34 deletions

View File

@@ -2,7 +2,7 @@ import { ipcMain } from "electron";
import { db } from "../../db";
import { apps, messages } from "../../db/schema";
import { desc, eq, and, gt } from "drizzle-orm";
import type { Version } from "../ipc_types";
import type { Version, BranchResult } from "../ipc_types";
import fs from "node:fs";
import path from "node:path";
import { getDyadAppPath } from "../../paths/paths";
@@ -51,6 +51,53 @@ export function registerVersionHandlers() {
}
});
ipcMain.handle(
"get-current-branch",
async (_, { appId }: { appId: number }): Promise<BranchResult> => {
const app = await db.query.apps.findFirst({
where: eq(apps.id, appId),
});
if (!app) {
return {
success: false,
errorMessage: "App not found",
};
}
const appPath = getDyadAppPath(app.path);
// Return appropriate result if the app is not a git repo
if (!fs.existsSync(path.join(appPath, ".git"))) {
return {
success: false,
errorMessage: "Not a git repository",
};
}
try {
const currentBranch = await git.currentBranch({
fs,
dir: appPath,
fullname: false,
});
return {
success: true,
data: {
branch: currentBranch || "<no-branch>",
},
};
} catch (error: any) {
logger.error(`Error getting current branch for app ${appId}:`, error);
return {
success: false,
errorMessage: `Failed to get current branch: ${error.message}`,
};
}
}
);
ipcMain.handle(
"revert-version",
async (

View File

@@ -22,6 +22,7 @@ import type {
TokenCountParams,
TokenCountResult,
ChatLogsData,
BranchResult,
} from "./ipc_types";
import type { CodeProposal, ProposalResult } from "@/lib/schemas";
import { showError } from "@/lib/toast";
@@ -478,6 +479,14 @@ export class IpcClient {
}
}
// Get the current branch of an app
public async getCurrentBranch(appId: number): Promise<BranchResult> {
const result = await this.ipcRenderer.invoke("get-current-branch", {
appId,
});
return result;
}
// Get user settings
public async getUserSettings(): Promise<UserSettings> {
try {

View File

@@ -74,6 +74,18 @@ export interface Version {
timestamp: number;
}
export type Result<T> =
| {
success: true;
data: T;
}
| {
success: false;
errorMessage: string;
};
export type BranchResult = Result<{ branch: string }>;
export interface SandboxConfig {
files: Record<string, string>;
dependencies: Record<string, string>;