@h-rig/repos-plugin 0.0.6-alpha.156
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 +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +491 -0
- package/dist/src/layout.d.ts +10 -0
- package/dist/src/layout.js +83 -0
- package/dist/src/mirror/bootstrap.d.ts +2 -0
- package/dist/src/mirror/bootstrap.js +192 -0
- package/dist/src/mirror/refresh.d.ts +3 -0
- package/dist/src/mirror/refresh.js +322 -0
- package/dist/src/mirror/state.d.ts +3 -0
- package/dist/src/mirror/state.js +93 -0
- package/dist/src/plugin.d.ts +4 -0
- package/dist/src/plugin.js +457 -0
- package/dist/src/registry.d.ts +21 -0
- package/dist/src/registry.js +77 -0
- package/dist/src/service.d.ts +13 -0
- package/dist/src/service.js +391 -0
- package/package.json +36 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/repos-plugin/src/registry.ts
|
|
3
|
+
function createRepoRegistry(entries) {
|
|
4
|
+
const map = new Map;
|
|
5
|
+
for (const e of entries) {
|
|
6
|
+
if (map.has(e.id))
|
|
7
|
+
throw new Error(`repo already registered: ${e.id}`);
|
|
8
|
+
map.set(e.id, { ...e });
|
|
9
|
+
}
|
|
10
|
+
const ordered = Array.from(map.values());
|
|
11
|
+
return {
|
|
12
|
+
getById: (id) => map.get(id),
|
|
13
|
+
list: () => ordered
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
var MANAGED_REPOS = new Map;
|
|
17
|
+
function setManagedRepos(entries) {
|
|
18
|
+
const next = new Map;
|
|
19
|
+
for (const e of entries) {
|
|
20
|
+
if (next.has(e.id)) {
|
|
21
|
+
throw new Error(`managed repo already registered: ${e.id}`);
|
|
22
|
+
}
|
|
23
|
+
next.set(e.id, e);
|
|
24
|
+
}
|
|
25
|
+
MANAGED_REPOS = next;
|
|
26
|
+
}
|
|
27
|
+
function getManagedRepoEntry(repoId) {
|
|
28
|
+
const entry = MANAGED_REPOS.get(repoId);
|
|
29
|
+
if (!entry) {
|
|
30
|
+
throw new Error(`managed repo not registered: ${repoId}. Plugins contribute repos via RigPlugin.contributes.repoSources; ` + `make sure a plugin declares this id and the plugin host has been initialized.`);
|
|
31
|
+
}
|
|
32
|
+
return entry;
|
|
33
|
+
}
|
|
34
|
+
function listManagedRepoEntries() {
|
|
35
|
+
return Array.from(MANAGED_REPOS.values());
|
|
36
|
+
}
|
|
37
|
+
function resolveManagedRepoIdByAlias(alias) {
|
|
38
|
+
for (const entry of MANAGED_REPOS.values()) {
|
|
39
|
+
if (entry.alias === alias) {
|
|
40
|
+
return entry.id;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function repoRegistrationToManagedEntry(reg) {
|
|
46
|
+
if (!reg.defaultBranch) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
id: reg.id,
|
|
51
|
+
alias: reg.defaultPath ?? reg.id,
|
|
52
|
+
defaultBranch: reg.defaultBranch,
|
|
53
|
+
defaultRemoteUrl: reg.url,
|
|
54
|
+
remoteEnvVar: reg.remoteEnvVar,
|
|
55
|
+
checkoutEnvVar: reg.checkoutEnvVar
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// packages/repos-plugin/src/layout.ts
|
|
60
|
+
import { existsSync } from "fs";
|
|
61
|
+
import { basename, dirname, join, resolve } from "path";
|
|
62
|
+
import { resolveMonorepoRoot } from "@rig/runtime/layout";
|
|
63
|
+
function resolveRepoStateDir(projectRoot) {
|
|
64
|
+
const normalizedProjectRoot = resolve(projectRoot);
|
|
65
|
+
const projectParent = dirname(normalizedProjectRoot);
|
|
66
|
+
if (basename(projectParent) === ".worktrees") {
|
|
67
|
+
const ownerRoot = dirname(projectParent);
|
|
68
|
+
const ownerHasRepoMarkers = existsSync(resolve(ownerRoot, ".git")) || existsSync(resolve(ownerRoot, ".rig", "state"));
|
|
69
|
+
if (ownerHasRepoMarkers) {
|
|
70
|
+
return resolve(ownerRoot, ".rig", "state");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return resolve(projectRoot, ".rig", "state");
|
|
74
|
+
}
|
|
75
|
+
function resolveManagedRepoLayout(projectRoot, repoId) {
|
|
76
|
+
const normalizedProjectRoot = resolve(projectRoot);
|
|
77
|
+
const entry = getManagedRepoEntry(repoId);
|
|
78
|
+
const stateDir = resolveRepoStateDir(normalizedProjectRoot);
|
|
79
|
+
const metadataRelativePath = join("repos", entry.id);
|
|
80
|
+
const metadataRoot = resolve(stateDir, metadataRelativePath);
|
|
81
|
+
const runtimeWorkspace = process.env.RIG_TASK_WORKSPACE?.trim();
|
|
82
|
+
const runsInsideTaskWorktree = runtimeWorkspace && resolve(runtimeWorkspace) === normalizedProjectRoot || basename(dirname(normalizedProjectRoot)) === ".worktrees";
|
|
83
|
+
const isPrimaryManagedRepo = listManagedRepoEntries()[0]?.id === repoId;
|
|
84
|
+
const checkoutRoot = isPrimaryManagedRepo && runsInsideTaskWorktree ? resolveMonorepoRoot(normalizedProjectRoot) : entry.checkoutEnvVar && process.env[entry.checkoutEnvVar]?.trim() ? resolve(process.env[entry.checkoutEnvVar].trim()) : resolve(normalizedProjectRoot, entry.alias);
|
|
85
|
+
return {
|
|
86
|
+
projectRoot: normalizedProjectRoot,
|
|
87
|
+
repoId: entry.id,
|
|
88
|
+
alias: entry.alias,
|
|
89
|
+
defaultBranch: entry.defaultBranch,
|
|
90
|
+
remoteUrl: entry.remoteEnvVar && process.env[entry.remoteEnvVar]?.trim() ? process.env[entry.remoteEnvVar].trim() : entry.defaultRemoteUrl,
|
|
91
|
+
checkoutRoot,
|
|
92
|
+
worktreesRoot: resolve(checkoutRoot, ".worktrees"),
|
|
93
|
+
stateDir,
|
|
94
|
+
metadataRoot,
|
|
95
|
+
metadataRelativePath,
|
|
96
|
+
mirrorRoot: resolve(metadataRoot, "mirror.git"),
|
|
97
|
+
mirrorStatePath: resolve(metadataRoot, "mirror-state.json"),
|
|
98
|
+
mirrorStateRelativePath: join(metadataRelativePath, "mirror-state.json")
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function resolveManagedRepoLayoutByAlias(projectRoot, alias) {
|
|
102
|
+
const repoId = resolveManagedRepoIdByAlias(alias);
|
|
103
|
+
return repoId ? resolveManagedRepoLayout(projectRoot, repoId) : null;
|
|
104
|
+
}
|
|
105
|
+
function resolveMonorepoRepoLayout(projectRoot) {
|
|
106
|
+
const entries = listManagedRepoEntries();
|
|
107
|
+
if (entries.length === 0) {
|
|
108
|
+
throw new Error("resolveMonorepoRepoLayout: no managed repos registered. Either contribute one via " + "RigPlugin.contributes.repoSources (with defaultBranch set), or avoid calling this " + "function for projects where the project root IS the monorepo.");
|
|
109
|
+
}
|
|
110
|
+
const primary = entries[0];
|
|
111
|
+
return resolveManagedRepoLayout(projectRoot, primary.id);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// packages/repos-plugin/src/mirror/refresh.ts
|
|
115
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, realpathSync as realpathSync2, rmSync } from "fs";
|
|
116
|
+
import { resolve as resolve3 } from "path";
|
|
117
|
+
|
|
118
|
+
// packages/repos-plugin/src/mirror/bootstrap.ts
|
|
119
|
+
import { existsSync as existsSync2, mkdirSync, realpathSync } from "fs";
|
|
120
|
+
import { resolve as resolve2 } from "path";
|
|
121
|
+
|
|
122
|
+
// packages/repos-plugin/src/mirror/state.ts
|
|
123
|
+
import { readAuthorityProjectStateJson, writeAuthorityProjectStateJson } from "@rig/runtime/control-plane/json-files";
|
|
124
|
+
var STATE_VERSION = 1;
|
|
125
|
+
function defaultMirrorState(projectRoot, repoId) {
|
|
126
|
+
const layout = resolveManagedRepoLayout(projectRoot, repoId);
|
|
127
|
+
return {
|
|
128
|
+
version: STATE_VERSION,
|
|
129
|
+
repoId,
|
|
130
|
+
remoteUrl: layout.remoteUrl,
|
|
131
|
+
defaultBranch: layout.defaultBranch
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function readManagedRepoMirrorState(projectRoot, repoId) {
|
|
135
|
+
const layout = resolveManagedRepoLayout(projectRoot, repoId);
|
|
136
|
+
return readAuthorityProjectStateJson(projectRoot, layout.mirrorStateRelativePath, null);
|
|
137
|
+
}
|
|
138
|
+
function writeManagedRepoMirrorState(projectRoot, repoId, patch) {
|
|
139
|
+
const current = readManagedRepoMirrorState(projectRoot, repoId) || defaultMirrorState(projectRoot, repoId);
|
|
140
|
+
const next = {
|
|
141
|
+
...current,
|
|
142
|
+
...patch,
|
|
143
|
+
version: STATE_VERSION,
|
|
144
|
+
repoId
|
|
145
|
+
};
|
|
146
|
+
const layout = resolveManagedRepoLayout(projectRoot, repoId);
|
|
147
|
+
writeAuthorityProjectStateJson(projectRoot, layout.mirrorStateRelativePath, next);
|
|
148
|
+
return next;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// packages/repos-plugin/src/mirror/bootstrap.ts
|
|
152
|
+
function nowIso() {
|
|
153
|
+
return new Date().toISOString();
|
|
154
|
+
}
|
|
155
|
+
function runGit(command, cwd) {
|
|
156
|
+
const result = Bun.spawnSync(command, {
|
|
157
|
+
cwd,
|
|
158
|
+
stdout: "pipe",
|
|
159
|
+
stderr: "pipe",
|
|
160
|
+
env: process.env
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
exitCode: result.exitCode,
|
|
164
|
+
stdout: result.stdout.toString(),
|
|
165
|
+
stderr: result.stderr.toString()
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function ensureGitSuccess(result, command) {
|
|
169
|
+
if (result.exitCode !== 0) {
|
|
170
|
+
throw new Error(result.stderr || result.stdout || `git command failed: ${command.join(" ")}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function isUsableRemoteUrl(candidate, layout) {
|
|
174
|
+
return candidate.length > 0 && candidate !== layout.mirrorRoot && candidate !== layout.checkoutRoot;
|
|
175
|
+
}
|
|
176
|
+
function sameExistingPath(left, right) {
|
|
177
|
+
try {
|
|
178
|
+
return realpathSync(left) === realpathSync(right);
|
|
179
|
+
} catch {
|
|
180
|
+
return resolve2(left) === resolve2(right);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function repoLooksUsable(repoRoot, projectRoot) {
|
|
184
|
+
const probe = runGit(["git", "-C", repoRoot, "rev-parse", "--show-toplevel"], projectRoot);
|
|
185
|
+
return probe.exitCode === 0 && sameExistingPath(probe.stdout.trim(), repoRoot);
|
|
186
|
+
}
|
|
187
|
+
function checkoutLooksUsable(layout) {
|
|
188
|
+
return repoLooksUsable(layout.checkoutRoot, layout.projectRoot);
|
|
189
|
+
}
|
|
190
|
+
function resolveMirrorRemoteUrl(layout) {
|
|
191
|
+
const entry = getManagedRepoEntry(layout.repoId);
|
|
192
|
+
const explicit = entry.remoteEnvVar ? process.env[entry.remoteEnvVar]?.trim() : "";
|
|
193
|
+
if (explicit) {
|
|
194
|
+
return explicit;
|
|
195
|
+
}
|
|
196
|
+
const persisted = readManagedRepoMirrorState(layout.projectRoot, layout.repoId)?.remoteUrl?.trim();
|
|
197
|
+
if (persisted && isUsableRemoteUrl(persisted, layout)) {
|
|
198
|
+
return persisted;
|
|
199
|
+
}
|
|
200
|
+
const mirrorOrigin = runGit(["git", "--git-dir", layout.mirrorRoot, "remote", "get-url", "origin"], layout.projectRoot);
|
|
201
|
+
if (mirrorOrigin.exitCode === 0) {
|
|
202
|
+
const currentOrigin = mirrorOrigin.stdout.trim();
|
|
203
|
+
if (isUsableRemoteUrl(currentOrigin, layout)) {
|
|
204
|
+
return currentOrigin;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (repoLooksUsable(layout.projectRoot, layout.projectRoot)) {
|
|
208
|
+
const projectOrigin = runGit(["git", "-C", layout.projectRoot, "remote", "get-url", "origin"], layout.projectRoot);
|
|
209
|
+
if (projectOrigin.exitCode === 0) {
|
|
210
|
+
const currentOrigin = projectOrigin.stdout.trim();
|
|
211
|
+
if (isUsableRemoteUrl(currentOrigin, layout)) {
|
|
212
|
+
return currentOrigin;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (existsSync2(resolve2(layout.checkoutRoot, ".git")) && checkoutLooksUsable(layout)) {
|
|
217
|
+
const checkoutOrigin = runGit(["git", "-C", layout.checkoutRoot, "remote", "get-url", "origin"], layout.projectRoot);
|
|
218
|
+
if (checkoutOrigin.exitCode === 0) {
|
|
219
|
+
const currentOrigin = checkoutOrigin.stdout.trim();
|
|
220
|
+
if (isUsableRemoteUrl(currentOrigin, layout)) {
|
|
221
|
+
return currentOrigin;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return layout.remoteUrl;
|
|
226
|
+
}
|
|
227
|
+
function ensureManagedRepoMirror(projectRoot, repoId) {
|
|
228
|
+
const layout = resolveManagedRepoLayout(projectRoot, repoId);
|
|
229
|
+
mkdirSync(layout.metadataRoot, { recursive: true });
|
|
230
|
+
const remoteUrl = resolveMirrorRemoteUrl(layout);
|
|
231
|
+
if (!existsSync2(resolve2(layout.mirrorRoot, "HEAD"))) {
|
|
232
|
+
ensureGitSuccess(runGit(["git", "init", "--bare", layout.mirrorRoot], layout.projectRoot), ["git", "init", "--bare", layout.mirrorRoot]);
|
|
233
|
+
}
|
|
234
|
+
const getOrigin = runGit(["git", "--git-dir", layout.mirrorRoot, "remote", "get-url", "origin"], layout.projectRoot);
|
|
235
|
+
if (getOrigin.exitCode === 0) {
|
|
236
|
+
const currentOrigin = getOrigin.stdout.trim();
|
|
237
|
+
if (currentOrigin !== remoteUrl) {
|
|
238
|
+
ensureGitSuccess(runGit(["git", "--git-dir", layout.mirrorRoot, "remote", "set-url", "origin", remoteUrl], layout.projectRoot), ["git", "--git-dir", layout.mirrorRoot, "remote", "set-url", "origin", remoteUrl]);
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
ensureGitSuccess(runGit(["git", "--git-dir", layout.mirrorRoot, "remote", "add", "origin", remoteUrl], layout.projectRoot), ["git", "--git-dir", layout.mirrorRoot, "remote", "add", "origin", remoteUrl]);
|
|
242
|
+
}
|
|
243
|
+
writeManagedRepoMirrorState(projectRoot, repoId, {
|
|
244
|
+
remoteUrl,
|
|
245
|
+
defaultBranch: layout.defaultBranch,
|
|
246
|
+
initializedAt: nowIso()
|
|
247
|
+
});
|
|
248
|
+
return layout;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// packages/repos-plugin/src/mirror/refresh.ts
|
|
252
|
+
function nowIso2() {
|
|
253
|
+
return new Date().toISOString();
|
|
254
|
+
}
|
|
255
|
+
function runGit2(command, cwd) {
|
|
256
|
+
const result = Bun.spawnSync(command, {
|
|
257
|
+
cwd,
|
|
258
|
+
stdout: "pipe",
|
|
259
|
+
stderr: "pipe",
|
|
260
|
+
env: process.env
|
|
261
|
+
});
|
|
262
|
+
return {
|
|
263
|
+
exitCode: result.exitCode,
|
|
264
|
+
stdout: result.stdout.toString(),
|
|
265
|
+
stderr: result.stderr.toString()
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function ensureGitSuccess2(result, command) {
|
|
269
|
+
if (result.exitCode !== 0) {
|
|
270
|
+
throw new Error(result.stderr || result.stdout || `git command failed: ${command.join(" ")}`);
|
|
271
|
+
}
|
|
272
|
+
return result.stdout.trim();
|
|
273
|
+
}
|
|
274
|
+
function sameExistingPath2(left, right) {
|
|
275
|
+
try {
|
|
276
|
+
return realpathSync2(left) === realpathSync2(right);
|
|
277
|
+
} catch {
|
|
278
|
+
return resolve3(left) === resolve3(right);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function ensureMirrorHead(layout) {
|
|
282
|
+
ensureGitSuccess2(runGit2([
|
|
283
|
+
"git",
|
|
284
|
+
"--git-dir",
|
|
285
|
+
layout.mirrorRoot,
|
|
286
|
+
"fetch",
|
|
287
|
+
"--prune",
|
|
288
|
+
"origin",
|
|
289
|
+
"+refs/heads/*:refs/heads/*",
|
|
290
|
+
"+refs/tags/*:refs/tags/*"
|
|
291
|
+
], layout.projectRoot), [
|
|
292
|
+
"git",
|
|
293
|
+
"--git-dir",
|
|
294
|
+
layout.mirrorRoot,
|
|
295
|
+
"fetch",
|
|
296
|
+
"--prune",
|
|
297
|
+
"origin",
|
|
298
|
+
"+refs/heads/*:refs/heads/*",
|
|
299
|
+
"+refs/tags/*:refs/tags/*"
|
|
300
|
+
]);
|
|
301
|
+
const headRef = `refs/heads/${layout.defaultBranch}`;
|
|
302
|
+
const headCommit = ensureGitSuccess2(runGit2(["git", "--git-dir", layout.mirrorRoot, "rev-parse", headRef], layout.projectRoot), ["git", "--git-dir", layout.mirrorRoot, "rev-parse", headRef]);
|
|
303
|
+
const remoteUrl = ensureGitSuccess2(runGit2(["git", "--git-dir", layout.mirrorRoot, "remote", "get-url", "origin"], layout.projectRoot), ["git", "--git-dir", layout.mirrorRoot, "remote", "get-url", "origin"]);
|
|
304
|
+
ensureGitSuccess2(runGit2(["git", "--git-dir", layout.mirrorRoot, "symbolic-ref", "HEAD", headRef], layout.projectRoot), ["git", "--git-dir", layout.mirrorRoot, "symbolic-ref", "HEAD", headRef]);
|
|
305
|
+
writeManagedRepoMirrorState(layout.projectRoot, layout.repoId, {
|
|
306
|
+
remoteUrl,
|
|
307
|
+
defaultBranch: layout.defaultBranch,
|
|
308
|
+
lastSyncedAt: nowIso2(),
|
|
309
|
+
headRef,
|
|
310
|
+
headCommit
|
|
311
|
+
});
|
|
312
|
+
return headCommit;
|
|
313
|
+
}
|
|
314
|
+
function refreshManagedRepoMirror(projectRoot, repoId) {
|
|
315
|
+
const layout = ensureManagedRepoMirror(projectRoot, repoId);
|
|
316
|
+
const headCommit = ensureMirrorHead(layout);
|
|
317
|
+
return { layout, headCommit };
|
|
318
|
+
}
|
|
319
|
+
function checkoutLooksUsable2(layout) {
|
|
320
|
+
const probe = runGit2(["git", "-C", layout.checkoutRoot, "rev-parse", "--show-toplevel"], layout.projectRoot);
|
|
321
|
+
return probe.exitCode === 0 && sameExistingPath2(probe.stdout.trim(), layout.checkoutRoot);
|
|
322
|
+
}
|
|
323
|
+
function ensureCheckoutFromMirror(layout) {
|
|
324
|
+
mkdirSync2(resolve3(layout.checkoutRoot, ".."), { recursive: true });
|
|
325
|
+
const gitPath = resolve3(layout.checkoutRoot, ".git");
|
|
326
|
+
if (existsSync3(layout.checkoutRoot) && (!existsSync3(gitPath) || !checkoutLooksUsable2(layout))) {
|
|
327
|
+
rmSync(layout.checkoutRoot, { recursive: true, force: true });
|
|
328
|
+
}
|
|
329
|
+
if (!existsSync3(gitPath)) {
|
|
330
|
+
ensureGitSuccess2(runGit2(["git", "clone", layout.mirrorRoot, layout.checkoutRoot], layout.projectRoot), ["git", "clone", layout.mirrorRoot, layout.checkoutRoot]);
|
|
331
|
+
}
|
|
332
|
+
const getOrigin = runGit2(["git", "-C", layout.checkoutRoot, "remote", "get-url", "origin"], layout.projectRoot);
|
|
333
|
+
if (getOrigin.exitCode === 0) {
|
|
334
|
+
const currentOrigin = getOrigin.stdout.trim();
|
|
335
|
+
if (currentOrigin !== layout.mirrorRoot) {
|
|
336
|
+
ensureGitSuccess2(runGit2(["git", "-C", layout.checkoutRoot, "remote", "set-url", "origin", layout.mirrorRoot], layout.projectRoot), ["git", "-C", layout.checkoutRoot, "remote", "set-url", "origin", layout.mirrorRoot]);
|
|
337
|
+
}
|
|
338
|
+
} else {
|
|
339
|
+
ensureGitSuccess2(runGit2(["git", "-C", layout.checkoutRoot, "remote", "add", "origin", layout.mirrorRoot], layout.projectRoot), ["git", "-C", layout.checkoutRoot, "remote", "add", "origin", layout.mirrorRoot]);
|
|
340
|
+
}
|
|
341
|
+
ensureGitSuccess2(runGit2(["git", "-C", layout.checkoutRoot, "fetch", "origin", layout.defaultBranch], layout.projectRoot), ["git", "-C", layout.checkoutRoot, "fetch", "origin", layout.defaultBranch]);
|
|
342
|
+
ensureGitSuccess2(runGit2(["git", "-C", layout.checkoutRoot, "reset", "--hard"], layout.projectRoot), ["git", "-C", layout.checkoutRoot, "reset", "--hard"]);
|
|
343
|
+
ensureGitSuccess2(runGit2(["git", "-C", layout.checkoutRoot, "clean", "-fd"], layout.projectRoot), ["git", "-C", layout.checkoutRoot, "clean", "-fd"]);
|
|
344
|
+
ensureGitSuccess2(runGit2([
|
|
345
|
+
"git",
|
|
346
|
+
"-C",
|
|
347
|
+
layout.checkoutRoot,
|
|
348
|
+
"checkout",
|
|
349
|
+
"--force",
|
|
350
|
+
"-B",
|
|
351
|
+
layout.defaultBranch,
|
|
352
|
+
`origin/${layout.defaultBranch}`
|
|
353
|
+
], layout.projectRoot), [
|
|
354
|
+
"git",
|
|
355
|
+
"-C",
|
|
356
|
+
layout.checkoutRoot,
|
|
357
|
+
"checkout",
|
|
358
|
+
"--force",
|
|
359
|
+
"-B",
|
|
360
|
+
layout.defaultBranch,
|
|
361
|
+
`origin/${layout.defaultBranch}`
|
|
362
|
+
]);
|
|
363
|
+
ensureGitSuccess2(runGit2(["git", "-C", layout.checkoutRoot, "reset", "--hard", `origin/${layout.defaultBranch}`], layout.projectRoot), ["git", "-C", layout.checkoutRoot, "reset", "--hard", `origin/${layout.defaultBranch}`]);
|
|
364
|
+
ensureGitSuccess2(runGit2(["git", "-C", layout.checkoutRoot, "clean", "-fd"], layout.projectRoot), ["git", "-C", layout.checkoutRoot, "clean", "-fd"]);
|
|
365
|
+
return ensureGitSuccess2(runGit2(["git", "-C", layout.checkoutRoot, "rev-parse", "HEAD"], layout.projectRoot), ["git", "-C", layout.checkoutRoot, "rev-parse", "HEAD"]);
|
|
366
|
+
}
|
|
367
|
+
function syncManagedRepo(projectRoot, repoId) {
|
|
368
|
+
const { layout, headCommit } = refreshManagedRepoMirror(projectRoot, repoId);
|
|
369
|
+
const checkoutCommit = ensureCheckoutFromMirror(layout);
|
|
370
|
+
if (checkoutCommit !== headCommit) {
|
|
371
|
+
throw new Error(`Managed repo checkout ${layout.alias} is out of sync with mirror: expected ${headCommit}, got ${checkoutCommit}.`);
|
|
372
|
+
}
|
|
373
|
+
return { layout, headCommit };
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// packages/repos-plugin/src/service.ts
|
|
377
|
+
var managedRepoService = {
|
|
378
|
+
setManagedRepos,
|
|
379
|
+
listManagedRepoEntries,
|
|
380
|
+
resolveManagedRepoIdByAlias,
|
|
381
|
+
repoRegistrationToManagedEntry,
|
|
382
|
+
createRepoRegistry,
|
|
383
|
+
resolveManagedRepoLayoutByAlias,
|
|
384
|
+
resolveMonorepoRepoLayout,
|
|
385
|
+
syncManagedRepo
|
|
386
|
+
};
|
|
387
|
+
var svc = managedRepoService;
|
|
388
|
+
export {
|
|
389
|
+
svc,
|
|
390
|
+
managedRepoService
|
|
391
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@h-rig/repos-plugin",
|
|
3
|
+
"version": "0.0.6-alpha.156",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "First-party managed-repo (registry/layout/mirror) capability plugin for Rig.",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/src/plugin.d.ts",
|
|
14
|
+
"import": "./dist/src/plugin.js"
|
|
15
|
+
},
|
|
16
|
+
"./plugin": {
|
|
17
|
+
"types": "./dist/src/plugin.d.ts",
|
|
18
|
+
"import": "./dist/src/plugin.js"
|
|
19
|
+
},
|
|
20
|
+
"./index": {
|
|
21
|
+
"types": "./dist/src/index.d.ts",
|
|
22
|
+
"import": "./dist/src/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"bun": ">=1.3.11"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/src/index.js",
|
|
29
|
+
"module": "./dist/src/index.js",
|
|
30
|
+
"types": "./dist/src/index.d.ts",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.156",
|
|
33
|
+
"@rig/core": "npm:@h-rig/core@0.0.6-alpha.156",
|
|
34
|
+
"@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.156"
|
|
35
|
+
}
|
|
36
|
+
}
|