Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions apps/desktop/src/lib/trpc/routers/workspaces/utils/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
import { existsSync, readFileSync } from "node:fs";
import { cpSync, existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { CONFIG_FILE_NAME, PROJECT_SUPERSET_DIR_NAME } from "shared/constants";
import type { SetupConfig } from "shared/types";

/**
* Copies the .superset directory from main repo to worktree if it exists in main but not in worktree.
* This handles the case where .superset is gitignored - worktrees won't have it since git only
* includes tracked files. By copying it, setup scripts like "./.superset/setup.sh" will work.
*/
export function copySupersetConfigToWorktree(
mainRepoPath: string,
worktreePath: string,
): void {
const mainSupersetDir = join(mainRepoPath, PROJECT_SUPERSET_DIR_NAME);
const worktreeSupersetDir = join(worktreePath, PROJECT_SUPERSET_DIR_NAME);

// Only copy if it exists in main repo but not in worktree
if (existsSync(mainSupersetDir) && !existsSync(worktreeSupersetDir)) {
try {
cpSync(mainSupersetDir, worktreeSupersetDir, { recursive: true });
} catch (error) {
console.error(
`Failed to copy ${PROJECT_SUPERSET_DIR_NAME} to worktree: ${error instanceof Error ? error.message : String(error)}`,
);
}
}
}

export function loadSetupConfig(mainRepoPath: string): SetupConfig | null {
const configPath = join(mainRepoPath, ".superset", "config.json");
const configPath = join(
mainRepoPath,
PROJECT_SUPERSET_DIR_NAME,
CONFIG_FILE_NAME,
);

if (!existsSync(configPath)) {
return null;
Expand Down
6 changes: 5 additions & 1 deletion apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
worktreeExists,
} from "./utils/git";
import { fetchGitHubPRStatus } from "./utils/github";
import { loadSetupConfig } from "./utils/setup";
import { copySupersetConfigToWorktree, loadSetupConfig } from "./utils/setup";
import { runTeardown } from "./utils/teardown";
import { getWorkspacePath } from "./utils/worktree";

Expand Down Expand Up @@ -124,6 +124,10 @@ export const createWorkspacesRouter = () => {
startPoint,
);

// Copy .superset directory to worktree if it's gitignored (not present in worktree)
// This ensures setup scripts like "./.superset/setup.sh" work even when gitignored
copySupersetConfigToWorktree(project.mainRepoPath, worktreePath);

// Insert worktree
const worktree = localDb
.insert(worktrees)
Expand Down
13 changes: 6 additions & 7 deletions apps/marketing/src/app/scripts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,16 @@ export default function ScriptsPage() {
to chain commands that depend on each other
</li>
<li>
Add{" "}
Commit{" "}
<code className="text-amber-500 dark:text-amber-400">
.superset/
</code>{" "}
to your{" "}
<code className="text-amber-500 dark:text-amber-400">
.gitignore
</code>{" "}
if you don&apos;t want to share configs
to share workspace setup with your team
</li>
<li>
For machine-specific values, use environment variables in your
scripts instead of hardcoding paths
</li>
Comment on lines +177 to 186
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Document the automatic .superset/ copying behavior.

The tips recommend committing .superset/ but don't mention the automatic copying behavior that this PR introduces. According to the PR objectives, the documentation should clarify that users can either commit .superset/ or keep it gitignored and Superset will automatically copy it to new worktrees.

Consider adding a tip that explains this fallback mechanism so users who prefer to gitignore .superset/ understand it will still work in worktrees.

📝 Suggested documentation addition
 			<li>
 				Commit{" "}
 				<code className="text-amber-500 dark:text-amber-400">
 					.superset/
 				</code>{" "}
 				to share workspace setup with your team
 			</li>
+			<li>
+				If{" "}
+				<code className="text-amber-500 dark:text-amber-400">
+					.superset/
+				</code>{" "}
+				is gitignored, Superset will automatically copy it from your main
+				repository to new worktrees
+			</li>
 			<li>
 				For machine-specific values, use environment variables in your
 				scripts instead of hardcoding paths
 			</li>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Commit{" "}
<code className="text-amber-500 dark:text-amber-400">
.superset/
</code>{" "}
to your{" "}
<code className="text-amber-500 dark:text-amber-400">
.gitignore
</code>{" "}
if you don&apos;t want to share configs
to share workspace setup with your team
</li>
<li>
For machine-specific values, use environment variables in your
scripts instead of hardcoding paths
</li>
Commit{" "}
<code className="text-amber-500 dark:text-amber-400">
.superset/
</code>{" "}
to share workspace setup with your team
</li>
<li>
If{" "}
<code className="text-amber-500 dark:text-amber-400">
.superset/
</code>{" "}
is gitignored, Superset will automatically copy it from your main
repository to new worktrees
</li>
<li>
For machine-specific values, use environment variables in your
scripts instead of hardcoding paths
</li>
🤖 Prompt for AI Agents
In apps/marketing/src/app/scripts/page.tsx around lines 177 to 186, add a new
list item documenting the automatic .superset/ copying behavior introduced by
this PR: state that users can either commit .superset/ to the repo or keep it
gitignored — Superset will automatically copy a .superset/ directory into new
worktrees as a fallback so workspaces still get the default config; insert this
as an additional <li> immediately after the existing items and keep the note
concise and mention machine-specific values should still use env vars.

<li>Or commit it to share workspace setup with your team</li>
</ul>
</section>
</motion.div>
Expand Down
Loading