@kaynooo/cli-git 0.15.1 → 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 +11 -1
- package/dist/gb.js +262 -60
- package/dist/gc.js +81 -33
- package/dist/gcl.js +70 -32
- package/dist/gd.js +77 -39
- package/dist/gf.js +74 -36
- package/dist/gm.js +2885 -0
- package/dist/gp.js +74 -36
- package/dist/gst.js +115 -50
- package/dist/gu.js +68 -29
- package/package.json +6 -4
package/dist/gp.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gp.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));
|
|
@@ -1138,13 +1150,31 @@ 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/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
|
+
}
|
|
1142
1172
|
|
|
1143
1173
|
// ../kit/src/usage.ts
|
|
1144
1174
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1145
1175
|
import { homedir as homedir3 } from "os";
|
|
1146
1176
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1147
|
-
import
|
|
1177
|
+
import process14 from "process";
|
|
1148
1178
|
|
|
1149
1179
|
// ../kit/src/logs.ts
|
|
1150
1180
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1158,14 +1188,14 @@ var usageError;
|
|
|
1158
1188
|
function noteUsageError(message) {
|
|
1159
1189
|
usageError = message;
|
|
1160
1190
|
}
|
|
1161
|
-
function stateHome(env =
|
|
1191
|
+
function stateHome(env = process14.env) {
|
|
1162
1192
|
const dir = env.XDG_STATE_HOME;
|
|
1163
1193
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1164
1194
|
}
|
|
1165
|
-
function usagePath(env =
|
|
1195
|
+
function usagePath(env = process14.env) {
|
|
1166
1196
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1167
1197
|
}
|
|
1168
|
-
function usageRecorded(env =
|
|
1198
|
+
function usageRecorded(env = process14.env) {
|
|
1169
1199
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1170
1200
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1171
1201
|
}
|
|
@@ -1179,7 +1209,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1179
1209
|
usageError = undefined;
|
|
1180
1210
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1181
1211
|
}
|
|
1182
|
-
function recordUsage(entry, env =
|
|
1212
|
+
function recordUsage(entry, env = process14.env) {
|
|
1183
1213
|
if (!usageRecorded(env))
|
|
1184
1214
|
return;
|
|
1185
1215
|
try {
|
|
@@ -1197,8 +1227,8 @@ var LEVEL_OPTIONS = {
|
|
|
1197
1227
|
};
|
|
1198
1228
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
1199
1229
|
function printError(prefix, message, hint, cause) {
|
|
1200
|
-
const colors = paint(
|
|
1201
|
-
const styled = takesControlCodes(
|
|
1230
|
+
const colors = paint(process15.stderr);
|
|
1231
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1202
1232
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1203
1233
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1204
1234
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1306,11 +1336,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1306
1336
|
return 0;
|
|
1307
1337
|
}
|
|
1308
1338
|
let code;
|
|
1339
|
+
const started = performance.now();
|
|
1309
1340
|
try {
|
|
1310
1341
|
code = await run(argv);
|
|
1311
1342
|
} catch (error) {
|
|
1312
1343
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1313
1344
|
}
|
|
1345
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1314
1346
|
if (usage !== false) {
|
|
1315
1347
|
try {
|
|
1316
1348
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1327,7 +1359,7 @@ var {Glob } = globalThis.Bun;
|
|
|
1327
1359
|
var SESSION_FILES = new Glob("*.json");
|
|
1328
1360
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1329
1361
|
// ../kit/src/watch.ts
|
|
1330
|
-
import
|
|
1362
|
+
import process16 from "process";
|
|
1331
1363
|
import { format } from "util";
|
|
1332
1364
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1333
1365
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1349,7 +1381,7 @@ function withoutWatch(args) {
|
|
|
1349
1381
|
}
|
|
1350
1382
|
return rest;
|
|
1351
1383
|
}
|
|
1352
|
-
async function watching(value, step, stream =
|
|
1384
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1353
1385
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1354
1386
|
if (!takesControlCodes(stream))
|
|
1355
1387
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1357,12 +1389,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1357
1389
|
for (let round = 0;round < rounds; round++) {
|
|
1358
1390
|
const held = [];
|
|
1359
1391
|
const { log, info } = console;
|
|
1360
|
-
const write =
|
|
1392
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1361
1393
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1362
1394
|
`);
|
|
1363
1395
|
console.log = hold;
|
|
1364
1396
|
console.info = hold;
|
|
1365
|
-
|
|
1397
|
+
process16.stdout.write = (text) => {
|
|
1366
1398
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1367
1399
|
return true;
|
|
1368
1400
|
};
|
|
@@ -1371,7 +1403,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1371
1403
|
} finally {
|
|
1372
1404
|
console.log = log;
|
|
1373
1405
|
console.info = info;
|
|
1374
|
-
|
|
1406
|
+
process16.stdout.write = write;
|
|
1375
1407
|
}
|
|
1376
1408
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1377
1409
|
await sleep(interval);
|
|
@@ -1381,7 +1413,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1381
1413
|
// ../kit/src/workspace-root.ts
|
|
1382
1414
|
import { homedir as homedir4 } from "os";
|
|
1383
1415
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1384
|
-
import
|
|
1416
|
+
import process17 from "process";
|
|
1385
1417
|
function expandHome(path, home) {
|
|
1386
1418
|
if (path === "~")
|
|
1387
1419
|
return home;
|
|
@@ -1391,7 +1423,7 @@ function configured(env, home) {
|
|
|
1391
1423
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1392
1424
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1393
1425
|
}
|
|
1394
|
-
function workspaceRoot({ given, env =
|
|
1426
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1395
1427
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1396
1428
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1397
1429
|
}
|
|
@@ -1405,14 +1437,18 @@ async function git2(args, env) {
|
|
|
1405
1437
|
// src/repos.ts
|
|
1406
1438
|
import { readdir } from "fs/promises";
|
|
1407
1439
|
import { join as join7, relative, resolve as resolve5 } from "path";
|
|
1408
|
-
import
|
|
1440
|
+
import process19 from "process";
|
|
1409
1441
|
|
|
1410
1442
|
// src/status.ts
|
|
1411
1443
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
1444
|
+
var STASH = /^# stash (\d+)$/m;
|
|
1412
1445
|
var OCTAL = /[0-7]/;
|
|
1413
1446
|
var ESCAPES = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13 };
|
|
1414
1447
|
var ENCODER = new TextEncoder;
|
|
1415
1448
|
var DECODER = new TextDecoder;
|
|
1449
|
+
function stashOf(text) {
|
|
1450
|
+
return Number(STASH.exec(text)?.[1] ?? 0);
|
|
1451
|
+
}
|
|
1416
1452
|
function unquote(path) {
|
|
1417
1453
|
if (!path.startsWith('"') || !path.endsWith('"'))
|
|
1418
1454
|
return path;
|
|
@@ -1467,16 +1503,18 @@ function parseStatus(text) {
|
|
|
1467
1503
|
}
|
|
1468
1504
|
return hasBranch ? status : null;
|
|
1469
1505
|
}
|
|
1470
|
-
function summary(status, head) {
|
|
1506
|
+
function summary(status, head, { operation = null, stash = 0 } = {}) {
|
|
1471
1507
|
const { branch, oid, upstream, aheadBehind, changes, conflicted, untracked } = status;
|
|
1472
|
-
const
|
|
1508
|
+
const steps = operation?.step !== undefined && operation.total !== undefined ? ` ${operation.step}/${operation.total}` : "";
|
|
1509
|
+
const during = operation === null ? "" : ` (${operation.kind}${steps} in progress)`;
|
|
1510
|
+
const on = (branch === "(detached)" ? `detached at ${oid.slice(0, 7)}` : `branch \`${branch}\``) + during;
|
|
1473
1511
|
let tracking = "no upstream";
|
|
1474
1512
|
if (upstream !== null)
|
|
1475
1513
|
tracking = aheadBehind === null ? `upstream \`${upstream}\` gone or never fetched` : `${aheadBehind.ahead} ahead and ${aheadBehind.behind} behind \`${upstream}\` as of the last fetch`;
|
|
1476
1514
|
const files = [`${changes.length} changed`, untracked.length > 0 ? `${untracked.length} untracked` : "", conflicted.length > 0 ? `${conflicted.length} conflicted` : ""].filter(Boolean).join(", ");
|
|
1477
1515
|
const [sha, title] = head.trim().split("\x00");
|
|
1478
1516
|
const last = sha === undefined || sha === "" ? "; no commit yet" : `; HEAD ${sha} ${title ?? ""}`.trimEnd();
|
|
1479
|
-
return `${on}, ${tracking}; ${files} files${last}`;
|
|
1517
|
+
return `${on}, ${tracking}; ${files} files${stash > 0 ? `; ${stash} stashed` : ""}${last}`;
|
|
1480
1518
|
}
|
|
1481
1519
|
|
|
1482
1520
|
// src/repos.ts
|
|
@@ -1505,14 +1543,14 @@ async function toplevelOf(dir) {
|
|
|
1505
1543
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1506
1544
|
}
|
|
1507
1545
|
async function reposOf(roots) {
|
|
1508
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
1546
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process19.cwd()];
|
|
1509
1547
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1510
1548
|
return [...new Set(found.flat())].sort();
|
|
1511
1549
|
}
|
|
1512
1550
|
async function repoState(dir) {
|
|
1513
1551
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1514
1552
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1515
|
-
return { path: relative(
|
|
1553
|
+
return { path: relative(process19.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1516
1554
|
}
|
|
1517
1555
|
function trackingOf(status) {
|
|
1518
1556
|
if (status.upstream === null)
|
|
@@ -1606,16 +1644,16 @@ async function push(repo, { dryRun, extra }) {
|
|
|
1606
1644
|
return pushed.code === 0 ? { path, branch, remote, commits, outcome: "pushed" } : { path, branch, remote, commits, outcome: "refused", reason: whyRefused(pushed.stderr) };
|
|
1607
1645
|
}
|
|
1608
1646
|
function line(result) {
|
|
1609
|
-
const { dim } = paint(
|
|
1647
|
+
const { dim } = paint(process20.stdout);
|
|
1610
1648
|
const sent = result.commits === null ? "" : `, ${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
|
|
1611
1649
|
const what = `${result.branch} -> ${result.remote}${sent}`;
|
|
1612
1650
|
const said = {
|
|
1613
|
-
pushed: () => marked("ok", `pushed ${what}`,
|
|
1651
|
+
pushed: () => marked("ok", `pushed ${what}`, process20.stdout),
|
|
1614
1652
|
"would-push": () => `would push ${what}`,
|
|
1615
1653
|
skipped: () => dim(result.reason ?? "skipped"),
|
|
1616
|
-
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`,
|
|
1654
|
+
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process20.stdout)
|
|
1617
1655
|
}[result.outcome];
|
|
1618
|
-
return [role("path",
|
|
1656
|
+
return [role("path", process20.stdout)(result.path), said()];
|
|
1619
1657
|
}
|
|
1620
1658
|
async function main(argv) {
|
|
1621
1659
|
const { values, positionals, rest = [] } = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], rest: true, exits: EXITS, replaces: "git push, git push -u origin <branch> and a git -C <repo> push per nested repository", examples: ["gp", ["gp --repos", "every repository nested in this one"], ["gp --repos --dry-run", "what would go out"], ["gp . ../other", "this repository and a sibling"], ["gp -- --force-with-lease", "flags for git push"]] });
|
|
@@ -1634,4 +1672,4 @@ async function main(argv) {
|
|
|
1634
1672
|
console.log(table(results.map(line)));
|
|
1635
1673
|
return results.some((result) => result.outcome === "refused") ? 1 : 0;
|
|
1636
1674
|
}
|
|
1637
|
-
|
|
1675
|
+
process20.exitCode = await runMain({ name: "gp", run: main });
|