Skip to content

Commit d56053b

Browse files
committed
Refine global worktrees root save behavior
1 parent dd72acd commit d56053b

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/features/settings/components/SettingsView.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ describe("SettingsView Environments", () => {
789789
}),
790790
);
791791
});
792+
expect(onUpdateWorkspaceSettings).not.toHaveBeenCalled();
792793
});
793794

794795
it("does not clear an existing global worktrees root when saving project-only changes", async () => {
@@ -834,6 +835,24 @@ describe("SettingsView Environments", () => {
834835
});
835836
});
836837

838+
it("shows save errors for the global worktrees root when there are no projects", async () => {
839+
const onUpdateAppSettings = vi
840+
.fn()
841+
.mockRejectedValue(new Error("Failed to save global worktrees root"));
842+
renderEnvironmentsSection({
843+
groupedWorkspaces: [],
844+
onUpdateAppSettings,
845+
});
846+
847+
const input = screen.getByLabelText("Global worktrees root");
848+
fireEvent.change(input, { target: { value: "I:/cm-worktrees" } });
849+
fireEvent.click(screen.getByRole("button", { name: "Save" }));
850+
851+
expect(
852+
await screen.findByText("Failed to save global worktrees root"),
853+
).toBeTruthy();
854+
});
855+
837856
it("saves the setup script for the selected project", async () => {
838857
const onUpdateWorkspaceSettings = vi.fn().mockResolvedValue(undefined);
839858
renderEnvironmentsSection({ onUpdateWorkspaceSettings });

src/features/settings/components/sections/SettingsEnvironmentsSection.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ export function SettingsEnvironmentsSection({
119119
</button>
120120
</div>
121121
) : null}
122+
{!hasProjects && environmentError ? (
123+
<div className="settings-agents-error">{environmentError}</div>
124+
) : null}
122125
</div>
123126

124127
{!hasProjects ? (

src/features/settings/hooks/useSettingsEnvironmentsSection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export const useSettingsEnvironmentsSection = ({
147147
const nextScript = environmentDraftNormalized;
148148
const nextGlobalFolder = globalWorktreesFolderDraft.trim() || null;
149149
const nextFolder = worktreesFolderDraft.trim() || null;
150+
const workspaceSettingsDirty = environmentDirty || worktreesFolderDirty;
150151
setEnvironmentSaving(true);
151152
setEnvironmentError(null);
152153
try {
@@ -156,7 +157,7 @@ export const useSettingsEnvironmentsSection = ({
156157
globalWorktreesFolder: nextGlobalFolder,
157158
});
158159
}
159-
if (environmentWorkspace) {
160+
if (environmentWorkspace && workspaceSettingsDirty) {
160161
await onUpdateWorkspaceSettings(environmentWorkspace.id, {
161162
worktreeSetupScript: nextScript,
162163
worktreesFolder: nextFolder,

0 commit comments

Comments
 (0)