@kaynooo/cli-git 0.15.1 → 0.16.1
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 +11 -1
- package/dist/gb.js +343 -62
- package/dist/gc.js +162 -35
- package/dist/gcl.js +151 -34
- package/dist/gd.js +158 -41
- package/dist/gf.js +155 -38
- package/dist/gm.js +2964 -0
- package/dist/gp.js +155 -38
- package/dist/gst.js +196 -52
- package/dist/gu.js +149 -31
- package/package.json +6 -4
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";
|
|
@@ -493,7 +493,7 @@ function printJson(value) {
|
|
|
493
493
|
|
|
494
494
|
// ../kit/src/help.ts
|
|
495
495
|
import process8 from "process";
|
|
496
|
-
var OPTIONAL =
|
|
496
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
497
497
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
498
498
|
var FULL_STOP = /\.$/;
|
|
499
499
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
@@ -532,29 +532,41 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
532
532
|
return [];
|
|
533
533
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
534
534
|
}
|
|
535
|
+
var MAX_INLINE_CHOICES = 24;
|
|
535
536
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
536
537
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
537
538
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
538
|
-
const
|
|
539
|
+
const choices = option.choices?.join("|");
|
|
540
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
541
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
539
542
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
540
543
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
541
|
-
|
|
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 };
|
|
542
546
|
});
|
|
543
547
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
544
548
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
545
549
|
}
|
|
546
550
|
|
|
547
551
|
// ../kit/src/text.ts
|
|
548
|
-
var ANSI =
|
|
552
|
+
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
549
553
|
function distance(a, b) {
|
|
550
|
-
|
|
551
|
-
|
|
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()) {
|
|
552
559
|
const current = [i + 1];
|
|
553
|
-
for (const [j,
|
|
554
|
-
|
|
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;
|
|
555
567
|
previous = current;
|
|
556
568
|
}
|
|
557
|
-
return previous[
|
|
569
|
+
return previous[right.length] ?? 0;
|
|
558
570
|
}
|
|
559
571
|
function closest(name, names) {
|
|
560
572
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -630,7 +642,7 @@ class Completing {
|
|
|
630
642
|
}
|
|
631
643
|
var completion = { active: false };
|
|
632
644
|
var OUTPUT_OPTIONS = {
|
|
633
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
645
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
634
646
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
635
647
|
};
|
|
636
648
|
function applyOutput(color, plain, env = process9.env) {
|
|
@@ -1138,13 +1150,91 @@ function interceptOutput(clear) {
|
|
|
1138
1150
|
// ../kit/src/cli.ts
|
|
1139
1151
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1140
1152
|
import { dirname as dirname3, join as join5 } from "path";
|
|
1141
|
-
import
|
|
1153
|
+
import process15 from "process";
|
|
1154
|
+
|
|
1155
|
+
// ../kit/src/completions.ts
|
|
1156
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1157
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
1158
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1159
|
+
set -l current (commandline -ct)
|
|
1160
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1161
|
+
if test "$line" = __files__
|
|
1162
|
+
__fish_complete_path $current
|
|
1163
|
+
else
|
|
1164
|
+
echo $line
|
|
1165
|
+
end
|
|
1166
|
+
end
|
|
1167
|
+
end`;
|
|
1168
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1169
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1170
|
+
local -a lines
|
|
1171
|
+
COMPREPLY=()
|
|
1172
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1173
|
+
for line in "\${lines[@]}"; do
|
|
1174
|
+
if [[ $line == __files__ ]]; then
|
|
1175
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1176
|
+
else
|
|
1177
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1178
|
+
fi
|
|
1179
|
+
done
|
|
1180
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1181
|
+
}`;
|
|
1182
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1183
|
+
local line
|
|
1184
|
+
local -a described plain
|
|
1185
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1186
|
+
if [[ $line == __files__ ]]; then
|
|
1187
|
+
_files
|
|
1188
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1189
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1190
|
+
else
|
|
1191
|
+
plain+=("$line")
|
|
1192
|
+
fi
|
|
1193
|
+
done
|
|
1194
|
+
(( \${#described} )) && _describe -V value described
|
|
1195
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1196
|
+
return 0
|
|
1197
|
+
}`;
|
|
1198
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1199
|
+
if (shell === "fish")
|
|
1200
|
+
return `${header}
|
|
1201
|
+
${FISH_FUNCTION}
|
|
1202
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1203
|
+
`).join("")}`;
|
|
1204
|
+
if (shell === "bash")
|
|
1205
|
+
return `${header}
|
|
1206
|
+
${BASH_FUNCTION}
|
|
1207
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1208
|
+
`;
|
|
1209
|
+
return `${header}
|
|
1210
|
+
${ZSH_FUNCTION}
|
|
1211
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1212
|
+
`;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// ../kit/src/notify.ts
|
|
1216
|
+
import process13 from "process";
|
|
1217
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1218
|
+
var CANCELLED = 130;
|
|
1219
|
+
function base64(text) {
|
|
1220
|
+
return Buffer.from(text).toString("base64");
|
|
1221
|
+
}
|
|
1222
|
+
function notification(title, body, env = process13.env) {
|
|
1223
|
+
const id = `kit${process13.pid}`;
|
|
1224
|
+
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\\`];
|
|
1225
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1226
|
+
}
|
|
1227
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1228
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1229
|
+
return;
|
|
1230
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1231
|
+
}
|
|
1142
1232
|
|
|
1143
1233
|
// ../kit/src/usage.ts
|
|
1144
1234
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1145
1235
|
import { homedir as homedir3 } from "os";
|
|
1146
1236
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1147
|
-
import
|
|
1237
|
+
import process14 from "process";
|
|
1148
1238
|
|
|
1149
1239
|
// ../kit/src/logs.ts
|
|
1150
1240
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1158,14 +1248,14 @@ var usageError;
|
|
|
1158
1248
|
function noteUsageError(message) {
|
|
1159
1249
|
usageError = message;
|
|
1160
1250
|
}
|
|
1161
|
-
function stateHome(env =
|
|
1251
|
+
function stateHome(env = process14.env) {
|
|
1162
1252
|
const dir = env.XDG_STATE_HOME;
|
|
1163
1253
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1164
1254
|
}
|
|
1165
|
-
function usagePath(env =
|
|
1255
|
+
function usagePath(env = process14.env) {
|
|
1166
1256
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1167
1257
|
}
|
|
1168
|
-
function usageRecorded(env =
|
|
1258
|
+
function usageRecorded(env = process14.env) {
|
|
1169
1259
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1170
1260
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1171
1261
|
}
|
|
@@ -1179,7 +1269,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1179
1269
|
usageError = undefined;
|
|
1180
1270
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1181
1271
|
}
|
|
1182
|
-
function recordUsage(entry, env =
|
|
1272
|
+
function recordUsage(entry, env = process14.env) {
|
|
1183
1273
|
if (!usageRecorded(env))
|
|
1184
1274
|
return;
|
|
1185
1275
|
try {
|
|
@@ -1195,10 +1285,14 @@ var LEVEL_OPTIONS = {
|
|
|
1195
1285
|
...OUTPUT_OPTIONS,
|
|
1196
1286
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1197
1287
|
};
|
|
1198
|
-
var TOP_OPTIONS = {
|
|
1288
|
+
var TOP_OPTIONS = {
|
|
1289
|
+
...LEVEL_OPTIONS,
|
|
1290
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1291
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1292
|
+
};
|
|
1199
1293
|
function printError(prefix, message, hint, cause) {
|
|
1200
|
-
const colors = paint(
|
|
1201
|
-
const styled = takesControlCodes(
|
|
1294
|
+
const colors = paint(process15.stderr);
|
|
1295
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1202
1296
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1203
1297
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1204
1298
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1278,6 +1372,19 @@ async function leafCandidates(run, words) {
|
|
|
1278
1372
|
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1279
1373
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1280
1374
|
}
|
|
1375
|
+
var COMPLETIONS = "--completions";
|
|
1376
|
+
function flagValue([flag = "", ...rest]) {
|
|
1377
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1378
|
+
}
|
|
1379
|
+
function printCompletionScript(name, args) {
|
|
1380
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1381
|
+
if (shell === undefined || args.length !== 1) {
|
|
1382
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1383
|
+
return 2;
|
|
1384
|
+
}
|
|
1385
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1386
|
+
return 0;
|
|
1387
|
+
}
|
|
1281
1388
|
async function printCandidates(found) {
|
|
1282
1389
|
for (const line of await found)
|
|
1283
1390
|
console.log(line);
|
|
@@ -1301,16 +1408,20 @@ function packageVersion(entry = Bun.main) {
|
|
|
1301
1408
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1302
1409
|
if (argv[0] === COMPLETE)
|
|
1303
1410
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1411
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1412
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1304
1413
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1305
1414
|
console.log(version ?? packageVersion());
|
|
1306
1415
|
return 0;
|
|
1307
1416
|
}
|
|
1308
1417
|
let code;
|
|
1418
|
+
const started = performance.now();
|
|
1309
1419
|
try {
|
|
1310
1420
|
code = await run(argv);
|
|
1311
1421
|
} catch (error) {
|
|
1312
1422
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1313
1423
|
}
|
|
1424
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1314
1425
|
if (usage !== false) {
|
|
1315
1426
|
try {
|
|
1316
1427
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1327,7 +1438,7 @@ var {Glob } = globalThis.Bun;
|
|
|
1327
1438
|
var SESSION_FILES = new Glob("*.json");
|
|
1328
1439
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1329
1440
|
// ../kit/src/watch.ts
|
|
1330
|
-
import
|
|
1441
|
+
import process16 from "process";
|
|
1331
1442
|
import { format } from "util";
|
|
1332
1443
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1333
1444
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1349,7 +1460,7 @@ function withoutWatch(args) {
|
|
|
1349
1460
|
}
|
|
1350
1461
|
return rest;
|
|
1351
1462
|
}
|
|
1352
|
-
async function watching(value, step, stream =
|
|
1463
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1353
1464
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1354
1465
|
if (!takesControlCodes(stream))
|
|
1355
1466
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1357,12 +1468,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1357
1468
|
for (let round = 0;round < rounds; round++) {
|
|
1358
1469
|
const held = [];
|
|
1359
1470
|
const { log, info } = console;
|
|
1360
|
-
const write =
|
|
1471
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1361
1472
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1362
1473
|
`);
|
|
1363
1474
|
console.log = hold;
|
|
1364
1475
|
console.info = hold;
|
|
1365
|
-
|
|
1476
|
+
process16.stdout.write = (text) => {
|
|
1366
1477
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1367
1478
|
return true;
|
|
1368
1479
|
};
|
|
@@ -1371,7 +1482,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1371
1482
|
} finally {
|
|
1372
1483
|
console.log = log;
|
|
1373
1484
|
console.info = info;
|
|
1374
|
-
|
|
1485
|
+
process16.stdout.write = write;
|
|
1375
1486
|
}
|
|
1376
1487
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1377
1488
|
await sleep(interval);
|
|
@@ -1381,7 +1492,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1381
1492
|
// ../kit/src/workspace-root.ts
|
|
1382
1493
|
import { homedir as homedir4 } from "os";
|
|
1383
1494
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1384
|
-
import
|
|
1495
|
+
import process17 from "process";
|
|
1385
1496
|
function expandHome(path, home) {
|
|
1386
1497
|
if (path === "~")
|
|
1387
1498
|
return home;
|
|
@@ -1391,13 +1502,13 @@ function configured(env, home) {
|
|
|
1391
1502
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1392
1503
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1393
1504
|
}
|
|
1394
|
-
function workspaceRoot({ given, env =
|
|
1505
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1395
1506
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1396
1507
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1397
1508
|
}
|
|
1398
1509
|
// src/colour.ts
|
|
1399
|
-
import
|
|
1400
|
-
function letter(status, stream =
|
|
1510
|
+
import process19 from "process";
|
|
1511
|
+
function letter(status, stream = process19.stdout) {
|
|
1401
1512
|
const colors = paint(stream);
|
|
1402
1513
|
const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
|
|
1403
1514
|
return tint(status);
|
|
@@ -1410,17 +1521,45 @@ async function git2(args, env) {
|
|
|
1410
1521
|
return { code: ran.code, stdout: text("stdout"), stderr: text("stderr") };
|
|
1411
1522
|
}
|
|
1412
1523
|
|
|
1524
|
+
// src/operation.ts
|
|
1525
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
1526
|
+
import { join as join7 } from "path";
|
|
1527
|
+
function numberIn(path) {
|
|
1528
|
+
try {
|
|
1529
|
+
const value = Number.parseInt(readFileSync5(path, "utf8"), 10);
|
|
1530
|
+
return Number.isNaN(value) ? undefined : value;
|
|
1531
|
+
} catch {
|
|
1532
|
+
return;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
function operationOf(gitDir) {
|
|
1536
|
+
const has = (name) => existsSync4(join7(gitDir, name));
|
|
1537
|
+
if (has("rebase-merge"))
|
|
1538
|
+
return { kind: "rebase", step: numberIn(join7(gitDir, "rebase-merge/msgnum")), total: numberIn(join7(gitDir, "rebase-merge/end")) };
|
|
1539
|
+
if (has("rebase-apply"))
|
|
1540
|
+
return { kind: "rebase", step: numberIn(join7(gitDir, "rebase-apply/next")), total: numberIn(join7(gitDir, "rebase-apply/last")) };
|
|
1541
|
+
for (const [file, kind] of [["MERGE_HEAD", "merge"], ["CHERRY_PICK_HEAD", "cherry-pick"], ["REVERT_HEAD", "revert"], ["BISECT_LOG", "bisect"]]) {
|
|
1542
|
+
if (has(file))
|
|
1543
|
+
return { kind };
|
|
1544
|
+
}
|
|
1545
|
+
return null;
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1413
1548
|
// src/repos.ts
|
|
1414
1549
|
import { readdir } from "fs/promises";
|
|
1415
|
-
import { join as
|
|
1416
|
-
import
|
|
1550
|
+
import { join as join8, relative, resolve as resolve5 } from "path";
|
|
1551
|
+
import process20 from "process";
|
|
1417
1552
|
|
|
1418
1553
|
// src/status.ts
|
|
1419
1554
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
1555
|
+
var STASH = /^# stash (\d+)$/m;
|
|
1420
1556
|
var OCTAL = /[0-7]/;
|
|
1421
1557
|
var ESCAPES = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13 };
|
|
1422
1558
|
var ENCODER = new TextEncoder;
|
|
1423
1559
|
var DECODER = new TextDecoder;
|
|
1560
|
+
function stashOf(text) {
|
|
1561
|
+
return Number(STASH.exec(text)?.[1] ?? 0);
|
|
1562
|
+
}
|
|
1424
1563
|
function unquote(path) {
|
|
1425
1564
|
if (!path.startsWith('"') || !path.endsWith('"'))
|
|
1426
1565
|
return path;
|
|
@@ -1475,16 +1614,18 @@ function parseStatus(text) {
|
|
|
1475
1614
|
}
|
|
1476
1615
|
return hasBranch ? status : null;
|
|
1477
1616
|
}
|
|
1478
|
-
function summary(status, head) {
|
|
1617
|
+
function summary(status, head, { operation = null, stash = 0 } = {}) {
|
|
1479
1618
|
const { branch, oid, upstream, aheadBehind, changes, conflicted, untracked } = status;
|
|
1480
|
-
const
|
|
1619
|
+
const steps = operation?.step !== undefined && operation.total !== undefined ? ` ${operation.step}/${operation.total}` : "";
|
|
1620
|
+
const during = operation === null ? "" : ` (${operation.kind}${steps} in progress)`;
|
|
1621
|
+
const on = (branch === "(detached)" ? `detached at ${oid.slice(0, 7)}` : `branch \`${branch}\``) + during;
|
|
1481
1622
|
let tracking = "no upstream";
|
|
1482
1623
|
if (upstream !== null)
|
|
1483
1624
|
tracking = aheadBehind === null ? `upstream \`${upstream}\` gone or never fetched` : `${aheadBehind.ahead} ahead and ${aheadBehind.behind} behind \`${upstream}\` as of the last fetch`;
|
|
1484
1625
|
const files = [`${changes.length} changed`, untracked.length > 0 ? `${untracked.length} untracked` : "", conflicted.length > 0 ? `${conflicted.length} conflicted` : ""].filter(Boolean).join(", ");
|
|
1485
1626
|
const [sha, title] = head.trim().split("\x00");
|
|
1486
1627
|
const last = sha === undefined || sha === "" ? "; no commit yet" : `; HEAD ${sha} ${title ?? ""}`.trimEnd();
|
|
1487
|
-
return `${on}, ${tracking}; ${files} files${last}`;
|
|
1628
|
+
return `${on}, ${tracking}; ${files} files${stash > 0 ? `; ${stash} stashed` : ""}${last}`;
|
|
1488
1629
|
}
|
|
1489
1630
|
|
|
1490
1631
|
// src/repos.ts
|
|
@@ -1503,7 +1644,7 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
1503
1644
|
found.push(dir);
|
|
1504
1645
|
if (left === 0)
|
|
1505
1646
|
return;
|
|
1506
|
-
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(
|
|
1647
|
+
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)));
|
|
1507
1648
|
}
|
|
1508
1649
|
await walk(resolve5(root), depth);
|
|
1509
1650
|
return found.sort();
|
|
@@ -1513,14 +1654,14 @@ async function toplevelOf(dir) {
|
|
|
1513
1654
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1514
1655
|
}
|
|
1515
1656
|
async function reposOf(roots) {
|
|
1516
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
1657
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process20.cwd()];
|
|
1517
1658
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1518
1659
|
return [...new Set(found.flat())].sort();
|
|
1519
1660
|
}
|
|
1520
1661
|
async function repoState(dir) {
|
|
1521
1662
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1522
1663
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1523
|
-
return { path: relative(
|
|
1664
|
+
return { path: relative(process20.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1524
1665
|
}
|
|
1525
1666
|
function trackingOf(status) {
|
|
1526
1667
|
if (status.upstream === null)
|
|
@@ -1565,9 +1706,9 @@ var OPTIONS = {
|
|
|
1565
1706
|
log: { type: "string", short: "l", description: "the former spelling of --limit" },
|
|
1566
1707
|
repos: { type: "boolean", short: "r", description: "one line for each repository nested below, the current one included", conflicts: ["limit", "log"] },
|
|
1567
1708
|
watch: watchOption("the status"),
|
|
1568
|
-
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}")
|
|
1709
|
+
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}")
|
|
1569
1710
|
};
|
|
1570
|
-
function jsonOf(status, head, commits) {
|
|
1711
|
+
function jsonOf(status, head, commits, extra) {
|
|
1571
1712
|
return {
|
|
1572
1713
|
branch: status.branch,
|
|
1573
1714
|
oid: status.oid,
|
|
@@ -1579,6 +1720,7 @@ function jsonOf(status, head, commits) {
|
|
|
1579
1720
|
unstaged: status.changes.filter((change) => change.worktree !== ".").map(({ worktree, path }) => ({ status: worktree, path })),
|
|
1580
1721
|
untracked: status.untracked,
|
|
1581
1722
|
conflicted: status.conflicted,
|
|
1723
|
+
...extra === undefined ? {} : { operation: extra.operation, stash: extra.stash },
|
|
1582
1724
|
...commits === undefined ? {} : { commits: commits.map(([commitSha = "", commitTitle = ""]) => ({ sha: commitSha, title: commitTitle })) }
|
|
1583
1725
|
};
|
|
1584
1726
|
}
|
|
@@ -1591,18 +1733,18 @@ async function listRepos(roots, json) {
|
|
|
1591
1733
|
printJson(repos.map(({ path, status, head }) => status === null ? { path, error: "git could not read it" } : { path, ...jsonOf(status, head) }));
|
|
1592
1734
|
return 0;
|
|
1593
1735
|
}
|
|
1594
|
-
const dim = paint(
|
|
1736
|
+
const dim = paint(process21.stdout).dim;
|
|
1595
1737
|
const cells = (repo) => {
|
|
1596
1738
|
if (repo.status === null)
|
|
1597
|
-
return [role("path",
|
|
1739
|
+
return [role("path", process21.stdout)(repo.path), "", "", "git could not read it"];
|
|
1598
1740
|
const changes = changesOf(repo.status);
|
|
1599
|
-
return [role("path",
|
|
1741
|
+
return [role("path", process21.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
|
|
1600
1742
|
};
|
|
1601
1743
|
console.log(table(repos.map(cells)));
|
|
1602
1744
|
return 0;
|
|
1603
1745
|
}
|
|
1604
1746
|
function group(title, lines) {
|
|
1605
|
-
return lines.length === 0 ? [] : [paint(
|
|
1747
|
+
return lines.length === 0 ? [] : [paint(process21.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
|
|
1606
1748
|
}
|
|
1607
1749
|
function staged({ index, from, path }) {
|
|
1608
1750
|
return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
|
|
@@ -1621,31 +1763,33 @@ ${USAGE}`);
|
|
|
1621
1763
|
fail("--limit and --log are the same flag, give one");
|
|
1622
1764
|
const asked = parsed.values.limit ?? parsed.values.log;
|
|
1623
1765
|
const count = asked === undefined ? 0 : wholeNumber(asked, "limit", 1);
|
|
1624
|
-
const [read, head, log] = await Promise.all([
|
|
1625
|
-
git2(["status", "--porcelain=v2", "--branch"]),
|
|
1766
|
+
const [read, head, log, gitDir] = await Promise.all([
|
|
1767
|
+
git2(["status", "--porcelain=v2", "--branch", "--show-stash"]),
|
|
1626
1768
|
git2(["log", "-1", "--format=%h%x00%s"]),
|
|
1627
|
-
count === 0 ? undefined : git2(["log", `-${count}`, "--format=%h%x00%s"])
|
|
1769
|
+
count === 0 ? undefined : git2(["log", `-${count}`, "--format=%h%x00%s"]),
|
|
1770
|
+
git2(["rev-parse", "--absolute-git-dir"])
|
|
1628
1771
|
]);
|
|
1629
1772
|
const status = read.code === 0 ? parseStatus(read.stdout) : null;
|
|
1630
1773
|
if (status === null)
|
|
1631
1774
|
fail(read.stderr.trim() || "not inside a git repository");
|
|
1775
|
+
const extra = { operation: gitDir.code === 0 ? operationOf(gitDir.stdout.trim()) : null, stash: stashOf(read.stdout) };
|
|
1632
1776
|
const commits = log?.code === 0 ? log.stdout.trimEnd().split(`
|
|
1633
1777
|
`).filter(Boolean).map((line) => line.split("\x00")) : [];
|
|
1634
1778
|
if (parsed.values.json === true) {
|
|
1635
1779
|
const [sha, title] = head.code === 0 && head.stdout.trim() !== "" ? head.stdout.trim().split("\x00") : [];
|
|
1636
|
-
printJson(jsonOf(status, sha === undefined ? null : { sha, title: title ?? "" }, commits));
|
|
1780
|
+
printJson(jsonOf(status, sha === undefined ? null : { sha, title: title ?? "" }, commits, extra));
|
|
1637
1781
|
return 0;
|
|
1638
1782
|
}
|
|
1639
1783
|
const lines = [
|
|
1640
|
-
summary(status, head.code === 0 ? head.stdout : ""),
|
|
1784
|
+
summary(status, head.code === 0 ? head.stdout : "", extra),
|
|
1641
1785
|
...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
|
|
1642
1786
|
...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${letter(change.worktree)} ${change.path}`)),
|
|
1643
|
-
...group("untracked", status.untracked.map((file) => paint(
|
|
1644
|
-
...group("conflicted", status.conflicted.map((file) => paint(
|
|
1645
|
-
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id",
|
|
1787
|
+
...group("untracked", status.untracked.map((file) => paint(process21.stdout).dim(file))),
|
|
1788
|
+
...group("conflicted", status.conflicted.map((file) => paint(process21.stdout).red(file))),
|
|
1789
|
+
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process21.stdout)(commitSha)} ${commitTitle}`))
|
|
1646
1790
|
];
|
|
1647
1791
|
console.log(lines.join(`
|
|
1648
1792
|
`));
|
|
1649
1793
|
return 0;
|
|
1650
1794
|
}
|
|
1651
|
-
|
|
1795
|
+
process21.exitCode = await runMain({ name: "gst", run: main });
|