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
11 changes: 0 additions & 11 deletions src/core/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ import {
PLACEHOLDER_DIR,
readPlaceholder,
writePlaceholder,
type PlaceholderMeta,
} from "./placeholder";
import { quoteUserValue, sanitizeUserText } from "./userErrors";

export type HydrateOutcome = "hydrated" | "hydrated-checkout-failed" | "already-hydrated";

/** Optional callbacks so callers can report progress without the core logging itself. */
export interface HydrateHooks {
onPlaceholderFound?(meta: PlaceholderMeta): void;
onCloned?(remoteUrl: string): void;
onCheckedOut?(branch: string): void;
onCheckoutFailed?(branch: string): void;
onUpdated?(): void;
}

function hydrationLockPath(repoDir: string): string {
Expand Down Expand Up @@ -91,8 +86,6 @@ export async function hydratePlaceholder(
`${quoteUserValue(label, 500)} does not contain repository download information (.boot/repo.json). Run \`boot pull\` from the workspace root to recreate it.`,
);
}
hooks.onPlaceholderFound?.(meta);

if (!meta.remoteUrl) {
throw new Error(
`Repository ${quoteUserValue(meta.name)} has no URL, so it cannot be downloaded. Add its URL to \`boot.yaml\`, then run \`boot up .\` from the workspace root.`,
Expand Down Expand Up @@ -125,8 +118,6 @@ export async function hydratePlaceholder(
);
}

hooks.onCloned?.(meta.remoteUrl);

await excludePlaceholderFromGit(clonePath);
await writePlaceholder(clonePath, { ...meta, hydrateStatus: "hydrated" });

Expand All @@ -149,10 +140,8 @@ export async function hydratePlaceholder(
hooks.onCheckedOut?.(meta.branch);
} catch {
checkoutFailed = true;
hooks.onCheckoutFailed?.(meta.branch);
}
}
hooks.onUpdated?.();

return checkoutFailed ? "hydrated-checkout-failed" : "hydrated";
},
Expand Down
6 changes: 1 addition & 5 deletions src/tests/hydrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,15 @@ describe("hydrateCommand", () => {

it("returns a distinct outcome when clone succeeds but checkout fails", async () => {
const repoDir = await makePlaceholder("apps/mismatch", "git@example.com:mismatch.git");
const failedBranches: string[] = [];
cloneMock.mockImplementation(async (_url: string, target: string) => {
await fs.mkdir(path.join(target, ".git"), { recursive: true });
await fs.writeFile(path.join(target, "README.md"), "# mismatch\n");
});
checkoutMock.mockRejectedValue(new Error("branch not found"));

const outcome = await hydratePlaceholder(repoDir, {
onCheckoutFailed: (branch) => failedBranches.push(branch),
});
const outcome = await hydratePlaceholder(repoDir);

expect(outcome).toBe("hydrated-checkout-failed");
expect(failedBranches).toEqual(["main"]);
expect((await readPlaceholder(repoDir))?.hydrateStatus).toBe("hydrated");
});

Expand Down
Loading