@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/README.md +44 -1
- package/dist/gb.js +311 -73
- package/dist/gc.js +130 -46
- package/dist/gcl.js +1700 -0
- package/dist/gd.js +1680 -0
- package/dist/gf.js +1662 -0
- package/dist/gm.js +2885 -0
- package/dist/gp.js +142 -63
- package/dist/gst.js +183 -68
- package/dist/gu.js +1523 -0
- package/package.json +16 -6
package/dist/gst.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gst.ts
|
|
5
|
-
import
|
|
5
|
+
import process21 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
|
|
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(
|
|
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) ||
|
|
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 =
|
|
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 = [],
|
|
484
|
-
return [usageLine(usage, colors),
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
536
|
-
|
|
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,
|
|
539
|
-
|
|
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[
|
|
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
|
|
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
|
|
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
|
|
1151
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1125
1152
|
import { dirname as dirname3, join as join5 } from "path";
|
|
1126
|
-
import
|
|
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
|
|
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 =
|
|
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 =
|
|
1195
|
+
function usagePath(env = process14.env) {
|
|
1151
1196
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1152
1197
|
}
|
|
1153
|
-
function usageRecorded(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 =
|
|
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(
|
|
1186
|
-
const styled = takesControlCodes(
|
|
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
|
-
|
|
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(
|
|
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
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
1397
|
+
process16.stdout.write = (text) => {
|
|
1347
1398
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1348
1399
|
return true;
|
|
1349
1400
|
};
|
|
@@ -1352,16 +1403,33 @@ 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
|
-
|
|
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
|
}
|
|
1362
|
-
// src/
|
|
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";
|
|
1363
1416
|
import process17 from "process";
|
|
1364
|
-
function
|
|
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
|
+
}
|
|
1430
|
+
// src/colour.ts
|
|
1431
|
+
import process19 from "process";
|
|
1432
|
+
function letter(status, stream = process19.stdout) {
|
|
1365
1433
|
const colors = paint(stream);
|
|
1366
1434
|
const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
|
|
1367
1435
|
return tint(status);
|
|
@@ -1374,17 +1442,45 @@ async function git2(args, env) {
|
|
|
1374
1442
|
return { code: ran.code, stdout: text("stdout"), stderr: text("stderr") };
|
|
1375
1443
|
}
|
|
1376
1444
|
|
|
1445
|
+
// src/operation.ts
|
|
1446
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
1447
|
+
import { join as join7 } from "path";
|
|
1448
|
+
function numberIn(path) {
|
|
1449
|
+
try {
|
|
1450
|
+
const value = Number.parseInt(readFileSync5(path, "utf8"), 10);
|
|
1451
|
+
return Number.isNaN(value) ? undefined : value;
|
|
1452
|
+
} catch {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
function operationOf(gitDir) {
|
|
1457
|
+
const has = (name) => existsSync4(join7(gitDir, name));
|
|
1458
|
+
if (has("rebase-merge"))
|
|
1459
|
+
return { kind: "rebase", step: numberIn(join7(gitDir, "rebase-merge/msgnum")), total: numberIn(join7(gitDir, "rebase-merge/end")) };
|
|
1460
|
+
if (has("rebase-apply"))
|
|
1461
|
+
return { kind: "rebase", step: numberIn(join7(gitDir, "rebase-apply/next")), total: numberIn(join7(gitDir, "rebase-apply/last")) };
|
|
1462
|
+
for (const [file, kind] of [["MERGE_HEAD", "merge"], ["CHERRY_PICK_HEAD", "cherry-pick"], ["REVERT_HEAD", "revert"], ["BISECT_LOG", "bisect"]]) {
|
|
1463
|
+
if (has(file))
|
|
1464
|
+
return { kind };
|
|
1465
|
+
}
|
|
1466
|
+
return null;
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1377
1469
|
// src/repos.ts
|
|
1378
1470
|
import { readdir } from "fs/promises";
|
|
1379
|
-
import { join as
|
|
1380
|
-
import
|
|
1471
|
+
import { join as join8, relative, resolve as resolve5 } from "path";
|
|
1472
|
+
import process20 from "process";
|
|
1381
1473
|
|
|
1382
1474
|
// src/status.ts
|
|
1383
1475
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
1476
|
+
var STASH = /^# stash (\d+)$/m;
|
|
1384
1477
|
var OCTAL = /[0-7]/;
|
|
1385
1478
|
var ESCAPES = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13 };
|
|
1386
1479
|
var ENCODER = new TextEncoder;
|
|
1387
1480
|
var DECODER = new TextDecoder;
|
|
1481
|
+
function stashOf(text) {
|
|
1482
|
+
return Number(STASH.exec(text)?.[1] ?? 0);
|
|
1483
|
+
}
|
|
1388
1484
|
function unquote(path) {
|
|
1389
1485
|
if (!path.startsWith('"') || !path.endsWith('"'))
|
|
1390
1486
|
return path;
|
|
@@ -1439,16 +1535,18 @@ function parseStatus(text) {
|
|
|
1439
1535
|
}
|
|
1440
1536
|
return hasBranch ? status : null;
|
|
1441
1537
|
}
|
|
1442
|
-
function summary(status, head) {
|
|
1538
|
+
function summary(status, head, { operation = null, stash = 0 } = {}) {
|
|
1443
1539
|
const { branch, oid, upstream, aheadBehind, changes, conflicted, untracked } = status;
|
|
1444
|
-
const
|
|
1540
|
+
const steps = operation?.step !== undefined && operation.total !== undefined ? ` ${operation.step}/${operation.total}` : "";
|
|
1541
|
+
const during = operation === null ? "" : ` (${operation.kind}${steps} in progress)`;
|
|
1542
|
+
const on = (branch === "(detached)" ? `detached at ${oid.slice(0, 7)}` : `branch \`${branch}\``) + during;
|
|
1445
1543
|
let tracking = "no upstream";
|
|
1446
1544
|
if (upstream !== null)
|
|
1447
1545
|
tracking = aheadBehind === null ? `upstream \`${upstream}\` gone or never fetched` : `${aheadBehind.ahead} ahead and ${aheadBehind.behind} behind \`${upstream}\` as of the last fetch`;
|
|
1448
1546
|
const files = [`${changes.length} changed`, untracked.length > 0 ? `${untracked.length} untracked` : "", conflicted.length > 0 ? `${conflicted.length} conflicted` : ""].filter(Boolean).join(", ");
|
|
1449
1547
|
const [sha, title] = head.trim().split("\x00");
|
|
1450
1548
|
const last = sha === undefined || sha === "" ? "; no commit yet" : `; HEAD ${sha} ${title ?? ""}`.trimEnd();
|
|
1451
|
-
return `${on}, ${tracking}; ${files} files${last}`;
|
|
1549
|
+
return `${on}, ${tracking}; ${files} files${stash > 0 ? `; ${stash} stashed` : ""}${last}`;
|
|
1452
1550
|
}
|
|
1453
1551
|
|
|
1454
1552
|
// src/repos.ts
|
|
@@ -1467,9 +1565,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
1467
1565
|
found.push(dir);
|
|
1468
1566
|
if (left === 0)
|
|
1469
1567
|
return;
|
|
1470
|
-
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(
|
|
1568
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join8(dir, entry.name), left - 1)));
|
|
1471
1569
|
}
|
|
1472
|
-
await walk(
|
|
1570
|
+
await walk(resolve5(root), depth);
|
|
1473
1571
|
return found.sort();
|
|
1474
1572
|
}
|
|
1475
1573
|
async function toplevelOf(dir) {
|
|
@@ -1477,14 +1575,14 @@ async function toplevelOf(dir) {
|
|
|
1477
1575
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1478
1576
|
}
|
|
1479
1577
|
async function reposOf(roots) {
|
|
1480
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
1578
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process20.cwd()];
|
|
1481
1579
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1482
1580
|
return [...new Set(found.flat())].sort();
|
|
1483
1581
|
}
|
|
1484
1582
|
async function repoState(dir) {
|
|
1485
1583
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1486
1584
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1487
|
-
return { path: relative(
|
|
1585
|
+
return { path: relative(process20.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1488
1586
|
}
|
|
1489
1587
|
function trackingOf(status) {
|
|
1490
1588
|
if (status.upstream === null)
|
|
@@ -1503,21 +1601,35 @@ function changesOf(status) {
|
|
|
1503
1601
|
function branchOf(status) {
|
|
1504
1602
|
return status.branch === "(detached)" ? `detached at ${status.oid.slice(0, 7)}` : status.branch;
|
|
1505
1603
|
}
|
|
1604
|
+
async function dirsOf(positionals, all) {
|
|
1605
|
+
const asked = positionals.length > 0 ? positionals : ["."];
|
|
1606
|
+
let dirs;
|
|
1607
|
+
if (all) {
|
|
1608
|
+
dirs = await reposOf(positionals);
|
|
1609
|
+
} else {
|
|
1610
|
+
const found = await Promise.all(asked.map(async (dir) => toplevelOf(dir)));
|
|
1611
|
+
if (found.includes(undefined))
|
|
1612
|
+
fail(`not inside a git repository: ${asked.filter((_, at) => found[at] === undefined).join(", ")}`);
|
|
1613
|
+
dirs = [...new Set(found)];
|
|
1614
|
+
}
|
|
1615
|
+
if (dirs.length === 0)
|
|
1616
|
+
fail(`no git repository at or below ${positionals.length === 0 ? "the current directory" : positionals.join(", ")}`);
|
|
1617
|
+
return dirs;
|
|
1618
|
+
}
|
|
1506
1619
|
|
|
1507
1620
|
// src/gst.ts
|
|
1508
1621
|
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
1622
|
|
|
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.`;
|
|
1623
|
+
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.`;
|
|
1624
|
+
var EXITS = [[0, "it printed the status"], [2, "outside a git repository or a usage error"]];
|
|
1513
1625
|
var OPTIONS = {
|
|
1514
1626
|
limit: { type: "string", short: "n", description: "add the last N commits as <sha7> <title>" },
|
|
1515
1627
|
log: { type: "string", short: "l", description: "the former spelling of --limit" },
|
|
1516
1628
|
repos: { type: "boolean", short: "r", description: "one line for each repository nested below, the current one included", conflicts: ["limit", "log"] },
|
|
1517
1629
|
watch: watchOption("the status"),
|
|
1518
|
-
json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}; with --repos an array of them, each with its path and no commits, a repository git cannot read being {path, error}")
|
|
1630
|
+
json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, operation, stash, commits}, operation being {kind, step?, total?} while a rebase, merge, cherry-pick, revert or bisect is in progress and null otherwise; with --repos an array of them, each with its path and no commits, a repository git cannot read being {path, error}")
|
|
1519
1631
|
};
|
|
1520
|
-
function jsonOf(status, head, commits) {
|
|
1632
|
+
function jsonOf(status, head, commits, extra) {
|
|
1521
1633
|
return {
|
|
1522
1634
|
branch: status.branch,
|
|
1523
1635
|
oid: status.oid,
|
|
@@ -1529,6 +1641,7 @@ function jsonOf(status, head, commits) {
|
|
|
1529
1641
|
unstaged: status.changes.filter((change) => change.worktree !== ".").map(({ worktree, path }) => ({ status: worktree, path })),
|
|
1530
1642
|
untracked: status.untracked,
|
|
1531
1643
|
conflicted: status.conflicted,
|
|
1644
|
+
...extra === undefined ? {} : { operation: extra.operation, stash: extra.stash },
|
|
1532
1645
|
...commits === undefined ? {} : { commits: commits.map(([commitSha = "", commitTitle = ""]) => ({ sha: commitSha, title: commitTitle })) }
|
|
1533
1646
|
};
|
|
1534
1647
|
}
|
|
@@ -1541,24 +1654,24 @@ async function listRepos(roots, json) {
|
|
|
1541
1654
|
printJson(repos.map(({ path, status, head }) => status === null ? { path, error: "git could not read it" } : { path, ...jsonOf(status, head) }));
|
|
1542
1655
|
return 0;
|
|
1543
1656
|
}
|
|
1544
|
-
const dim = paint(
|
|
1657
|
+
const dim = paint(process21.stdout).dim;
|
|
1545
1658
|
const cells = (repo) => {
|
|
1546
1659
|
if (repo.status === null)
|
|
1547
|
-
return [role("path",
|
|
1660
|
+
return [role("path", process21.stdout)(repo.path), "", "", "git could not read it"];
|
|
1548
1661
|
const changes = changesOf(repo.status);
|
|
1549
|
-
return [role("path",
|
|
1662
|
+
return [role("path", process21.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
|
|
1550
1663
|
};
|
|
1551
1664
|
console.log(table(repos.map(cells)));
|
|
1552
1665
|
return 0;
|
|
1553
1666
|
}
|
|
1554
1667
|
function group(title, lines) {
|
|
1555
|
-
return lines.length === 0 ? [] : [paint(
|
|
1668
|
+
return lines.length === 0 ? [] : [paint(process21.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
|
|
1556
1669
|
}
|
|
1557
1670
|
function staged({ index, from, path }) {
|
|
1558
1671
|
return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
|
|
1559
1672
|
}
|
|
1560
1673
|
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"]] });
|
|
1674
|
+
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
1675
|
if (parsed.positionals.length > 0 && parsed.values.repos !== true)
|
|
1563
1676
|
fail(`gst takes dirs with --repos alone
|
|
1564
1677
|
|
|
@@ -1571,31 +1684,33 @@ ${USAGE}`);
|
|
|
1571
1684
|
fail("--limit and --log are the same flag, give one");
|
|
1572
1685
|
const asked = parsed.values.limit ?? parsed.values.log;
|
|
1573
1686
|
const count = asked === undefined ? 0 : wholeNumber(asked, "limit", 1);
|
|
1574
|
-
const [read, head, log] = await Promise.all([
|
|
1575
|
-
git2(["status", "--porcelain=v2", "--branch"]),
|
|
1687
|
+
const [read, head, log, gitDir] = await Promise.all([
|
|
1688
|
+
git2(["status", "--porcelain=v2", "--branch", "--show-stash"]),
|
|
1576
1689
|
git2(["log", "-1", "--format=%h%x00%s"]),
|
|
1577
|
-
count === 0 ? undefined : git2(["log", `-${count}`, "--format=%h%x00%s"])
|
|
1690
|
+
count === 0 ? undefined : git2(["log", `-${count}`, "--format=%h%x00%s"]),
|
|
1691
|
+
git2(["rev-parse", "--absolute-git-dir"])
|
|
1578
1692
|
]);
|
|
1579
1693
|
const status = read.code === 0 ? parseStatus(read.stdout) : null;
|
|
1580
1694
|
if (status === null)
|
|
1581
1695
|
fail(read.stderr.trim() || "not inside a git repository");
|
|
1696
|
+
const extra = { operation: gitDir.code === 0 ? operationOf(gitDir.stdout.trim()) : null, stash: stashOf(read.stdout) };
|
|
1582
1697
|
const commits = log?.code === 0 ? log.stdout.trimEnd().split(`
|
|
1583
1698
|
`).filter(Boolean).map((line) => line.split("\x00")) : [];
|
|
1584
1699
|
if (parsed.values.json === true) {
|
|
1585
1700
|
const [sha, title] = head.code === 0 && head.stdout.trim() !== "" ? head.stdout.trim().split("\x00") : [];
|
|
1586
|
-
printJson(jsonOf(status, sha === undefined ? null : { sha, title: title ?? "" }, commits));
|
|
1701
|
+
printJson(jsonOf(status, sha === undefined ? null : { sha, title: title ?? "" }, commits, extra));
|
|
1587
1702
|
return 0;
|
|
1588
1703
|
}
|
|
1589
1704
|
const lines = [
|
|
1590
|
-
summary(status, head.code === 0 ? head.stdout : ""),
|
|
1705
|
+
summary(status, head.code === 0 ? head.stdout : "", extra),
|
|
1591
1706
|
...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
|
|
1592
1707
|
...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${letter(change.worktree)} ${change.path}`)),
|
|
1593
|
-
...group("untracked", status.untracked.map((file) => paint(
|
|
1594
|
-
...group("conflicted", status.conflicted.map((file) => paint(
|
|
1595
|
-
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id",
|
|
1708
|
+
...group("untracked", status.untracked.map((file) => paint(process21.stdout).dim(file))),
|
|
1709
|
+
...group("conflicted", status.conflicted.map((file) => paint(process21.stdout).red(file))),
|
|
1710
|
+
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process21.stdout)(commitSha)} ${commitTitle}`))
|
|
1596
1711
|
];
|
|
1597
1712
|
console.log(lines.join(`
|
|
1598
1713
|
`));
|
|
1599
1714
|
return 0;
|
|
1600
1715
|
}
|
|
1601
|
-
|
|
1716
|
+
process21.exitCode = await runMain({ name: "gst", run: main });
|