summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/paths.ts
diff options
context:
space:
mode:
authorchristine betts <[email protected]>2025-08-14 20:12:57 +0000
committerGitHub <[email protected]>2025-08-14 20:12:57 +0000
commit5c5fc89eb16afb65a5bbcb30e3bc576ed55e66b8 (patch)
treebf83a82c461085cf06d1082b251eadbbd6091ae1 /packages/core/src/utils/paths.ts
parente06d774996c0f09e1881201dca278720af2bf5b5 (diff)
[ide-mode] Support multi-folder workspaces (#6177)
Diffstat (limited to 'packages/core/src/utils/paths.ts')
-rw-r--r--packages/core/src/utils/paths.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/core/src/utils/paths.ts b/packages/core/src/utils/paths.ts
index 7bab888e..e7cf54cc 100644
--- a/packages/core/src/utils/paths.ts
+++ b/packages/core/src/utils/paths.ts
@@ -200,3 +200,23 @@ export function getUserCommandsDir(): string {
export function getProjectCommandsDir(projectRoot: string): string {
return path.join(projectRoot, GEMINI_DIR, COMMANDS_DIR_NAME);
}
+
+/**
+ * Checks if a path is a subpath of another path.
+ * @param parentPath The parent path.
+ * @param childPath The child path.
+ * @returns True if childPath is a subpath of parentPath, false otherwise.
+ */
+export function isSubpath(parentPath: string, childPath: string): boolean {
+ const isWindows = os.platform() === 'win32';
+ const pathModule = isWindows ? path.win32 : path;
+
+ // On Windows, path.relative is case-insensitive. On POSIX, it's case-sensitive.
+ const relative = pathModule.relative(parentPath, childPath);
+
+ return (
+ !relative.startsWith(`..${pathModule.sep}`) &&
+ relative !== '..' &&
+ !pathModule.isAbsolute(relative)
+ );
+}