neurastream 0.2.73 → 0.2.74
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/package.json +1 -1
- package/src/core/wip-backup.ts +9 -4
- package/src/core/wip-roots.ts +19 -2
- package/src/core/wip-snapshot.ts +15 -6
package/package.json
CHANGED
package/src/core/wip-backup.ts
CHANGED
|
@@ -92,12 +92,17 @@ export function wipBackup(
|
|
|
92
92
|
const mainWt = top.stdout ? top.stdout.split("\n")[0]!.slice(9) : repo;
|
|
93
93
|
const rkey = keyOf(mainWt, cfg.paths.home);
|
|
94
94
|
const specs: { src: string; dst: string }[] = [];
|
|
95
|
-
const heads = gitOrFail(failed, repo, ["for-each-ref", "--format=%(refname
|
|
95
|
+
const heads = gitOrFail(failed, repo, ["for-each-ref", "--format=%(refname)", "refs/heads"]);
|
|
96
96
|
if (!heads) continue;
|
|
97
|
-
for (const
|
|
98
|
-
|
|
97
|
+
for (const ref of heads.stdout.split("\n").filter(Boolean)) {
|
|
98
|
+
// Full refname and a trailing `--`: a branch named like an existing file (ops/x) is not
|
|
99
|
+
// "ambiguous argument" — that failure must not drop the branch from the backup.
|
|
100
|
+
const n = gitOrFail(failed, repo, ["rev-list", "--count", ref, "--not", "--remotes", "--"]);
|
|
99
101
|
if (!n) continue;
|
|
100
|
-
if (/^\d+$/.test(n.stdout) && Number(n.stdout) > 0)
|
|
102
|
+
if (/^\d+$/.test(n.stdout) && Number(n.stdout) > 0) {
|
|
103
|
+
const branch = ref.slice("refs/heads/".length);
|
|
104
|
+
specs.push({ src: ref, dst: `refs/heads/${rkey}/${branch}` });
|
|
105
|
+
}
|
|
101
106
|
}
|
|
102
107
|
const wips = gitOrFail(failed, repo, ["for-each-ref", "--sort=-refname", "--format=%(refname)", "refs/wip"]);
|
|
103
108
|
if (!wips) continue;
|
package/src/core/wip-roots.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import { existsSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
2
|
-
import { join, relative } from "node:path";
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve } from "node:path";
|
|
3
3
|
import type { Config } from "./config.ts";
|
|
4
4
|
|
|
5
|
+
/** True when `dir/.git` is a file naming a gitdir that no longer exists: no repo is left to save. */
|
|
6
|
+
export function deadGitfile(dir: string): boolean {
|
|
7
|
+
const gitPath = join(dir, ".git");
|
|
8
|
+
let first: string | undefined;
|
|
9
|
+
try {
|
|
10
|
+
if (!statSync(gitPath).isFile()) return false;
|
|
11
|
+
first = readFileSync(gitPath, "utf8").split("\n")[0];
|
|
12
|
+
} catch {
|
|
13
|
+
return false; // an unreadable .git file is not our call: the repo stays and its failure is real
|
|
14
|
+
}
|
|
15
|
+
if (!first?.startsWith("gitdir: ")) return false;
|
|
16
|
+
return !existsSync(resolve(dir, first.slice("gitdir: ".length).trim()));
|
|
17
|
+
}
|
|
18
|
+
|
|
5
19
|
export function keyOf(path: string, home: string): string {
|
|
6
20
|
const realHome = existsSync(home) ? realpathSync(home) : home;
|
|
7
21
|
const realPath = existsSync(path) ? realpathSync(path) : path;
|
|
@@ -27,6 +41,8 @@ function walkFolder(dir: string, currentDepth: number, maxDepth: number, out: st
|
|
|
27
41
|
}
|
|
28
42
|
if (!st.isDirectory()) continue;
|
|
29
43
|
|
|
44
|
+
// A dead worktree dir has no repo left to save: not pushed as a repo, not recursed into.
|
|
45
|
+
if (deadGitfile(fullPath)) continue;
|
|
30
46
|
if (existsSync(join(fullPath, ".git"))) {
|
|
31
47
|
out.push(fullPath);
|
|
32
48
|
} else {
|
|
@@ -48,6 +64,7 @@ export function wipRepos(cfg: Config): string[] {
|
|
|
48
64
|
}
|
|
49
65
|
if (!st.isDirectory()) continue;
|
|
50
66
|
|
|
67
|
+
if (deadGitfile(root)) continue;
|
|
51
68
|
if (existsSync(join(root, ".git"))) {
|
|
52
69
|
out.push(root);
|
|
53
70
|
} else {
|
package/src/core/wip-snapshot.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Config } from "./config.ts";
|
|
|
5
5
|
import { nowSec, strftime } from "./clock.ts";
|
|
6
6
|
import { printText } from "./help.ts";
|
|
7
7
|
import { pyFloatStr } from "./pyfmt.ts";
|
|
8
|
-
import { cmd } from "./proc.ts";
|
|
8
|
+
import { cmd, gitRaw } from "./proc.ts";
|
|
9
9
|
import { failureLine, gitOrFail, realpathOrFail, recordWipRun } from "./wip-fail.ts";
|
|
10
10
|
import { keyOf, wipRepos } from "./wip-roots.ts";
|
|
11
11
|
|
|
@@ -102,9 +102,14 @@ export function wipSnapshot(args: string[], cfg: Config): number {
|
|
|
102
102
|
seen.set(common, repo);
|
|
103
103
|
const list = gitOrFail(failed, repo, ["worktree", "list", "--porcelain"]);
|
|
104
104
|
if (!list) continue;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
// Blocks (blank-line separated) match `worktree list --porcelain`; the bare entry of a
|
|
106
|
+
// bare main repo carries a `bare` line and is no worktree to snapshot.
|
|
107
|
+
for (const block of list.stdout.split("\n\n")) {
|
|
108
|
+
if (block.split("\n").some(line => line === "bare")) continue;
|
|
109
|
+
for (const line of block.split("\n")) {
|
|
110
|
+
if (line.startsWith("worktree ") && existsSync(line.slice(9)) && statSync(line.slice(9)).isDirectory()) {
|
|
111
|
+
worktrees.push(line.slice(9));
|
|
112
|
+
}
|
|
108
113
|
}
|
|
109
114
|
}
|
|
110
115
|
}
|
|
@@ -112,8 +117,12 @@ export function wipSnapshot(args: string[], cfg: Config): number {
|
|
|
112
117
|
const saved: { wt: string; br: string; n: number; sk: number; ref: string }[] = [];
|
|
113
118
|
let same = 0;
|
|
114
119
|
for (const wt of worktrees) {
|
|
115
|
-
|
|
116
|
-
|
|
120
|
+
// Unborn HEAD (no commit yet): nothing to save, skipped quietly. Any other git failure is real.
|
|
121
|
+
const head = gitRaw(wt, ["rev-parse", "--verify", "-q", "HEAD"]);
|
|
122
|
+
if (head.code !== 0) {
|
|
123
|
+
if (!(head.code === 1 && head.stderr === "")) failed.push(failureLine(wt, "git rev-parse --verify HEAD", head.stderr));
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
117
126
|
const st = gitOrFail(failed, wt, ["status", "--porcelain"]);
|
|
118
127
|
if (!st || !st.stdout) continue;
|
|
119
128
|
const gitdir = gitOrFail(failed, wt, ["rev-parse", "--absolute-git-dir"]);
|