-
Notifications
You must be signed in to change notification settings - Fork 904
worktree #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
worktree #140
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
45a9a13
working setup worktree using script
Kitenite cf4d2ce
Merge branch 'main' into worktree
Kitenite 0365130
clean up
Kitenite 9cea400
clean setup terminal
Kitenite e2a02fd
add setup tab
Kitenite 720e426
simple setup
Kitenite 68ca4a7
simple setup
Kitenite b198d78
save
Kitenite 06a481d
Merge branch 'main' into worktree
Kitenite 30d0c8e
merge main
Kitenite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,6 @@ | |
| "**/.env*" | ||
| ], | ||
| "commands": [ | ||
| "bun i" | ||
| "echo 'Hello world'" | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
apps/desktop/src/lib/trpc/routers/workspaces/utils/setup.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | ||
| import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { copySetupFiles, loadSetupConfig } from "./setup"; | ||
|
|
||
| const TEST_DIR = join(__dirname, ".test-tmp"); | ||
| const MAIN_REPO = join(TEST_DIR, "main-repo"); | ||
| const WORKTREE = join(TEST_DIR, "worktree"); | ||
|
|
||
| describe("loadSetupConfig", () => { | ||
| beforeEach(() => { | ||
| // Create test directories | ||
| mkdirSync(join(MAIN_REPO, ".superset"), { recursive: true }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| // Clean up | ||
| if (existsSync(TEST_DIR)) { | ||
| rmSync(TEST_DIR, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| test("returns null when setup.json does not exist", () => { | ||
| const config = loadSetupConfig(MAIN_REPO); | ||
| expect(config).toBeNull(); | ||
| }); | ||
|
|
||
| test("loads valid setup config", () => { | ||
| const setupConfig = { | ||
| copy: ["*.env", "package.json"], | ||
| commands: ["npm install", "npm run build"], | ||
| }; | ||
|
|
||
| writeFileSync( | ||
| join(MAIN_REPO, ".superset", "setup.json"), | ||
| JSON.stringify(setupConfig), | ||
| ); | ||
|
|
||
| const config = loadSetupConfig(MAIN_REPO); | ||
| expect(config).toEqual(setupConfig); | ||
| }); | ||
|
|
||
| test("returns null for invalid JSON", () => { | ||
| writeFileSync(join(MAIN_REPO, ".superset", "setup.json"), "{ invalid json"); | ||
|
|
||
| const config = loadSetupConfig(MAIN_REPO); | ||
| expect(config).toBeNull(); | ||
| }); | ||
|
|
||
| test("validates copy field must be an array", () => { | ||
| writeFileSync( | ||
| join(MAIN_REPO, ".superset", "setup.json"), | ||
| JSON.stringify({ copy: "not-an-array" }), | ||
| ); | ||
|
|
||
| const config = loadSetupConfig(MAIN_REPO); | ||
| expect(config).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("copySetupFiles", () => { | ||
| beforeEach(() => { | ||
| // Create test directories | ||
| mkdirSync(MAIN_REPO, { recursive: true }); | ||
| mkdirSync(WORKTREE, { recursive: true }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| // Clean up | ||
| if (existsSync(TEST_DIR)) { | ||
| rmSync(TEST_DIR, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| test("returns empty result for empty patterns", async () => { | ||
| const result = await copySetupFiles(MAIN_REPO, WORKTREE, []); | ||
| expect(result.copied).toEqual([]); | ||
| expect(result.errors).toEqual([]); | ||
| }); | ||
|
|
||
| test("copies matching files", async () => { | ||
| // Create test files | ||
| writeFileSync(join(MAIN_REPO, "test.txt"), "test content"); | ||
| writeFileSync(join(MAIN_REPO, "README.md"), "readme"); | ||
|
|
||
| const result = await copySetupFiles(MAIN_REPO, WORKTREE, ["*.txt"]); | ||
|
|
||
| expect(result.copied).toContain("test.txt"); | ||
| expect(result.errors).toEqual([]); | ||
| expect(existsSync(join(WORKTREE, "test.txt"))).toBe(true); | ||
| }); | ||
|
|
||
| test("creates nested directories", async () => { | ||
| // Create nested file | ||
| mkdirSync(join(MAIN_REPO, "src"), { recursive: true }); | ||
| writeFileSync(join(MAIN_REPO, "src", "index.ts"), "export {}"); | ||
|
|
||
| const result = await copySetupFiles(MAIN_REPO, WORKTREE, ["src/**/*.ts"]); | ||
|
|
||
| expect(result.copied).toContain("src/index.ts"); | ||
| expect(existsSync(join(WORKTREE, "src", "index.ts"))).toBe(true); | ||
| }); | ||
|
|
||
| test("reports errors for files that don't match", async () => { | ||
| const result = await copySetupFiles(MAIN_REPO, WORKTREE, [ | ||
| "nonexistent.txt", | ||
| ]); | ||
|
|
||
| expect(result.copied).toEqual([]); | ||
| expect(result.errors.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| test("copies multiple files matching glob pattern", async () => { | ||
| writeFileSync(join(MAIN_REPO, "file1.txt"), "content1"); | ||
| writeFileSync(join(MAIN_REPO, "file2.txt"), "content2"); | ||
| writeFileSync(join(MAIN_REPO, "file.md"), "markdown"); | ||
|
|
||
| const result = await copySetupFiles(MAIN_REPO, WORKTREE, ["*.txt"]); | ||
|
|
||
| expect(result.copied).toContain("file1.txt"); | ||
| expect(result.copied).toContain("file2.txt"); | ||
| expect(result.copied).not.toContain("file.md"); | ||
| expect(result.errors).toEqual([]); | ||
| }); | ||
| }); |
80 changes: 80 additions & 0 deletions
80
apps/desktop/src/lib/trpc/routers/workspaces/utils/setup.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { existsSync, readFileSync } from "node:fs"; | ||
| import { copyFile, mkdir } from "node:fs/promises"; | ||
| import { dirname, join } from "node:path"; | ||
| import fg from "fast-glob"; | ||
| import type { SetupConfig } from "shared/types"; | ||
|
|
||
| export function loadSetupConfig(mainRepoPath: string): SetupConfig | null { | ||
| const configPath = join(mainRepoPath, ".superset", "setup.json"); | ||
|
|
||
| if (!existsSync(configPath)) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| const content = readFileSync(configPath, "utf-8"); | ||
| const parsed = JSON.parse(content) as SetupConfig; | ||
|
|
||
| if (parsed.copy && !Array.isArray(parsed.copy)) { | ||
| throw new Error("'copy' field must be an array of strings"); | ||
| } | ||
|
|
||
| if (parsed.commands && !Array.isArray(parsed.commands)) { | ||
| throw new Error("'commands' field must be an array of strings"); | ||
| } | ||
|
|
||
| return parsed; | ||
| } catch (error) { | ||
| console.error( | ||
| `Failed to read setup config at ${configPath}: ${error instanceof Error ? error.message : String(error)}`, | ||
| ); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export async function copySetupFiles( | ||
| mainRepoPath: string, | ||
| worktreePath: string, | ||
| patterns: string[], | ||
| ): Promise<{ copied: string[]; errors: string[] }> { | ||
| const copied: string[] = []; | ||
| const errors: string[] = []; | ||
|
|
||
| for (const pattern of patterns) { | ||
| try { | ||
| const matches = await fg(pattern, { | ||
| cwd: mainRepoPath, | ||
| dot: true, | ||
| followSymbolicLinks: false, | ||
| onlyFiles: true, | ||
| ignore: [".superset/**"], | ||
| }); | ||
|
|
||
| if (matches.length === 0) { | ||
| errors.push(`No files matched pattern: ${pattern}`); | ||
| continue; | ||
| } | ||
|
|
||
| for (const relativePath of matches) { | ||
| const sourcePath = join(mainRepoPath, relativePath); | ||
| const destinationPath = join(worktreePath, relativePath); | ||
|
|
||
| try { | ||
| await mkdir(dirname(destinationPath), { recursive: true }); | ||
| await copyFile(sourcePath, destinationPath); | ||
| copied.push(relativePath); | ||
| } catch (copyError) { | ||
| errors.push( | ||
| `Failed to copy ${relativePath}: ${copyError instanceof Error ? copyError.message : String(copyError)}`, | ||
| ); | ||
| } | ||
| } | ||
| } catch (globError) { | ||
| errors.push( | ||
| `Failed to process pattern '${pattern}': ${globError instanceof Error ? globError.message : String(globError)}`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return { copied, errors }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert placeholder command — dependency installation is missing.
Line 6 replaces the meaningful
"bun i"(dependency installation) command with"echo 'Hello world'"(a trivial placeholder). This breaks the workspace setup flow and prevents dependencies from being installed in new workspaces.Revert to the original install command:
If this change was intentional and the setup flow no longer requires dependency installation, please clarify the updated setup strategy and ensure all downstream setup utilities (file copying, terminal execution) account for this change.
📝 Committable suggestion
🤖 Prompt for AI Agents