@moberg_hr/work-tree 1.16.0 → 2.0.1
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 +56 -142
- package/dist/answer-2J4XLIP7.js +63 -0
- package/dist/answer-2J4XLIP7.js.map +1 -0
- package/dist/attach-CZKRNPAJ.js +59 -0
- package/dist/attach-CZKRNPAJ.js.map +1 -0
- package/dist/bin.js +26 -11924
- package/dist/bin.js.map +1 -1
- package/dist/block-RAIDCJ4F.js +84 -0
- package/dist/block-RAIDCJ4F.js.map +1 -0
- package/dist/broadcast-BSI5NDDB.js +104 -0
- package/dist/broadcast-BSI5NDDB.js.map +1 -0
- package/dist/catchup-VVOPL2S5.js +51 -0
- package/dist/catchup-VVOPL2S5.js.map +1 -0
- package/dist/chunk-3JWTO5VZ.js +135 -0
- package/dist/chunk-3JWTO5VZ.js.map +1 -0
- package/dist/chunk-4BOK2GXL.js +210 -0
- package/dist/chunk-4BOK2GXL.js.map +1 -0
- package/dist/chunk-5QK7GB5K.js +112 -0
- package/dist/chunk-5QK7GB5K.js.map +1 -0
- package/dist/chunk-6AQRYLOB.js +16 -0
- package/dist/chunk-6AQRYLOB.js.map +1 -0
- package/dist/chunk-6FTIY5M6.js +120 -0
- package/dist/chunk-6FTIY5M6.js.map +1 -0
- package/dist/chunk-6H3MLDGG.js +48 -0
- package/dist/chunk-6H3MLDGG.js.map +1 -0
- package/dist/chunk-77XFJQGC.js +103 -0
- package/dist/chunk-77XFJQGC.js.map +1 -0
- package/dist/chunk-7HEB6SQS.js +257 -0
- package/dist/chunk-7HEB6SQS.js.map +1 -0
- package/dist/chunk-7NAXFBFI.js +206 -0
- package/dist/chunk-7NAXFBFI.js.map +1 -0
- package/dist/chunk-7NCW3LUT.js +358 -0
- package/dist/chunk-7NCW3LUT.js.map +1 -0
- package/dist/chunk-7OLPI334.js +537 -0
- package/dist/chunk-7OLPI334.js.map +1 -0
- package/dist/chunk-ABQYKTG4.js +38 -0
- package/dist/chunk-ABQYKTG4.js.map +1 -0
- package/dist/chunk-AH5TM3NB.js +21 -0
- package/dist/chunk-AH5TM3NB.js.map +1 -0
- package/dist/chunk-AKMPF72Y.js +274 -0
- package/dist/chunk-AKMPF72Y.js.map +1 -0
- package/dist/chunk-BR6OPEE4.js +162 -0
- package/dist/chunk-BR6OPEE4.js.map +1 -0
- package/dist/chunk-C2BK6EBN.js +162 -0
- package/dist/chunk-C2BK6EBN.js.map +1 -0
- package/dist/chunk-C2THFSXA.js +37 -0
- package/dist/chunk-C2THFSXA.js.map +1 -0
- package/dist/chunk-C7W5TMFB.js +308 -0
- package/dist/chunk-C7W5TMFB.js.map +1 -0
- package/dist/chunk-CLGVSX36.js +668 -0
- package/dist/chunk-CLGVSX36.js.map +1 -0
- package/dist/chunk-CVAVYDXO.js +295 -0
- package/dist/chunk-CVAVYDXO.js.map +1 -0
- package/dist/chunk-DW4JPVXB.js +41 -0
- package/dist/chunk-DW4JPVXB.js.map +1 -0
- package/dist/chunk-FPKERDK7.js +142 -0
- package/dist/chunk-FPKERDK7.js.map +1 -0
- package/dist/chunk-FR3EWVXI.js +188 -0
- package/dist/chunk-FR3EWVXI.js.map +1 -0
- package/dist/chunk-H5LKMR45.js +117 -0
- package/dist/chunk-H5LKMR45.js.map +1 -0
- package/dist/chunk-HIZBWYPL.js +267 -0
- package/dist/chunk-HIZBWYPL.js.map +1 -0
- package/dist/chunk-HSICXDMZ.js +41 -0
- package/dist/chunk-HSICXDMZ.js.map +1 -0
- package/dist/chunk-HUXS3VAI.js +90 -0
- package/dist/chunk-HUXS3VAI.js.map +1 -0
- package/dist/chunk-HWUINPIL.js +151 -0
- package/dist/chunk-HWUINPIL.js.map +1 -0
- package/dist/chunk-IXKVCR4Y.js +487 -0
- package/dist/chunk-IXKVCR4Y.js.map +1 -0
- package/dist/chunk-JNBYNRFS.js +54 -0
- package/dist/chunk-JNBYNRFS.js.map +1 -0
- package/dist/chunk-JYTMT5DF.js +421 -0
- package/dist/chunk-JYTMT5DF.js.map +1 -0
- package/dist/chunk-KGZ6OZ2T.js +102 -0
- package/dist/chunk-KGZ6OZ2T.js.map +1 -0
- package/dist/chunk-LMIEEDDC.js +9 -0
- package/dist/chunk-LMIEEDDC.js.map +1 -0
- package/dist/chunk-LNHSBM4L.js +26 -0
- package/dist/chunk-LNHSBM4L.js.map +1 -0
- package/dist/chunk-M4FVCAT6.js +2406 -0
- package/dist/chunk-M4FVCAT6.js.map +1 -0
- package/dist/chunk-N4EYQKSM.js +104 -0
- package/dist/chunk-N4EYQKSM.js.map +1 -0
- package/dist/chunk-NDWSLQPB.js +112 -0
- package/dist/chunk-NDWSLQPB.js.map +1 -0
- package/dist/chunk-O3QTWVSK.js +323 -0
- package/dist/chunk-O3QTWVSK.js.map +1 -0
- package/dist/chunk-P3BL4EOP.js +37 -0
- package/dist/chunk-P3BL4EOP.js.map +1 -0
- package/dist/chunk-PN44M5EE.js +887 -0
- package/dist/chunk-PN44M5EE.js.map +1 -0
- package/dist/chunk-Q6WZCO45.js +47 -0
- package/dist/chunk-Q6WZCO45.js.map +1 -0
- package/dist/chunk-QBAZG4CY.js +230 -0
- package/dist/chunk-QBAZG4CY.js.map +1 -0
- package/dist/chunk-R2LN3JJJ.js +132 -0
- package/dist/chunk-R2LN3JJJ.js.map +1 -0
- package/dist/chunk-RCYI7SRA.js +15 -0
- package/dist/chunk-RCYI7SRA.js.map +1 -0
- package/dist/chunk-RYNBBSLY.js +67 -0
- package/dist/chunk-RYNBBSLY.js.map +1 -0
- package/dist/chunk-S5HJT7CM.js +30 -0
- package/dist/chunk-S5HJT7CM.js.map +1 -0
- package/dist/chunk-SNAQOHNL.js +285 -0
- package/dist/chunk-SNAQOHNL.js.map +1 -0
- package/dist/chunk-SOCPIHCS.js +181 -0
- package/dist/chunk-SOCPIHCS.js.map +1 -0
- package/dist/chunk-TUC4QY4O.js +147 -0
- package/dist/chunk-TUC4QY4O.js.map +1 -0
- package/dist/chunk-TUFQJXXO.js +19 -0
- package/dist/chunk-TUFQJXXO.js.map +1 -0
- package/dist/chunk-UFY7C5PP.js +90 -0
- package/dist/chunk-UFY7C5PP.js.map +1 -0
- package/dist/chunk-UQ35KLHH.js +34 -0
- package/dist/chunk-UQ35KLHH.js.map +1 -0
- package/dist/chunk-VJ7SVDED.js +177 -0
- package/dist/chunk-VJ7SVDED.js.map +1 -0
- package/dist/chunk-VJNSIDOA.js +23 -0
- package/dist/chunk-VJNSIDOA.js.map +1 -0
- package/dist/chunk-WF5SBVPZ.js +190 -0
- package/dist/chunk-WF5SBVPZ.js.map +1 -0
- package/dist/chunk-WMJIU3YW.js +29 -0
- package/dist/chunk-WMJIU3YW.js.map +1 -0
- package/dist/chunk-XJDEROHY.js +19 -0
- package/dist/chunk-XJDEROHY.js.map +1 -0
- package/dist/chunk-YKODIG22.js +221 -0
- package/dist/chunk-YKODIG22.js.map +1 -0
- package/dist/chunk-YNKWLC45.js +122 -0
- package/dist/chunk-YNKWLC45.js.map +1 -0
- package/dist/chunk-YZDD5YGE.js +165 -0
- package/dist/chunk-YZDD5YGE.js.map +1 -0
- package/dist/chunk-YZWADOEW.js +151 -0
- package/dist/chunk-YZWADOEW.js.map +1 -0
- package/dist/chunk-ZJN5RWZD.js +76 -0
- package/dist/chunk-ZJN5RWZD.js.map +1 -0
- package/dist/chunk-ZSHWP2VS.js +22 -0
- package/dist/chunk-ZSHWP2VS.js.map +1 -0
- package/dist/chunk-ZXPYWZL5.js +307 -0
- package/dist/chunk-ZXPYWZL5.js.map +1 -0
- package/dist/cleanup-LDBGWEKZ.js +192 -0
- package/dist/cleanup-LDBGWEKZ.js.map +1 -0
- package/dist/cli-UATB4RM2.js +18 -0
- package/dist/cli-UATB4RM2.js.map +1 -0
- package/dist/command-hook-installer-SGEJTZ2Y.js +204 -0
- package/dist/command-hook-installer-SGEJTZ2Y.js.map +1 -0
- package/dist/completion-MXX5TRIV.js +118 -0
- package/dist/completion-MXX5TRIV.js.map +1 -0
- package/dist/config-IEIU7A66.js +410 -0
- package/dist/config-IEIU7A66.js.map +1 -0
- package/dist/console-reporter-XU6VFUZE.js +10 -0
- package/dist/console-reporter-XU6VFUZE.js.map +1 -0
- package/dist/diff-K47HB6SA.js +582 -0
- package/dist/diff-K47HB6SA.js.map +1 -0
- package/dist/digest-FBZTBXQO.js +100 -0
- package/dist/digest-FBZTBXQO.js.map +1 -0
- package/dist/fork-BKI5UNNS.js +120 -0
- package/dist/fork-BKI5UNNS.js.map +1 -0
- package/dist/hook-SLMZT5OV.js +220 -0
- package/dist/hook-SLMZT5OV.js.map +1 -0
- package/dist/hydrate-Y2AAMZTA.js +121 -0
- package/dist/hydrate-Y2AAMZTA.js.map +1 -0
- package/dist/init-7ESFTYZC.js +187 -0
- package/dist/init-7ESFTYZC.js.map +1 -0
- package/dist/install-skills-O34BHFHD.js +14 -0
- package/dist/install-skills-O34BHFHD.js.map +1 -0
- package/dist/install-skills-bin.js +12 -0
- package/dist/install-skills-bin.js.map +1 -0
- package/dist/list-KEF73NLQ.js +126 -0
- package/dist/list-KEF73NLQ.js.map +1 -0
- package/dist/move-FKT2P5LY.js +313 -0
- package/dist/move-FKT2P5LY.js.map +1 -0
- package/dist/note-WGM6LCP2.js +78 -0
- package/dist/note-WGM6LCP2.js.map +1 -0
- package/dist/overlaps-FRLMMIGC.js +56 -0
- package/dist/overlaps-FRLMMIGC.js.map +1 -0
- package/dist/pin-MQ5ZE37R.js +45 -0
- package/dist/pin-MQ5ZE37R.js.map +1 -0
- package/dist/pr-527S5HXB.js +122 -0
- package/dist/pr-527S5HXB.js.map +1 -0
- package/dist/prune-AIS5YEXP.js +92 -0
- package/dist/prune-AIS5YEXP.js.map +1 -0
- package/dist/pty-host-RWIS55N4.js +826 -0
- package/dist/pty-host-RWIS55N4.js.map +1 -0
- package/dist/read-AP6T3ZGN.js +57 -0
- package/dist/read-AP6T3ZGN.js.map +1 -0
- package/dist/recent-IE3LYQ65.js +111 -0
- package/dist/recent-IE3LYQ65.js.map +1 -0
- package/dist/remove-YGUTSKZP.js +108 -0
- package/dist/remove-YGUTSKZP.js.map +1 -0
- package/dist/report-KM4OZCZB.js +16 -0
- package/dist/report-KM4OZCZB.js.map +1 -0
- package/dist/resume-UUP6R2IE.js +81 -0
- package/dist/resume-UUP6R2IE.js.map +1 -0
- package/dist/run-V4755W7C.js +263 -0
- package/dist/run-V4755W7C.js.map +1 -0
- package/dist/screen-DNX4K23V.js +58 -0
- package/dist/screen-DNX4K23V.js.map +1 -0
- package/dist/search-3JZXLCR2.js +46 -0
- package/dist/search-3JZXLCR2.js.map +1 -0
- package/dist/section-TXLC5XO3.js +79 -0
- package/dist/section-TXLC5XO3.js.map +1 -0
- package/dist/send-6X46WZLC.js +87 -0
- package/dist/send-6X46WZLC.js.map +1 -0
- package/dist/sessions-T3QDTNP7.js +135 -0
- package/dist/sessions-T3QDTNP7.js.map +1 -0
- package/dist/snooze-KYSFXLPY.js +65 -0
- package/dist/snooze-KYSFXLPY.js.map +1 -0
- package/dist/start-SQSDQK4F.js +56 -0
- package/dist/start-SQSDQK4F.js.map +1 -0
- package/dist/state-4DFV6SHG.js +147 -0
- package/dist/state-4DFV6SHG.js.map +1 -0
- package/dist/status-H5OW4LYE.js +118 -0
- package/dist/status-H5OW4LYE.js.map +1 -0
- package/dist/stop-HC7XPSSP.js +45 -0
- package/dist/stop-HC7XPSSP.js.map +1 -0
- package/dist/sync-ITK5UYGM.js +96 -0
- package/dist/sync-ITK5UYGM.js.map +1 -0
- package/dist/time-GN6B4QD6.js +111 -0
- package/dist/time-GN6B4QD6.js.map +1 -0
- package/dist/todo-LWMQY6XW.js +152 -0
- package/dist/todo-LWMQY6XW.js.map +1 -0
- package/dist/tree-7BMORJ6J.js +235 -0
- package/dist/tree-7BMORJ6J.js.map +1 -0
- package/dist/update-6LQNLRA4.js +57 -0
- package/dist/update-6LQNLRA4.js.map +1 -0
- package/dist/wait-MZOZQ3CI.js +57 -0
- package/dist/wait-MZOZQ3CI.js.map +1 -0
- package/dist/wd-bin.js +21 -11912
- package/dist/wd-bin.js.map +1 -1
- package/dist/web/assets/PtyView-BrP-ENHg.css +1 -0
- package/dist/web/assets/PtyView-DYvawzWb.js +90 -0
- package/dist/web/assets/PtyView-DYvawzWb.js.map +1 -0
- package/dist/web/assets/index-C5lJhIwK.js +116 -0
- package/dist/web/assets/index-C5lJhIwK.js.map +1 -0
- package/dist/web/assets/index-L8mjakHP.css +1 -0
- package/dist/web/index.html +3 -5
- package/dist/web-IC3P7EHZ.js +7689 -0
- package/dist/web-IC3P7EHZ.js.map +1 -0
- package/npm-shrinkwrap.json +6947 -0
- package/package.json +52 -34
- package/plugins/work-tree/.claude-plugin/plugin.json +1 -1
- package/plugins/work-tree/skills/wd-review/SKILL.md +4 -4
- package/plugins/work-tree/skills/work-sessions/SKILL.md +62 -0
- package/scripts/postinstall.mjs +15 -45
- package/dist/web/assets/index-B9H3vCtL.js +0 -107
- package/dist/web/assets/index-B9H3vCtL.js.map +0 -1
- package/dist/web/assets/index-BseMpW5i.css +0 -1
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
resolveProjectTarget
|
|
4
|
+
} from "./chunk-H5LKMR45.js";
|
|
5
|
+
import {
|
|
6
|
+
getCurrentBranch,
|
|
7
|
+
getStatusChecked,
|
|
8
|
+
getUnpushedCommits,
|
|
9
|
+
git,
|
|
10
|
+
isGitRepo,
|
|
11
|
+
localBranchExists,
|
|
12
|
+
parseWorktreeList,
|
|
13
|
+
remoteBranchExists,
|
|
14
|
+
repoState
|
|
15
|
+
} from "./chunk-7NAXFBFI.js";
|
|
16
|
+
import {
|
|
17
|
+
archiveDirFor,
|
|
18
|
+
archiveRoot,
|
|
19
|
+
bestEffort,
|
|
20
|
+
findSession,
|
|
21
|
+
forgetOtherBaseCheckoutEntries,
|
|
22
|
+
loadHistory,
|
|
23
|
+
readArchive,
|
|
24
|
+
restoreArchivedTranscripts,
|
|
25
|
+
restoreUncommitted,
|
|
26
|
+
setSessionTitle,
|
|
27
|
+
upsertSession,
|
|
28
|
+
upsertSessionWithPort,
|
|
29
|
+
writeArchiveRecord
|
|
30
|
+
} from "./chunk-M4FVCAT6.js";
|
|
31
|
+
import {
|
|
32
|
+
sessionIdFor
|
|
33
|
+
} from "./chunk-7NCW3LUT.js";
|
|
34
|
+
import {
|
|
35
|
+
agentFor
|
|
36
|
+
} from "./chunk-PN44M5EE.js";
|
|
37
|
+
import {
|
|
38
|
+
report
|
|
39
|
+
} from "./chunk-DW4JPVXB.js";
|
|
40
|
+
import {
|
|
41
|
+
debug
|
|
42
|
+
} from "./chunk-N4EYQKSM.js";
|
|
43
|
+
import {
|
|
44
|
+
getConfigDir
|
|
45
|
+
} from "./chunk-7HEB6SQS.js";
|
|
46
|
+
|
|
47
|
+
// src/core/git/base-spec.ts
|
|
48
|
+
var BaseSpecError = class extends Error {
|
|
49
|
+
constructor(message) {
|
|
50
|
+
super(message);
|
|
51
|
+
this.name = "BaseSpecError";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function parseBaseSpec(raw) {
|
|
55
|
+
const spec = { perRepo: {} };
|
|
56
|
+
if (raw === void 0) return spec;
|
|
57
|
+
const values = Array.isArray(raw) ? raw : [raw];
|
|
58
|
+
for (const value of values) {
|
|
59
|
+
const v = value.trim();
|
|
60
|
+
if (!v) continue;
|
|
61
|
+
const eq = v.indexOf("=");
|
|
62
|
+
if (eq === -1) {
|
|
63
|
+
if (spec.default !== void 0 && spec.default !== v) {
|
|
64
|
+
throw new BaseSpecError(`Conflicting default --base values: '${spec.default}' and '${v}'`);
|
|
65
|
+
}
|
|
66
|
+
spec.default = v;
|
|
67
|
+
} else {
|
|
68
|
+
const alias = v.slice(0, eq).trim();
|
|
69
|
+
const branch = v.slice(eq + 1).trim();
|
|
70
|
+
if (!alias || !branch) {
|
|
71
|
+
throw new BaseSpecError(`Invalid --base '${value}'. Use 'alias=branch' or a bare 'branch'.`);
|
|
72
|
+
}
|
|
73
|
+
const prior = spec.perRepo[alias];
|
|
74
|
+
if (prior !== void 0 && prior !== branch) {
|
|
75
|
+
throw new BaseSpecError(`Conflicting --base for '${alias}': '${prior}' and '${branch}'`);
|
|
76
|
+
}
|
|
77
|
+
spec.perRepo[alias] = branch;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return spec;
|
|
81
|
+
}
|
|
82
|
+
function baseForAlias(spec, alias) {
|
|
83
|
+
return spec.perRepo[alias] ?? spec.default;
|
|
84
|
+
}
|
|
85
|
+
function isEmptyBaseSpec(spec) {
|
|
86
|
+
return spec.default === void 0 && Object.keys(spec.perRepo).length === 0;
|
|
87
|
+
}
|
|
88
|
+
function baseSpecOverrideAliases(spec) {
|
|
89
|
+
return Object.keys(spec.perRepo);
|
|
90
|
+
}
|
|
91
|
+
function toBaseSpec(base) {
|
|
92
|
+
if (base === void 0) return { perRepo: {} };
|
|
93
|
+
if (typeof base === "string") return { default: base, perRepo: {} };
|
|
94
|
+
return base;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/core/worktree/worktree.ts
|
|
98
|
+
import fs2 from "fs";
|
|
99
|
+
|
|
100
|
+
// src/core/archive/archive-restore.ts
|
|
101
|
+
import path from "path";
|
|
102
|
+
async function restoreArchivedUncommitted(s, config, root = archiveRoot()) {
|
|
103
|
+
const id = sessionIdFor(s);
|
|
104
|
+
const rec = readArchive(id, root);
|
|
105
|
+
const out = { restored: [], failed: [] };
|
|
106
|
+
if (!rec?.worktreeRemoved || !rec.uncommitted) return out;
|
|
107
|
+
const dir = archiveDirFor(id, root);
|
|
108
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
109
|
+
let changed = false;
|
|
110
|
+
for (const [alias, saved] of Object.entries(rec.uncommitted)) {
|
|
111
|
+
if (saved.restoredAt || saved.restoreError) continue;
|
|
112
|
+
const wt = worktreeFor(s, alias, config);
|
|
113
|
+
const r = wt ? await restoreUncommitted(wt, saved, dir) : { ok: false, error: `no worktree of ${alias} in the session` };
|
|
114
|
+
if (r.ok) {
|
|
115
|
+
saved.restoredAt = now;
|
|
116
|
+
out.restored.push(alias);
|
|
117
|
+
report("info", `${alias}: put back ${saved.files} uncommitted file${saved.files === 1 ? "" : "s"} saved when it was archived`);
|
|
118
|
+
} else {
|
|
119
|
+
saved.restoreError = r.error;
|
|
120
|
+
out.failed.push({ repo: alias, error: r.error });
|
|
121
|
+
report("warn", `${alias}: its uncommitted changes from the archive weren't put back: ${r.error}`);
|
|
122
|
+
}
|
|
123
|
+
changed = true;
|
|
124
|
+
}
|
|
125
|
+
if (changed) writeArchiveRecord(rec, root);
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
function worktreeFor(s, alias, config) {
|
|
129
|
+
if (!s.isGroup) return s.paths[0] ?? null;
|
|
130
|
+
const repo = config.repos[alias];
|
|
131
|
+
if (!repo) return null;
|
|
132
|
+
const name = path.basename(repo).toLowerCase();
|
|
133
|
+
return s.paths.find((p) => path.basename(p).toLowerCase() === name) ?? null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/core/worktree/worktree.ts
|
|
137
|
+
import path3 from "path";
|
|
138
|
+
|
|
139
|
+
// src/core/worktree/copy-files.ts
|
|
140
|
+
import fs from "fs";
|
|
141
|
+
import path2 from "path";
|
|
142
|
+
import { globSync } from "glob";
|
|
143
|
+
var EXCLUDED_DIRS = ["bin", "obj", "node_modules", ".git"];
|
|
144
|
+
function copyConfigFiles(repoPath, worktreePath, patterns) {
|
|
145
|
+
for (const pattern of patterns) {
|
|
146
|
+
const normalized = pattern.replace(/\\/g, "/");
|
|
147
|
+
if (normalized.startsWith(".claude/")) {
|
|
148
|
+
const relativePath = normalized;
|
|
149
|
+
const sourcePath = path2.join(repoPath, relativePath);
|
|
150
|
+
if (fs.existsSync(sourcePath)) {
|
|
151
|
+
const destPath = path2.join(worktreePath, relativePath);
|
|
152
|
+
const destDir = path2.dirname(destPath);
|
|
153
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
154
|
+
fs.copyFileSync(sourcePath, destPath);
|
|
155
|
+
report("info", ` Copied: ${relativePath}`);
|
|
156
|
+
}
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const matches = globSync(`**/${normalized}`, {
|
|
160
|
+
cwd: repoPath,
|
|
161
|
+
nodir: true,
|
|
162
|
+
posix: true,
|
|
163
|
+
dot: true
|
|
164
|
+
});
|
|
165
|
+
for (const match of matches) {
|
|
166
|
+
const parts = match.split("/");
|
|
167
|
+
if (parts.some((p) => EXCLUDED_DIRS.includes(p))) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const sourcePath = path2.join(repoPath, match);
|
|
171
|
+
const destPath = path2.join(worktreePath, match);
|
|
172
|
+
const destDir = path2.dirname(destPath);
|
|
173
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
174
|
+
fs.copyFileSync(sourcePath, destPath);
|
|
175
|
+
report("info", ` Copied: ${match}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/core/worktree/worktree.ts
|
|
181
|
+
function pullLatestForBranch(worktreePath, branchName) {
|
|
182
|
+
const upstream = git(["rev-parse", "--abbrev-ref", `${branchName}@{upstream}`], worktreePath);
|
|
183
|
+
if (upstream.exitCode !== 0) return;
|
|
184
|
+
report("info", ` Pulling latest changes for ${branchName}...`);
|
|
185
|
+
git(["fetch", "--quiet"], worktreePath);
|
|
186
|
+
const pull = git(["pull", "--quiet"], worktreePath);
|
|
187
|
+
if (pull.exitCode !== 0) {
|
|
188
|
+
report("warn", ` \u26A0 Could not pull '${branchName}' (uncommitted changes or conflicts). Worktree may be behind origin.`);
|
|
189
|
+
const firstErrLine = pull.stderr.split("\n")[0];
|
|
190
|
+
if (firstErrLine) report("detail", ` ${firstErrLine}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function samePath(a, b) {
|
|
194
|
+
const norm = (p) => {
|
|
195
|
+
let r = path3.resolve(p);
|
|
196
|
+
try {
|
|
197
|
+
r = fs2.realpathSync.native(r);
|
|
198
|
+
} catch {
|
|
199
|
+
}
|
|
200
|
+
return process.platform === "win32" ? r.toLowerCase() : r;
|
|
201
|
+
};
|
|
202
|
+
return norm(a) === norm(b);
|
|
203
|
+
}
|
|
204
|
+
function createSingleWorktree(repoPath, worktreePath, branchName, config, baseBranch, pull = true) {
|
|
205
|
+
debug("createSingleWorktree", { repoPath, worktreePath, branchName, baseBranch });
|
|
206
|
+
if (fs2.existsSync(worktreePath)) {
|
|
207
|
+
if (isGitRepo(worktreePath)) {
|
|
208
|
+
const currentBranch = getCurrentBranch(worktreePath);
|
|
209
|
+
if (currentBranch === branchName) {
|
|
210
|
+
report("warn", ` Worktree already exists at: ${worktreePath}`);
|
|
211
|
+
if (pull) pullLatestForBranch(worktreePath, branchName);
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
const ours = parseWorktreeList(repoPath).some((wt) => samePath(wt.path, worktreePath));
|
|
215
|
+
if (ours) {
|
|
216
|
+
report(
|
|
217
|
+
"warn",
|
|
218
|
+
` Worktree already exists at: ${worktreePath} (on ${currentBranch ?? "a detached HEAD"}, not ${branchName}: using it as it is)`
|
|
219
|
+
);
|
|
220
|
+
if (pull && currentBranch) pullLatestForBranch(worktreePath, currentBranch);
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const worktrees = parseWorktreeList(repoPath);
|
|
226
|
+
const existingForBranch = worktrees.find((wt) => wt.branch === branchName && wt.path !== worktreePath);
|
|
227
|
+
if (existingForBranch) {
|
|
228
|
+
report("error", ` Branch '${branchName}' is already checked out in a worktree at: ${existingForBranch.path}`);
|
|
229
|
+
report("error", " Remove that worktree first, or use the existing one.");
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const parentDir = path3.dirname(worktreePath);
|
|
233
|
+
fs2.mkdirSync(parentDir, { recursive: true });
|
|
234
|
+
git(["fetch", "--quiet"], repoPath);
|
|
235
|
+
const baseRepoBranch = getCurrentBranch(repoPath);
|
|
236
|
+
const baseBranchLabel = baseRepoBranch ?? "(detached HEAD)";
|
|
237
|
+
report("info", ` Pulling latest changes for main repo (on ${baseBranchLabel})...`);
|
|
238
|
+
if (baseRepoBranch && !["master", "main", "dev"].includes(baseRepoBranch)) {
|
|
239
|
+
report("warn", ` \u26A0 Warning: base repo is on '${baseRepoBranch}', not master/main/dev`);
|
|
240
|
+
}
|
|
241
|
+
const baseRepoPull = git(["pull", "--quiet"], repoPath);
|
|
242
|
+
const baseRepoPullFailed = baseRepoPull.exitCode !== 0;
|
|
243
|
+
if (baseRepoPullFailed) {
|
|
244
|
+
report("warn", ` \u26A0 Could not pull '${baseBranchLabel}' (uncommitted changes, conflicts, or no upstream).`);
|
|
245
|
+
const firstErrLine = baseRepoPull.stderr.split("\n")[0];
|
|
246
|
+
if (firstErrLine) report("detail", ` ${firstErrLine}`);
|
|
247
|
+
}
|
|
248
|
+
const hasLocal = localBranchExists(branchName, repoPath);
|
|
249
|
+
const hasRemote = remoteBranchExists(branchName, repoPath);
|
|
250
|
+
if (baseBranch && (hasLocal || hasRemote)) {
|
|
251
|
+
report("error", ` Cannot use --base: branch '${branchName}' already exists ${hasLocal ? "locally" : "on remote"}`);
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
if (hasLocal) {
|
|
255
|
+
report("info", ` Pulling latest changes for ${branchName}...`);
|
|
256
|
+
const prevBranch = getCurrentBranch(repoPath);
|
|
257
|
+
git(["checkout", branchName, "--quiet"], repoPath);
|
|
258
|
+
const branchPull = git(["pull", "--quiet"], repoPath);
|
|
259
|
+
if (branchPull.exitCode !== 0) {
|
|
260
|
+
report("warn", ` \u26A0 Could not pull '${branchName}'. Worktree may be behind origin.`);
|
|
261
|
+
const firstErrLine = branchPull.stderr.split("\n")[0];
|
|
262
|
+
if (firstErrLine) report("detail", ` ${firstErrLine}`);
|
|
263
|
+
}
|
|
264
|
+
if (prevBranch) {
|
|
265
|
+
git(["checkout", prevBranch, "--quiet"], repoPath);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
let result;
|
|
269
|
+
let branchSource = "new";
|
|
270
|
+
if (hasLocal || hasRemote) {
|
|
271
|
+
if (hasRemote && !hasLocal) {
|
|
272
|
+
branchSource = "remote";
|
|
273
|
+
result = git(["worktree", "add", worktreePath, "-b", branchName, "--track", `origin/${branchName}`], repoPath);
|
|
274
|
+
} else {
|
|
275
|
+
branchSource = "local";
|
|
276
|
+
result = git(["worktree", "add", worktreePath, branchName], repoPath);
|
|
277
|
+
}
|
|
278
|
+
} else if (baseBranch) {
|
|
279
|
+
const baseLocal = localBranchExists(baseBranch, repoPath);
|
|
280
|
+
const baseRemote = remoteBranchExists(baseBranch, repoPath);
|
|
281
|
+
if (!baseLocal && !baseRemote) {
|
|
282
|
+
report("error", ` Base branch '${baseBranch}' does not exist locally or on remote`);
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
const baseRef = baseLocal ? baseBranch : `origin/${baseBranch}`;
|
|
286
|
+
result = git(["worktree", "add", worktreePath, "-b", branchName, baseRef], repoPath);
|
|
287
|
+
} else {
|
|
288
|
+
const fallbackToRemote = baseRepoPullFailed && !!baseRepoBranch && remoteBranchExists(baseRepoBranch, repoPath);
|
|
289
|
+
if (fallbackToRemote) {
|
|
290
|
+
report("step", ` Using origin/${baseRepoBranch} as base (local '${baseRepoBranch}' is stale)`);
|
|
291
|
+
result = git(["worktree", "add", worktreePath, "-b", branchName, `origin/${baseRepoBranch}`], repoPath);
|
|
292
|
+
} else {
|
|
293
|
+
result = git(["worktree", "add", worktreePath, "-b", branchName], repoPath);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (result.exitCode !== 0) {
|
|
297
|
+
debug("git worktree add failed", { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr });
|
|
298
|
+
report("error", " Failed to create worktree");
|
|
299
|
+
if (result.stderr) {
|
|
300
|
+
report("error", ` ${result.stderr}`);
|
|
301
|
+
}
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
if (config.copyFiles && config.copyFiles.length > 0) {
|
|
305
|
+
copyConfigFiles(repoPath, worktreePath, config.copyFiles);
|
|
306
|
+
}
|
|
307
|
+
if (branchSource === "remote") {
|
|
308
|
+
report("step", ` Tracking remote branch origin/${branchName}`);
|
|
309
|
+
} else if (branchSource === "local") {
|
|
310
|
+
report("step", ` Using existing local branch ${branchName}`);
|
|
311
|
+
} else if (baseBranch) {
|
|
312
|
+
report("step", ` Created new branch ${branchName} from ${baseBranch}`);
|
|
313
|
+
} else {
|
|
314
|
+
report("step", ` Created new branch ${branchName}`);
|
|
315
|
+
}
|
|
316
|
+
report("success", ` Created worktree: ${worktreePath}`);
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
function wouldRefuseRemoval(worktreePath, force) {
|
|
320
|
+
if (force || !fs2.existsSync(worktreePath)) return false;
|
|
321
|
+
const state = repoState(worktreePath);
|
|
322
|
+
if (state === "not-a-repo") return false;
|
|
323
|
+
if (state === "unknown") return true;
|
|
324
|
+
const status = getStatusChecked(worktreePath);
|
|
325
|
+
if (status === null) return true;
|
|
326
|
+
return !!status || !!getUnpushedCommits(worktreePath);
|
|
327
|
+
}
|
|
328
|
+
function isDeleteFailure(stderr) {
|
|
329
|
+
return /failed to delete/i.test(stderr);
|
|
330
|
+
}
|
|
331
|
+
function removeSingleWorktree(repoPath, worktreePath, branchName, force) {
|
|
332
|
+
if (!fs2.existsSync(worktreePath)) {
|
|
333
|
+
report("warn", ` Worktree does not exist at: ${worktreePath}`);
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
const state = repoState(worktreePath);
|
|
337
|
+
if (state === "not-a-repo") {
|
|
338
|
+
fs2.rmSync(worktreePath, { recursive: true, force: true });
|
|
339
|
+
git(["worktree", "prune"], repoPath);
|
|
340
|
+
report("info", ` Removed invalid worktree directory: ${worktreePath}`);
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
if (state === "unknown" && !force) {
|
|
344
|
+
report(
|
|
345
|
+
"warn",
|
|
346
|
+
` git can't read ${worktreePath} (ownership, a moved main repo, git not on PATH?) \u2014 not removing it. Check it, or use --force.`
|
|
347
|
+
);
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
if (!force) {
|
|
351
|
+
const status = getStatusChecked(worktreePath);
|
|
352
|
+
if (status === null) {
|
|
353
|
+
report("warn", ` Could not check ${worktreePath} for uncommitted changes \u2014 not removing it.`);
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
if (status) {
|
|
357
|
+
report("warn", ` Uncommitted changes in: ${worktreePath}`);
|
|
358
|
+
report("info", status);
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
const unpushed = getUnpushedCommits(worktreePath);
|
|
362
|
+
if (unpushed) {
|
|
363
|
+
report("warn", ` Unpushed commits in: ${worktreePath}`);
|
|
364
|
+
report("info", unpushed);
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const args = force ? ["-c", "core.longpaths=true", "worktree", "remove", worktreePath, "--force"] : ["-c", "core.longpaths=true", "worktree", "remove", worktreePath];
|
|
369
|
+
const result = git(args, repoPath);
|
|
370
|
+
if (result.exitCode === 0) {
|
|
371
|
+
report("success", ` Removed worktree: ${worktreePath}`);
|
|
372
|
+
return true;
|
|
373
|
+
} else if (isDeleteFailure(result.stderr)) {
|
|
374
|
+
try {
|
|
375
|
+
fs2.rmSync(worktreePath, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 });
|
|
376
|
+
} catch (err) {
|
|
377
|
+
report("error", ` Failed to remove worktree: ${worktreePath}`);
|
|
378
|
+
report("error", ` ${err.message}`);
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
git(["worktree", "prune"], repoPath);
|
|
382
|
+
const why = result.stderr.split("\n")[0].replace(/^error:\s*/, "");
|
|
383
|
+
report("success", ` Removed worktree: ${worktreePath} (finished the delete git could not: ${why})`);
|
|
384
|
+
return true;
|
|
385
|
+
} else if (force && state === "unknown") {
|
|
386
|
+
fs2.rmSync(worktreePath, { recursive: true, force: true });
|
|
387
|
+
git(["worktree", "prune"], repoPath);
|
|
388
|
+
report("success", ` Removed worktree folder git could not read: ${worktreePath}`);
|
|
389
|
+
return true;
|
|
390
|
+
} else {
|
|
391
|
+
report("error", ` Failed to remove worktree: ${worktreePath}`);
|
|
392
|
+
if (result.stderr) {
|
|
393
|
+
report("error", ` ${result.stderr}`);
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
async function setupWorktree(targetName, branchName, config, base, jiraKey, opts = {}) {
|
|
399
|
+
const spec = toBaseSpec(base);
|
|
400
|
+
debug("setupWorktree", { targetName, branchName, spec, jiraKey, opts });
|
|
401
|
+
const target = resolveProjectTarget(targetName, config);
|
|
402
|
+
if (!target) {
|
|
403
|
+
debug("setupWorktree: target not found", targetName);
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
const workTreeDirName = branchName.replace(/\//g, "-");
|
|
407
|
+
bestEffort(
|
|
408
|
+
"recreate the archived branch",
|
|
409
|
+
() => recreateArchivedBranches(target.isGroup ? target.name : targetName, branchName, target.repoAliases, config)
|
|
410
|
+
);
|
|
411
|
+
const checkoutFor = opts.checkoutFor ?? archivedHeads(target.isGroup ? target.name : targetName, branchName);
|
|
412
|
+
if (checkoutFor) opts = { ...opts, checkoutFor };
|
|
413
|
+
const result = target.isGroup ? await setupGroupWorktree(target.name, target.repoAliases, branchName, workTreeDirName, config, spec, jiraKey, opts) : await setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey, opts);
|
|
414
|
+
if (result) {
|
|
415
|
+
const sessionTarget = target.isGroup ? target.name : targetName;
|
|
416
|
+
const session = findSession(loadHistory(), sessionTarget, branchName);
|
|
417
|
+
if (session) bestEffort("restore the archived conversation", () => restoreArchivedTranscripts(session), 0);
|
|
418
|
+
if (session)
|
|
419
|
+
await restoreArchivedUncommitted(session, config).catch(
|
|
420
|
+
(err) => report("warn", `couldn't put back its uncommitted changes: ${err.message}`)
|
|
421
|
+
);
|
|
422
|
+
if (opts.name?.trim()) await setSessionTitle(sessionTarget, branchName, opts.name);
|
|
423
|
+
}
|
|
424
|
+
return result;
|
|
425
|
+
}
|
|
426
|
+
function recreateArchivedBranches(sessionTarget, branch, aliases, config) {
|
|
427
|
+
const session = findSession(loadHistory(), sessionTarget, branch);
|
|
428
|
+
if (!session) return [];
|
|
429
|
+
const rec = readArchive(sessionIdFor(session));
|
|
430
|
+
if (!rec?.tips || !rec.branchesDeleted?.length) return [];
|
|
431
|
+
const done = [];
|
|
432
|
+
for (const alias of aliases) {
|
|
433
|
+
const repo = config.repos[alias];
|
|
434
|
+
const tip = rec.tips[alias];
|
|
435
|
+
const name = rec.heads?.[alias] ?? branch;
|
|
436
|
+
if (!repo || !tip || !rec.branchesDeleted.includes(alias)) continue;
|
|
437
|
+
if (localBranchExists(name, repo) || remoteBranchExists(name, repo)) continue;
|
|
438
|
+
if (git(["cat-file", "-e", `${tip}^{commit}`], repo).exitCode !== 0) continue;
|
|
439
|
+
if (git(["branch", name, tip], repo).exitCode === 0) done.push(alias);
|
|
440
|
+
}
|
|
441
|
+
return done;
|
|
442
|
+
}
|
|
443
|
+
function archivedHeads(sessionTarget, branch) {
|
|
444
|
+
const session = findSession(loadHistory(), sessionTarget, branch);
|
|
445
|
+
if (!session?.archivedAt) return void 0;
|
|
446
|
+
const rec = readArchive(sessionIdFor(session));
|
|
447
|
+
return rec?.worktreeRemoved && rec.heads && Object.keys(rec.heads).length ? rec.heads : void 0;
|
|
448
|
+
}
|
|
449
|
+
async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDirName, config, spec, jiraKey, opts = {}) {
|
|
450
|
+
const groupWorktreePath = path3.join(config.worktreesRoot, groupName, workTreeDirName);
|
|
451
|
+
if (!isEmptyBaseSpec(spec)) {
|
|
452
|
+
const unknownAliases = baseSpecOverrideAliases(spec).filter((a) => !repoAliases.includes(a));
|
|
453
|
+
if (unknownAliases.length > 0) {
|
|
454
|
+
report(
|
|
455
|
+
"error",
|
|
456
|
+
`--base names repo(s) not in group '${groupName}': ${unknownAliases.join(", ")}. Group repos: ${repoAliases.join(", ")}`
|
|
457
|
+
);
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
const missingBase = [];
|
|
461
|
+
const branchExists = [];
|
|
462
|
+
for (const alias of repoAliases) {
|
|
463
|
+
const repoPath = config.repos[alias];
|
|
464
|
+
const repoBase = baseForAlias(spec, alias);
|
|
465
|
+
if (!repoBase) continue;
|
|
466
|
+
if (!localBranchExists(repoBase, repoPath) && !remoteBranchExists(repoBase, repoPath)) {
|
|
467
|
+
missingBase.push(`${alias} (${repoBase})`);
|
|
468
|
+
}
|
|
469
|
+
if (localBranchExists(branchName, repoPath) || remoteBranchExists(branchName, repoPath)) {
|
|
470
|
+
branchExists.push(alias);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if (missingBase.length > 0) {
|
|
474
|
+
report("error", `Base branch not found in: ${missingBase.join(", ")}`);
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
if (branchExists.length > 0) {
|
|
478
|
+
report("error", `Cannot use --base: branch '${branchName}' already exists in: ${branchExists.join(", ")}`);
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
report("step", `Creating group worktree: ${groupName}/${branchName}`);
|
|
483
|
+
report("detail", `Directory: ${groupWorktreePath}`);
|
|
484
|
+
report("info", "");
|
|
485
|
+
fs2.mkdirSync(groupWorktreePath, { recursive: true });
|
|
486
|
+
const createdWorktrees = [];
|
|
487
|
+
const baseBranches = {};
|
|
488
|
+
for (const alias of repoAliases) {
|
|
489
|
+
const repoPath = config.repos[alias];
|
|
490
|
+
const repoName = path3.basename(repoPath);
|
|
491
|
+
const subWorktreePath = path3.join(groupWorktreePath, repoName);
|
|
492
|
+
const repoBase = baseForAlias(spec, alias);
|
|
493
|
+
report("step", `[${alias}] (${repoName}):`);
|
|
494
|
+
const success = createSingleWorktree(
|
|
495
|
+
repoPath,
|
|
496
|
+
subWorktreePath,
|
|
497
|
+
opts.checkoutFor?.[alias] ?? branchName,
|
|
498
|
+
config,
|
|
499
|
+
repoBase,
|
|
500
|
+
opts.pull !== false
|
|
501
|
+
);
|
|
502
|
+
if (success) {
|
|
503
|
+
createdWorktrees.push({ repoPath, worktreePath: subWorktreePath });
|
|
504
|
+
if (repoBase) baseBranches[subWorktreePath] = repoBase;
|
|
505
|
+
} else {
|
|
506
|
+
report("info", "");
|
|
507
|
+
report("warn", "Rolling back created worktrees due to failure...");
|
|
508
|
+
for (const wt of createdWorktrees) {
|
|
509
|
+
removeSingleWorktree(wt.repoPath, wt.worktreePath, branchName, true);
|
|
510
|
+
}
|
|
511
|
+
try {
|
|
512
|
+
if (fs2.readdirSync(groupWorktreePath).length === 0) {
|
|
513
|
+
fs2.rmSync(groupWorktreePath, { recursive: true, force: true });
|
|
514
|
+
}
|
|
515
|
+
} catch {
|
|
516
|
+
}
|
|
517
|
+
report("error", "Failed to create group worktree. Changes have been rolled back.");
|
|
518
|
+
return null;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
const configDir = getConfigDir();
|
|
522
|
+
const claudeMdSrc = path3.join(configDir, `${groupName}.claude.md`);
|
|
523
|
+
const instructionsFile = agentFor(config, findSession(loadHistory(), groupName, branchName)).instructionsFile;
|
|
524
|
+
const claudeMdDest = path3.join(groupWorktreePath, instructionsFile);
|
|
525
|
+
if (fs2.existsSync(claudeMdSrc)) {
|
|
526
|
+
fs2.copyFileSync(claudeMdSrc, claudeMdDest);
|
|
527
|
+
report("info", "");
|
|
528
|
+
report("success", `Copied the group's ${instructionsFile} to the worktree root`);
|
|
529
|
+
} else {
|
|
530
|
+
report("info", "");
|
|
531
|
+
report("warn", `Warning: the group's ${instructionsFile} not found at ${claudeMdSrc}`);
|
|
532
|
+
report("warn", `Run 'work config regengroup ${groupName}' to generate it.`);
|
|
533
|
+
}
|
|
534
|
+
const allPaths = createdWorktrees.map((wt) => wt.worktreePath);
|
|
535
|
+
const distinctBases = [...new Set(Object.values(baseBranches))];
|
|
536
|
+
const representativeBase = spec.default ?? (distinctBases.length === 1 ? distinctBases[0] : void 0);
|
|
537
|
+
const { port } = await upsertSessionWithPort(groupName, true, branchName, allPaths, config, jiraKey, representativeBase, baseBranches);
|
|
538
|
+
report("info", "");
|
|
539
|
+
report("info", `Branch: ${branchName}`);
|
|
540
|
+
if (port !== void 0) report("detail", `Dev-server port: ${port}`);
|
|
541
|
+
return { launchDir: groupWorktreePath, paths: allPaths, isGroup: true, port };
|
|
542
|
+
}
|
|
543
|
+
async function setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey, opts = {}) {
|
|
544
|
+
const repoPath = config.repos[targetName];
|
|
545
|
+
const repoName = path3.basename(repoPath);
|
|
546
|
+
let workTreePath = path3.join(config.worktreesRoot, repoName, workTreeDirName);
|
|
547
|
+
const unknownAliases = baseSpecOverrideAliases(spec).filter((a) => a !== targetName);
|
|
548
|
+
if (unknownAliases.length > 0) {
|
|
549
|
+
report("error", `--base names repo(s) other than '${targetName}': ${unknownAliases.join(", ")}`);
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
const baseBranch = baseForAlias(spec, targetName);
|
|
553
|
+
if (!fs2.existsSync(repoPath)) {
|
|
554
|
+
report("error", `Repository path does not exist: ${repoPath}`);
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
const worktrees = parseWorktreeList(repoPath);
|
|
558
|
+
const existing = worktrees.find((wt) => wt.branch === branchName && path3.resolve(wt.path) !== path3.resolve(repoPath));
|
|
559
|
+
if (existing) {
|
|
560
|
+
if (baseBranch) {
|
|
561
|
+
report("error", `Cannot use --base: worktree for '${branchName}' already exists at ${existing.path}`);
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
report("info", `Worktree already exists at: ${existing.path}`);
|
|
565
|
+
workTreePath = existing.path;
|
|
566
|
+
if (opts.pull !== false) pullLatestForBranch(workTreePath, branchName);
|
|
567
|
+
} else {
|
|
568
|
+
const success = createSingleWorktree(
|
|
569
|
+
repoPath,
|
|
570
|
+
workTreePath,
|
|
571
|
+
opts.checkoutFor?.[targetName] ?? branchName,
|
|
572
|
+
config,
|
|
573
|
+
baseBranch,
|
|
574
|
+
opts.pull !== false
|
|
575
|
+
);
|
|
576
|
+
if (!success) return null;
|
|
577
|
+
}
|
|
578
|
+
const { port } = await upsertSessionWithPort(
|
|
579
|
+
targetName,
|
|
580
|
+
false,
|
|
581
|
+
branchName,
|
|
582
|
+
[workTreePath],
|
|
583
|
+
config,
|
|
584
|
+
jiraKey,
|
|
585
|
+
baseBranch,
|
|
586
|
+
baseBranch ? { [workTreePath]: baseBranch } : void 0
|
|
587
|
+
);
|
|
588
|
+
report("info", `Branch: ${branchName}`);
|
|
589
|
+
if (port !== void 0) report("detail", `Dev-server port: ${port}`);
|
|
590
|
+
return { launchDir: workTreePath, paths: [workTreePath], isGroup: false, port };
|
|
591
|
+
}
|
|
592
|
+
var normalizeWorktreePath = (p) => {
|
|
593
|
+
let full = path3.resolve(p);
|
|
594
|
+
try {
|
|
595
|
+
full = fs2.realpathSync.native(full);
|
|
596
|
+
} catch {
|
|
597
|
+
}
|
|
598
|
+
return full.replace(/\\/g, "/").replace(/\/$/, "").toLowerCase();
|
|
599
|
+
};
|
|
600
|
+
function teardownWorktree(target, isGroup, branch, config, force = true, paths) {
|
|
601
|
+
const workTreeDirName = branch.replace(/\//g, "-");
|
|
602
|
+
if (isGroup && config.groups[target]) {
|
|
603
|
+
const aliases = config.groups[target];
|
|
604
|
+
const groupWorktreePath = path3.join(config.worktreesRoot, target, workTreeDirName);
|
|
605
|
+
let allRemoved = true;
|
|
606
|
+
for (const alias of aliases) {
|
|
607
|
+
const repoPath = config.repos[alias];
|
|
608
|
+
if (!repoPath) continue;
|
|
609
|
+
const repoName = path3.basename(repoPath);
|
|
610
|
+
const subWorktreePath = path3.join(groupWorktreePath, repoName);
|
|
611
|
+
report("step", `[${alias}] (${repoName}):`);
|
|
612
|
+
if (!removeSingleWorktree(repoPath, subWorktreePath, branch, force)) {
|
|
613
|
+
allRemoved = false;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
const claudeMd = path3.join(groupWorktreePath, agentFor(config, findSession(loadHistory(), target, branch)).instructionsFile);
|
|
617
|
+
try {
|
|
618
|
+
if (fs2.existsSync(claudeMd)) fs2.unlinkSync(claudeMd);
|
|
619
|
+
} catch {
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
if (fs2.existsSync(groupWorktreePath) && fs2.readdirSync(groupWorktreePath).length === 0) {
|
|
623
|
+
fs2.rmSync(groupWorktreePath, { recursive: true, force: true });
|
|
624
|
+
report("success", `Cleaned up group directory: ${groupWorktreePath}`);
|
|
625
|
+
}
|
|
626
|
+
} catch {
|
|
627
|
+
}
|
|
628
|
+
return allRemoved;
|
|
629
|
+
} else {
|
|
630
|
+
const repoPath = config.repos[target];
|
|
631
|
+
if (repoPath) {
|
|
632
|
+
const worktrees = parseWorktreeList(repoPath);
|
|
633
|
+
const at = paths?.[0] ? normalizeWorktreePath(paths[0]) : null;
|
|
634
|
+
const wt = (at ? worktrees.find((w) => normalizeWorktreePath(w.path) === at) : void 0) ?? worktrees.find((w) => w.branch === branch);
|
|
635
|
+
if (wt) {
|
|
636
|
+
return removeSingleWorktree(repoPath, wt.path, branch, force);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
report("warn", `No worktree found for branch '${branch}' in '${target}'.`);
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
async function openBaseCheckout(targetName, config, opts = {}) {
|
|
644
|
+
const target = resolveProjectTarget(targetName, config);
|
|
645
|
+
if (!target) return { ok: false, error: `Project or group not found: ${targetName}` };
|
|
646
|
+
if (target.isGroup) return { ok: false, error: `${targetName} is a group: give it a branch (a group has no one checkout to open)` };
|
|
647
|
+
const repoPath = config.repos[targetName];
|
|
648
|
+
if (!repoPath) return { ok: false, error: `Repository path not configured for: ${targetName}` };
|
|
649
|
+
if (!fs2.existsSync(repoPath)) return { ok: false, error: `Repository path does not exist: ${repoPath}` };
|
|
650
|
+
const branch = getCurrentBranch(repoPath) ?? "(detached)";
|
|
651
|
+
if (opts.pull !== false && branch && branch !== "(detached)") pullLatestForBranch(repoPath, branch);
|
|
652
|
+
await upsertSession(targetName, false, branch, [repoPath], opts.jiraKey);
|
|
653
|
+
if (opts.name?.trim()) await setSessionTitle(targetName, branch, opts.name);
|
|
654
|
+
const dropped = await forgetOtherBaseCheckoutEntries(targetName, branch, repoPath);
|
|
655
|
+
return { ok: true, repoPath, branch, dropped };
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
export {
|
|
659
|
+
BaseSpecError,
|
|
660
|
+
parseBaseSpec,
|
|
661
|
+
isEmptyBaseSpec,
|
|
662
|
+
toBaseSpec,
|
|
663
|
+
wouldRefuseRemoval,
|
|
664
|
+
setupWorktree,
|
|
665
|
+
teardownWorktree,
|
|
666
|
+
openBaseCheckout
|
|
667
|
+
};
|
|
668
|
+
//# sourceMappingURL=chunk-CLGVSX36.js.map
|