@biffo/cli 0.324.2 → 0.324.3

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.
Files changed (2) hide show
  1. package/dist/index.js +74 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1104,6 +1104,7 @@ function classifyUpgradeBranches(refs, currentBranch) {
1104
1104
  }
1105
1105
 
1106
1106
  // src/adapters/git/index.ts
1107
+ var LITERAL = "--literal-pathspecs";
1107
1108
  var GitAdapter = class {
1108
1109
  /** True if `cwd` is inside a git working tree. */
1109
1110
  /**
@@ -1210,19 +1211,68 @@ var GitAdapter = class {
1210
1211
  await execa("git", ["remote", "add", name, url], { cwd });
1211
1212
  }
1212
1213
  async add(cwd, paths) {
1213
- await execa("git", ["add", ...paths], { cwd });
1214
+ await execa("git", [LITERAL, "add", ...paths], { cwd });
1214
1215
  }
1215
- async commit(cwd, message) {
1216
- await execa("git", ["commit", "-m", message], { cwd });
1216
+ /**
1217
+ * Commits `paths` and nothing else (#2113).
1218
+ *
1219
+ * `paths` is required, and a bare `git commit -m` is unrepresentable here:
1220
+ * without a pathspec git commits the *whole index*, so anything the operator
1221
+ * had already staged for unrelated work (in `--cwd`, or in someone else's
1222
+ * `--frontend-cwd` checkout) was swept into the plugin commit. With a
1223
+ * pathspec git commits only those paths' working-tree state — their changes
1224
+ * were staged by the preceding `add`, so they are all included — and leaves
1225
+ * every other staged file staged, untouched, for the operator.
1226
+ *
1227
+ * Pass exactly what the same command handed to `add`. Throws on an empty
1228
+ * list rather than degrading to a bare commit (`git commit -- ` with no
1229
+ * paths is a bare commit).
1230
+ *
1231
+ * ## Two properties the pathspec form needs handled here (#2113 review)
1232
+ *
1233
+ * **The real index is reconciled afterwards.** `git commit -- <paths>` (git's
1234
+ * `--only` mode) commits via a *temporary* index, which is exactly what stops
1235
+ * the operator's other staged files being swept in. But a pre-commit hook that
1236
+ * rewrites files (the estate's lint-staged: prettier / eslint --fix / ruff
1237
+ * format) re-stages its output into that temporary index only — the real index
1238
+ * keeps the pre-hook content, so a successful commit left `MM <file>` and a
1239
+ * staged revert of the formatting for the operator's next commit to pick up. A
1240
+ * bare commit never had this, because it commits the real index. After the
1241
+ * commit, `paths` are therefore reset in the real index to HEAD, which is what
1242
+ * was just committed. Only `paths` are touched, so every other staged file
1243
+ * stays staged. If the commit itself fails nothing is reconciled and the
1244
+ * paths stay staged, as before.
1245
+ *
1246
+ * **Paths are literal, not pathspecs** (`--literal-pathspecs`). Otherwise
1247
+ * `[a].txt` also matches `a.txt`, and the commit widens to an unrelated
1248
+ * staged file.
1249
+ */
1250
+ async commit(cwd, message, paths) {
1251
+ if (paths.length === 0) {
1252
+ throw new Error(
1253
+ "GitAdapter.commit requires at least one path: a commit with no pathspec would sweep in whatever else is staged."
1254
+ );
1255
+ }
1256
+ await execa("git", [LITERAL, "commit", "-m", message, "--", ...paths], { cwd });
1257
+ await execa("git", [LITERAL, "reset", "-q", "--", ...paths], { cwd });
1217
1258
  }
1218
1259
  /** The current branch name (e.g. "dev"). */
1219
1260
  async currentBranch(cwd) {
1220
1261
  const { stdout } = await execa("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd });
1221
1262
  return stdout.trim();
1222
1263
  }
1223
- /** True if the working tree or index has uncommitted changes. */
1224
- async hasUncommittedChanges(cwd) {
1225
- const { stdout } = await execa("git", ["status", "--porcelain"], { cwd });
1264
+ /**
1265
+ * True if the working tree or index has uncommitted changes — restricted to
1266
+ * `paths` when given (#2113: a pathspec commit only commits those, so "is
1267
+ * there anything for *me* to commit" must not be answered by an unrelated
1268
+ * staged file).
1269
+ */
1270
+ async hasUncommittedChanges(cwd, paths) {
1271
+ const { stdout } = await execa(
1272
+ "git",
1273
+ [LITERAL, "status", "--porcelain", ...paths && paths.length > 0 ? ["--", ...paths] : []],
1274
+ { cwd }
1275
+ );
1226
1276
  return stdout.trim().length > 0;
1227
1277
  }
1228
1278
  /**
@@ -4305,7 +4355,7 @@ async function buildCommitAndOpenPr(options, deps, plan, migrations, fromVersion
4305
4355
  const lockfiles = await refreshInstanceLockfiles(options.cwd, applied, deps);
4306
4356
  const carriedPrs = readCarriedPrs(options.templateRepo, fromVersion, toVersion);
4307
4357
  await git.add(options.cwd, ["-A"]);
4308
- await git.commit(options.cwd, buildCommitMessage(fromVersion, toVersion, carriedPrs));
4358
+ await git.commit(options.cwd, buildCommitMessage(fromVersion, toVersion, carriedPrs), ["."]);
4309
4359
  const run = deps.runCommand ?? defaultRunCommand;
4310
4360
  const installOutcomes = await installInstanceDependencies(options.cwd, run);
4311
4361
  const installFailures = describeInstallFailures(installOutcomes);
@@ -5696,7 +5746,7 @@ async function runDataImport(name, options, deps) {
5696
5746
  log.success(`Imported ${String(sqlFiles.length)} .sql file(s) to db/imports/${name}/`);
5697
5747
  const commitMessage = `feat(data): import ${name} (${String(sqlFiles.length)} SQL file(s))`;
5698
5748
  await deps.git.add(options.cwd, [`db/imports/${name}`]);
5699
- await deps.git.commit(options.cwd, commitMessage);
5749
+ await deps.git.commit(options.cwd, commitMessage, [`db/imports/${name}`]);
5700
5750
  log.success(`Committed: ${commitMessage}`);
5701
5751
  console.log(chalk6.bold("\n Data import staged!\n"));
5702
5752
  console.log(
@@ -8817,7 +8867,8 @@ async function pushSkeleton(git, skeletonRoot, cloneUrl, config, coreConfig, git
8817
8867
  workDir,
8818
8868
  `feat: scaffold ${config.project.name} sibling app (ADR-0007)
8819
8869
 
8820
- [skip ci]`
8870
+ [skip ci]`,
8871
+ ["."]
8821
8872
  );
8822
8873
  await git.push(workDir, "dev", { token: githubToken });
8823
8874
  } finally {
@@ -9028,7 +9079,8 @@ async function registerWithCore(git, github, config, coreConfig, pathPrefix, git
9028
9079
  await git.add(cloneDir, touchedFiles);
9029
9080
  await git.commit(
9030
9081
  cloneDir,
9031
- isRootPathPrefix(pathPrefix) ? `infra(cdn): register root application sibling "${name}" at / (ADR-0007)` : `infra(cdn): register sibling "${name}" for path-based routing (ADR-0007)`
9082
+ isRootPathPrefix(pathPrefix) ? `infra(cdn): register root application sibling "${name}" at / (ADR-0007)` : `infra(cdn): register sibling "${name}" for path-based routing (ADR-0007)`,
9083
+ touchedFiles
9032
9084
  );
9033
9085
  await git.push(cloneDir, branch, { token: githubToken });
9034
9086
  const remoteUrl = await git.getRemoteUrl(cloneDir);
@@ -10137,7 +10189,7 @@ async function runPluginCreate(name, options, deps) {
10137
10189
  }
10138
10190
  const commitMessage = `feat(plugins): scaffold ${names.slug} plugin`;
10139
10191
  await deps.git.add(options.cwd, [relDir]);
10140
- await deps.git.commit(options.cwd, commitMessage);
10192
+ await deps.git.commit(options.cwd, commitMessage, [relDir]);
10141
10193
  log.success(`Committed: ${commitMessage}`);
10142
10194
  }
10143
10195
  printNextSteps(names, relDir, channel);
@@ -10185,7 +10237,7 @@ async function runStandaloneCreate(names, options, deps) {
10185
10237
  }
10186
10238
  await deps.git.init(destDir);
10187
10239
  await deps.git.add(destDir, ["."]);
10188
- await deps.git.commit(destDir, `feat: scaffold ${names.slug} plugin`);
10240
+ await deps.git.commit(destDir, `feat: scaffold ${names.slug} plugin`, ["."]);
10189
10241
  log.success(`Initialised a git repo on dev with an initial commit`);
10190
10242
  }
10191
10243
  if (options.org !== void 0 && options.org !== "") {
@@ -10255,7 +10307,9 @@ async function registerInRegistrySources(names, cloneUrl, token, deps) {
10255
10307
  }
10256
10308
  writeFileSync11(path, serialiseSources(next));
10257
10309
  await deps.git.add(dir, ["sources.json"]);
10258
- await deps.git.commit(dir, `feat(registry): track ${names.slug} in sources.json`);
10310
+ await deps.git.commit(dir, `feat(registry): track ${names.slug} in sources.json`, [
10311
+ "sources.json"
10312
+ ]);
10259
10313
  await deps.git.push(dir, "main", { token });
10260
10314
  log.success(`Registered ${names.slug} in the plugin registry's sources.json`);
10261
10315
  } catch (err) {
@@ -11220,7 +11274,7 @@ async function runPluginInstall(target, options, deps) {
11220
11274
  await deps.git.add(registryCwd, [PLUGIN_REGISTRY_RELATIVE_PATH]);
11221
11275
  left.dashboard.stage = "staged";
11222
11276
  left.dashboard.staged = [PLUGIN_REGISTRY_RELATIVE_PATH];
11223
- await deps.git.commit(registryCwd, dashboardCommitMessage);
11277
+ await deps.git.commit(registryCwd, dashboardCommitMessage, [PLUGIN_REGISTRY_RELATIVE_PATH]);
11224
11278
  left.dashboard.stage = "committed";
11225
11279
  left.dashboard.committed = dashboardCommitMessage;
11226
11280
  log.success(
@@ -11236,7 +11290,7 @@ async function runPluginInstall(target, options, deps) {
11236
11290
  await deps.git.add(options.cwd, stagePaths);
11237
11291
  left.core.stage = "staged";
11238
11292
  left.core.staged = stagePaths;
11239
- await deps.git.commit(options.cwd, commitMessage);
11293
+ await deps.git.commit(options.cwd, commitMessage, stagePaths);
11240
11294
  log.success(`Committed: ${commitMessage}`);
11241
11295
  console.log(chalk15.bold("\n Plugin installed!\n"));
11242
11296
  console.log(` ${pluginName}@${source.version} is committed at ${relTargetDir}/`);
@@ -11779,7 +11833,7 @@ async function runPluginSyncMigrations(name, options, deps) {
11779
11833
  await deps.git.add(options.cwd, relativePaths);
11780
11834
  const label = name ?? `${String(generated.length)} plugin(s)`;
11781
11835
  const commitMessage = `chore(plugins): sync migration(s) for ${label}`;
11782
- await deps.git.commit(options.cwd, commitMessage);
11836
+ await deps.git.commit(options.cwd, commitMessage, relativePaths);
11783
11837
  log.success(`Committed: ${commitMessage}`);
11784
11838
  } else {
11785
11839
  log.warn("--no-commit: generated file(s) are on disk but not staged/committed.");
@@ -11900,7 +11954,7 @@ Remove the reference(s) above first, then re-run uninstall.`
11900
11954
  const label = version ? `${name}@${version}` : name;
11901
11955
  const commitMessage = `chore(plugins): uninstall ${label}`;
11902
11956
  await deps.git.add(options.cwd, stagePaths);
11903
- await deps.git.commit(options.cwd, commitMessage);
11957
+ await deps.git.commit(options.cwd, commitMessage, stagePaths);
11904
11958
  log.success(`Committed: ${commitMessage}`);
11905
11959
  console.log(chalk18.bold("\n Plugin uninstalled!\n"));
11906
11960
  console.log(` services/${name}/ has been removed and committed.`);
@@ -12129,7 +12183,7 @@ async function runPluginUpgrade(target, options, deps) {
12129
12183
  const label = currentVersion ? `${entry.name} ${currentVersion} -> ${entry.version}` : `${entry.name} to ${entry.version}`;
12130
12184
  const commitMessage = `feat(plugins): upgrade ${label}`;
12131
12185
  await deps.git.add(options.cwd, stagePaths);
12132
- await deps.git.commit(options.cwd, commitMessage);
12186
+ await deps.git.commit(options.cwd, commitMessage, stagePaths);
12133
12187
  log.success(`Committed: ${commitMessage}`);
12134
12188
  const lockFailures = describeFailures(lockOutcomes);
12135
12189
  if (lockFailures.length > 0) {
@@ -12250,12 +12304,12 @@ async function runLocalPluginRefresh(localPath, options, deps) {
12250
12304
  if (outcome.ok) stagePaths.push(outcome.trigger.lockfile);
12251
12305
  }
12252
12306
  await deps.git.add(options.cwd, stagePaths);
12253
- if (!await deps.git.hasUncommittedChanges(options.cwd)) {
12307
+ if (!await deps.git.hasUncommittedChanges(options.cwd, stagePaths)) {
12254
12308
  log.warn(`services/${source.name}/ already matches ${source.origin} \u2014 nothing to commit.`);
12255
12309
  return;
12256
12310
  }
12257
12311
  const commitMessage = `chore(plugins): refresh ${source.name} from local checkout`;
12258
- await deps.git.commit(options.cwd, commitMessage);
12312
+ await deps.git.commit(options.cwd, commitMessage, stagePaths);
12259
12313
  log.success(`Committed: ${commitMessage}`);
12260
12314
  const lockFailures = describeFailures(lockOutcomes);
12261
12315
  if (lockFailures.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.324.2",
3
+ "version": "0.324.3",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",