-
Notifications
You must be signed in to change notification settings - Fork 431
Expand file tree
/
Copy pathworkspaceConfiguration.test.ts
More file actions
654 lines (556 loc) · 28.3 KB
/
Copy pathworkspaceConfiguration.test.ts
File metadata and controls
654 lines (556 loc) · 28.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { assert } from 'chai';
import * as path from 'path';
import { getWorkspaceConfiguration } from '../spec-node/utils';
import { CLIHost } from '../spec-common/cliHost';
import { Workspace } from '../spec-utils/workspaces';
import { nullLog } from '../spec-utils/log';
function createMockCLIHost(options: {
platform: NodeJS.Platform;
files?: Record<string, string>;
useFileHost?: boolean; // Use FileHost path in findGitRootFolder (for testing parent folder git root)
}): CLIHost {
const { platform, files = {}, useFileHost = false } = options;
const pathModule = platform === 'win32' ? path.win32 : path.posix;
const baseHost = {
type: 'local' as const,
platform,
arch: 'x64' as const,
path: pathModule,
cwd: platform === 'win32' ? 'C:\\' : '/',
env: {},
ptyExec: () => { throw new Error('Not implemented'); },
homedir: async () => platform === 'win32' ? 'C:\\Users\\test' : '/home/test',
tmpdir: async () => platform === 'win32' ? 'C:\\tmp' : '/tmp',
isFile: async (filepath: string) => filepath in files,
isFolder: async () => false,
readFile: async (filepath: string) => {
if (filepath in files) {
return Buffer.from(files[filepath]);
}
throw new Error(`File not found: ${filepath}`);
},
writeFile: async () => { },
rename: async () => { },
mkdirp: async () => { },
readDir: async () => [],
getUsername: async () => 'test',
toCommonURI: async () => undefined,
connect: () => { throw new Error('Not implemented'); },
};
// If useFileHost is true, don't include exec so findGitRootFolder uses the FileHost code path
if (useFileHost) {
return baseHost as unknown as CLIHost;
}
return {
...baseHost,
exec: () => { throw new Error('Not implemented'); },
} as CLIHost;
}
function createWorkspace(rootFolderPath: string, configFolderPath?: string): Workspace {
return {
isWorkspaceFile: false,
workspaceOrFolderPath: rootFolderPath,
rootFolderPath,
configFolderPath: configFolderPath || rootFolderPath,
};
}
type TestPlatform = 'linux' | 'darwin' | 'win32';
const platforms: TestPlatform[] = ['linux', 'darwin', 'win32'];
describe('getWorkspaceConfiguration', function () {
for (const platform of platforms) {
describe(`platform: ${platform}`, function () {
describe('basic workspace mounting', function () {
it('should mount workspace at /workspaces/<basename>', async () => {
const p = {
linux: { projectPath: '/home/user/project', consistency: '' },
darwin: { projectPath: '/Users/user/project', consistency: ',consistency=consistent' },
win32: { projectPath: 'C:\\Users\\user\\project', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({ platform });
const workspace = createWorkspace(p.projectPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
false,
false,
nullLog
);
assert.strictEqual(result.workspaceFolder, '/workspaces/project');
assert.strictEqual(result.workspaceMount, `type=bind,source=${p.projectPath},target=/workspaces/project${p.consistency}`);
assert.isUndefined(result.additionalMountString);
});
});
describe('git worktree handling', function () {
it('should not add additional mount when .git is not a file', async () => {
const p = {
linux: { projectPath: '/home/user/project' },
darwin: { projectPath: '/Users/user/project' },
win32: { projectPath: 'C:\\Users\\user\\project' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {}
});
const workspace = createWorkspace(p.projectPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
true,
nullLog
);
assert.isUndefined(result.additionalMountString);
});
it('should not add additional mount when gitdir is an absolute path', async () => {
const p = {
linux: { projectPath: '/home/user/project', gitFile: '/home/user/project/.git', absoluteGitdir: 'gitdir: /absolute/path/to/.git/worktrees/project' },
darwin: { projectPath: '/Users/user/project', gitFile: '/Users/user/project/.git', absoluteGitdir: 'gitdir: /absolute/path/to/.git/worktrees/project' },
win32: { projectPath: 'C:\\Users\\user\\project', gitFile: 'C:\\Users\\user\\project\\.git', absoluteGitdir: 'gitdir: C:/absolute/path/to/.git/worktrees/project' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitFile]: p.absoluteGitdir
}
});
const workspace = createWorkspace(p.projectPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
true,
nullLog
);
assert.isUndefined(result.additionalMountString);
});
it('should not add additional mount when mountGitWorktreeCommonDir is false', async () => {
const p = {
linux: { worktreePath: '/home/user/worktrees/feature', gitFile: '/home/user/worktrees/feature/.git', gitdir: 'gitdir: ../../repo/.git/worktrees/feature', consistency: '' },
darwin: { worktreePath: '/Users/user/worktrees/feature', gitFile: '/Users/user/worktrees/feature/.git', gitdir: 'gitdir: ../../repo/.git/worktrees/feature', consistency: ',consistency=consistent' },
win32: { worktreePath: 'C:\\Users\\user\\worktrees\\feature', gitFile: 'C:\\Users\\user\\worktrees\\feature\\.git', gitdir: 'gitdir: ../../repo/.git/worktrees/feature', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitFile]: p.gitdir
}
});
const workspace = createWorkspace(p.worktreePath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
false,
nullLog
);
assert.strictEqual(result.workspaceFolder, '/workspaces/feature');
assert.strictEqual(result.workspaceMount, `type=bind,source=${p.worktreePath},target=/workspaces/feature${p.consistency}`);
assert.isUndefined(result.additionalMountString);
});
it('should not add additional mount when mountGitWorktreeCommonDir is false with workspace in subfolder', async () => {
const p = {
linux: { worktreePath: '/home/user/worktrees/feature', gitConfigFile: '/home/user/worktrees/feature/.git/config', gitFile: '/home/user/worktrees/feature/.git', gitdir: 'gitdir: ../../repo/.git/worktrees/feature', subfolderPath: '/home/user/worktrees/feature/packages/app', consistency: '' },
darwin: { worktreePath: '/Users/user/worktrees/feature', gitConfigFile: '/Users/user/worktrees/feature/.git/config', gitFile: '/Users/user/worktrees/feature/.git', gitdir: 'gitdir: ../../repo/.git/worktrees/feature', subfolderPath: '/Users/user/worktrees/feature/packages/app', consistency: ',consistency=consistent' },
win32: { worktreePath: 'C:\\Users\\user\\worktrees\\feature', gitConfigFile: 'C:\\Users\\user\\worktrees\\feature\\.git\\config', gitFile: 'C:\\Users\\user\\worktrees\\feature\\.git', gitdir: 'gitdir: ../../repo/.git/worktrees/feature', subfolderPath: 'C:\\Users\\user\\worktrees\\feature\\packages\\app', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitConfigFile]: '[core]',
[p.gitFile]: p.gitdir
},
useFileHost: true
});
const workspace = createWorkspace(p.subfolderPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
false,
nullLog
);
assert.strictEqual(result.workspaceFolder, '/workspaces/feature/packages/app');
assert.strictEqual(result.workspaceMount, `type=bind,source=${p.worktreePath},target=/workspaces/feature${p.consistency}`);
assert.isUndefined(result.additionalMountString);
});
it('should add additional mount when gitdir is a relative path', async () => {
const p = {
linux: { worktreePath: '/home/user/worktrees/feature', gitFile: '/home/user/worktrees/feature/.git', gitdir: 'gitdir: ../../repo/.git/worktrees/feature', repoGitPath: '/home/user/repo/.git', consistency: '' },
darwin: { worktreePath: '/Users/user/worktrees/feature', gitFile: '/Users/user/worktrees/feature/.git', gitdir: 'gitdir: ../../repo/.git/worktrees/feature', repoGitPath: '/Users/user/repo/.git', consistency: ',consistency=consistent' },
win32: { worktreePath: 'C:\\Users\\user\\worktrees\\feature', gitFile: 'C:\\Users\\user\\worktrees\\feature\\.git', gitdir: 'gitdir: ../../repo/.git/worktrees/feature', repoGitPath: 'C:\\Users\\user\\repo\\.git', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitFile]: p.gitdir
}
});
const workspace = createWorkspace(p.worktreePath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
true,
nullLog
);
assert.strictEqual(result.workspaceFolder, '/workspaces/worktrees/feature');
assert.strictEqual(result.workspaceMount, `type=bind,source=${p.worktreePath},target=/workspaces/worktrees/feature${p.consistency}`);
assert.strictEqual(result.additionalMountString, `type=bind,source=${p.repoGitPath},target=/workspaces/repo/.git${p.consistency}`);
});
it('should handle gitdir with single level up', async () => {
const p = {
linux: { worktreePath: '/home/user/repo-worktree', gitFile: '/home/user/repo-worktree/.git', gitdir: 'gitdir: ../repo/.git/worktrees/worktree', repoGitPath: '/home/user/repo/.git', consistency: '' },
darwin: { worktreePath: '/Users/user/repo-worktree', gitFile: '/Users/user/repo-worktree/.git', gitdir: 'gitdir: ../repo/.git/worktrees/worktree', repoGitPath: '/Users/user/repo/.git', consistency: ',consistency=consistent' },
win32: { worktreePath: 'C:\\Users\\user\\repo-worktree', gitFile: 'C:\\Users\\user\\repo-worktree\\.git', gitdir: 'gitdir: ../repo/.git/worktrees/worktree', repoGitPath: 'C:\\Users\\user\\repo\\.git', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitFile]: p.gitdir
}
});
const workspace = createWorkspace(p.worktreePath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
true,
nullLog
);
assert.strictEqual(result.workspaceFolder, '/workspaces/repo-worktree');
assert.strictEqual(result.additionalMountString, `type=bind,source=${p.repoGitPath},target=/workspaces/repo/.git${p.consistency}`);
});
it('should handle worktree two levels deep from common parent with main repo', async () => {
const p = {
linux: { worktreePath: '/home/user/projects/worktrees/feature', gitFile: '/home/user/projects/worktrees/feature/.git', gitdir: 'gitdir: ../../repos/main/.git/worktrees/feature', repoGitPath: '/home/user/projects/repos/main/.git', consistency: '' },
darwin: { worktreePath: '/Users/user/projects/worktrees/feature', gitFile: '/Users/user/projects/worktrees/feature/.git', gitdir: 'gitdir: ../../repos/main/.git/worktrees/feature', repoGitPath: '/Users/user/projects/repos/main/.git', consistency: ',consistency=consistent' },
win32: { worktreePath: 'C:\\Users\\user\\projects\\worktrees\\feature', gitFile: 'C:\\Users\\user\\projects\\worktrees\\feature\\.git', gitdir: 'gitdir: ../../repos/main/.git/worktrees/feature', repoGitPath: 'C:\\Users\\user\\projects\\repos\\main\\.git', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitFile]: p.gitdir
}
});
const workspace = createWorkspace(p.worktreePath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
true,
nullLog
);
assert.strictEqual(result.workspaceFolder, '/workspaces/worktrees/feature');
assert.strictEqual(result.workspaceMount, `type=bind,source=${p.worktreePath},target=/workspaces/worktrees/feature${p.consistency}`);
assert.strictEqual(result.additionalMountString, `type=bind,source=${p.repoGitPath},target=/workspaces/repos/main/.git${p.consistency}`);
});
it('should handle worktree two levels deep with workspace in subfolder', async () => {
const p = {
linux: { worktreePath: '/home/user/projects/worktrees/feature', gitConfigFile: '/home/user/projects/worktrees/feature/.git/config', gitFile: '/home/user/projects/worktrees/feature/.git', gitdir: 'gitdir: ../../repos/main/.git/worktrees/feature', subfolderPath: '/home/user/projects/worktrees/feature/packages/app', repoGitPath: '/home/user/projects/repos/main/.git', consistency: '' },
darwin: { worktreePath: '/Users/user/projects/worktrees/feature', gitConfigFile: '/Users/user/projects/worktrees/feature/.git/config', gitFile: '/Users/user/projects/worktrees/feature/.git', gitdir: 'gitdir: ../../repos/main/.git/worktrees/feature', subfolderPath: '/Users/user/projects/worktrees/feature/packages/app', repoGitPath: '/Users/user/projects/repos/main/.git', consistency: ',consistency=consistent' },
win32: { worktreePath: 'C:\\Users\\user\\projects\\worktrees\\feature', gitConfigFile: 'C:\\Users\\user\\projects\\worktrees\\feature\\.git\\config', gitFile: 'C:\\Users\\user\\projects\\worktrees\\feature\\.git', gitdir: 'gitdir: ../../repos/main/.git/worktrees/feature', subfolderPath: 'C:\\Users\\user\\projects\\worktrees\\feature\\packages\\app', repoGitPath: 'C:\\Users\\user\\projects\\repos\\main\\.git', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitConfigFile]: '[core]',
[p.gitFile]: p.gitdir
},
useFileHost: true
});
const workspace = createWorkspace(p.subfolderPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
true,
nullLog
);
assert.strictEqual(result.workspaceFolder, '/workspaces/worktrees/feature/packages/app');
assert.strictEqual(result.workspaceMount, `type=bind,source=${p.worktreePath},target=/workspaces/worktrees/feature${p.consistency}`);
assert.strictEqual(result.additionalMountString, `type=bind,source=${p.repoGitPath},target=/workspaces/repos/main/.git${p.consistency}`);
});
});
describe('git worktree with custom workspaceMount', function () {
it('should add common dir mount when a custom workspaceMount and workspaceFolder are set', async () => {
const p = {
linux: { worktreePath: '/home/user/worktrees/feature', gitFile: '/home/user/worktrees/feature/.git', gitdir: 'gitdir: ../main/.git/worktrees/feature', mainGitPath: '/home/user/worktrees/main/.git', consistency: '' },
darwin: { worktreePath: '/Users/user/worktrees/feature', gitFile: '/Users/user/worktrees/feature/.git', gitdir: 'gitdir: ../main/.git/worktrees/feature', mainGitPath: '/Users/user/worktrees/main/.git', consistency: ',consistency=consistent' },
win32: { worktreePath: 'C:\\Users\\user\\worktrees\\feature', gitFile: 'C:\\Users\\user\\worktrees\\feature\\.git', gitdir: 'gitdir: ../main/.git/worktrees/feature', mainGitPath: 'C:\\Users\\user\\worktrees\\main\\.git', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitFile]: p.gitdir
}
});
const workspace = createWorkspace(p.worktreePath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{ workspaceMount: 'type=bind,source=/host/wt,target=/workspace', workspaceFolder: '/workspace' },
true,
true,
nullLog
);
// The custom workspaceMount/workspaceFolder are respected unchanged, and the common dir is
// still mounted, with its target resolved relative to the custom mount target (/workspace).
assert.strictEqual(result.workspaceMount, 'type=bind,source=/host/wt,target=/workspace');
assert.strictEqual(result.workspaceFolder, '/workspace');
assert.strictEqual(result.additionalMountString, `type=bind,source=${p.mainGitPath},target=/main/.git${p.consistency}`);
});
it('should substitute variables in the custom workspaceMount target', async () => {
const p = {
linux: { worktreePath: '/home/user/worktrees/feature', gitFile: '/home/user/worktrees/feature/.git', gitdir: 'gitdir: ../main/.git/worktrees/feature', mainGitPath: '/home/user/worktrees/main/.git', consistency: '' },
darwin: { worktreePath: '/Users/user/worktrees/feature', gitFile: '/Users/user/worktrees/feature/.git', gitdir: 'gitdir: ../main/.git/worktrees/feature', mainGitPath: '/Users/user/worktrees/main/.git', consistency: ',consistency=consistent' },
win32: { worktreePath: 'C:\\Users\\user\\worktrees\\feature', gitFile: 'C:\\Users\\user\\worktrees\\feature\\.git', gitdir: 'gitdir: ../main/.git/worktrees/feature', mainGitPath: 'C:\\Users\\user\\worktrees\\main\\.git', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitFile]: p.gitdir
}
});
const workspace = createWorkspace(p.worktreePath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{ workspaceMount: 'type=bind,source=${localWorkspaceFolder},target=/workspaces/${localWorkspaceFolderBasename}', workspaceFolder: '/workspaces/feature' },
true,
true,
nullLog
);
// ${localWorkspaceFolderBasename} in the target is substituted before resolving the common dir.
assert.strictEqual(result.additionalMountString, `type=bind,source=${p.mainGitPath},target=/workspaces/main/.git${p.consistency}`);
});
it('should not add common dir mount when mountGitWorktreeCommonDir is false', async () => {
const p = {
linux: { worktreePath: '/home/user/worktrees/feature', gitFile: '/home/user/worktrees/feature/.git', gitdir: 'gitdir: ../main/.git/worktrees/feature' },
darwin: { worktreePath: '/Users/user/worktrees/feature', gitFile: '/Users/user/worktrees/feature/.git', gitdir: 'gitdir: ../main/.git/worktrees/feature' },
win32: { worktreePath: 'C:\\Users\\user\\worktrees\\feature', gitFile: 'C:\\Users\\user\\worktrees\\feature\\.git', gitdir: 'gitdir: ../main/.git/worktrees/feature' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitFile]: p.gitdir
}
});
const workspace = createWorkspace(p.worktreePath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{ workspaceMount: 'type=bind,source=/host/wt,target=/workspace', workspaceFolder: '/workspace' },
true,
false,
nullLog
);
assert.strictEqual(result.workspaceMount, 'type=bind,source=/host/wt,target=/workspace');
assert.strictEqual(result.workspaceFolder, '/workspace');
assert.isUndefined(result.additionalMountString);
});
it('should not add common dir mount when .git is not a worktree file', async () => {
const p = {
linux: { projectPath: '/home/user/project' },
darwin: { projectPath: '/Users/user/project' },
win32: { projectPath: 'C:\\Users\\user\\project' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {}
});
const workspace = createWorkspace(p.projectPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{ workspaceMount: 'type=bind,source=/host/wt,target=/workspace', workspaceFolder: '/workspace' },
true,
true,
nullLog
);
assert.strictEqual(result.workspaceMount, 'type=bind,source=/host/wt,target=/workspace');
assert.strictEqual(result.workspaceFolder, '/workspace');
assert.isUndefined(result.additionalMountString);
});
it('should add common dir mount for a worktree nested inside the main repo', async () => {
const p = {
linux: { worktreePath: '/home/user/main/wt', gitFile: '/home/user/main/wt/.git', gitdir: 'gitdir: ../.git/worktrees/wt', mainGitPath: '/home/user/main/.git', consistency: '' },
darwin: { worktreePath: '/Users/user/main/wt', gitFile: '/Users/user/main/wt/.git', gitdir: 'gitdir: ../.git/worktrees/wt', mainGitPath: '/Users/user/main/.git', consistency: ',consistency=consistent' },
win32: { worktreePath: 'C:\\Users\\user\\main\\wt', gitFile: 'C:\\Users\\user\\main\\wt\\.git', gitdir: 'gitdir: ../.git/worktrees/wt', mainGitPath: 'C:\\Users\\user\\main\\.git', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitFile]: p.gitdir
}
});
const workspace = createWorkspace(p.worktreePath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{ workspaceMount: 'type=bind,source=/host/wt,target=/workspace', workspaceFolder: '/workspace' },
true,
true,
nullLog
);
// Worktree nested under the main repo: gitdir points up one level; the common dir resolves to
// a root-level target inside the container, consistent with how git resolves it there.
assert.strictEqual(result.additionalMountString, `type=bind,source=${p.mainGitPath},target=/.git${p.consistency}`);
});
});
describe('git root in parent folder', function () {
it('should mount from git root when .git/config is in parent folder', async () => {
const p = {
linux: { repoPath: '/home/user/repo', gitConfigFile: '/home/user/repo/.git/config', subfolderPath: '/home/user/repo/packages/frontend', consistency: '' },
darwin: { repoPath: '/Users/user/repo', gitConfigFile: '/Users/user/repo/.git/config', subfolderPath: '/Users/user/repo/packages/frontend', consistency: ',consistency=consistent' },
win32: { repoPath: 'C:\\Users\\user\\repo', gitConfigFile: 'C:\\Users\\user\\repo\\.git\\config', subfolderPath: 'C:\\Users\\user\\repo\\packages\\frontend', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitConfigFile]: '[core]'
},
useFileHost: true
});
const workspace = createWorkspace(p.subfolderPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
true,
nullLog
);
assert.strictEqual(result.workspaceMount, `type=bind,source=${p.repoPath},target=/workspaces/repo${p.consistency}`);
assert.strictEqual(result.workspaceFolder, '/workspaces/repo/packages/frontend');
assert.isUndefined(result.additionalMountString);
});
it('should mount workspace folder when mountWorkspaceGitRoot is false even with .git in parent', async () => {
const p = {
linux: { gitConfigFile: '/home/user/repo/.git/config', subfolderPath: '/home/user/repo/packages/frontend', consistency: '' },
darwin: { gitConfigFile: '/Users/user/repo/.git/config', subfolderPath: '/Users/user/repo/packages/frontend', consistency: ',consistency=consistent' },
win32: { gitConfigFile: 'C:\\Users\\user\\repo\\.git\\config', subfolderPath: 'C:\\Users\\user\\repo\\packages\\frontend', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitConfigFile]: '[core]'
},
useFileHost: true
});
const workspace = createWorkspace(p.subfolderPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
false,
false,
nullLog
);
assert.strictEqual(result.workspaceMount, `type=bind,source=${p.subfolderPath},target=/workspaces/frontend${p.consistency}`);
assert.strictEqual(result.workspaceFolder, '/workspaces/frontend');
});
it('should handle deeply nested workspace in git repo', async () => {
const p = {
linux: { monorepoPath: '/home/user/monorepo', gitConfigFile: '/home/user/monorepo/.git/config', subfolderPath: '/home/user/monorepo/packages/apps/web', consistency: '' },
darwin: { monorepoPath: '/Users/user/monorepo', gitConfigFile: '/Users/user/monorepo/.git/config', subfolderPath: '/Users/user/monorepo/packages/apps/web', consistency: ',consistency=consistent' },
win32: { monorepoPath: 'C:\\Users\\user\\monorepo', gitConfigFile: 'C:\\Users\\user\\monorepo\\.git\\config', subfolderPath: 'C:\\Users\\user\\monorepo\\packages\\apps\\web', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitConfigFile]: '[core]'
},
useFileHost: true
});
const workspace = createWorkspace(p.subfolderPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
true,
nullLog
);
assert.strictEqual(result.workspaceMount, `type=bind,source=${p.monorepoPath},target=/workspaces/monorepo${p.consistency}`);
assert.strictEqual(result.workspaceFolder, '/workspaces/monorepo/packages/apps/web');
});
it('should handle worktree with git root in parent folder', async () => {
const p = {
linux: { repoPath: '/home/user/repo', gitConfigFile: '/home/user/repo/.git/config', gitFile: '/home/user/repo/.git', gitdir: 'gitdir: ../main-repo/.git/worktrees/repo', mainRepoGitPath: '/home/user/main-repo/.git', subfolderPath: '/home/user/repo/packages/lib', consistency: '' },
darwin: { repoPath: '/Users/user/repo', gitConfigFile: '/Users/user/repo/.git/config', gitFile: '/Users/user/repo/.git', gitdir: 'gitdir: ../main-repo/.git/worktrees/repo', mainRepoGitPath: '/Users/user/main-repo/.git', subfolderPath: '/Users/user/repo/packages/lib', consistency: ',consistency=consistent' },
win32: { repoPath: 'C:\\Users\\user\\repo', gitConfigFile: 'C:\\Users\\user\\repo\\.git\\config', gitFile: 'C:\\Users\\user\\repo\\.git', gitdir: 'gitdir: ../main-repo/.git/worktrees/repo', mainRepoGitPath: 'C:\\Users\\user\\main-repo\\.git', subfolderPath: 'C:\\Users\\user\\repo\\packages\\lib', consistency: ',consistency=consistent' },
}[platform];
const cliHost = createMockCLIHost({
platform,
files: {
[p.gitConfigFile]: '[core]',
[p.gitFile]: p.gitdir
},
useFileHost: true
});
const workspace = createWorkspace(p.subfolderPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{},
true,
true,
nullLog
);
assert.strictEqual(result.workspaceFolder, '/workspaces/repo/packages/lib');
assert.strictEqual(result.additionalMountString, `type=bind,source=${p.mainRepoGitPath},target=/workspaces/main-repo/.git${p.consistency}`);
});
});
describe('config overrides', function () {
it('should use workspaceFolder from config when provided', async () => {
const p = {
linux: { projectPath: '/home/user/project' },
darwin: { projectPath: '/Users/user/project' },
win32: { projectPath: 'C:\\Users\\user\\project' },
}[platform];
const cliHost = createMockCLIHost({ platform });
const workspace = createWorkspace(p.projectPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{ workspaceFolder: '/custom/path' },
false,
false,
nullLog
);
assert.strictEqual(result.workspaceFolder, '/custom/path');
});
it('should use workspaceMount from config when provided', async () => {
const p = {
linux: { projectPath: '/home/user/project' },
darwin: { projectPath: '/Users/user/project' },
win32: { projectPath: 'C:\\Users\\user\\project' },
}[platform];
const cliHost = createMockCLIHost({ platform });
const workspace = createWorkspace(p.projectPath);
const result = await getWorkspaceConfiguration(
cliHost,
workspace,
{ workspaceMount: 'type=bind,source=/custom,target=/workspace' },
false,
false,
nullLog
);
assert.strictEqual(result.workspaceMount, 'type=bind,source=/custom,target=/workspace');
});
});
});
}
});