@feigi/fleet-ctl 3.30.16 → 3.30.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.30.16",
3
+ "version": "3.30.17",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -112,11 +112,13 @@ export function resolveMainCheckout(cwd = process.cwd(), env = process.env) {
112
112
 
113
113
  export const baselinePath = (root) => join(root, ".fleet", BASELINE_FILE);
114
114
 
115
- // A content hash of one path porcelain named, relative to the main checkout.
116
- // Gone is an answer (a deleted tracked file is a ` D` entry), and so is a
117
- // directory (an untracked nested repository is listed as `dir/`); anything
118
- // else that fails to read throws, and the caller's answer is `unknown`.
119
- function hashPath(root, rel) {
115
+ // A content hash of one path porcelain named, relative to `root`. Gone is an
116
+ // answer (a deleted tracked file is a ` D` entry); anything else that fails
117
+ // to read throws, and the caller's answer is `unknown`. A directory holding
118
+ // `.git` is a nested repository (an untracked one is listed as `dir/`, a
119
+ // submodule by its own path), hashed as `nestedHash` below; any other
120
+ // directory hashes as `dir`.
121
+ function hashPath(root, rel, env) {
120
122
  const abs = join(root, rel);
121
123
  let st;
122
124
  try {
@@ -125,13 +127,38 @@ function hashPath(root, rel) {
125
127
  if (e?.code === "ENOENT" || e?.code === "ENOTDIR") return "absent";
126
128
  throw e;
127
129
  }
128
- const sha = (buf) => createHash("sha256").update(buf).digest("hex");
129
130
  if (st.isSymbolicLink()) return `link:${sha(readlinkSync(abs))}`;
130
- if (st.isDirectory()) return "dir";
131
+ if (st.isDirectory()) {
132
+ try {
133
+ lstatSync(join(abs, ".git"));
134
+ } catch (e) {
135
+ if (e?.code === "ENOENT") return "dir";
136
+ throw e;
137
+ }
138
+ return nestedHash(abs, env);
139
+ }
131
140
  if (st.isFile()) return `sha256:${sha(readFileSync(abs))}`;
132
141
  return "other";
133
142
  }
134
143
 
144
+ const sha = (buf) => createHash("sha256").update(buf).digest("hex");
145
+
146
+ // A nested repository's own snapshot — its porcelain entries and the hash of
147
+ // every path they name, so a further edit to a file already dirty in it moves
148
+ // the hash where its status line would not — folded with its HEAD, so a
149
+ // commit in it moves the hash too. A commitless repository's HEAD is the
150
+ // branch it names. Nothing is left out: the run's bookkeeping is the main
151
+ // checkout's two paths, not a nested repository's. Any git that fails
152
+ // throws: `unknown`, never a hash that reads clean.
153
+ function nestedHash(abs, env) {
154
+ const now = entriesAt(abs, env, new Set());
155
+ if (!now.ok) throw new Error(now.why);
156
+ let head = git("git rev-parse HEAD", ["rev-parse", "-q", "--verify", "HEAD^{commit}"], abs, env);
157
+ if (!head.ok) head = git("git symbolic-ref HEAD", ["symbolic-ref", "-q", "HEAD"], abs, env);
158
+ if (!head.ok) throw new Error(head.why);
159
+ return `repo:${sha(`${head.stdout}${formatBaseline(now.entries)}`)}`;
160
+ }
161
+
135
162
  /**
136
163
  * The main checkout as it stands: `{ok, entries}` — a Map from each porcelain
137
164
  * entry (`XY path`) to its path's hash, the run's own bookkeeping left out
@@ -141,6 +168,11 @@ function hashPath(root, rel) {
141
168
  * `--no-renames` so every entry names exactly one path.
142
169
  */
143
170
  export function snapshot(root, env = process.env) {
171
+ return entriesAt(root, env, RUN_BOOKKEEPING);
172
+ }
173
+
174
+ // `snapshot` of the repository at `root`, leaving out the paths in `skip`.
175
+ function entriesAt(root, env, skip) {
144
176
  const r = git("git status --porcelain -uall", ["--no-optional-locks", "status", "--porcelain", "-uall", "-z", "--no-renames"], root, env);
145
177
  if (!r.ok) return r;
146
178
  const entries = new Map();
@@ -148,9 +180,9 @@ export function snapshot(root, env = process.env) {
148
180
  if (!line) continue;
149
181
  if (line.length < 4 || line[2] !== " ") return { ok: false, why: `git status printed an entry it does not document: ${JSON.stringify(line)}` };
150
182
  const rel = line.slice(3);
151
- if (RUN_BOOKKEEPING.has(rel)) continue;
183
+ if (skip.has(rel)) continue;
152
184
  try {
153
- entries.set(line, hashPath(root, rel));
185
+ entries.set(line, hashPath(root, rel, env));
154
186
  } catch (e) {
155
187
  return { ok: false, why: `cannot hash ${rel}: ${e?.code ?? e?.message ?? e}` };
156
188
  }