@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/gc.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gc.ts
|
|
5
|
-
import
|
|
5
|
+
import process19 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -108,7 +108,7 @@ function Fe(r = {}) {
|
|
|
108
108
|
var o = Fe();
|
|
109
109
|
|
|
110
110
|
// ../kit/src/theme.ts
|
|
111
|
-
import { existsSync as
|
|
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,13 +1403,30 @@ 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
|
}
|
|
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";
|
|
1416
|
+
import process17 from "process";
|
|
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
|
+
}
|
|
1362
1430
|
// src/git.ts
|
|
1363
1431
|
async function git2(args, env) {
|
|
1364
1432
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -1431,7 +1499,7 @@ var OPTIONS = {
|
|
|
1431
1499
|
};
|
|
1432
1500
|
var RENAME = /^[RC]\d*$/;
|
|
1433
1501
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
1434
|
-
var LITERAL = { ...
|
|
1502
|
+
var LITERAL = { ...process19.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
1435
1503
|
function messageOf(title, lines, tickets) {
|
|
1436
1504
|
return [title, lines.join(`
|
|
1437
1505
|
`), tickets.join(`
|
|
@@ -1451,6 +1519,20 @@ async function stagedElsewhere(paths) {
|
|
|
1451
1519
|
const ours = new Set(given.split("\x00"));
|
|
1452
1520
|
return all.split("\x00").filter((path) => path !== "" && !ours.has(path));
|
|
1453
1521
|
}
|
|
1522
|
+
async function renameSources(paths) {
|
|
1523
|
+
const fields = (await checked(["diff", "--cached", "-M", "--name-status", "-z"])).split("\x00");
|
|
1524
|
+
const sources = [];
|
|
1525
|
+
for (let i = 0;i < fields.length; i++) {
|
|
1526
|
+
if (!RENAME.test(fields[i] ?? ""))
|
|
1527
|
+
continue;
|
|
1528
|
+
const from = fields[i + 1] ?? "";
|
|
1529
|
+
const to = fields[i + 2] ?? "";
|
|
1530
|
+
if (paths.includes(to) && !paths.includes(from))
|
|
1531
|
+
sources.push(from);
|
|
1532
|
+
i += 2;
|
|
1533
|
+
}
|
|
1534
|
+
return sources;
|
|
1535
|
+
}
|
|
1454
1536
|
async function unstage(paths) {
|
|
1455
1537
|
const hasHead = (await git2(["rev-parse", "--verify", "-q", "HEAD"], LITERAL)).code === 0;
|
|
1456
1538
|
await git2(hasHead ? ["reset", "-q", "--", ...paths] : ["rm", "-r", "-q", "--cached", "--", ...paths], LITERAL);
|
|
@@ -1462,12 +1544,12 @@ function fileLine(line) {
|
|
|
1462
1544
|
async function main(argv) {
|
|
1463
1545
|
const parsed = parse(argv, USAGE, OPTIONS, { rest: true, replaces: "git add, git status and git commit chained", examples: ['gc "fix(api): retry a timed-out fetch" -- src/api.ts', ['gc "feat(ui): a dark theme" -m "The toggle sits in the header." --ticket "#12 - Dark theme" -- src/theme.ts src/header.ts', "a body line and a ticket"]] });
|
|
1464
1546
|
const { values, positionals, rest = [] } = parsed;
|
|
1465
|
-
const
|
|
1547
|
+
const given = [...new Set(rest)];
|
|
1466
1548
|
if (positionals.length !== 1)
|
|
1467
1549
|
fail(`give the title as one quoted argument and the paths after --
|
|
1468
1550
|
|
|
1469
1551
|
${USAGE}`);
|
|
1470
|
-
if (
|
|
1552
|
+
if (given.length === 0)
|
|
1471
1553
|
fail(`give the paths to commit after --
|
|
1472
1554
|
|
|
1473
1555
|
${USAGE}`);
|
|
@@ -1484,12 +1566,14 @@ ${USAGE}`);
|
|
|
1484
1566
|
const violation = commitMessageViolation(message);
|
|
1485
1567
|
if (violation !== null)
|
|
1486
1568
|
fail(`nothing staged: ${violation}`, 1);
|
|
1487
|
-
const statuses = await Promise.all(
|
|
1488
|
-
const unchanged =
|
|
1489
|
-
const addable =
|
|
1569
|
+
const statuses = await Promise.all(given.map(async (path) => checked(["status", "--porcelain", "--untracked-files=all", "--", path])));
|
|
1570
|
+
const unchanged = given.filter((_, i) => statuses[i] === "");
|
|
1571
|
+
const addable = given.filter((_, i) => !(statuses[i] ?? "").trimEnd().split(`
|
|
1490
1572
|
`).every((line) => line.startsWith("D ")));
|
|
1491
1573
|
if (unchanged.length > 0)
|
|
1492
1574
|
fail(`nothing staged: no change to commit in ${unchanged.join(", ")} (unchanged, ignored or missing)`, 1, runHint("gst", "see what changed"));
|
|
1575
|
+
const sources = await renameSources(given);
|
|
1576
|
+
const paths = [...given, ...sources];
|
|
1493
1577
|
const others = await stagedElsewhere(paths);
|
|
1494
1578
|
if (others.length > 0)
|
|
1495
1579
|
fail(`nothing staged: the index already holds ${others.join(", ")}, which this commit would carry along`, 1, runHint(`git restore --staged -- ${others.join(" ")}`, "unstage them, or name them in the paths too"));
|
|
@@ -1521,7 +1605,7 @@ ${(commit.stderr + commit.stdout).trim()}`;
|
|
|
1521
1605
|
});
|
|
1522
1606
|
printJson({ sha: (await checked(["rev-parse", "HEAD"])).trim(), subject: head.slice(head.indexOf(" ") + 1), files: changes });
|
|
1523
1607
|
} else if (values.quiet !== true) {
|
|
1524
|
-
console.log([head, ...lines.filter(Boolean).map(fileLine)].join(`
|
|
1608
|
+
console.log([head, ...lines.filter(Boolean).map(fileLine), ...sources.map((from) => `also committed ${from}, the other side of a staged rename`)].join(`
|
|
1525
1609
|
`));
|
|
1526
1610
|
}
|
|
1527
1611
|
return signals.signal === undefined ? 0 : exitCodeOf(null, signals.signal);
|
|
@@ -1529,4 +1613,4 @@ ${(commit.stderr + commit.stdout).trim()}`;
|
|
|
1529
1613
|
signals.release();
|
|
1530
1614
|
}
|
|
1531
1615
|
}
|
|
1532
|
-
|
|
1616
|
+
process19.exitCode = await runMain({ name: "gc", run: main });
|