@agimon-ai/po-git 0.0.0-alpha.45 → 0.0.0-alpha.46
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/dist/extensions/native.mjs +6 -3
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +57 -53
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.mjs +56 -52
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{worktreeOperations-CU0iV2h-.cjs → worktreeOperations-C1ygq-Na.cjs} +73 -65
- package/dist/worktreeOperations-C1ygq-Na.cjs.map +1 -0
- package/dist/{worktreeOperations-BqLLypS5.mjs → worktreeOperations-CP2lYxrI.mjs} +72 -64
- package/dist/worktreeOperations-CP2lYxrI.mjs.map +1 -0
- package/package.json +8 -8
- package/dist/worktreeOperations-BqLLypS5.mjs.map +0 -1
- package/dist/worktreeOperations-CU0iV2h-.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_worktreeOperations = require("./worktreeOperations-
|
|
2
|
+
const require_worktreeOperations = require("./worktreeOperations-C1ygq-Na.cjs");
|
|
3
3
|
//#region src/services/extensionService/index.ts
|
|
4
4
|
var DefaultGitExtensionService = class {
|
|
5
5
|
async execute() {
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["_$___worktreeEvents0.WorktreeMessage"],"sources":["../src/services/worktreeEvents/index.ts","../src/types/worktreeRegistry.ts","../src/services/worktreeNaming/index.ts","../src/services/worktreeOperations/index.ts","../src/types/extension.ts","../src/services/extensionService/index.ts","../src/services/gitDependencies/index.ts"],"mappings":";;;cASa;KASD;UAEK;WACN,gBAAgB;WAChB;WACA;WACA,MAAM;WACN;WACA;;;;;;;;;;;KCRC;cAEC;UAEI;EACf,gBAAgB;;EAEhB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;EAKA;EACA,QAAQ;;EAER;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["_$___worktreeEvents0.WorktreeMessage"],"sources":["../src/services/worktreeEvents/index.ts","../src/types/worktreeRegistry.ts","../src/services/worktreeNaming/index.ts","../src/services/worktreeOperations/index.ts","../src/types/extension.ts","../src/services/extensionService/index.ts","../src/services/gitDependencies/index.ts"],"mappings":";;;cASa;KASD;UAEK;WACN,gBAAgB;WAChB;WACA;WACA,MAAM;WACN;WACA;;;;;;;;;;;KCRC;cAEC;UAEI;EACf,gBAAgB;;EAEhB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;EAKA;EACA,QAAQ;;EAER;;;;UCgEe;;EAEf,QAAQ;;EAER,QAAQ;;EAER;;EAEA,WAAW;;;;;;;EAOX;;;;;;;;iBASc,UAAU;EACxB,kBAAkB;EAClB;EACA;EACA,aAAa;IACX;;;UCrFa;;EAEf;;;;;EAKA;;UAGe;EACf;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;UAGe;;EAEf,SAAS;;EAET,cAAc;;UAGC;EACf,MAAM,SAAS,iBAAiB,SAAS,sBAAsB,UAAU,eAAe,QAAQ;EAChG,MAAM,SAAS,iBAAiB,YAAY,iBAAiB,QAAQ;EACrE,KAAK,SAAS,kBAAkB,QAAQ;EACxC,OAAO,SAAS,iBAAiB,aAAa;IAAU,QAAQ;IAAgB;;EAChF,MAAM,SAAS,iBAAiB,YAAY,mBAAmB,QAAQ;EACvE,MAAM,SAAS,iBAAiB,kBAAkB,QAAQ,kBAAkB;EAC5E,KAAK,SAAS,iBAAiB,YAAY,kBAAkB;EAC7D,SAAS,SAAS,iBAAiB,aAAa,QAA9BA;;;;KCtFR;UAEK;EACf;EACA,OAAO;;UAGQ;EACf,WAAW,QAAQ;;UAGJ;EACf,SAAS;EACT,YAAY;;;;qBCbD,sCAAsC;EAC3C,WAAW,QAAQ;;;;wBCEX,sBAAsB,YAAW,QAAQ,4BAAiC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as createWorktreeGit, t as createWorktreeOperations } from "./worktreeOperations-
|
|
1
|
+
import { T as createWorktreeGit, t as createWorktreeOperations } from "./worktreeOperations-CP2lYxrI.mjs";
|
|
2
2
|
//#region src/services/extensionService/index.ts
|
|
3
3
|
var DefaultGitExtensionService = class {
|
|
4
4
|
async execute() {
|
|
@@ -21,8 +21,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
//#endregion
|
|
23
23
|
let node_child_process = require("node:child_process");
|
|
24
|
-
let
|
|
25
|
-
|
|
24
|
+
let node_fs_promises = require("node:fs/promises");
|
|
25
|
+
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
26
26
|
let node_crypto = require("node:crypto");
|
|
27
27
|
let node_path = require("node:path");
|
|
28
28
|
node_path = __toESM(node_path, 1);
|
|
@@ -200,7 +200,7 @@ function createWorktreeGit() {
|
|
|
200
200
|
path
|
|
201
201
|
], REMOVE_TIMEOUT_MS);
|
|
202
202
|
if (result.code === 0) return;
|
|
203
|
-
if (missingWorktree(result.stderr) && !
|
|
203
|
+
if (missingWorktree(result.stderr) && !await node_fs_promises.default.access(path).then(() => true, () => false)) {
|
|
204
204
|
await prune(repositoryRoot);
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
@@ -338,12 +338,12 @@ const OWNER_ONLY_FILE = 384;
|
|
|
338
338
|
* record in it. Writing beside the target and renaming makes the swap atomic on
|
|
339
339
|
* the same filesystem, so a reader sees either the old file or the new one.
|
|
340
340
|
*/
|
|
341
|
-
function writeJsonAtomic(file, value) {
|
|
341
|
+
async function writeJsonAtomic(file, value) {
|
|
342
342
|
const directory = node_path.default.dirname(file);
|
|
343
|
-
|
|
344
|
-
const temporary = node_path.default.join(directory, `.${node_path.default.basename(file)}.${
|
|
345
|
-
|
|
346
|
-
|
|
343
|
+
await node_fs_promises.default.mkdir(directory, { recursive: true });
|
|
344
|
+
const temporary = node_path.default.join(directory, `.${node_path.default.basename(file)}.${(0, node_crypto.randomUUID)()}.tmp`);
|
|
345
|
+
await node_fs_promises.default.writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: OWNER_ONLY_FILE });
|
|
346
|
+
await node_fs_promises.default.rename(temporary, file);
|
|
347
347
|
}
|
|
348
348
|
/**
|
|
349
349
|
* Reads JSON, treating every failure as absent.
|
|
@@ -352,9 +352,9 @@ function writeJsonAtomic(file, value) {
|
|
|
352
352
|
* here: there is nothing to act on. Distinguishing them would only offer a
|
|
353
353
|
* choice no caller wants to make.
|
|
354
354
|
*/
|
|
355
|
-
function readJson(file) {
|
|
355
|
+
async function readJson(file) {
|
|
356
356
|
try {
|
|
357
|
-
return JSON.parse(
|
|
357
|
+
return JSON.parse(await node_fs_promises.default.readFile(file, "utf8"));
|
|
358
358
|
} catch {
|
|
359
359
|
return;
|
|
360
360
|
}
|
|
@@ -373,12 +373,12 @@ const MAX_LABEL_LENGTH = 32;
|
|
|
373
373
|
* the registry is per repository and must be found from inside a worktree too.
|
|
374
374
|
* A session may run in a subdirectory, so the nearest enclosing checkout is used.
|
|
375
375
|
*/
|
|
376
|
-
function gitCommonDirectory(directory) {
|
|
376
|
+
async function gitCommonDirectory(directory) {
|
|
377
377
|
let root = node_path.default.resolve(directory);
|
|
378
378
|
let marker = node_path.default.join(root, ".git");
|
|
379
379
|
let stat;
|
|
380
380
|
for (;;) try {
|
|
381
|
-
stat =
|
|
381
|
+
stat = await node_fs_promises.default.stat(marker);
|
|
382
382
|
break;
|
|
383
383
|
} catch {
|
|
384
384
|
const parent = node_path.default.dirname(root);
|
|
@@ -389,14 +389,14 @@ function gitCommonDirectory(directory) {
|
|
|
389
389
|
if (stat.isDirectory()) return marker;
|
|
390
390
|
let pointer;
|
|
391
391
|
try {
|
|
392
|
-
pointer =
|
|
392
|
+
pointer = (await node_fs_promises.default.readFile(marker, "utf8")).trim();
|
|
393
393
|
} catch {
|
|
394
394
|
return;
|
|
395
395
|
}
|
|
396
396
|
if (!pointer.startsWith("gitdir:")) return void 0;
|
|
397
397
|
const gitDir = node_path.default.resolve(root, pointer.slice(7).trim());
|
|
398
398
|
try {
|
|
399
|
-
const common =
|
|
399
|
+
const common = (await node_fs_promises.default.readFile(node_path.default.join(gitDir, "commondir"), "utf8")).trim();
|
|
400
400
|
return node_path.default.resolve(gitDir, common);
|
|
401
401
|
} catch {
|
|
402
402
|
return gitDir;
|
|
@@ -415,8 +415,8 @@ function repositoryLabel(root) {
|
|
|
415
415
|
* registry. Falling back to the path keeps a non-repository directory usable
|
|
416
416
|
* instead of failing, though nothing here should reach that case.
|
|
417
417
|
*/
|
|
418
|
-
function repositoryId(root) {
|
|
419
|
-
const common = gitCommonDirectory(root);
|
|
418
|
+
async function repositoryId(root) {
|
|
419
|
+
const common = await gitCommonDirectory(root);
|
|
420
420
|
const token = common === void 0 ? `root:${node_path.default.resolve(root)}` : `git:${common}`;
|
|
421
421
|
return (0, node_crypto.createHash)("sha256").update(token).digest("hex").slice(0, ID_LENGTH);
|
|
422
422
|
}
|
|
@@ -452,22 +452,26 @@ function credentialsFile(homeDir = node_os.default.homedir()) {
|
|
|
452
452
|
return node_path.default.join(poGitRoot(homeDir), "credentials.json");
|
|
453
453
|
}
|
|
454
454
|
/** One registry file per repository, keyed by the shared git directory. */
|
|
455
|
-
function registryFile(repositoryRoot, homeDir = node_os.default.homedir()) {
|
|
456
|
-
const id = repositoryId(repositoryRoot);
|
|
455
|
+
async function registryFile(repositoryRoot, homeDir = node_os.default.homedir()) {
|
|
456
|
+
const id = await repositoryId(repositoryRoot);
|
|
457
457
|
const root = node_path.default.join(poGitRoot(homeDir), "registry");
|
|
458
458
|
const canonical = node_path.default.join(root, id, "worktrees.json");
|
|
459
|
-
if (
|
|
459
|
+
if (await node_fs_promises.default.access(canonical).then(() => true, () => false)) return canonical;
|
|
460
460
|
let names;
|
|
461
461
|
try {
|
|
462
|
-
names =
|
|
462
|
+
names = await node_fs_promises.default.readdir(root);
|
|
463
463
|
} catch {
|
|
464
464
|
return canonical;
|
|
465
465
|
}
|
|
466
|
-
const legacyFiles =
|
|
466
|
+
const legacyFiles = [];
|
|
467
|
+
for (const entry of names.filter((name) => name.endsWith(`--${id}`)).sort()) {
|
|
468
|
+
const file = node_path.default.join(root, entry, "worktrees.json");
|
|
469
|
+
if (await node_fs_promises.default.access(file).then(() => true, () => false)) legacyFiles.push(file);
|
|
470
|
+
}
|
|
467
471
|
if (legacyFiles.length === 0) return canonical;
|
|
468
472
|
const entries = /* @__PURE__ */ new Map();
|
|
469
473
|
for (const file of legacyFiles) {
|
|
470
|
-
const legacy = readJson(file);
|
|
474
|
+
const legacy = await readJson(file);
|
|
471
475
|
if (legacy?.version !== 1 || !Array.isArray(legacy.entries)) continue;
|
|
472
476
|
for (const value of legacy.entries) {
|
|
473
477
|
if (typeof value !== "object" || value === null || !("id" in value) || typeof value.id !== "string" || value.id === "") continue;
|
|
@@ -478,16 +482,16 @@ function registryFile(repositoryRoot, homeDir = node_os.default.homedir()) {
|
|
|
478
482
|
}
|
|
479
483
|
}
|
|
480
484
|
const temporary = `${canonical}.${(0, node_crypto.randomUUID)()}.migration`;
|
|
481
|
-
writeJsonAtomic(temporary, {
|
|
485
|
+
await writeJsonAtomic(temporary, {
|
|
482
486
|
version: 1,
|
|
483
487
|
entries: [...entries.values()]
|
|
484
488
|
});
|
|
485
489
|
try {
|
|
486
|
-
|
|
490
|
+
await node_fs_promises.default.link(temporary, canonical);
|
|
487
491
|
} catch (error) {
|
|
488
492
|
if (error.code !== "EEXIST") throw error;
|
|
489
493
|
} finally {
|
|
490
|
-
|
|
494
|
+
await node_fs_promises.default.rm(temporary);
|
|
491
495
|
}
|
|
492
496
|
return canonical;
|
|
493
497
|
}
|
|
@@ -606,18 +610,22 @@ function refuseClose(input) {
|
|
|
606
610
|
* uncommitted work, so losing the record would lose the only pointer to it.
|
|
607
611
|
* Deletion is always a separate, named decision.
|
|
608
612
|
*/
|
|
609
|
-
function reconcile(records, probe) {
|
|
613
|
+
async function reconcile(records, probe) {
|
|
610
614
|
const changed = [];
|
|
615
|
+
const next = [];
|
|
616
|
+
for (const record of records) {
|
|
617
|
+
if (record.status === "orphaned" || await probe.exists(record.path) && probe.alive(record)) {
|
|
618
|
+
next.push(record);
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
changed.push(record.id);
|
|
622
|
+
next.push({
|
|
623
|
+
...record,
|
|
624
|
+
status: "orphaned"
|
|
625
|
+
});
|
|
626
|
+
}
|
|
611
627
|
return {
|
|
612
|
-
records:
|
|
613
|
-
if (record.status === "orphaned") return record;
|
|
614
|
-
if (!(!probe.exists(record.path) || !probe.alive(record))) return record;
|
|
615
|
-
changed.push(record.id);
|
|
616
|
-
return {
|
|
617
|
-
...record,
|
|
618
|
-
status: "orphaned"
|
|
619
|
-
};
|
|
620
|
-
}),
|
|
628
|
+
records: next,
|
|
621
629
|
changed
|
|
622
630
|
};
|
|
623
631
|
}
|
|
@@ -677,25 +685,25 @@ function isRecord(value) {
|
|
|
677
685
|
*/
|
|
678
686
|
function createWorktreeRegistry(file) {
|
|
679
687
|
return {
|
|
680
|
-
list() {
|
|
681
|
-
const parsed = readJson(file);
|
|
688
|
+
async list() {
|
|
689
|
+
const parsed = await readJson(file);
|
|
682
690
|
if (!parsed || parsed.version !== 1 || !Array.isArray(parsed.entries)) return [];
|
|
683
691
|
return parsed.entries.filter(isRecord);
|
|
684
692
|
},
|
|
685
|
-
replace(entries) {
|
|
686
|
-
writeJsonAtomic(file, {
|
|
693
|
+
async replace(entries) {
|
|
694
|
+
await writeJsonAtomic(file, {
|
|
687
695
|
version: 1,
|
|
688
696
|
entries
|
|
689
697
|
});
|
|
690
698
|
},
|
|
691
699
|
async transaction(operation, signal) {
|
|
692
700
|
const lock = `${file}.lock`;
|
|
693
|
-
|
|
701
|
+
await node_fs_promises.default.mkdir(node_path.default.dirname(file), { recursive: true });
|
|
694
702
|
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
695
703
|
for (;;) {
|
|
696
704
|
signal?.throwIfAborted();
|
|
697
705
|
try {
|
|
698
|
-
|
|
706
|
+
await node_fs_promises.default.mkdir(lock, { mode: 448 });
|
|
699
707
|
break;
|
|
700
708
|
} catch (error) {
|
|
701
709
|
if (error.code !== "EEXIST") throw error;
|
|
@@ -704,14 +712,14 @@ function createWorktreeRegistry(file) {
|
|
|
704
712
|
}
|
|
705
713
|
}
|
|
706
714
|
try {
|
|
707
|
-
|
|
715
|
+
await node_fs_promises.default.writeFile(node_path.default.join(lock, "owner.json"), JSON.stringify({
|
|
708
716
|
pid: process.pid,
|
|
709
717
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
710
718
|
}), { mode: 384 });
|
|
711
719
|
signal?.throwIfAborted();
|
|
712
720
|
return await operation();
|
|
713
721
|
} finally {
|
|
714
|
-
|
|
722
|
+
await node_fs_promises.default.rm(lock, { recursive: true });
|
|
715
723
|
}
|
|
716
724
|
}
|
|
717
725
|
};
|
|
@@ -725,13 +733,13 @@ const GIT_WORKTREE_REPORT_KIND = "git.worktree.report";
|
|
|
725
733
|
* The repository's worktree setup as one shell command, or undefined when it asks for none.
|
|
726
734
|
* Read from the checkout the spawn starts in, so an uncommitted edit applies at once.
|
|
727
735
|
*/
|
|
728
|
-
function readWorktreeSetup(root) {
|
|
736
|
+
async function readWorktreeSetup(root) {
|
|
729
737
|
const file = node_path.default.join(root, WORKTREE_CONFIG_FILE);
|
|
730
|
-
if (!node_fs.default.existsSync(file)) return void 0;
|
|
731
738
|
let setup;
|
|
732
739
|
try {
|
|
733
|
-
setup = (0, js_yaml.load)(
|
|
740
|
+
setup = (0, js_yaml.load)(await node_fs_promises.default.readFile(file, "utf8"))?.setup;
|
|
734
741
|
} catch (error) {
|
|
742
|
+
if (error.code === "ENOENT") return void 0;
|
|
735
743
|
throw new PoGitExpectedError("invalid_request", `${WORKTREE_CONFIG_FILE} is not valid YAML (${error.message}).`, false, "Fix the file and try again.");
|
|
736
744
|
}
|
|
737
745
|
const commands = [setup ?? []].flat();
|
|
@@ -758,7 +766,7 @@ function createWorktreeOperations(deps) {
|
|
|
758
766
|
};
|
|
759
767
|
const probe = {
|
|
760
768
|
alive: (record) => requireSessionService().isLive(record.sessionId),
|
|
761
|
-
exists: (path) =>
|
|
769
|
+
exists: (path) => node_fs_promises.default.access(path).then(() => true, () => false)
|
|
762
770
|
};
|
|
763
771
|
/**
|
|
764
772
|
* Everything an action needs about the repository it is acting on.
|
|
@@ -770,11 +778,11 @@ function createWorktreeOperations(deps) {
|
|
|
770
778
|
const resolve = async (context) => {
|
|
771
779
|
const root = await git.repositoryRoot(context.cwd);
|
|
772
780
|
if (root === void 0) throw new PoGitExpectedError("not_a_repository", `${context.cwd} is not inside a git repository.`, false, "Run this from a repository checkout.");
|
|
773
|
-
const store = createWorktreeRegistry(registryFile(root, deps.homeDir));
|
|
781
|
+
const store = createWorktreeRegistry(await registryFile(root, deps.homeDir));
|
|
774
782
|
return {
|
|
775
783
|
root,
|
|
776
784
|
store,
|
|
777
|
-
records: store.list()
|
|
785
|
+
records: await store.list()
|
|
778
786
|
};
|
|
779
787
|
};
|
|
780
788
|
const require$1 = (records, id) => {
|
|
@@ -825,11 +833,11 @@ function createWorktreeOperations(deps) {
|
|
|
825
833
|
const expectedPath = worktreeDirectory({
|
|
826
834
|
worktreesRoot: worktreesRoot(deps.homeDir),
|
|
827
835
|
repositoryLabel: repositoryLabel(root),
|
|
828
|
-
repositoryId: repositoryId(root),
|
|
836
|
+
repositoryId: await repositoryId(root),
|
|
829
837
|
branch: request.branch,
|
|
830
838
|
shortId: shortId(reserved.sessionId)
|
|
831
839
|
});
|
|
832
|
-
if (existing.parentSessionId !== parentSessionId || existing.repositoryRoot !== root || existing.branch !== request.branch || existing.path !== expectedPath || existing.path !== reserved?.cwd || request.baseRef !== void 0 && existing.baseRef !== request.baseRef || !
|
|
840
|
+
if (existing.parentSessionId !== parentSessionId || existing.repositoryRoot !== root || existing.branch !== request.branch || existing.path !== expectedPath || existing.path !== reserved?.cwd || request.baseRef !== void 0 && existing.baseRef !== request.baseRef || !await probe.exists(existing.path) || !(await git.listWorktreePaths(root)).includes(existing.path) || await git.repositoryRoot(existing.path) !== existing.path || await git.currentBranch(existing.path) !== request.branch) throw new PoGitExpectedError("invalid_request", "The reserved checkout no longer matches this setup.", false, "Inspect the existing branch and checkout; they will not be replaced.");
|
|
833
841
|
if (!requireSessionService().isLive(existing.sessionId)) {
|
|
834
842
|
if ((await requireSessionService().create({
|
|
835
843
|
cwd: existing.path,
|
|
@@ -849,18 +857,18 @@ function createWorktreeOperations(deps) {
|
|
|
849
857
|
});
|
|
850
858
|
if (refusal !== void 0) throw new PoGitExpectedError("worktree_exists", refusal, false, "Pick another branch name, or close it.");
|
|
851
859
|
const taskDelivery = request.task === void 0 ? void 0 : requireSessionDelivery();
|
|
852
|
-
const setup = readWorktreeSetup(root);
|
|
860
|
+
const setup = await readWorktreeSetup(root);
|
|
853
861
|
const existingBranch = request.checkout === "existing";
|
|
854
862
|
const id = shortId(reserved?.sessionId ?? (0, node_crypto.randomUUID)());
|
|
855
863
|
let path = worktreeDirectory({
|
|
856
864
|
worktreesRoot: worktreesRoot(deps.homeDir),
|
|
857
865
|
repositoryLabel: repositoryLabel(root),
|
|
858
|
-
repositoryId: repositoryId(root),
|
|
866
|
+
repositoryId: await repositoryId(root),
|
|
859
867
|
branch: request.branch,
|
|
860
868
|
shortId: id
|
|
861
869
|
});
|
|
862
870
|
if (request.reservationId !== void 0) path = (await reservations.prepare(request.reservationId, parentSessionId, path)).cwd;
|
|
863
|
-
const recovering = reserved?.cwd !== void 0 &&
|
|
871
|
+
const recovering = reserved?.cwd !== void 0 && await probe.exists(path);
|
|
864
872
|
if (recovering && (!(await git.listWorktreePaths(root)).includes(path) || await git.currentBranch(path) !== request.branch)) throw new PoGitExpectedError("invalid_request", "The reserved checkout no longer matches this setup.", false, "Inspect the existing directory; it will not be replaced.");
|
|
865
873
|
if (!recovering) {
|
|
866
874
|
if (existingBranch) {
|
|
@@ -932,7 +940,7 @@ function createWorktreeOperations(deps) {
|
|
|
932
940
|
createdAt: now().toISOString()
|
|
933
941
|
};
|
|
934
942
|
try {
|
|
935
|
-
store.replace([...records, record]);
|
|
943
|
+
await store.replace([...records, record]);
|
|
936
944
|
} catch (error) {
|
|
937
945
|
await requireSessionService().close(sessionId).catch(() => void 0);
|
|
938
946
|
const kept = await rollback();
|
|
@@ -974,7 +982,7 @@ function createWorktreeOperations(deps) {
|
|
|
974
982
|
requireOwner(context, record, "close");
|
|
975
983
|
const refusal = refuseClose({
|
|
976
984
|
record,
|
|
977
|
-
dirtyFiles:
|
|
985
|
+
dirtyFiles: await probe.exists(record.path) ? await git.dirtyFiles(record.path) : [],
|
|
978
986
|
force
|
|
979
987
|
});
|
|
980
988
|
if (refusal !== void 0) throw new PoGitExpectedError("worktree_dirty", refusal, false, "Commit the work, or pass force: true.");
|
|
@@ -984,13 +992,13 @@ function createWorktreeOperations(deps) {
|
|
|
984
992
|
path: record.path,
|
|
985
993
|
force
|
|
986
994
|
});
|
|
987
|
-
store.replace(records.filter((entry) => entry.id !== id));
|
|
995
|
+
await store.replace(records.filter((entry) => entry.id !== id));
|
|
988
996
|
return record;
|
|
989
997
|
},
|
|
990
998
|
async list(context) {
|
|
991
999
|
const { store, records } = await resolve(context);
|
|
992
|
-
const outcome = reconcile(records, probe);
|
|
993
|
-
if (outcome.changed.length > 0) store.replace(outcome.records);
|
|
1000
|
+
const outcome = await reconcile(records, probe);
|
|
1001
|
+
if (outcome.changed.length > 0) await store.replace(outcome.records);
|
|
994
1002
|
return outcome.records;
|
|
995
1003
|
},
|
|
996
1004
|
async status(context, id) {
|
|
@@ -998,7 +1006,7 @@ function createWorktreeOperations(deps) {
|
|
|
998
1006
|
const record = require$1(records, id);
|
|
999
1007
|
return {
|
|
1000
1008
|
record,
|
|
1001
|
-
dirtyFiles:
|
|
1009
|
+
dirtyFiles: await probe.exists(record.path) ? await git.dirtyFiles(record.path) : []
|
|
1002
1010
|
};
|
|
1003
1011
|
},
|
|
1004
1012
|
async merge(context, id, message) {
|
|
@@ -1071,10 +1079,10 @@ function createWorktreeOperations(deps) {
|
|
|
1071
1079
|
},
|
|
1072
1080
|
async prune(context, dryRun) {
|
|
1073
1081
|
const { root, store, records } = await resolve(context);
|
|
1074
|
-
const reconciled = reconcile(records, probe);
|
|
1082
|
+
const reconciled = await reconcile(records, probe);
|
|
1075
1083
|
const gitPaths = await git.listWorktreePaths(root);
|
|
1076
1084
|
const dirtyByPath = /* @__PURE__ */ new Map();
|
|
1077
|
-
for (const record of reconciled.records) if (record.status === "orphaned" &&
|
|
1085
|
+
for (const record of reconciled.records) if (record.status === "orphaned" && await probe.exists(record.path)) dirtyByPath.set(record.path, await git.dirtyFiles(record.path));
|
|
1078
1086
|
const plan = planPrune({
|
|
1079
1087
|
records: reconciled.records,
|
|
1080
1088
|
gitPaths,
|
|
@@ -1082,7 +1090,7 @@ function createWorktreeOperations(deps) {
|
|
|
1082
1090
|
dirtyByPath
|
|
1083
1091
|
});
|
|
1084
1092
|
if (dryRun) {
|
|
1085
|
-
store.replace(reconciled.records);
|
|
1093
|
+
await store.replace(reconciled.records);
|
|
1086
1094
|
return plan;
|
|
1087
1095
|
}
|
|
1088
1096
|
for (const record of plan.remove) await git.removeWorktree({
|
|
@@ -1095,7 +1103,7 @@ function createWorktreeOperations(deps) {
|
|
|
1095
1103
|
branch: record.branch
|
|
1096
1104
|
}).catch(() => false)) plan.keptBranches.push(record.branch);
|
|
1097
1105
|
const dropped = new Set([...plan.remove, ...plan.forget].map((record) => record.id));
|
|
1098
|
-
store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));
|
|
1106
|
+
await store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));
|
|
1099
1107
|
return plan;
|
|
1100
1108
|
}
|
|
1101
1109
|
};
|
|
@@ -1292,4 +1300,4 @@ Object.defineProperty(exports, "writeJsonAtomic", {
|
|
|
1292
1300
|
}
|
|
1293
1301
|
});
|
|
1294
1302
|
|
|
1295
|
-
//# sourceMappingURL=worktreeOperations-
|
|
1303
|
+
//# sourceMappingURL=worktreeOperations-C1ygq-Na.cjs.map
|