@joberthel/worktree 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -8
- package/dist/cli-spec.js +49 -10
- package/dist/cli.js +70 -137
- package/dist/completion.js +3 -3
- package/dist/config/json-schema.js +4 -2
- package/dist/config/schema.js +15 -3
- package/dist/docker/compose.js +53 -4
- package/dist/docker/containers.js +67 -0
- package/dist/docker/orbstack.js +20 -9
- package/dist/docker/pause.js +36 -0
- package/dist/docker/service-order.js +242 -0
- package/dist/environment-state.js +25 -0
- package/dist/errors.js +4 -2
- package/dist/git/repository.js +40 -3
- package/dist/help.js +111 -0
- package/dist/list-filter.js +2 -4
- package/dist/operations/commands.js +28 -11
- package/dist/operations/confirmation.js +11 -0
- package/dist/operations/create.js +3 -2
- package/dist/operations/manage.js +22 -31
- package/dist/operations/progress.js +39 -0
- package/dist/operations/unlock.js +111 -0
- package/dist/shell-init.js +46 -0
- package/dist/state/lock-file.js +245 -0
- package/dist/state/process-start.js +29 -0
- package/dist/state/store.js +104 -37
- package/dist/ui/environment-table.js +11 -10
- package/dist/ui/json-output.js +10 -1
- package/dist/ui/show-operation.js +9 -3
- package/package.json +1 -1
- package/schema/wt.schema.json +36 -4
- package/dist/cli.test/harness.js +0 -64
- package/dist/operations/manage.test/fixture.js +0 -67
package/schema/wt.schema.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
8
|
"host": {
|
|
9
|
-
"description": "Runs this repository inside the Docker environment of a host repository. Cannot be combined with `worktrees`.",
|
|
9
|
+
"description": "Runs this repository inside the Docker environment of a host repository. Cannot be combined with `worktrees` or `volumes`.",
|
|
10
10
|
"type": "object",
|
|
11
11
|
"properties": {
|
|
12
12
|
"path": {
|
|
@@ -63,6 +63,28 @@
|
|
|
63
63
|
}
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
|
+
"volumes": {
|
|
67
|
+
"description": "How the named Docker volumes of the source project are cloned.",
|
|
68
|
+
"default": {
|
|
69
|
+
"pause_source": false
|
|
70
|
+
},
|
|
71
|
+
"anyOf": [
|
|
72
|
+
{
|
|
73
|
+
"type": "object",
|
|
74
|
+
"properties": {
|
|
75
|
+
"pause_source": {
|
|
76
|
+
"default": false,
|
|
77
|
+
"description": "Pauses the running containers that mount a source volume while `wt create` and `wt reset` copy the volumes, for a crash-consistent copy. These services do not respond until the copy has finished.",
|
|
78
|
+
"type": "boolean"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"additionalProperties": false
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"type": "null"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
66
88
|
"hooks": {
|
|
67
89
|
"description": "Commands run by `wt create` and `wt reset`.",
|
|
68
90
|
"anyOf": [
|
|
@@ -200,9 +222,19 @@
|
|
|
200
222
|
},
|
|
201
223
|
"additionalProperties": false,
|
|
202
224
|
"not": {
|
|
203
|
-
"
|
|
204
|
-
|
|
205
|
-
|
|
225
|
+
"anyOf": [
|
|
226
|
+
{
|
|
227
|
+
"required": [
|
|
228
|
+
"host",
|
|
229
|
+
"worktrees"
|
|
230
|
+
]
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"required": [
|
|
234
|
+
"host",
|
|
235
|
+
"volumes"
|
|
236
|
+
]
|
|
237
|
+
}
|
|
206
238
|
]
|
|
207
239
|
}
|
|
208
240
|
}
|
package/dist/cli.test/harness.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import process from 'node:process';
|
|
2
|
-
import { afterEach, beforeEach, vi } from 'vitest';
|
|
3
|
-
export function commandMocks() {
|
|
4
|
-
return {
|
|
5
|
-
composeOperation: vi.fn(),
|
|
6
|
-
createEnvironment: vi.fn(),
|
|
7
|
-
inspectEnvironment: vi.fn(),
|
|
8
|
-
listEnvironmentNames: vi.fn(),
|
|
9
|
-
listEnvironments: vi.fn(),
|
|
10
|
-
removeEnvironment: vi.fn(),
|
|
11
|
-
resetEnvironment: vi.fn(),
|
|
12
|
-
resolveEnvironmentName: vi.fn(),
|
|
13
|
-
runningEnvironmentNames: vi.fn(),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
/** The `process.stdout` error listeners that were there before wt added its own. */
|
|
17
|
-
export const originalListeners = new Set(process.stdout.listeners('error'));
|
|
18
|
-
/**
|
|
19
|
-
* Registers hooks that load a fresh CLI for each test, record stdout and
|
|
20
|
-
* stderr, and restore the process afterwards. The returned spies are replaced
|
|
21
|
-
* before each test.
|
|
22
|
-
*/
|
|
23
|
-
export function setupCli(mocks) {
|
|
24
|
-
const originalArgv = process.argv;
|
|
25
|
-
const io = {};
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
vi.resetModules();
|
|
28
|
-
vi.clearAllMocks();
|
|
29
|
-
io.stdout = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
|
|
30
|
-
io.stderr = vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
31
|
-
mocks.resolveEnvironmentName.mockImplementation(async (name) => name ?? 'detected');
|
|
32
|
-
mocks.composeOperation.mockResolvedValue(undefined);
|
|
33
|
-
process.exitCode = 0;
|
|
34
|
-
});
|
|
35
|
-
afterEach(() => {
|
|
36
|
-
vi.restoreAllMocks();
|
|
37
|
-
vi.unstubAllEnvs();
|
|
38
|
-
process.argv = originalArgv;
|
|
39
|
-
process.exitCode = 0;
|
|
40
|
-
for (const listener of process.stdout.listeners('error')) {
|
|
41
|
-
if (!originalListeners.has(listener))
|
|
42
|
-
process.stdout.off('error', listener);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return io;
|
|
46
|
-
}
|
|
47
|
-
export async function cli(...args) {
|
|
48
|
-
process.argv = ['node', 'wt', ...args];
|
|
49
|
-
await import('../cli.js');
|
|
50
|
-
}
|
|
51
|
-
/** Runs the CLI a second time in the same test. */
|
|
52
|
-
export async function cliAgain(...args) {
|
|
53
|
-
vi.resetModules();
|
|
54
|
-
await cli(...args);
|
|
55
|
-
}
|
|
56
|
-
/** An error of the module graph the next `cli` call loads, so `instanceof` holds there. */
|
|
57
|
-
export async function codedError(code, message) {
|
|
58
|
-
const { WtError } = await import('../errors.js');
|
|
59
|
-
return new WtError(code, message);
|
|
60
|
-
}
|
|
61
|
-
/** The handler wt installed for `signal`, called directly so the test runner never sees the signal. */
|
|
62
|
-
export function signalHandler(signal) {
|
|
63
|
-
return process.listeners(signal).at(-1);
|
|
64
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { mkdir, mkdtemp, realpath, rm } from 'node:fs/promises';
|
|
2
|
-
import { tmpdir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import process from 'node:process';
|
|
5
|
-
import { vi } from 'vitest';
|
|
6
|
-
import { StateStore } from '../../state/store.js';
|
|
7
|
-
/**
|
|
8
|
-
* Creates a source checkout and a saved, ready `feature` environment in a
|
|
9
|
-
* temporary directory, and gives the mocks working defaults.
|
|
10
|
-
*/
|
|
11
|
-
export async function createFixture(mocks) {
|
|
12
|
-
vi.resetAllMocks();
|
|
13
|
-
const base = await realpath(await mkdtemp(join(tmpdir(), 'wt-manage-')));
|
|
14
|
-
const source = join(base, 'source');
|
|
15
|
-
const common = join(source, '.git');
|
|
16
|
-
const store = new StateStore(common);
|
|
17
|
-
const state = {
|
|
18
|
-
schemaVersion: 1,
|
|
19
|
-
repositoryId: 'repo',
|
|
20
|
-
name: 'feature',
|
|
21
|
-
path: join(base, 'feature'),
|
|
22
|
-
branch: 'feature',
|
|
23
|
-
sourceWorktreePath: source,
|
|
24
|
-
sourceProject: 'parent',
|
|
25
|
-
composeFiles: [
|
|
26
|
-
join(source, 'compose.yml'),
|
|
27
|
-
],
|
|
28
|
-
overridePath: join(store.directory, 'feature.compose.yml'),
|
|
29
|
-
projectName: 'wt-repo-feature',
|
|
30
|
-
volumes: { db: 'old' },
|
|
31
|
-
status: 'ready',
|
|
32
|
-
};
|
|
33
|
-
await mkdir(state.path);
|
|
34
|
-
await store.save(state);
|
|
35
|
-
mocks.repositoryInfo.mockResolvedValue({ root: source, repositoryRoot: source, gitCommonDir: common });
|
|
36
|
-
mocks.git.mockResolvedValue('');
|
|
37
|
-
mocks.docker.mockImplementation(async (args) => {
|
|
38
|
-
if (args[0] === 'volume' && args[1] === 'inspect')
|
|
39
|
-
return '{"com.wt.repository":"repo","com.wt.worktree":"feature"}';
|
|
40
|
-
return '';
|
|
41
|
-
});
|
|
42
|
-
mocks.resolveSourceVolumes.mockResolvedValue({ db: 'source-volume' });
|
|
43
|
-
mocks.prepareVolumeCopy.mockResolvedValue('image');
|
|
44
|
-
mocks.cloneNamedVolumes.mockImplementation(async (_sources, _owner, _cwd, _image, record) => {
|
|
45
|
-
await record('fresh', { db: 'fresh' });
|
|
46
|
-
return { db: 'fresh' };
|
|
47
|
-
});
|
|
48
|
-
return { base, source, common, state, store };
|
|
49
|
-
}
|
|
50
|
-
export async function removeFixture(fixture) {
|
|
51
|
-
vi.restoreAllMocks();
|
|
52
|
-
await rm(fixture.base, { recursive: true, force: true });
|
|
53
|
-
}
|
|
54
|
-
/** Runs `operation` while `process.stdin.isTTY` reports `isTTY`. */
|
|
55
|
-
export async function withTTY(isTTY, operation) {
|
|
56
|
-
const previous = Object.getOwnPropertyDescriptor(process.stdin, 'isTTY');
|
|
57
|
-
Object.defineProperty(process.stdin, 'isTTY', { configurable: true, value: isTTY });
|
|
58
|
-
try {
|
|
59
|
-
return await operation();
|
|
60
|
-
}
|
|
61
|
-
finally {
|
|
62
|
-
if (previous)
|
|
63
|
-
Object.defineProperty(process.stdin, 'isTTY', previous);
|
|
64
|
-
else
|
|
65
|
-
Reflect.deleteProperty(process.stdin, 'isTTY');
|
|
66
|
-
}
|
|
67
|
-
}
|