@kaynooo/cli-git 0.15.0 → 0.16.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/gp.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/gp.ts
5
- import process18 from "process";
5
+ import process20 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process9 from "process";
8
8
  import { parseArgs } from "util";
@@ -108,7 +108,7 @@ function Fe(r = {}) {
108
108
  var o = Fe();
109
109
 
110
110
  // ../kit/src/theme.ts
111
- import { existsSync as existsSync2, readFileSync, statSync } from "fs";
111
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
112
112
  import { homedir as homedir2 } from "os";
113
113
  import { join as join3, resolve as resolve2 } from "path";
114
114
  import process5 from "process";
@@ -129,6 +129,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
129
129
  }
130
130
 
131
131
  // ../kit/src/user-config.ts
132
+ import { existsSync as existsSync2, readFileSync } from "fs";
132
133
  import { homedir } from "os";
133
134
  import { join as join2 } from "path";
134
135
  import process4 from "process";
@@ -139,6 +140,24 @@ function configBase(where = {}) {
139
140
  function userConfigPath(bin, where = {}) {
140
141
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
141
142
  }
143
+ function userConfigReadPath(bin, legacy = [], where = {}) {
144
+ const current = userConfigPath(bin, where);
145
+ if (existsSync2(current))
146
+ return current;
147
+ const base = configBase(where);
148
+ return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
149
+ }
150
+ function readUserConfig(bin, where = {}, legacy = []) {
151
+ const path = userConfigReadPath(bin, legacy, where);
152
+ if (!existsSync2(path))
153
+ return {};
154
+ try {
155
+ const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
156
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
157
+ } catch {
158
+ return {};
159
+ }
160
+ }
142
161
 
143
162
  // ../kit/src/theme.ts
144
163
  function toLinear(channel) {
@@ -240,7 +259,7 @@ function readThemeFile(path, warn) {
240
259
  warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
241
260
  return;
242
261
  }
243
- const parsed = JSON.parse(readFileSync(path, "utf8"));
262
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
244
263
  if (isRecord(parsed))
245
264
  return parsed;
246
265
  warn(`${path} is not a JSON object, theme ignored`);
@@ -306,7 +325,7 @@ function applyFile(theme, file, where, warn) {
306
325
  }
307
326
  }
308
327
  function endsWalk(home) {
309
- return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
328
+ return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
310
329
  }
311
330
  var warned = new Set;
312
331
  function warnOnce(message) {
@@ -474,24 +493,20 @@ function printJson(value) {
474
493
 
475
494
  // ../kit/src/help.ts
476
495
  import process8 from "process";
477
- var OPTIONAL = /\[[^\]]+\]/g;
496
+ var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
478
497
  var USAGE_PREFIX = /^usage:\s*/i;
479
498
  var FULL_STOP = /\.$/;
480
499
  function usageLine(usage, colors = paint(process8.stdout)) {
481
500
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
482
501
  }
483
- function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
484
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
502
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
503
+ return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
485
504
  `);
486
505
  }
487
506
  function exitRows(exits, colors = paint(process8.stdout)) {
488
507
  if (exits.length === 0)
489
508
  return [];
490
- const width = Math.max(...exits.map(([code]) => String(code).length));
491
- return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
492
- }
493
- function replacesRows(replaces, colors = paint(process8.stdout)) {
494
- return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
509
+ return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
495
510
  }
496
511
  function wantsHelpJson(env = process8.env) {
497
512
  return env.KIT_HELP === "json";
@@ -517,29 +532,41 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
517
532
  return [];
518
533
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
519
534
  }
535
+ var MAX_INLINE_CHOICES = 24;
520
536
  function optionRows(options, colors = paint(process8.stdout)) {
521
537
  const rows = Object.entries(options).map(([name, option]) => {
522
538
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
523
- const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
539
+ const choices = option.choices?.join("|");
540
+ const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
541
+ const named = inline ? `<${choices}>` : "<value>";
524
542
  const placeholder = option.optional === undefined ? named : `[${named}]`;
525
543
  const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
526
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
544
+ const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
545
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
527
546
  });
528
547
  const width = Math.max(0, ...rows.map((row) => row.width));
529
548
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
530
549
  }
531
550
 
532
551
  // ../kit/src/text.ts
533
- var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
552
+ var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
534
553
  function distance(a, b) {
535
- let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
536
- for (const [i, left] of [...a].entries()) {
554
+ const left = [...a];
555
+ const right = [...b];
556
+ let before = [];
557
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
558
+ for (const [i, x] of left.entries()) {
537
559
  const current = [i + 1];
538
- for (const [j, right] of [...b].entries())
539
- current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
560
+ for (const [j, y] of right.entries()) {
561
+ let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
562
+ if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
563
+ cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
564
+ current.push(cost);
565
+ }
566
+ before = previous;
540
567
  previous = current;
541
568
  }
542
- return previous[b.length] ?? 0;
569
+ return previous[right.length] ?? 0;
543
570
  }
544
571
  function closest(name, names) {
545
572
  const started = names.find((known) => known.startsWith(name));
@@ -788,12 +815,12 @@ function nearestOption(message, options, allowNegative) {
788
815
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
789
816
  }
790
817
  // ../kit/src/argv.ts
791
- import { readFileSync as readFileSync2, realpathSync } from "fs";
818
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
792
819
  import { resolve as resolve3 } from "path";
793
820
  import process10 from "process";
794
821
  function commandLine() {
795
822
  try {
796
- return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
823
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
797
824
  } catch {
798
825
  return;
799
826
  }
@@ -1121,15 +1148,33 @@ function interceptOutput(clear) {
1121
1148
  };
1122
1149
  }
1123
1150
  // ../kit/src/cli.ts
1124
- import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
1151
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1125
1152
  import { dirname as dirname3, join as join5 } from "path";
1126
- import process14 from "process";
1153
+ import process15 from "process";
1154
+
1155
+ // ../kit/src/notify.ts
1156
+ import process13 from "process";
1157
+ var NOTIFY_AFTER_MS = 1e4;
1158
+ var CANCELLED = 130;
1159
+ function base64(text) {
1160
+ return Buffer.from(text).toString("base64");
1161
+ }
1162
+ function notification(title, body, env = process13.env) {
1163
+ const id = `kit${process13.pid}`;
1164
+ const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
1165
+ return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
1166
+ }
1167
+ function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
1168
+ if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
1169
+ return;
1170
+ stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
1171
+ }
1127
1172
 
1128
1173
  // ../kit/src/usage.ts
1129
1174
  import { appendFileSync, mkdirSync } from "fs";
1130
1175
  import { homedir as homedir3 } from "os";
1131
1176
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1132
- import process13 from "process";
1177
+ import process14 from "process";
1133
1178
 
1134
1179
  // ../kit/src/logs.ts
1135
1180
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -1143,14 +1188,14 @@ var usageError;
1143
1188
  function noteUsageError(message) {
1144
1189
  usageError = message;
1145
1190
  }
1146
- function stateHome(env = process13.env) {
1191
+ function stateHome(env = process14.env) {
1147
1192
  const dir = env.XDG_STATE_HOME;
1148
1193
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1149
1194
  }
1150
- function usagePath(env = process13.env) {
1195
+ function usagePath(env = process14.env) {
1151
1196
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
1152
1197
  }
1153
- function usageRecorded(env = process13.env) {
1198
+ function usageRecorded(env = process14.env) {
1154
1199
  const off = env.KAYNOOO_CLI_NO_USAGE;
1155
1200
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1156
1201
  }
@@ -1164,7 +1209,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1164
1209
  usageError = undefined;
1165
1210
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1166
1211
  }
1167
- function recordUsage(entry, env = process13.env) {
1212
+ function recordUsage(entry, env = process14.env) {
1168
1213
  if (!usageRecorded(env))
1169
1214
  return;
1170
1215
  try {
@@ -1182,8 +1227,8 @@ var LEVEL_OPTIONS = {
1182
1227
  };
1183
1228
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1184
1229
  function printError(prefix, message, hint, cause) {
1185
- const colors = paint(process14.stderr);
1186
- const styled = takesControlCodes(process14.stderr);
1230
+ const colors = paint(process15.stderr);
1231
+ const styled = takesControlCodes(process15.stderr);
1187
1232
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1188
1233
  const under = (label, text, tint) => text === undefined ? "" : `
1189
1234
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1269,9 +1314,13 @@ async function printCandidates(found) {
1269
1314
  return 0;
1270
1315
  }
1271
1316
  function packageVersion(entry = Bun.main) {
1272
- for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
1317
+ let resolved = entry;
1318
+ try {
1319
+ resolved = realpathSync2(entry);
1320
+ } catch {}
1321
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1273
1322
  try {
1274
- const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1323
+ const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
1275
1324
  if (typeof version === "string")
1276
1325
  return version;
1277
1326
  } catch {}
@@ -1287,11 +1336,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
1287
1336
  return 0;
1288
1337
  }
1289
1338
  let code;
1339
+ const started = performance.now();
1290
1340
  try {
1291
1341
  code = await run(argv);
1292
1342
  } catch (error) {
1293
1343
  code = reportThrown(name, error, redact, wantsJson(argv));
1294
1344
  }
1345
+ notifyEnd(name, code, performance.now() - started);
1295
1346
  if (usage !== false) {
1296
1347
  try {
1297
1348
  recordUsage(usageEntry(name, undefined, argv, code));
@@ -1308,7 +1359,7 @@ var {Glob } = globalThis.Bun;
1308
1359
  var SESSION_FILES = new Glob("*.json");
1309
1360
  var ACCOUNT_DIRS = new Glob("*/sessions");
1310
1361
  // ../kit/src/watch.ts
1311
- import process15 from "process";
1362
+ import process16 from "process";
1312
1363
  import { format } from "util";
1313
1364
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1314
1365
  var DEFAULT_SECONDS = 2;
@@ -1330,7 +1381,7 @@ function withoutWatch(args) {
1330
1381
  }
1331
1382
  return rest;
1332
1383
  }
1333
- async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1384
+ async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1334
1385
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1335
1386
  if (!takesControlCodes(stream))
1336
1387
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1338,12 +1389,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1338
1389
  for (let round = 0;round < rounds; round++) {
1339
1390
  const held = [];
1340
1391
  const { log, info } = console;
1341
- const write = process15.stdout.write.bind(process15.stdout);
1392
+ const write = process16.stdout.write.bind(process16.stdout);
1342
1393
  const hold = (...parts) => void held.push(`${format(...parts)}
1343
1394
  `);
1344
1395
  console.log = hold;
1345
1396
  console.info = hold;
1346
- process15.stdout.write = (text) => {
1397
+ process16.stdout.write = (text) => {
1347
1398
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1348
1399
  return true;
1349
1400
  };
@@ -1352,13 +1403,30 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1352
1403
  } finally {
1353
1404
  console.log = log;
1354
1405
  console.info = info;
1355
- process15.stdout.write = write;
1406
+ process16.stdout.write = write;
1356
1407
  }
1357
1408
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1358
1409
  await sleep(interval);
1359
1410
  }
1360
1411
  return code;
1361
1412
  }
1413
+ // ../kit/src/workspace-root.ts
1414
+ import { homedir as homedir4 } from "os";
1415
+ import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1416
+ import process17 from "process";
1417
+ function expandHome(path, home) {
1418
+ if (path === "~")
1419
+ return home;
1420
+ return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
1421
+ }
1422
+ function configured(env, home) {
1423
+ const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1424
+ return typeof folder === "string" && folder !== "" ? folder : undefined;
1425
+ }
1426
+ function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
1427
+ const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1428
+ return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1429
+ }
1362
1430
  // src/git.ts
1363
1431
  async function git2(args, env) {
1364
1432
  const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
@@ -1368,15 +1436,19 @@ async function git2(args, env) {
1368
1436
 
1369
1437
  // src/repos.ts
1370
1438
  import { readdir } from "fs/promises";
1371
- import { join as join6, relative, resolve as resolve4 } from "path";
1372
- import process17 from "process";
1439
+ import { join as join7, relative, resolve as resolve5 } from "path";
1440
+ import process19 from "process";
1373
1441
 
1374
1442
  // src/status.ts
1375
1443
  var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
1444
+ var STASH = /^# stash (\d+)$/m;
1376
1445
  var OCTAL = /[0-7]/;
1377
1446
  var ESCAPES = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13 };
1378
1447
  var ENCODER = new TextEncoder;
1379
1448
  var DECODER = new TextDecoder;
1449
+ function stashOf(text) {
1450
+ return Number(STASH.exec(text)?.[1] ?? 0);
1451
+ }
1380
1452
  function unquote(path) {
1381
1453
  if (!path.startsWith('"') || !path.endsWith('"'))
1382
1454
  return path;
@@ -1431,16 +1503,18 @@ function parseStatus(text) {
1431
1503
  }
1432
1504
  return hasBranch ? status : null;
1433
1505
  }
1434
- function summary(status, head) {
1506
+ function summary(status, head, { operation = null, stash = 0 } = {}) {
1435
1507
  const { branch, oid, upstream, aheadBehind, changes, conflicted, untracked } = status;
1436
- const on = branch === "(detached)" ? `detached at ${oid.slice(0, 7)}` : `branch \`${branch}\``;
1508
+ const steps = operation?.step !== undefined && operation.total !== undefined ? ` ${operation.step}/${operation.total}` : "";
1509
+ const during = operation === null ? "" : ` (${operation.kind}${steps} in progress)`;
1510
+ const on = (branch === "(detached)" ? `detached at ${oid.slice(0, 7)}` : `branch \`${branch}\``) + during;
1437
1511
  let tracking = "no upstream";
1438
1512
  if (upstream !== null)
1439
1513
  tracking = aheadBehind === null ? `upstream \`${upstream}\` gone or never fetched` : `${aheadBehind.ahead} ahead and ${aheadBehind.behind} behind \`${upstream}\` as of the last fetch`;
1440
1514
  const files = [`${changes.length} changed`, untracked.length > 0 ? `${untracked.length} untracked` : "", conflicted.length > 0 ? `${conflicted.length} conflicted` : ""].filter(Boolean).join(", ");
1441
1515
  const [sha, title] = head.trim().split("\x00");
1442
1516
  const last = sha === undefined || sha === "" ? "; no commit yet" : `; HEAD ${sha} ${title ?? ""}`.trimEnd();
1443
- return `${on}, ${tracking}; ${files} files${last}`;
1517
+ return `${on}, ${tracking}; ${files} files${stash > 0 ? `; ${stash} stashed` : ""}${last}`;
1444
1518
  }
1445
1519
 
1446
1520
  // src/repos.ts
@@ -1459,9 +1533,9 @@ async function reposUnder(root, depth = DEPTH) {
1459
1533
  found.push(dir);
1460
1534
  if (left === 0)
1461
1535
  return;
1462
- await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join6(dir, entry.name), left - 1)));
1536
+ await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join7(dir, entry.name), left - 1)));
1463
1537
  }
1464
- await walk(resolve4(root), depth);
1538
+ await walk(resolve5(root), depth);
1465
1539
  return found.sort();
1466
1540
  }
1467
1541
  async function toplevelOf(dir) {
@@ -1469,14 +1543,14 @@ async function toplevelOf(dir) {
1469
1543
  return read.code === 0 ? read.stdout.trim() : undefined;
1470
1544
  }
1471
1545
  async function reposOf(roots) {
1472
- const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process17.cwd()];
1546
+ const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process19.cwd()];
1473
1547
  const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
1474
1548
  return [...new Set(found.flat())].sort();
1475
1549
  }
1476
1550
  async function repoState(dir) {
1477
1551
  const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
1478
1552
  const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
1479
- return { path: relative(process17.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
1553
+ return { path: relative(process19.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
1480
1554
  }
1481
1555
  function trackingOf(status) {
1482
1556
  if (status.upstream === null)
@@ -1495,6 +1569,21 @@ function changesOf(status) {
1495
1569
  function branchOf(status) {
1496
1570
  return status.branch === "(detached)" ? `detached at ${status.oid.slice(0, 7)}` : status.branch;
1497
1571
  }
1572
+ async function dirsOf(positionals, all) {
1573
+ const asked = positionals.length > 0 ? positionals : ["."];
1574
+ let dirs;
1575
+ if (all) {
1576
+ dirs = await reposOf(positionals);
1577
+ } else {
1578
+ const found = await Promise.all(asked.map(async (dir) => toplevelOf(dir)));
1579
+ if (found.includes(undefined))
1580
+ fail(`not inside a git repository: ${asked.filter((_, at) => found[at] === undefined).join(", ")}`);
1581
+ dirs = [...new Set(found)];
1582
+ }
1583
+ if (dirs.length === 0)
1584
+ fail(`no git repository at or below ${positionals.length === 0 ? "the current directory" : positionals.join(", ")}`);
1585
+ return dirs;
1586
+ }
1498
1587
 
1499
1588
  // src/gp.ts
1500
1589
  var USAGE = `gp [dir]...: pushes the current branch of the repository, or of each dir's, when it is ahead of its upstream as of the last fetch or has none yet, the latter with -u to origin (the only remote when there is no origin)
@@ -1555,30 +1644,20 @@ async function push(repo, { dryRun, extra }) {
1555
1644
  return pushed.code === 0 ? { path, branch, remote, commits, outcome: "pushed" } : { path, branch, remote, commits, outcome: "refused", reason: whyRefused(pushed.stderr) };
1556
1645
  }
1557
1646
  function line(result) {
1558
- const { dim } = paint(process18.stdout);
1647
+ const { dim } = paint(process20.stdout);
1559
1648
  const sent = result.commits === null ? "" : `, ${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
1560
1649
  const what = `${result.branch} -> ${result.remote}${sent}`;
1561
1650
  const said = {
1562
- pushed: () => marked("ok", `pushed ${what}`, process18.stdout),
1651
+ pushed: () => marked("ok", `pushed ${what}`, process20.stdout),
1563
1652
  "would-push": () => `would push ${what}`,
1564
1653
  skipped: () => dim(result.reason ?? "skipped"),
1565
- refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process18.stdout)
1654
+ refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process20.stdout)
1566
1655
  }[result.outcome];
1567
- return [role("path", process18.stdout)(result.path), said()];
1656
+ return [role("path", process20.stdout)(result.path), said()];
1568
1657
  }
1569
1658
  async function main(argv) {
1570
1659
  const { values, positionals, rest = [] } = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], rest: true, exits: EXITS, replaces: "git push, git push -u origin <branch> and a git -C <repo> push per nested repository", examples: ["gp", ["gp --repos", "every repository nested in this one"], ["gp --repos --dry-run", "what would go out"], ["gp . ../other", "this repository and a sibling"], ["gp -- --force-with-lease", "flags for git push"]] });
1571
- let dirs;
1572
- if (values.repos === true) {
1573
- dirs = await reposOf(positionals);
1574
- } else {
1575
- const found = await Promise.all((positionals.length > 0 ? positionals : ["."]).map(async (dir) => toplevelOf(dir)));
1576
- if (found.includes(undefined))
1577
- fail(`not inside a git repository: ${(positionals.length > 0 ? positionals : ["."]).filter((_, at) => found[at] === undefined).join(", ")}`);
1578
- dirs = [...new Set(found)];
1579
- }
1580
- if (dirs.length === 0)
1581
- fail(`no git repository at or below ${positionals.length === 0 ? "the current directory" : positionals.join(", ")}`);
1660
+ const dirs = await dirsOf(positionals, values.repos === true);
1582
1661
  const repos = await Promise.all(dirs.map(repoState));
1583
1662
  const results = [];
1584
1663
  const progress = progressLine();
@@ -1593,4 +1672,4 @@ async function main(argv) {
1593
1672
  console.log(table(results.map(line)));
1594
1673
  return results.some((result) => result.outcome === "refused") ? 1 : 0;
1595
1674
  }
1596
- process18.exitCode = await runMain({ name: "gp", run: main });
1675
+ process20.exitCode = await runMain({ name: "gp", run: main });