@ricsam/r5d-worker 0.0.80 → 0.0.82
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 +7 -1
- package/dist/cjs/main.cjs +331 -98
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/workspace-command-sync-policy.cjs +3 -3
- package/dist/cjs/workspace-git-sync.cjs +377 -122
- package/dist/cjs/workspace-merge-projection.cjs +392 -0
- package/dist/mjs/main.mjs +329 -98
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/workspace-command-sync-policy.mjs +3 -3
- package/dist/mjs/workspace-git-sync.mjs +381 -122
- package/dist/mjs/workspace-merge-projection.mjs +355 -0
- package/dist/types/main.d.ts +63 -0
- package/dist/types/working-tree-mirror.d.ts +1 -2
- package/dist/types/workspace-command-sync-policy.d.ts +4 -3
- package/dist/types/workspace-git-sync.d.ts +6 -0
- package/dist/types/workspace-merge-projection.d.ts +42 -0
- package/package.json +1 -1
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var workspace_merge_projection_exports = {};
|
|
30
|
+
__export(workspace_merge_projection_exports, {
|
|
31
|
+
materializeWorkspaceProjectionTree: () => materializeWorkspaceProjectionTree,
|
|
32
|
+
mergeWorkspaceProjectionMount: () => mergeWorkspaceProjectionMount,
|
|
33
|
+
workspaceMergeProjectionSupport: () => workspaceMergeProjectionSupport,
|
|
34
|
+
workspaceMergeProjectionTestHarness: () => workspaceMergeProjectionTestHarness
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(workspace_merge_projection_exports);
|
|
37
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
38
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
39
|
+
var import_git_process_environment = require("./git-process-environment.cjs");
|
|
40
|
+
var import_working_tree_mirror = require("./working-tree-mirror.cjs");
|
|
41
|
+
var import_workspace_mount_boundary = require("./workspace-mount-boundary.cjs");
|
|
42
|
+
const MINIMUM_MERGE_TREE_GIT_VERSION = { major: 2, minor: 40 };
|
|
43
|
+
const NON_RECURSIVE_GIT_CONFIG = [
|
|
44
|
+
"-c",
|
|
45
|
+
"submodule.recurse=false",
|
|
46
|
+
"-c",
|
|
47
|
+
"fetch.recurseSubmodules=false",
|
|
48
|
+
"-c",
|
|
49
|
+
"push.recurseSubmodules=false"
|
|
50
|
+
];
|
|
51
|
+
let cachedWorkspaceMergeProjectionSupport = null;
|
|
52
|
+
function gitCommandArgs(args) {
|
|
53
|
+
return ["git", ...NON_RECURSIVE_GIT_CONFIG, ...args];
|
|
54
|
+
}
|
|
55
|
+
function gitResult(cwd, args, options = {}) {
|
|
56
|
+
const result = Bun.spawnSync(gitCommandArgs(args), {
|
|
57
|
+
cwd,
|
|
58
|
+
...options.stdin !== void 0 ? { stdin: options.stdin } : {},
|
|
59
|
+
stdout: "pipe",
|
|
60
|
+
stderr: "pipe",
|
|
61
|
+
env: options.environment ?? (0, import_git_process_environment.workerGitProcessEnvironment)()
|
|
62
|
+
});
|
|
63
|
+
return { exitCode: result.exitCode, stdout: Buffer.from(result.stdout), stderr: Buffer.from(result.stderr) };
|
|
64
|
+
}
|
|
65
|
+
function git(cwd, args, action, options = {}) {
|
|
66
|
+
const result = gitResult(cwd, args, options);
|
|
67
|
+
if (result.exitCode !== 0) {
|
|
68
|
+
const detail = result.stderr.toString().trim() || result.stdout.toString().trim() || `git exited ${result.exitCode}`;
|
|
69
|
+
throw new Error(`${action}: ${detail}`);
|
|
70
|
+
}
|
|
71
|
+
return result.stdout;
|
|
72
|
+
}
|
|
73
|
+
function gitText(cwd, args, action, options = {}) {
|
|
74
|
+
return git(cwd, args, action, options).toString().trim();
|
|
75
|
+
}
|
|
76
|
+
function gitVersionIsSupported(version) {
|
|
77
|
+
const match = /(?:^|\s)(\d+)\.(\d+)(?:\.\d+)?(?:\s|$)/u.exec(version);
|
|
78
|
+
if (!match) return false;
|
|
79
|
+
const major = Number(match[1]);
|
|
80
|
+
const minor = Number(match[2]);
|
|
81
|
+
return major > MINIMUM_MERGE_TREE_GIT_VERSION.major || major === MINIMUM_MERGE_TREE_GIT_VERSION.major && minor >= MINIMUM_MERGE_TREE_GIT_VERSION.minor;
|
|
82
|
+
}
|
|
83
|
+
function workspaceMergeProjectionSupport() {
|
|
84
|
+
if (cachedWorkspaceMergeProjectionSupport) return cachedWorkspaceMergeProjectionSupport;
|
|
85
|
+
if (process.env.R5D_WORKSPACE_MERGE_PROJECTION === "0") {
|
|
86
|
+
cachedWorkspaceMergeProjectionSupport = {
|
|
87
|
+
supported: false,
|
|
88
|
+
error: "Workspace merge projection is disabled by R5D_WORKSPACE_MERGE_PROJECTION=0; stale mounts will remain pinned until it is enabled"
|
|
89
|
+
};
|
|
90
|
+
return cachedWorkspaceMergeProjectionSupport;
|
|
91
|
+
}
|
|
92
|
+
const version = gitResult(void 0, ["--version"]);
|
|
93
|
+
const versionText = version.stdout.toString().trim();
|
|
94
|
+
if (version.exitCode !== 0 || !gitVersionIsSupported(versionText)) {
|
|
95
|
+
const observed = versionText || version.stderr.toString().trim() || `git exited ${version.exitCode}`;
|
|
96
|
+
cachedWorkspaceMergeProjectionSupport = {
|
|
97
|
+
supported: false,
|
|
98
|
+
error: `Workspace merge projection requires Git 2.40 or newer (found ${observed}); upgrade Git before synchronizing stale mounts`
|
|
99
|
+
};
|
|
100
|
+
return cachedWorkspaceMergeProjectionSupport;
|
|
101
|
+
}
|
|
102
|
+
cachedWorkspaceMergeProjectionSupport = { supported: true };
|
|
103
|
+
return cachedWorkspaceMergeProjectionSupport;
|
|
104
|
+
}
|
|
105
|
+
function normalizeWorkspaceRelativePath(value) {
|
|
106
|
+
const normalized = value.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
107
|
+
if (!normalized || normalized === "." || normalized.includes("\0") || normalized.split("/").some((segment) => segment === ".." || segment === ".git")) {
|
|
108
|
+
throw new Error(`Invalid workspace merge-projection path: ${value}`);
|
|
109
|
+
}
|
|
110
|
+
return normalized;
|
|
111
|
+
}
|
|
112
|
+
function requireObjectId(value, label) {
|
|
113
|
+
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(value)) throw new Error(`${label} is not a Git object id: ${value}`);
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
function requireCommit(workspacePath, revision, label) {
|
|
117
|
+
const head = gitText(workspacePath, ["rev-parse", "--verify", `${revision}^{commit}`], `resolve ${label}`);
|
|
118
|
+
return requireObjectId(head, label);
|
|
119
|
+
}
|
|
120
|
+
function workspacePrivateStateDirectory(workspacePath) {
|
|
121
|
+
const gitDirectory = import_node_path.default.join(workspacePath, ".git");
|
|
122
|
+
const gitStatus = import_node_fs.default.lstatSync(gitDirectory);
|
|
123
|
+
if (!gitStatus.isDirectory() || gitStatus.isSymbolicLink()) {
|
|
124
|
+
throw new Error(`Workspace Git directory is not a regular directory: ${gitDirectory}`);
|
|
125
|
+
}
|
|
126
|
+
const stateDirectory = import_node_path.default.join(gitDirectory, "r5d");
|
|
127
|
+
let stateStatus = null;
|
|
128
|
+
try {
|
|
129
|
+
stateStatus = import_node_fs.default.lstatSync(stateDirectory);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (error.code !== "ENOENT") throw error;
|
|
132
|
+
}
|
|
133
|
+
if (!stateStatus) import_node_fs.default.mkdirSync(stateDirectory, { mode: 448 });
|
|
134
|
+
else if (!stateStatus.isDirectory() || stateStatus.isSymbolicLink()) {
|
|
135
|
+
throw new Error(`Workspace Git private state is not a regular directory: ${stateDirectory}`);
|
|
136
|
+
}
|
|
137
|
+
return stateDirectory;
|
|
138
|
+
}
|
|
139
|
+
function temporaryIndexPath(workspacePath) {
|
|
140
|
+
return import_node_path.default.join(workspacePrivateStateDirectory(workspacePath), `tmp-index-${crypto.randomUUID()}`);
|
|
141
|
+
}
|
|
142
|
+
function temporaryIndexEnvironment(indexPath) {
|
|
143
|
+
return { ...(0, import_git_process_environment.workerGitProcessEnvironment)(), GIT_INDEX_FILE: indexPath };
|
|
144
|
+
}
|
|
145
|
+
function removeTemporaryIndex(indexPath) {
|
|
146
|
+
import_node_fs.default.rmSync(indexPath, { force: true });
|
|
147
|
+
import_node_fs.default.rmSync(`${indexPath}.lock`, { force: true });
|
|
148
|
+
}
|
|
149
|
+
function sourceEntryPath(sourceRoot, relativePath) {
|
|
150
|
+
const candidate = import_node_path.default.resolve(sourceRoot, ...relativePath.split("/"));
|
|
151
|
+
const relative = import_node_path.default.relative(sourceRoot, candidate);
|
|
152
|
+
if (relative === ".." || relative.startsWith(`..${import_node_path.default.sep}`) || import_node_path.default.isAbsolute(relative)) {
|
|
153
|
+
throw new Error(`Workspace merge-projection source escapes its root: ${relativePath}`);
|
|
154
|
+
}
|
|
155
|
+
return candidate;
|
|
156
|
+
}
|
|
157
|
+
function assertSameOpenFile(before, after, sourcePath) {
|
|
158
|
+
if (!after.isFile() || before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size || before.mode !== after.mode || before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs) {
|
|
159
|
+
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function hashRegularFile(workspacePath, sourcePath, entry) {
|
|
163
|
+
const descriptor = import_node_fs.default.openSync(sourcePath, import_node_fs.default.constants.O_RDONLY | import_node_fs.default.constants.O_NOFOLLOW);
|
|
164
|
+
try {
|
|
165
|
+
const before = import_node_fs.default.fstatSync(descriptor);
|
|
166
|
+
if (!before.isFile() || before.size !== entry.size || (before.mode & 511) !== (entry.mode & 511)) {
|
|
167
|
+
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
168
|
+
}
|
|
169
|
+
const objectId = requireObjectId(
|
|
170
|
+
gitText(workspacePath, ["hash-object", "-w", "--stdin"], `hash workspace projection file ${sourcePath}`, {
|
|
171
|
+
stdin: descriptor
|
|
172
|
+
}),
|
|
173
|
+
`Workspace projection blob for ${sourcePath}`
|
|
174
|
+
);
|
|
175
|
+
const after = import_node_fs.default.fstatSync(descriptor);
|
|
176
|
+
assertSameOpenFile(before, after, sourcePath);
|
|
177
|
+
const pathStatus = import_node_fs.default.lstatSync(sourcePath);
|
|
178
|
+
if (pathStatus.dev !== after.dev || pathStatus.ino !== after.ino || !pathStatus.isFile() || pathStatus.isSymbolicLink()) {
|
|
179
|
+
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
180
|
+
}
|
|
181
|
+
return objectId;
|
|
182
|
+
} finally {
|
|
183
|
+
import_node_fs.default.closeSync(descriptor);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function hashSymlink(workspacePath, sourcePath, entry) {
|
|
187
|
+
const status = import_node_fs.default.lstatSync(sourcePath);
|
|
188
|
+
if (!status.isSymbolicLink() || import_node_fs.default.readlinkSync(sourcePath) !== entry.target) {
|
|
189
|
+
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
190
|
+
}
|
|
191
|
+
const objectId = requireObjectId(
|
|
192
|
+
gitText(workspacePath, ["hash-object", "-w", "--stdin"], `hash workspace projection symlink ${sourcePath}`, {
|
|
193
|
+
stdin: Buffer.from(entry.target)
|
|
194
|
+
}),
|
|
195
|
+
`Workspace projection symlink blob for ${sourcePath}`
|
|
196
|
+
);
|
|
197
|
+
if (!import_node_fs.default.lstatSync(sourcePath).isSymbolicLink() || import_node_fs.default.readlinkSync(sourcePath) !== entry.target) {
|
|
198
|
+
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
199
|
+
}
|
|
200
|
+
return objectId;
|
|
201
|
+
}
|
|
202
|
+
function indexMode(entry) {
|
|
203
|
+
if (entry.kind === "symlink") return "120000";
|
|
204
|
+
return (entry.mode & 73) !== 0 ? "100755" : "100644";
|
|
205
|
+
}
|
|
206
|
+
function indexInfoRecord(mode, objectId, relativePath) {
|
|
207
|
+
return Buffer.concat([Buffer.from(`${mode} ${objectId} `), Buffer.from(relativePath), Buffer.from([0])]);
|
|
208
|
+
}
|
|
209
|
+
function synthesizeMountTree(input) {
|
|
210
|
+
const sourceRoot = import_node_path.default.resolve(input.sourcePath);
|
|
211
|
+
const entries = (0, import_working_tree_mirror.inspectWorkingTree)(sourceRoot, input.sourceMode);
|
|
212
|
+
const indexPath = temporaryIndexPath(input.workspacePath);
|
|
213
|
+
const environment = temporaryIndexEnvironment(indexPath);
|
|
214
|
+
try {
|
|
215
|
+
git(input.workspacePath, ["read-tree", "--empty"], "initialize workspace projection index", { environment });
|
|
216
|
+
const records = [];
|
|
217
|
+
for (const [relativePath, entry] of [...entries.entries()].sort(([left], [right]) => left.localeCompare(right))) {
|
|
218
|
+
if (entry.kind === "directory") continue;
|
|
219
|
+
const sourcePath = sourceEntryPath(sourceRoot, relativePath);
|
|
220
|
+
const objectId = entry.kind === "file" ? hashRegularFile(input.workspacePath, sourcePath, entry) : hashSymlink(input.workspacePath, sourcePath, entry);
|
|
221
|
+
records.push(indexInfoRecord(indexMode(entry), objectId, relativePath));
|
|
222
|
+
}
|
|
223
|
+
if (records.length > 0) {
|
|
224
|
+
git(input.workspacePath, ["update-index", "-z", "--index-info"], "populate workspace projection index", {
|
|
225
|
+
environment,
|
|
226
|
+
stdin: Buffer.concat(records)
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return requireObjectId(
|
|
230
|
+
gitText(input.workspacePath, ["write-tree"], "write workspace projection mount tree", { environment }),
|
|
231
|
+
"Workspace projection mount tree"
|
|
232
|
+
);
|
|
233
|
+
} finally {
|
|
234
|
+
removeTemporaryIndex(indexPath);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function nulRecords(content) {
|
|
238
|
+
const records = [];
|
|
239
|
+
let start = 0;
|
|
240
|
+
for (let index = 0; index < content.length; index += 1) {
|
|
241
|
+
if (content[index] !== 0) continue;
|
|
242
|
+
if (index > start) records.push(content.subarray(start, index));
|
|
243
|
+
start = index + 1;
|
|
244
|
+
}
|
|
245
|
+
if (start < content.length) records.push(content.subarray(start));
|
|
246
|
+
return records;
|
|
247
|
+
}
|
|
248
|
+
function indexedSubtreePaths(content, workspaceRelativePath) {
|
|
249
|
+
const prefix = Buffer.from(workspaceRelativePath);
|
|
250
|
+
const descendantPrefix = Buffer.from(`${workspaceRelativePath}/`);
|
|
251
|
+
const records = nulRecords(content).filter(
|
|
252
|
+
(record) => record.equals(prefix) || record.length > descendantPrefix.length && record.subarray(0, descendantPrefix.length).equals(descendantPrefix)
|
|
253
|
+
);
|
|
254
|
+
return records.length > 0 ? Buffer.concat(records.flatMap((record) => [record, Buffer.from([0])])) : Buffer.alloc(0);
|
|
255
|
+
}
|
|
256
|
+
function graftMountTree(input) {
|
|
257
|
+
const indexPath = temporaryIndexPath(input.workspacePath);
|
|
258
|
+
const environment = temporaryIndexEnvironment(indexPath);
|
|
259
|
+
try {
|
|
260
|
+
git(input.workspacePath, ["read-tree", input.basisHead], "read workspace projection basis", { environment });
|
|
261
|
+
const indexedPaths = git(input.workspacePath, ["ls-files", "-z"], "enumerate workspace projection basis", { environment });
|
|
262
|
+
const removedPaths = indexedSubtreePaths(indexedPaths, input.workspaceRelativePath);
|
|
263
|
+
if (removedPaths.length > 0) {
|
|
264
|
+
git(input.workspacePath, ["update-index", "--force-remove", "-z", "--stdin"], "remove prior workspace projection subtree", {
|
|
265
|
+
environment,
|
|
266
|
+
stdin: removedPaths
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
git(
|
|
270
|
+
input.workspacePath,
|
|
271
|
+
["read-tree", "-i", `--prefix=${input.workspaceRelativePath}/`, input.mountTree],
|
|
272
|
+
"graft workspace projection mount tree",
|
|
273
|
+
{ environment }
|
|
274
|
+
);
|
|
275
|
+
return requireObjectId(
|
|
276
|
+
gitText(input.workspacePath, ["write-tree"], "write grafted workspace projection tree", { environment }),
|
|
277
|
+
"Grafted workspace projection tree"
|
|
278
|
+
);
|
|
279
|
+
} finally {
|
|
280
|
+
removeTemporaryIndex(indexPath);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function synthesizeOursCommit(input) {
|
|
284
|
+
const mountTree = synthesizeMountTree({
|
|
285
|
+
workspacePath: input.workspacePath,
|
|
286
|
+
sourcePath: input.mount.sourcePath,
|
|
287
|
+
sourceMode: input.mount.sourceMode
|
|
288
|
+
});
|
|
289
|
+
const rootTree = graftMountTree({
|
|
290
|
+
workspacePath: input.workspacePath,
|
|
291
|
+
workspaceRelativePath: input.workspaceRelativePath,
|
|
292
|
+
basisHead: input.basisHead,
|
|
293
|
+
mountTree
|
|
294
|
+
});
|
|
295
|
+
const message = JSON.stringify({
|
|
296
|
+
type: "workspace_projection_basis",
|
|
297
|
+
mountId: input.mount.id,
|
|
298
|
+
attemptId: input.attemptId
|
|
299
|
+
});
|
|
300
|
+
return requireObjectId(
|
|
301
|
+
gitText(
|
|
302
|
+
input.workspacePath,
|
|
303
|
+
["commit-tree", rootTree, "-p", input.basisHead, "-m", message],
|
|
304
|
+
`commit synthesized workspace projection for mount ${input.mount.id}`
|
|
305
|
+
),
|
|
306
|
+
`Synthesized workspace projection commit for mount ${input.mount.id}`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
function mergeWorkspaceProjectionMount(input) {
|
|
310
|
+
const support = workspaceMergeProjectionSupport();
|
|
311
|
+
if (!support.supported) throw new Error(support.error);
|
|
312
|
+
const workspacePath = import_node_path.default.resolve(input.workspacePath);
|
|
313
|
+
const workspaceRelativePath = normalizeWorkspaceRelativePath(input.mount.workspaceRelativePath);
|
|
314
|
+
const basisHead = requireCommit(workspacePath, input.basisHead, `workspace projection basis for mount ${input.mount.id}`);
|
|
315
|
+
const currentHead = requireCommit(workspacePath, input.currentHead, "current workspace projection head");
|
|
316
|
+
const oursCommit = synthesizeOursCommit({
|
|
317
|
+
workspacePath,
|
|
318
|
+
mount: input.mount,
|
|
319
|
+
workspaceRelativePath,
|
|
320
|
+
basisHead,
|
|
321
|
+
attemptId: input.attemptId
|
|
322
|
+
});
|
|
323
|
+
const merged = gitResult(workspacePath, [
|
|
324
|
+
"merge-tree",
|
|
325
|
+
"--write-tree",
|
|
326
|
+
`--merge-base=${basisHead}`,
|
|
327
|
+
"--name-only",
|
|
328
|
+
"-z",
|
|
329
|
+
"--no-messages",
|
|
330
|
+
oursCommit,
|
|
331
|
+
currentHead
|
|
332
|
+
]);
|
|
333
|
+
if (merged.exitCode !== 0 && merged.exitCode !== 1) {
|
|
334
|
+
const detail = merged.stderr.toString().trim() || merged.stdout.toString().trim() || `git exited ${merged.exitCode}`;
|
|
335
|
+
throw new Error(`Merge workspace projection for mount ${input.mount.id}: ${detail}`);
|
|
336
|
+
}
|
|
337
|
+
const records = nulRecords(merged.stdout);
|
|
338
|
+
const resultTree = records.shift()?.toString() ?? "";
|
|
339
|
+
requireObjectId(resultTree, `Merged workspace projection tree for mount ${input.mount.id}`);
|
|
340
|
+
if (merged.exitCode === 0) return { kind: "clean", resultTree, oursCommit };
|
|
341
|
+
const conflictPaths = records.map((record) => record.toString()).sort();
|
|
342
|
+
return {
|
|
343
|
+
kind: "conflict",
|
|
344
|
+
oursCommit,
|
|
345
|
+
conflictPaths,
|
|
346
|
+
error: `Workspace projection for mount ${input.mount.id} conflicted with the current workspace head`
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function materializeWorkspaceProjectionTree(input) {
|
|
350
|
+
const workspacePath = import_node_path.default.resolve(input.workspacePath);
|
|
351
|
+
const workspaceRelativePath = normalizeWorkspaceRelativePath(input.workspaceRelativePath);
|
|
352
|
+
const resultTree = requireObjectId(input.resultTree, "Workspace projection result tree");
|
|
353
|
+
const targetPath = import_node_path.default.join(workspacePath, ...workspaceRelativePath.split("/"));
|
|
354
|
+
(0, import_workspace_mount_boundary.assertManagedDirectoryPath)({
|
|
355
|
+
trustedRoot: workspacePath,
|
|
356
|
+
candidate: targetPath,
|
|
357
|
+
label: "Workspace merge-projection target"
|
|
358
|
+
});
|
|
359
|
+
git(workspacePath, ["cat-file", "-e", `${resultTree}^{tree}`], "resolve workspace merge-projection result tree");
|
|
360
|
+
const subtree = gitResult(workspacePath, ["cat-file", "-e", `${resultTree}:${workspaceRelativePath}`]);
|
|
361
|
+
if (subtree.exitCode !== 0) {
|
|
362
|
+
import_node_fs.default.rmSync(targetPath, { recursive: true, force: true });
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
const subtreeType = gitText(
|
|
366
|
+
workspacePath,
|
|
367
|
+
["cat-file", "-t", `${resultTree}:${workspaceRelativePath}`],
|
|
368
|
+
"inspect workspace merge-projection result subtree"
|
|
369
|
+
);
|
|
370
|
+
if (subtreeType !== "tree") {
|
|
371
|
+
throw new Error(`Workspace merge-projection result is not a directory at ${workspaceRelativePath}`);
|
|
372
|
+
}
|
|
373
|
+
import_node_fs.default.rmSync(targetPath, { recursive: true, force: true });
|
|
374
|
+
git(
|
|
375
|
+
workspacePath,
|
|
376
|
+
["checkout", "--no-recurse-submodules", resultTree, "--", `:(literal)${workspaceRelativePath}`],
|
|
377
|
+
"materialize merged workspace projection subtree"
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
const workspaceMergeProjectionTestHarness = {
|
|
381
|
+
gitVersionIsSupported,
|
|
382
|
+
resetSupportProbe() {
|
|
383
|
+
cachedWorkspaceMergeProjectionSupport = null;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
387
|
+
0 && (module.exports = {
|
|
388
|
+
materializeWorkspaceProjectionTree,
|
|
389
|
+
mergeWorkspaceProjectionMount,
|
|
390
|
+
workspaceMergeProjectionSupport,
|
|
391
|
+
workspaceMergeProjectionTestHarness
|
|
392
|
+
});
|