Skip to content

Commit 1a1a573

Browse files
fix(web): start clone when destination is picked in file manager (pingdotgg#22226)
Co-authored-by: macodev00 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent a91d6c8 commit 1a1a573

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import {
1111
canCreateProjectInEnvironment,
1212
getCloneDestinationBrowsePath,
13+
getCloneDestinationForPickedFolder,
1314
getCloneDestinationPath,
1415
getCloneDirectoryLeafName,
1516
getCloneDirectoryPath,
@@ -2806,6 +2807,26 @@ function OpenCommandPaletteDialog(props: {
28062807
);
28072808
return;
28082809
}
2810+
if (addProjectCloneFlow?.step === "confirm") {
2811+
if (selection.environmentId !== addProjectCloneFlow.environmentId) {
2812+
toastManager.add(
2813+
stackedThreadToast({
2814+
type: "error",
2815+
title: "Clone failed",
2816+
description: "Choose a folder in the environment the repository is cloned into.",
2817+
}),
2818+
);
2819+
return;
2820+
}
2821+
await submitAddProjectCloneFlow(
2822+
getCloneDestinationForPickedFolder({
2823+
pickedPath: selection.linuxPath,
2824+
cloneDirectoryName: pinnedCloneDirectoryName,
2825+
caseSensitive: true,
2826+
}),
2827+
);
2828+
return;
2829+
}
28092830
await handleAddProjectForEnvironment({
28102831
environmentId: selection.environmentId,
28112832
rawCwd: selection.linuxPath,
@@ -2814,6 +2835,16 @@ function OpenCommandPaletteDialog(props: {
28142835
});
28152836
return;
28162837
}
2838+
if (addProjectCloneFlow?.step === "confirm") {
2839+
await submitAddProjectCloneFlow(
2840+
getCloneDestinationForPickedFolder({
2841+
pickedPath,
2842+
cloneDirectoryName: pinnedCloneDirectoryName,
2843+
caseSensitive: !isWindowsPlatform(browseEnvironmentPlatform),
2844+
}),
2845+
);
2846+
return;
2847+
}
28172848
await handleAddProject(pickedPath);
28182849
};
28192850

‎packages/client-runtime/src/operations/projects.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EnvironmentId, ProjectId } from "@t3tools/contracts";
44

55
import {
66
findExistingAddProject,
7+
getCloneDestinationForPickedFolder,
78
getCloneDestinationPath,
89
getCloneDirectoryLeafName,
910
getCloneDirectoryName,
@@ -162,6 +163,23 @@ describe("add project shared logic", () => {
162163
expect(getCloneDirectoryName("[email protected]:acme/123.git")).toBe("123");
163164
});
164165

166+
it("resolves a native-picker folder like an in-app clone selection", () => {
167+
const pick = (pickedPath: string, caseSensitive = true) =>
168+
getCloneDestinationForPickedFolder({
169+
pickedPath,
170+
cloneDirectoryName: "repo",
171+
caseSensitive,
172+
});
173+
174+
expect(pick("/Users/me/code")).toBe("/Users/me/code/repo");
175+
expect(pick("/Users/me/code/")).toBe("/Users/me/code/repo");
176+
expect(pick("/Users/me/repo")).toBe("/Users/me/repo/");
177+
expect(pick("/Users/me/Repo")).toBe("/Users/me/Repo/repo");
178+
expect(pick("C:\\Projects\\Repo", false)).toBe("C:\\Projects\\Repo\\");
179+
expect(pick("C:\\Projects", false)).toBe("C:\\Projects\\repo");
180+
expect(pick("/")).toBe("/repo");
181+
});
182+
165183
it("finds existing projects by normalized path in the target environment", () => {
166184
const env = EnvironmentId.make("env");
167185
const other = EnvironmentId.make("other");

‎packages/client-runtime/src/operations/projects.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
appendBrowsePathSegment,
2020
ensureBrowseDirectoryPath,
2121
findProjectByPath,
22+
getBrowseParentPath,
2223
inferProjectTitleFromPath,
2324
isExplicitRelativeProjectPath,
2425
isUnsupportedWindowsProjectPath,
@@ -299,6 +300,26 @@ export function getCloneDestinationBrowsePath(input: {
299300
: getCloneDestinationPath(selectedDirectoryPath, input.cloneDirectoryName);
300301
}
301302

303+
// The native picker returns a full path, not a name under the browsed directory.
304+
// Split it and reuse the in-app rules so a folder already named after the
305+
// repository stays that folder instead of becoming repo/repo.
306+
export function getCloneDestinationForPickedFolder(input: {
307+
readonly pickedPath: string;
308+
readonly cloneDirectoryName: string;
309+
readonly caseSensitive: boolean;
310+
}): string {
311+
const parentPath = getBrowseParentPath(input.pickedPath);
312+
if (parentPath === null) {
313+
return getCloneDestinationPath(input.pickedPath, input.cloneDirectoryName);
314+
}
315+
return getCloneDestinationBrowsePath({
316+
browseDirectoryPath: parentPath,
317+
selectedDirectoryName: inferProjectTitleFromPath(input.pickedPath),
318+
cloneDirectoryName: input.cloneDirectoryName,
319+
caseSensitive: input.caseSensitive,
320+
});
321+
}
322+
302323
export function resolveAddProjectPath(input: {
303324
readonly rawPath: string;
304325
readonly currentProjectCwd?: string | null;

0 commit comments

Comments
 (0)