@kaynooo/cli-git 0.15.0 → 0.15.2

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 process19 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) {
@@ -480,18 +499,14 @@ 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";
@@ -788,12 +803,12 @@ function nearestOption(message, options, allowNegative) {
788
803
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
789
804
  }
790
805
  // ../kit/src/argv.ts
791
- import { readFileSync as readFileSync2, realpathSync } from "fs";
806
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
792
807
  import { resolve as resolve3 } from "path";
793
808
  import process10 from "process";
794
809
  function commandLine() {
795
810
  try {
796
- return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
811
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
797
812
  } catch {
798
813
  return;
799
814
  }
@@ -1121,7 +1136,7 @@ function interceptOutput(clear) {
1121
1136
  };
1122
1137
  }
1123
1138
  // ../kit/src/cli.ts
1124
- import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
1139
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1125
1140
  import { dirname as dirname3, join as join5 } from "path";
1126
1141
  import process14 from "process";
1127
1142
 
@@ -1269,9 +1284,13 @@ async function printCandidates(found) {
1269
1284
  return 0;
1270
1285
  }
1271
1286
  function packageVersion(entry = Bun.main) {
1272
- for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
1287
+ let resolved = entry;
1288
+ try {
1289
+ resolved = realpathSync2(entry);
1290
+ } catch {}
1291
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1273
1292
  try {
1274
- const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1293
+ const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
1275
1294
  if (typeof version === "string")
1276
1295
  return version;
1277
1296
  } catch {}
@@ -1359,6 +1378,23 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1359
1378
  }
1360
1379
  return code;
1361
1380
  }
1381
+ // ../kit/src/workspace-root.ts
1382
+ import { homedir as homedir4 } from "os";
1383
+ import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1384
+ import process16 from "process";
1385
+ function expandHome(path, home) {
1386
+ if (path === "~")
1387
+ return home;
1388
+ return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
1389
+ }
1390
+ function configured(env, home) {
1391
+ const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1392
+ return typeof folder === "string" && folder !== "" ? folder : undefined;
1393
+ }
1394
+ function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
1395
+ const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1396
+ return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1397
+ }
1362
1398
  // src/git.ts
1363
1399
  async function git2(args, env) {
1364
1400
  const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
@@ -1368,8 +1404,8 @@ async function git2(args, env) {
1368
1404
 
1369
1405
  // src/repos.ts
1370
1406
  import { readdir } from "fs/promises";
1371
- import { join as join6, relative, resolve as resolve4 } from "path";
1372
- import process17 from "process";
1407
+ import { join as join7, relative, resolve as resolve5 } from "path";
1408
+ import process18 from "process";
1373
1409
 
1374
1410
  // src/status.ts
1375
1411
  var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
@@ -1459,9 +1495,9 @@ async function reposUnder(root, depth = DEPTH) {
1459
1495
  found.push(dir);
1460
1496
  if (left === 0)
1461
1497
  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)));
1498
+ 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
1499
  }
1464
- await walk(resolve4(root), depth);
1500
+ await walk(resolve5(root), depth);
1465
1501
  return found.sort();
1466
1502
  }
1467
1503
  async function toplevelOf(dir) {
@@ -1469,14 +1505,14 @@ async function toplevelOf(dir) {
1469
1505
  return read.code === 0 ? read.stdout.trim() : undefined;
1470
1506
  }
1471
1507
  async function reposOf(roots) {
1472
- const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process17.cwd()];
1508
+ const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process18.cwd()];
1473
1509
  const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
1474
1510
  return [...new Set(found.flat())].sort();
1475
1511
  }
1476
1512
  async function repoState(dir) {
1477
1513
  const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
1478
1514
  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 } };
1515
+ return { path: relative(process18.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
1480
1516
  }
1481
1517
  function trackingOf(status) {
1482
1518
  if (status.upstream === null)
@@ -1495,6 +1531,21 @@ function changesOf(status) {
1495
1531
  function branchOf(status) {
1496
1532
  return status.branch === "(detached)" ? `detached at ${status.oid.slice(0, 7)}` : status.branch;
1497
1533
  }
1534
+ async function dirsOf(positionals, all) {
1535
+ const asked = positionals.length > 0 ? positionals : ["."];
1536
+ let dirs;
1537
+ if (all) {
1538
+ dirs = await reposOf(positionals);
1539
+ } else {
1540
+ const found = await Promise.all(asked.map(async (dir) => toplevelOf(dir)));
1541
+ if (found.includes(undefined))
1542
+ fail(`not inside a git repository: ${asked.filter((_, at) => found[at] === undefined).join(", ")}`);
1543
+ dirs = [...new Set(found)];
1544
+ }
1545
+ if (dirs.length === 0)
1546
+ fail(`no git repository at or below ${positionals.length === 0 ? "the current directory" : positionals.join(", ")}`);
1547
+ return dirs;
1548
+ }
1498
1549
 
1499
1550
  // src/gp.ts
1500
1551
  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 +1606,20 @@ async function push(repo, { dryRun, extra }) {
1555
1606
  return pushed.code === 0 ? { path, branch, remote, commits, outcome: "pushed" } : { path, branch, remote, commits, outcome: "refused", reason: whyRefused(pushed.stderr) };
1556
1607
  }
1557
1608
  function line(result) {
1558
- const { dim } = paint(process18.stdout);
1609
+ const { dim } = paint(process19.stdout);
1559
1610
  const sent = result.commits === null ? "" : `, ${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
1560
1611
  const what = `${result.branch} -> ${result.remote}${sent}`;
1561
1612
  const said = {
1562
- pushed: () => marked("ok", `pushed ${what}`, process18.stdout),
1613
+ pushed: () => marked("ok", `pushed ${what}`, process19.stdout),
1563
1614
  "would-push": () => `would push ${what}`,
1564
1615
  skipped: () => dim(result.reason ?? "skipped"),
1565
- refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process18.stdout)
1616
+ refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process19.stdout)
1566
1617
  }[result.outcome];
1567
- return [role("path", process18.stdout)(result.path), said()];
1618
+ return [role("path", process19.stdout)(result.path), said()];
1568
1619
  }
1569
1620
  async function main(argv) {
1570
1621
  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(", ")}`);
1622
+ const dirs = await dirsOf(positionals, values.repos === true);
1582
1623
  const repos = await Promise.all(dirs.map(repoState));
1583
1624
  const results = [];
1584
1625
  const progress = progressLine();
@@ -1593,4 +1634,4 @@ async function main(argv) {
1593
1634
  console.log(table(results.map(line)));
1594
1635
  return results.some((result) => result.outcome === "refused") ? 1 : 0;
1595
1636
  }
1596
- process18.exitCode = await runMain({ name: "gp", run: main });
1637
+ process19.exitCode = await runMain({ name: "gp", run: main });
package/dist/gst.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/gst.ts
5
- import process19 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) {
@@ -480,18 +499,14 @@ 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";
@@ -788,12 +803,12 @@ function nearestOption(message, options, allowNegative) {
788
803
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
789
804
  }
790
805
  // ../kit/src/argv.ts
791
- import { readFileSync as readFileSync2, realpathSync } from "fs";
806
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
792
807
  import { resolve as resolve3 } from "path";
793
808
  import process10 from "process";
794
809
  function commandLine() {
795
810
  try {
796
- return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
811
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
797
812
  } catch {
798
813
  return;
799
814
  }
@@ -1121,7 +1136,7 @@ function interceptOutput(clear) {
1121
1136
  };
1122
1137
  }
1123
1138
  // ../kit/src/cli.ts
1124
- import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
1139
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1125
1140
  import { dirname as dirname3, join as join5 } from "path";
1126
1141
  import process14 from "process";
1127
1142
 
@@ -1269,9 +1284,13 @@ async function printCandidates(found) {
1269
1284
  return 0;
1270
1285
  }
1271
1286
  function packageVersion(entry = Bun.main) {
1272
- for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
1287
+ let resolved = entry;
1288
+ try {
1289
+ resolved = realpathSync2(entry);
1290
+ } catch {}
1291
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1273
1292
  try {
1274
- const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1293
+ const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
1275
1294
  if (typeof version === "string")
1276
1295
  return version;
1277
1296
  } catch {}
@@ -1359,9 +1378,26 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1359
1378
  }
1360
1379
  return code;
1361
1380
  }
1381
+ // ../kit/src/workspace-root.ts
1382
+ import { homedir as homedir4 } from "os";
1383
+ import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1384
+ import process16 from "process";
1385
+ function expandHome(path, home) {
1386
+ if (path === "~")
1387
+ return home;
1388
+ return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
1389
+ }
1390
+ function configured(env, home) {
1391
+ const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1392
+ return typeof folder === "string" && folder !== "" ? folder : undefined;
1393
+ }
1394
+ function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
1395
+ const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1396
+ return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1397
+ }
1362
1398
  // src/colour.ts
1363
- import process17 from "process";
1364
- function letter(status, stream = process17.stdout) {
1399
+ import process18 from "process";
1400
+ function letter(status, stream = process18.stdout) {
1365
1401
  const colors = paint(stream);
1366
1402
  const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
1367
1403
  return tint(status);
@@ -1376,8 +1412,8 @@ async function git2(args, env) {
1376
1412
 
1377
1413
  // src/repos.ts
1378
1414
  import { readdir } from "fs/promises";
1379
- import { join as join6, relative, resolve as resolve4 } from "path";
1380
- import process18 from "process";
1415
+ import { join as join7, relative, resolve as resolve5 } from "path";
1416
+ import process19 from "process";
1381
1417
 
1382
1418
  // src/status.ts
1383
1419
  var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
@@ -1467,9 +1503,9 @@ async function reposUnder(root, depth = DEPTH) {
1467
1503
  found.push(dir);
1468
1504
  if (left === 0)
1469
1505
  return;
1470
- 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)));
1506
+ 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)));
1471
1507
  }
1472
- await walk(resolve4(root), depth);
1508
+ await walk(resolve5(root), depth);
1473
1509
  return found.sort();
1474
1510
  }
1475
1511
  async function toplevelOf(dir) {
@@ -1477,14 +1513,14 @@ async function toplevelOf(dir) {
1477
1513
  return read.code === 0 ? read.stdout.trim() : undefined;
1478
1514
  }
1479
1515
  async function reposOf(roots) {
1480
- const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process18.cwd()];
1516
+ const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process19.cwd()];
1481
1517
  const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
1482
1518
  return [...new Set(found.flat())].sort();
1483
1519
  }
1484
1520
  async function repoState(dir) {
1485
1521
  const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
1486
1522
  const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
1487
- return { path: relative(process18.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
1523
+ return { path: relative(process19.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
1488
1524
  }
1489
1525
  function trackingOf(status) {
1490
1526
  if (status.upstream === null)
@@ -1503,13 +1539,27 @@ function changesOf(status) {
1503
1539
  function branchOf(status) {
1504
1540
  return status.branch === "(detached)" ? `detached at ${status.oid.slice(0, 7)}` : status.branch;
1505
1541
  }
1542
+ async function dirsOf(positionals, all) {
1543
+ const asked = positionals.length > 0 ? positionals : ["."];
1544
+ let dirs;
1545
+ if (all) {
1546
+ dirs = await reposOf(positionals);
1547
+ } else {
1548
+ const found = await Promise.all(asked.map(async (dir) => toplevelOf(dir)));
1549
+ if (found.includes(undefined))
1550
+ fail(`not inside a git repository: ${asked.filter((_, at) => found[at] === undefined).join(", ")}`);
1551
+ dirs = [...new Set(found)];
1552
+ }
1553
+ if (dirs.length === 0)
1554
+ fail(`no git repository at or below ${positionals.length === 0 ? "the current directory" : positionals.join(", ")}`);
1555
+ return dirs;
1556
+ }
1506
1557
 
1507
1558
  // src/gst.ts
1508
1559
  var USAGE = `gst [-n N]: the repository's branch, upstream, changed files and HEAD in one line, then the changed paths by staged, unstaged and untracked
1509
1560
 
1510
- gst --repos [dir]... lists every repository at and below the current one's toplevel (or below each dir given, the current directory outside a repository), four levels down, past node_modules, vendor, dist and hidden folders: one line each with its path, branch, how it stands against its upstream as of the last fetch, and the files left to commit.
1511
-
1512
- Exits 0 when it printed the status, 2 outside a git repository or on a usage error.`;
1561
+ gst --repos [dir]... lists every repository at and below the current one's toplevel (or below each dir given, the current directory outside a repository), four levels down, past node_modules, vendor, dist and hidden folders: one line each with its path, branch, how it stands against its upstream as of the last fetch, and the files left to commit.`;
1562
+ var EXITS = [[0, "it printed the status"], [2, "outside a git repository or a usage error"]];
1513
1563
  var OPTIONS = {
1514
1564
  limit: { type: "string", short: "n", description: "add the last N commits as <sha7> <title>" },
1515
1565
  log: { type: "string", short: "l", description: "the former spelling of --limit" },
@@ -1541,24 +1591,24 @@ async function listRepos(roots, json) {
1541
1591
  printJson(repos.map(({ path, status, head }) => status === null ? { path, error: "git could not read it" } : { path, ...jsonOf(status, head) }));
1542
1592
  return 0;
1543
1593
  }
1544
- const dim = paint(process19.stdout).dim;
1594
+ const dim = paint(process20.stdout).dim;
1545
1595
  const cells = (repo) => {
1546
1596
  if (repo.status === null)
1547
- return [role("path", process19.stdout)(repo.path), "", "", "git could not read it"];
1597
+ return [role("path", process20.stdout)(repo.path), "", "", "git could not read it"];
1548
1598
  const changes = changesOf(repo.status);
1549
- return [role("path", process19.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
1599
+ return [role("path", process20.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
1550
1600
  };
1551
1601
  console.log(table(repos.map(cells)));
1552
1602
  return 0;
1553
1603
  }
1554
1604
  function group(title, lines) {
1555
- return lines.length === 0 ? [] : [paint(process19.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
1605
+ return lines.length === 0 ? [] : [paint(process20.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
1556
1606
  }
1557
1607
  function staged({ index, from, path }) {
1558
1608
  return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
1559
1609
  }
1560
1610
  async function main(argv) {
1561
- const parsed = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], replaces: "git status --short, git log --oneline and a git -C <repo> status per nested repository", examples: ["gst", ["gst -n 5", "with the last five commits"], ["gst --repos", "the repositories nested in this one"]] });
1611
+ const parsed = parse(argv, USAGE, OPTIONS, { exits: EXITS, positionals: ["[dir]..."], replaces: "git status --short, git log --oneline and a git -C <repo> status per nested repository", examples: ["gst", ["gst -n 5", "with the last five commits"], ["gst --repos", "the repositories nested in this one"]] });
1562
1612
  if (parsed.positionals.length > 0 && parsed.values.repos !== true)
1563
1613
  fail(`gst takes dirs with --repos alone
1564
1614
 
@@ -1590,12 +1640,12 @@ ${USAGE}`);
1590
1640
  summary(status, head.code === 0 ? head.stdout : ""),
1591
1641
  ...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
1592
1642
  ...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${letter(change.worktree)} ${change.path}`)),
1593
- ...group("untracked", status.untracked.map((file) => paint(process19.stdout).dim(file))),
1594
- ...group("conflicted", status.conflicted.map((file) => paint(process19.stdout).red(file))),
1595
- ...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process19.stdout)(commitSha)} ${commitTitle}`))
1643
+ ...group("untracked", status.untracked.map((file) => paint(process20.stdout).dim(file))),
1644
+ ...group("conflicted", status.conflicted.map((file) => paint(process20.stdout).red(file))),
1645
+ ...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process20.stdout)(commitSha)} ${commitTitle}`))
1596
1646
  ];
1597
1647
  console.log(lines.join(`
1598
1648
  `));
1599
1649
  return 0;
1600
1650
  }
1601
- process19.exitCode = await runMain({ name: "gst", run: main });
1651
+ process20.exitCode = await runMain({ name: "gst", run: main });