@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/gf.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gf.ts
|
|
5
|
-
import
|
|
5
|
+
import process20 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,14 +1502,14 @@ 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/repos.ts
|
|
1399
1510
|
import { readdir } from "fs/promises";
|
|
1400
1511
|
import { join as join7, relative, resolve as resolve5 } from "path";
|
|
1401
|
-
import
|
|
1512
|
+
import process19 from "process";
|
|
1402
1513
|
|
|
1403
1514
|
// src/git.ts
|
|
1404
1515
|
async function git2(args, env) {
|
|
@@ -1409,10 +1520,14 @@ async function git2(args, env) {
|
|
|
1409
1520
|
|
|
1410
1521
|
// src/status.ts
|
|
1411
1522
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
1523
|
+
var STASH = /^# stash (\d+)$/m;
|
|
1412
1524
|
var OCTAL = /[0-7]/;
|
|
1413
1525
|
var ESCAPES = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13 };
|
|
1414
1526
|
var ENCODER = new TextEncoder;
|
|
1415
1527
|
var DECODER = new TextDecoder;
|
|
1528
|
+
function stashOf(text) {
|
|
1529
|
+
return Number(STASH.exec(text)?.[1] ?? 0);
|
|
1530
|
+
}
|
|
1416
1531
|
function unquote(path) {
|
|
1417
1532
|
if (!path.startsWith('"') || !path.endsWith('"'))
|
|
1418
1533
|
return path;
|
|
@@ -1467,16 +1582,18 @@ function parseStatus(text) {
|
|
|
1467
1582
|
}
|
|
1468
1583
|
return hasBranch ? status : null;
|
|
1469
1584
|
}
|
|
1470
|
-
function summary(status, head) {
|
|
1585
|
+
function summary(status, head, { operation = null, stash = 0 } = {}) {
|
|
1471
1586
|
const { branch, oid, upstream, aheadBehind, changes, conflicted, untracked } = status;
|
|
1472
|
-
const
|
|
1587
|
+
const steps = operation?.step !== undefined && operation.total !== undefined ? ` ${operation.step}/${operation.total}` : "";
|
|
1588
|
+
const during = operation === null ? "" : ` (${operation.kind}${steps} in progress)`;
|
|
1589
|
+
const on = (branch === "(detached)" ? `detached at ${oid.slice(0, 7)}` : `branch \`${branch}\``) + during;
|
|
1473
1590
|
let tracking = "no upstream";
|
|
1474
1591
|
if (upstream !== null)
|
|
1475
1592
|
tracking = aheadBehind === null ? `upstream \`${upstream}\` gone or never fetched` : `${aheadBehind.ahead} ahead and ${aheadBehind.behind} behind \`${upstream}\` as of the last fetch`;
|
|
1476
1593
|
const files = [`${changes.length} changed`, untracked.length > 0 ? `${untracked.length} untracked` : "", conflicted.length > 0 ? `${conflicted.length} conflicted` : ""].filter(Boolean).join(", ");
|
|
1477
1594
|
const [sha, title] = head.trim().split("\x00");
|
|
1478
1595
|
const last = sha === undefined || sha === "" ? "; no commit yet" : `; HEAD ${sha} ${title ?? ""}`.trimEnd();
|
|
1479
|
-
return `${on}, ${tracking}; ${files} files${last}`;
|
|
1596
|
+
return `${on}, ${tracking}; ${files} files${stash > 0 ? `; ${stash} stashed` : ""}${last}`;
|
|
1480
1597
|
}
|
|
1481
1598
|
|
|
1482
1599
|
// src/repos.ts
|
|
@@ -1505,14 +1622,14 @@ async function toplevelOf(dir) {
|
|
|
1505
1622
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1506
1623
|
}
|
|
1507
1624
|
async function reposOf(roots) {
|
|
1508
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
1625
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process19.cwd()];
|
|
1509
1626
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1510
1627
|
return [...new Set(found.flat())].sort();
|
|
1511
1628
|
}
|
|
1512
1629
|
async function repoState(dir) {
|
|
1513
1630
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1514
1631
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1515
|
-
return { path: relative(
|
|
1632
|
+
return { path: relative(process19.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1516
1633
|
}
|
|
1517
1634
|
function trackingOf(status) {
|
|
1518
1635
|
if (status.upstream === null)
|
|
@@ -1594,16 +1711,16 @@ var OPTIONS = {
|
|
|
1594
1711
|
json: jsonOption("one {path, branch, upstream, commits, outcome, reason?} per repository, outcome being updated, current, fetched, skipped or refused")
|
|
1595
1712
|
};
|
|
1596
1713
|
function line(result) {
|
|
1597
|
-
const { dim } = paint(
|
|
1714
|
+
const { dim } = paint(process20.stdout);
|
|
1598
1715
|
const count = `${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
|
|
1599
1716
|
const said = {
|
|
1600
|
-
updated: () => marked("ok", `${result.branch} <- ${result.upstream}, ${count}`,
|
|
1717
|
+
updated: () => marked("ok", `${result.branch} <- ${result.upstream}, ${count}`, process20.stdout),
|
|
1601
1718
|
current: () => dim(`${result.branch} up to date`),
|
|
1602
1719
|
fetched: () => `${result.branch} is ${result.commits} behind ${result.upstream}`,
|
|
1603
1720
|
skipped: () => dim(`${result.branch ?? ""} ${result.reason ?? "skipped"}`.trim()),
|
|
1604
|
-
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`,
|
|
1721
|
+
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process20.stdout)
|
|
1605
1722
|
}[result.outcome];
|
|
1606
|
-
return [role("path",
|
|
1723
|
+
return [role("path", process20.stdout)(result.path), said()];
|
|
1607
1724
|
}
|
|
1608
1725
|
async function main(argv) {
|
|
1609
1726
|
const { values, positionals } = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], exits: EXITS, replaces: "git fetch --prune, git pull --ff-only and a git -C <repo> pull per nested repository", examples: ["gf", ["gf --repos", "every repository nested in this one"], ["gf --no-pull", "fetch and say how far behind the branch is"]] });
|
|
@@ -1621,4 +1738,4 @@ async function main(argv) {
|
|
|
1621
1738
|
console.log(table(results.map(line)));
|
|
1622
1739
|
return results.some((result) => result.outcome === "refused") ? 1 : 0;
|
|
1623
1740
|
}
|
|
1624
|
-
|
|
1741
|
+
process20.exitCode = await runMain({ name: "gf", run: main });
|