git-worktree-organize 1.0.11 → 1.0.12
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/cli.js +21 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -144,6 +144,16 @@ async function moveDir(src, dest) {
|
|
|
144
144
|
function sanitizeBranch(branch) {
|
|
145
145
|
return branch.replace(/\//g, "-");
|
|
146
146
|
}
|
|
147
|
+
function resolveWorktreePath(worktreePath, dest, sourceParent) {
|
|
148
|
+
if (existsSync2(worktreePath))
|
|
149
|
+
return worktreePath;
|
|
150
|
+
if (worktreePath.startsWith(dest + "/")) {
|
|
151
|
+
const remapped = sourceParent + worktreePath.slice(dest.length);
|
|
152
|
+
if (existsSync2(remapped))
|
|
153
|
+
return remapped;
|
|
154
|
+
}
|
|
155
|
+
return worktreePath;
|
|
156
|
+
}
|
|
147
157
|
function isPartialMigration(dest) {
|
|
148
158
|
const gitFile = join2(dest, ".git");
|
|
149
159
|
return existsSync2(join2(dest, ".bare")) && existsSync2(gitFile) && statSync2(gitFile).isFile();
|
|
@@ -191,6 +201,8 @@ async function migrate(config, options) {
|
|
|
191
201
|
await setGitConfig("remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*", { gitdir: destBare });
|
|
192
202
|
writeFileSync(join2(dest, ".git"), `gitdir: ./.bare
|
|
193
203
|
`);
|
|
204
|
+
const sourceParent = dirname(source);
|
|
205
|
+
const worktreesResolved = worktrees.map((wt, i) => i === 0 && config.type === "standard" ? wt : { ...wt, path: resolveWorktreePath(wt.path, dest, sourceParent) });
|
|
194
206
|
if (config.type === "standard") {
|
|
195
207
|
const mainBranch = worktrees[0].branch;
|
|
196
208
|
const mainSafe = sanitizeBranch(mainBranch);
|
|
@@ -214,11 +226,11 @@ async function migrate(config, options) {
|
|
|
214
226
|
}
|
|
215
227
|
writeFileSync(join2(mainDest, ".git"), `gitdir: ${mainAdminDir}
|
|
216
228
|
`);
|
|
217
|
-
for (let i = 1;i <
|
|
218
|
-
await processLinkedWorktree(
|
|
229
|
+
for (let i = 1;i < worktreesResolved.length; i++) {
|
|
230
|
+
await processLinkedWorktree(worktreesResolved[i], dest, destBare);
|
|
219
231
|
}
|
|
220
232
|
} else {
|
|
221
|
-
for (const wt of
|
|
233
|
+
for (const wt of worktreesResolved) {
|
|
222
234
|
await processLinkedWorktree(wt, dest, destBare);
|
|
223
235
|
}
|
|
224
236
|
}
|
|
@@ -332,7 +344,12 @@ ${green("==>")} Reading worktrees from ${source}
|
|
|
332
344
|
`);
|
|
333
345
|
const config = await detect(source);
|
|
334
346
|
const allWorktrees = await listWorktrees(source);
|
|
335
|
-
const missing = allWorktrees.filter((wt) =>
|
|
347
|
+
const missing = allWorktrees.filter((wt) => {
|
|
348
|
+
if (wt.isBare)
|
|
349
|
+
return false;
|
|
350
|
+
const actual = resolveWorktreePath(wt.path, dest, dirname2(source));
|
|
351
|
+
return !existsSync3(actual);
|
|
352
|
+
});
|
|
336
353
|
if (missing.length > 0) {
|
|
337
354
|
console.log(`${yellow("warn:")} The following worktree paths no longer exist:`);
|
|
338
355
|
for (const wt of missing) {
|