fix worktree archive terminal cleanup and worktree setup

This commit is contained in:
Mohamed Boudra
2026-02-16 11:55:16 +07:00
parent 04a06197de
commit 90a81462cb
5 changed files with 178 additions and 22 deletions
@@ -93,6 +93,20 @@ describe("createWorktree", () => {
rmSync(varTempDir, { recursive: true, force: true });
});
it("reports repoRoot as the repository root for paseo-owned worktrees", async () => {
const result = await createWorktree({
branchName: "main",
cwd: repoDir,
baseBranch: "main",
worktreeSlug: "repo-root-check",
paseoHome,
});
const ownership = await isPaseoOwnedWorktreeCwd(result.worktreePath, { paseoHome });
expect(ownership.allowed).toBe(true);
expect(ownership.repoRoot).toBe(repoDir);
});
it("creates a worktree with a new branch", async () => {
const result = await createWorktree({
branchName: "feature-branch",
+10 -2
View File
@@ -667,11 +667,19 @@ function normalizePathForOwnership(input: string): string {
}
}
function resolveRepoRootFromGitCommonDir(commonDir: string): string {
const normalizedCommonDir = normalizePathForOwnership(commonDir);
return basename(normalizedCommonDir) === ".git"
? dirname(normalizedCommonDir)
: normalizedCommonDir;
}
export async function isPaseoOwnedWorktreeCwd(
cwd: string,
options?: { paseoHome?: string }
): Promise<PaseoWorktreeOwnership> {
const gitCommonDir = await getGitCommonDir(cwd);
const repoRoot = resolveRepoRootFromGitCommonDir(gitCommonDir);
const worktreesRoot = await getPaseoWorktreesRoot(cwd, options?.paseoHome);
const resolvedRoot = normalizePathForOwnership(worktreesRoot) + sep;
const resolvedCwd = normalizePathForOwnership(cwd);
@@ -679,7 +687,7 @@ export async function isPaseoOwnedWorktreeCwd(
if (!resolvedCwd.startsWith(resolvedRoot)) {
return {
allowed: false,
repoRoot: gitCommonDir,
repoRoot,
worktreeRoot: worktreesRoot,
worktreePath: resolvedCwd,
};
@@ -692,7 +700,7 @@ export async function isPaseoOwnedWorktreeCwd(
});
return {
allowed,
repoRoot: gitCommonDir,
repoRoot,
worktreeRoot: worktreesRoot,
worktreePath: resolvedCwd,
};