next-issue 17.3.0 → 17.5.0
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.mjs +7 -2
- package/dist/shared/lock.mjs +4 -7
- package/dist/shared/worktree.mjs +43 -4
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { startInWorker } from './cli/start.mjs';
|
|
|
12
12
|
import { STATE_DIR } from './shared/state.mjs';
|
|
13
13
|
import { statusInWorker, stopInWorker, switchInWorker } from './cli/switch-run.mjs';
|
|
14
14
|
import { chooseScope, installSkills, PROJECT_SKILL_FOLDERS, refreshSkills, untrackSkills, } from './cli/skills.mjs';
|
|
15
|
-
import { WORKTREE_DIR } from './shared/worktree.mjs';
|
|
15
|
+
import { removeOldWorktrees, WORKTREE_DIR } from './shared/worktree.mjs';
|
|
16
16
|
function write(stream, text) {
|
|
17
17
|
return new Promise((resolve, reject) => {
|
|
18
18
|
stream.write(text, (error) => (error ? reject(error) : resolve()));
|
|
@@ -116,9 +116,14 @@ async function excludeStateDirectories(root, stream) {
|
|
|
116
116
|
await write(stream, `added ${entry} to ${exclude}\n`);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
for (const entry of await removeIgnored(root, [`${STATE_DIR}
|
|
119
|
+
for (const entry of await removeIgnored(root, [`${STATE_DIR}/`])) {
|
|
120
120
|
await write(stream, `removed ${entry} from .gitignore\n`);
|
|
121
121
|
}
|
|
122
|
+
for (const { path, error } of await removeOldWorktrees(root)) {
|
|
123
|
+
await write(stream, error === undefined
|
|
124
|
+
? `removed old worktree ${path}\n`
|
|
125
|
+
: `could not remove ${path}: ${error}\n`);
|
|
126
|
+
}
|
|
122
127
|
}
|
|
123
128
|
main().then((code) => process.exit(code), async (error) => {
|
|
124
129
|
await write(process.stderr, `${message(error)}\n`);
|
package/dist/shared/lock.mjs
CHANGED
|
@@ -14,14 +14,14 @@ export function oneAtATime(root, work) {
|
|
|
14
14
|
worktreeQueues.set(root, result.catch(() => undefined));
|
|
15
15
|
return result;
|
|
16
16
|
}
|
|
17
|
-
export async function processStart(pid
|
|
17
|
+
export async function processStart(pid) {
|
|
18
18
|
const stat = await readTextOrEmpty(`/proc/${pid}/stat`);
|
|
19
19
|
if (stat !== '') {
|
|
20
20
|
return stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19];
|
|
21
21
|
}
|
|
22
22
|
try {
|
|
23
23
|
const { stdout } = await promisify(execFile)('ps', ['-o', 'lstart=', '-p', String(pid)], {
|
|
24
|
-
env: { ...process.env, LC_ALL: 'C',
|
|
24
|
+
env: { ...process.env, LC_ALL: 'C', TZ: 'UTC' },
|
|
25
25
|
});
|
|
26
26
|
return stdout.trim() || undefined;
|
|
27
27
|
}
|
|
@@ -33,17 +33,14 @@ async function holderOf(text) {
|
|
|
33
33
|
const [first = '', ...rest] = text.trim().split(' ');
|
|
34
34
|
const pid = Number(first);
|
|
35
35
|
const started = rest.join(' ');
|
|
36
|
-
if (!(pid > 0)) {
|
|
36
|
+
if (!(pid > 0) || started === '') {
|
|
37
37
|
return undefined;
|
|
38
38
|
}
|
|
39
|
-
if (started === '') {
|
|
40
|
-
return isAlive(pid) ? pid : undefined;
|
|
41
|
-
}
|
|
42
39
|
const now = await processStart(pid);
|
|
43
40
|
if (now === undefined) {
|
|
44
41
|
return isAlive(pid) ? pid : undefined;
|
|
45
42
|
}
|
|
46
|
-
return now === started
|
|
43
|
+
return now === started ? pid : undefined;
|
|
47
44
|
}
|
|
48
45
|
export async function lockHolder(lockPath) {
|
|
49
46
|
return holderOf(await readTextOrEmpty(lockPath));
|
package/dist/shared/worktree.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import { realpath } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
2
|
+
import { realpath, rm } from 'node:fs/promises';
|
|
3
|
+
import { basename, join, sep } from 'node:path';
|
|
4
|
+
import { message } from './errors.mjs';
|
|
4
5
|
import { commitAll } from './git-commit.mjs';
|
|
5
6
|
import { currentBranch, discardChanges, git, gitFetch, isAncestor, oneFetchAtATime, remoteRef, revision, succeeds, } from './git.mjs';
|
|
6
7
|
export const WORKTREE_DIR = '.claude/worktrees';
|
|
@@ -46,6 +47,45 @@ async function keepDetachedEdits(path, branch) {
|
|
|
46
47
|
}
|
|
47
48
|
await git(path, ['branch', `${branch}-detached-${(await revision(path)).slice(0, 7)}`]);
|
|
48
49
|
}
|
|
50
|
+
/** Removes the worktrees an older next-issue left in `.worktrees/`, keeping their uncommitted files on a `<name>-detached-<sha>` branch, then the folder when every one is gone. */
|
|
51
|
+
export async function removeOldWorktrees(root) {
|
|
52
|
+
const folder = join(root, '.worktrees');
|
|
53
|
+
if (!existsSync(folder)) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
await git(root, ['worktree', 'prune']);
|
|
57
|
+
const inside = `${await realpath(folder)}${sep}`;
|
|
58
|
+
const results = [];
|
|
59
|
+
for (const path of await linkedWorktrees(root)) {
|
|
60
|
+
if (!(await realpath(path).catch(() => path)).startsWith(inside)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
results.push(await removeOldWorktree(root, path));
|
|
64
|
+
}
|
|
65
|
+
if (results.every((result) => result.error === undefined)) {
|
|
66
|
+
await rm(folder, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
return results;
|
|
69
|
+
}
|
|
70
|
+
async function removeOldWorktree(root, path) {
|
|
71
|
+
try {
|
|
72
|
+
await git(path, ['checkout', '--detach']);
|
|
73
|
+
await keepDetachedEdits(path, basename(path));
|
|
74
|
+
await git(root, ['worktree', 'remove', '--force', path]);
|
|
75
|
+
return { path };
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
return { path, error: message(error) };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function linkedWorktrees(root) {
|
|
82
|
+
const list = await git(root, ['worktree', 'list', '--porcelain']);
|
|
83
|
+
return list
|
|
84
|
+
.split('\n')
|
|
85
|
+
.filter((line) => line.startsWith('worktree '))
|
|
86
|
+
.slice(1)
|
|
87
|
+
.map((line) => line.slice('worktree '.length));
|
|
88
|
+
}
|
|
49
89
|
async function keepUnmergedCommits(repo, branch, target) {
|
|
50
90
|
if (!(await hasBranch(repo, branch)) || (await isAncestor(repo.root, branch, target))) {
|
|
51
91
|
return;
|
|
@@ -82,8 +122,7 @@ export async function findWorktree(repo, branch) {
|
|
|
82
122
|
return found.path;
|
|
83
123
|
}
|
|
84
124
|
async function isOwn(repo, branch, path) {
|
|
85
|
-
return
|
|
86
|
-
(await samePath(path, join(repo.root, '.worktrees', branch))));
|
|
125
|
+
return samePath(path, join(repo.root, WORKTREE_DIR, `next-issue-${branch}`));
|
|
87
126
|
}
|
|
88
127
|
async function refuseOwnWorktree(repo, issue, branch, start) {
|
|
89
128
|
const found = await holder(repo, branch);
|