Skip to content

Commit 9d6a16e

Browse files
committed
Different checkouts in different dirs
1 parent 3d3eef2 commit 9d6a16e

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

src/vt/lib/checkout.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ export type BaseCheckoutParams = {
2121
projectId: string;
2222
dryRun?: boolean;
2323
gitignoreRules?: string[];
24+
version?: number;
2425
};
2526

2627
export type BranchCheckoutParams = BaseCheckoutParams & {
2728
branchId: string;
28-
version: number;
2929
fromBranchId: string;
3030
};
3131

3232
export type ForkCheckoutParams = BaseCheckoutParams & {
3333
forkedFromId: string;
3434
name: string;
35-
version: number;
3635
};
3736

3837
/**
@@ -42,8 +41,8 @@ export type ForkCheckoutParams = BaseCheckoutParams & {
4241
* @param {string} args.targetDir - The directory where the branch will be checked out.
4342
* @param {string} args.projectId - The ID of the project.
4443
* @param {string} args.branchId - The ID of the branch to checkout.
45-
* @param {number} args.version - The version of the branch to checkout.
46-
* @param {string[]} args.gitignoreRules - List of gitignore rules.
44+
* @param {number} [args.version] - The version of the branch to checkout. Defaults to latest.
45+
* @param {string[]} [args.gitignoreRules] - List of gitignore rules. Defaults to [].
4746
* @param {string} [args.fromBranchId] - The ID of the branch we're switching from.
4847
* @returns {Promise<CheckoutResult>} A promise that resolves with checkout information.
4948
*/
@@ -57,13 +56,11 @@ export function checkout(args: BranchCheckoutParams): Promise<CheckoutResult>;
5756
* @param {string} args.projectId - The ID of the project to fork.
5857
* @param {string} args.forkedFrom - The branch ID from which to create the fork.
5958
* @param {string} args.name - The name for the new forked branch.
60-
* @param {number} args.version - The version of the fork to checkout.
61-
* @param {string[]} args.gitignoreRules - List of gitignore rules.
59+
* @param {number} [args.version] - The version of the fork to checkout. Defaults to latest.
60+
* @param {string[]} [args.gitignoreRules] - List of gitignore rules. Defaults to [].
6261
* @returns {Promise<CheckoutResult>} A promise that resolves with checkout information (including the new branch details).
6362
*/
64-
export function checkout(
65-
args: ForkCheckoutParams,
66-
): Promise<CheckoutResult>;
63+
export function checkout(args: ForkCheckoutParams): Promise<CheckoutResult>;
6764
export function checkout(
6865
args: BranchCheckoutParams | ForkCheckoutParams,
6966
): Promise<CheckoutResult> {
@@ -72,7 +69,7 @@ export function checkout(
7269
const fileStateChanges = FileState.empty();
7370

7471
let checkoutBranchId: string | null = null;
75-
let checkoutVersion: number | null = null;
72+
let checkoutVersion: number | undefined = undefined;
7673
let toBranch: ValTown.Projects.BranchCreateResponse | null = null;
7774
let fromBranch: ValTown.Projects.BranchCreateResponse;
7875
let createdNew = false;

src/vt/lib/tests/checkout_test.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,11 @@ Deno.test("file not in target branch should be deleted", async (t) => {
275275
});
276276
});
277277

278-
await doWithTempDir(async (tempDir) => {
278+
// First temp directory for feature branch checkout
279+
await doWithTempDir(async (featureTempDir) => {
279280
await t.step("checkout feature branch", async () => {
280281
await checkout({
281-
targetDir: tempDir,
282+
targetDir: featureTempDir,
282283
projectId: project.id,
283284
branchId: featureBranch.id,
284285
fromBranchId: featureBranch.id,
@@ -287,36 +288,43 @@ Deno.test("file not in target branch should be deleted", async (t) => {
287288
});
288289

289290
assert(
290-
await exists(join(tempDir, "feature.txt")),
291+
await exists(join(featureTempDir, "feature.txt")),
291292
"feature file should exist",
292293
);
293294
});
294295

295296
await t.step("create local file", async () => {
296-
await Deno.writeTextFile(join(tempDir, "local.txt"), "local content");
297+
await Deno.writeTextFile(
298+
join(featureTempDir, "local.txt"),
299+
"local content",
300+
);
297301
});
298302

299-
await t.step("checkout main branch", async () => {
300-
await checkout({
301-
targetDir: tempDir,
302-
projectId: project.id,
303-
branchId: mainBranch.id,
304-
fromBranchId: featureBranch.id,
305-
version: mainBranch.version + 1,
306-
gitignoreRules: [],
303+
// Second temp directory for main branch checkout
304+
await doWithTempDir(async (mainTempDir) => {
305+
await t.step("checkout main branch", async () => {
306+
await checkout({
307+
targetDir: mainTempDir,
308+
projectId: project.id,
309+
branchId: mainBranch.id,
310+
fromBranchId: featureBranch.id,
311+
});
307312
});
308-
});
309313

310-
await t.step("verify file states", async () => {
311-
assert(
312-
!await exists(join(tempDir, "feature.txt")),
313-
"feature file should be deleted",
314-
);
315-
assert(
316-
await exists(join(tempDir, "local.txt")),
317-
"local file should be preserved",
318-
);
319-
});
320-
}, "vt_checkout_deletion_test_");
314+
await t.step("verify file states", async () => {
315+
assert(
316+
!await exists(join(mainTempDir, "feature.txt")),
317+
"feature file should be deleted",
318+
);
319+
320+
// Local file should not exist in the main branch temp dir
321+
// since it's a different directory
322+
assert(
323+
!await exists(join(mainTempDir, "local.txt")),
324+
"local file should not exist in main branch directory",
325+
);
326+
});
327+
}, "vt_checkout_main_branch_test_");
328+
}, "vt_checkout_feature_branch_test_");
321329
});
322330
});

0 commit comments

Comments
 (0)