Hide Git panel outside repositories

This commit is contained in:
Federico Jaramillo Martinez
2026-05-08 15:39:37 +02:00
parent 87d0aa3b21
commit 8b355f414b
9 changed files with 30 additions and 13 deletions
+7 -4
View File
@@ -7,12 +7,13 @@ const idFor = (value: string) => createHash("sha1").update(value).digest("hex").
export class WorkspaceService {
async list(project: Project): Promise<Workspace[]> {
if (!(await isGitRepository(project.path))) {
return [this.single(project)];
const isGitRepo = await isGitRepository(project.path);
if (!isGitRepo) {
return [this.single(project, false)];
}
const worktrees = await discoverGitWorktrees(project.path);
if (worktrees.length === 0) return [this.single(project)];
if (worktrees.length === 0) return [this.single(project, true)];
return worktrees.map((worktree) => {
const leafName = worktree.path.split("/").filter((part) => part !== "").at(-1);
@@ -23,18 +24,20 @@ export class WorkspaceService {
label: worktree.branch ?? (worktree.detached === true ? "detached" : leafName ?? worktree.path),
...(worktree.branch === undefined ? {} : { branch: worktree.branch }),
isMain: worktree.path === project.path,
isGitRepo: true,
isGitWorktree: true,
};
});
}
private single(project: Project): Workspace {
private single(project: Project, isGitRepo: boolean): Workspace {
return {
id: idFor(`${project.id}:${project.path}`),
projectId: project.id,
path: project.path,
label: project.name,
isMain: true,
isGitRepo,
isGitWorktree: false,
};
}