@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/gu.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// src/gu.ts
|
|
5
5
|
import { mkdirSync as mkdirSync2, writeFileSync } from "fs";
|
|
6
6
|
import { join as join7, resolve as resolve5 } from "path";
|
|
7
|
-
import
|
|
7
|
+
import process19 from "process";
|
|
8
8
|
// ../kit/src/args.ts
|
|
9
9
|
import process9 from "process";
|
|
10
10
|
import { parseArgs } from "util";
|
|
@@ -495,7 +495,7 @@ function printJson(value) {
|
|
|
495
495
|
|
|
496
496
|
// ../kit/src/help.ts
|
|
497
497
|
import process8 from "process";
|
|
498
|
-
var OPTIONAL =
|
|
498
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
499
499
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
500
500
|
var FULL_STOP = /\.$/;
|
|
501
501
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
@@ -534,29 +534,41 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
534
534
|
return [];
|
|
535
535
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
536
536
|
}
|
|
537
|
+
var MAX_INLINE_CHOICES = 24;
|
|
537
538
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
538
539
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
539
540
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
540
|
-
const
|
|
541
|
+
const choices = option.choices?.join("|");
|
|
542
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
543
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
541
544
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
542
545
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
543
|
-
|
|
546
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
547
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
544
548
|
});
|
|
545
549
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
546
550
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
547
551
|
}
|
|
548
552
|
|
|
549
553
|
// ../kit/src/text.ts
|
|
550
|
-
var ANSI =
|
|
554
|
+
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
551
555
|
function distance(a, b) {
|
|
552
|
-
|
|
553
|
-
|
|
556
|
+
const left = [...a];
|
|
557
|
+
const right = [...b];
|
|
558
|
+
let before = [];
|
|
559
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
560
|
+
for (const [i, x] of left.entries()) {
|
|
554
561
|
const current = [i + 1];
|
|
555
|
-
for (const [j,
|
|
556
|
-
|
|
562
|
+
for (const [j, y] of right.entries()) {
|
|
563
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
564
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
565
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
566
|
+
current.push(cost);
|
|
567
|
+
}
|
|
568
|
+
before = previous;
|
|
557
569
|
previous = current;
|
|
558
570
|
}
|
|
559
|
-
return previous[
|
|
571
|
+
return previous[right.length] ?? 0;
|
|
560
572
|
}
|
|
561
573
|
function closest(name, names) {
|
|
562
574
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -632,7 +644,7 @@ class Completing {
|
|
|
632
644
|
}
|
|
633
645
|
var completion = { active: false };
|
|
634
646
|
var OUTPUT_OPTIONS = {
|
|
635
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
647
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
636
648
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
637
649
|
};
|
|
638
650
|
function applyOutput(color, plain, env = process9.env) {
|
|
@@ -1140,13 +1152,91 @@ function interceptOutput(clear) {
|
|
|
1140
1152
|
// ../kit/src/cli.ts
|
|
1141
1153
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1142
1154
|
import { dirname as dirname3, join as join5 } from "path";
|
|
1143
|
-
import
|
|
1155
|
+
import process15 from "process";
|
|
1156
|
+
|
|
1157
|
+
// ../kit/src/completions.ts
|
|
1158
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1159
|
+
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'
|
|
1160
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1161
|
+
set -l current (commandline -ct)
|
|
1162
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1163
|
+
if test "$line" = __files__
|
|
1164
|
+
__fish_complete_path $current
|
|
1165
|
+
else
|
|
1166
|
+
echo $line
|
|
1167
|
+
end
|
|
1168
|
+
end
|
|
1169
|
+
end`;
|
|
1170
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1171
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1172
|
+
local -a lines
|
|
1173
|
+
COMPREPLY=()
|
|
1174
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1175
|
+
for line in "\${lines[@]}"; do
|
|
1176
|
+
if [[ $line == __files__ ]]; then
|
|
1177
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1178
|
+
else
|
|
1179
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1180
|
+
fi
|
|
1181
|
+
done
|
|
1182
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1183
|
+
}`;
|
|
1184
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1185
|
+
local line
|
|
1186
|
+
local -a described plain
|
|
1187
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1188
|
+
if [[ $line == __files__ ]]; then
|
|
1189
|
+
_files
|
|
1190
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1191
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1192
|
+
else
|
|
1193
|
+
plain+=("$line")
|
|
1194
|
+
fi
|
|
1195
|
+
done
|
|
1196
|
+
(( \${#described} )) && _describe -V value described
|
|
1197
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1198
|
+
return 0
|
|
1199
|
+
}`;
|
|
1200
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1201
|
+
if (shell === "fish")
|
|
1202
|
+
return `${header}
|
|
1203
|
+
${FISH_FUNCTION}
|
|
1204
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1205
|
+
`).join("")}`;
|
|
1206
|
+
if (shell === "bash")
|
|
1207
|
+
return `${header}
|
|
1208
|
+
${BASH_FUNCTION}
|
|
1209
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1210
|
+
`;
|
|
1211
|
+
return `${header}
|
|
1212
|
+
${ZSH_FUNCTION}
|
|
1213
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1214
|
+
`;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// ../kit/src/notify.ts
|
|
1218
|
+
import process13 from "process";
|
|
1219
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1220
|
+
var CANCELLED = 130;
|
|
1221
|
+
function base64(text) {
|
|
1222
|
+
return Buffer.from(text).toString("base64");
|
|
1223
|
+
}
|
|
1224
|
+
function notification(title, body, env = process13.env) {
|
|
1225
|
+
const id = `kit${process13.pid}`;
|
|
1226
|
+
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\\`];
|
|
1227
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1228
|
+
}
|
|
1229
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1230
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1231
|
+
return;
|
|
1232
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1233
|
+
}
|
|
1144
1234
|
|
|
1145
1235
|
// ../kit/src/usage.ts
|
|
1146
1236
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1147
1237
|
import { homedir as homedir3 } from "os";
|
|
1148
1238
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1149
|
-
import
|
|
1239
|
+
import process14 from "process";
|
|
1150
1240
|
|
|
1151
1241
|
// ../kit/src/logs.ts
|
|
1152
1242
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1160,14 +1250,14 @@ var usageError;
|
|
|
1160
1250
|
function noteUsageError(message) {
|
|
1161
1251
|
usageError = message;
|
|
1162
1252
|
}
|
|
1163
|
-
function stateHome(env =
|
|
1253
|
+
function stateHome(env = process14.env) {
|
|
1164
1254
|
const dir = env.XDG_STATE_HOME;
|
|
1165
1255
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1166
1256
|
}
|
|
1167
|
-
function usagePath(env =
|
|
1257
|
+
function usagePath(env = process14.env) {
|
|
1168
1258
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1169
1259
|
}
|
|
1170
|
-
function usageRecorded(env =
|
|
1260
|
+
function usageRecorded(env = process14.env) {
|
|
1171
1261
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1172
1262
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1173
1263
|
}
|
|
@@ -1181,7 +1271,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1181
1271
|
usageError = undefined;
|
|
1182
1272
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1183
1273
|
}
|
|
1184
|
-
function recordUsage(entry, env =
|
|
1274
|
+
function recordUsage(entry, env = process14.env) {
|
|
1185
1275
|
if (!usageRecorded(env))
|
|
1186
1276
|
return;
|
|
1187
1277
|
try {
|
|
@@ -1197,10 +1287,14 @@ var LEVEL_OPTIONS = {
|
|
|
1197
1287
|
...OUTPUT_OPTIONS,
|
|
1198
1288
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1199
1289
|
};
|
|
1200
|
-
var TOP_OPTIONS = {
|
|
1290
|
+
var TOP_OPTIONS = {
|
|
1291
|
+
...LEVEL_OPTIONS,
|
|
1292
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1293
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1294
|
+
};
|
|
1201
1295
|
function printError(prefix, message, hint, cause) {
|
|
1202
|
-
const colors = paint(
|
|
1203
|
-
const styled = takesControlCodes(
|
|
1296
|
+
const colors = paint(process15.stderr);
|
|
1297
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1204
1298
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1205
1299
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1206
1300
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1280,6 +1374,19 @@ async function leafCandidates(run, words) {
|
|
|
1280
1374
|
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1281
1375
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1282
1376
|
}
|
|
1377
|
+
var COMPLETIONS = "--completions";
|
|
1378
|
+
function flagValue([flag = "", ...rest]) {
|
|
1379
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1380
|
+
}
|
|
1381
|
+
function printCompletionScript(name, args) {
|
|
1382
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1383
|
+
if (shell === undefined || args.length !== 1) {
|
|
1384
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1385
|
+
return 2;
|
|
1386
|
+
}
|
|
1387
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1388
|
+
return 0;
|
|
1389
|
+
}
|
|
1283
1390
|
async function printCandidates(found) {
|
|
1284
1391
|
for (const line of await found)
|
|
1285
1392
|
console.log(line);
|
|
@@ -1303,16 +1410,20 @@ function packageVersion(entry = Bun.main) {
|
|
|
1303
1410
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1304
1411
|
if (argv[0] === COMPLETE)
|
|
1305
1412
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1413
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1414
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1306
1415
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1307
1416
|
console.log(version ?? packageVersion());
|
|
1308
1417
|
return 0;
|
|
1309
1418
|
}
|
|
1310
1419
|
let code;
|
|
1420
|
+
const started = performance.now();
|
|
1311
1421
|
try {
|
|
1312
1422
|
code = await run(argv);
|
|
1313
1423
|
} catch (error) {
|
|
1314
1424
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1315
1425
|
}
|
|
1426
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1316
1427
|
if (usage !== false) {
|
|
1317
1428
|
try {
|
|
1318
1429
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1329,7 +1440,7 @@ var {Glob } = globalThis.Bun;
|
|
|
1329
1440
|
var SESSION_FILES = new Glob("*.json");
|
|
1330
1441
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1331
1442
|
// ../kit/src/watch.ts
|
|
1332
|
-
import
|
|
1443
|
+
import process16 from "process";
|
|
1333
1444
|
import { format } from "util";
|
|
1334
1445
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1335
1446
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1351,7 +1462,7 @@ function withoutWatch(args) {
|
|
|
1351
1462
|
}
|
|
1352
1463
|
return rest;
|
|
1353
1464
|
}
|
|
1354
|
-
async function watching(value, step, stream =
|
|
1465
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1355
1466
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1356
1467
|
if (!takesControlCodes(stream))
|
|
1357
1468
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1359,12 +1470,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1359
1470
|
for (let round = 0;round < rounds; round++) {
|
|
1360
1471
|
const held = [];
|
|
1361
1472
|
const { log, info } = console;
|
|
1362
|
-
const write =
|
|
1473
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1363
1474
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1364
1475
|
`);
|
|
1365
1476
|
console.log = hold;
|
|
1366
1477
|
console.info = hold;
|
|
1367
|
-
|
|
1478
|
+
process16.stdout.write = (text) => {
|
|
1368
1479
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1369
1480
|
return true;
|
|
1370
1481
|
};
|
|
@@ -1373,7 +1484,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1373
1484
|
} finally {
|
|
1374
1485
|
console.log = log;
|
|
1375
1486
|
console.info = info;
|
|
1376
|
-
|
|
1487
|
+
process16.stdout.write = write;
|
|
1377
1488
|
}
|
|
1378
1489
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1379
1490
|
await sleep(interval);
|
|
@@ -1383,7 +1494,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1383
1494
|
// ../kit/src/workspace-root.ts
|
|
1384
1495
|
import { homedir as homedir4 } from "os";
|
|
1385
1496
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1386
|
-
import
|
|
1497
|
+
import process17 from "process";
|
|
1387
1498
|
function expandHome(path, home) {
|
|
1388
1499
|
if (path === "~")
|
|
1389
1500
|
return home;
|
|
@@ -1393,7 +1504,7 @@ function configured(env, home) {
|
|
|
1393
1504
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1394
1505
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1395
1506
|
}
|
|
1396
|
-
function workspaceRoot({ given, env =
|
|
1507
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1397
1508
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1398
1509
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1399
1510
|
}
|
|
@@ -1415,7 +1526,8 @@ var OPTIONS = {
|
|
|
1415
1526
|
commit: { type: "boolean", short: "c", description: "undo the last commit, keeping its changes staged" },
|
|
1416
1527
|
json: jsonOption("{action, paths?, saved?, commit?} of what was undone, saved being the patch of a discard")
|
|
1417
1528
|
};
|
|
1418
|
-
var LITERAL = { ...
|
|
1529
|
+
var LITERAL = { ...process19.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
1530
|
+
var PLAIN_PATCH = ["--binary", "--no-ext-diff", "--no-textconv", "--no-color", "--no-relative", "--submodule=short", "--src-prefix=a/", "--dst-prefix=b/"];
|
|
1419
1531
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
1420
1532
|
async function checked(args) {
|
|
1421
1533
|
const { code, stdout, stderr } = await git2(args, LITERAL);
|
|
@@ -1462,18 +1574,24 @@ async function main(argv) {
|
|
|
1462
1574
|
fail(`no ${staged ? "staged" : "unstaged"} change in ${unchanged.join(", ")}, nothing undone`, 1);
|
|
1463
1575
|
const paths = [...new Set(each.flat())];
|
|
1464
1576
|
if (staged) {
|
|
1465
|
-
await
|
|
1577
|
+
const hasHead = (await git2(["rev-parse", "--verify", "-q", "HEAD"], LITERAL)).code === 0;
|
|
1578
|
+
await checked(hasHead ? ["restore", "--staged", "--", ...positionals] : ["rm", "--cached", "-r", "--quiet", "--", ...positionals]);
|
|
1466
1579
|
if (values.json === true)
|
|
1467
1580
|
printJson({ action: "unstage", paths });
|
|
1468
1581
|
else
|
|
1469
1582
|
console.log(`unstaged ${paths.join(", ")}`);
|
|
1470
1583
|
return 0;
|
|
1471
1584
|
}
|
|
1472
|
-
const patch = await checked(["diff",
|
|
1585
|
+
const patch = await checked(["diff", ...PLAIN_PATCH, "--", ...positionals]);
|
|
1473
1586
|
const folder = join7(resolve5((await checked(["rev-parse", "--git-dir"])).trim()), "gu");
|
|
1474
1587
|
const saved = join7(folder, `${new Date().toISOString().replaceAll(":", "-")}.patch`);
|
|
1588
|
+
const top = (await checked(["rev-parse", "--show-toplevel"])).trim();
|
|
1475
1589
|
mkdirSync2(folder, { recursive: true });
|
|
1476
1590
|
writeFileSync(saved, patch);
|
|
1591
|
+
const reverts = await git2(["-C", top, "apply", "--check", "--reverse", "--whitespace=nowarn", saved]);
|
|
1592
|
+
if (reverts.code !== 0)
|
|
1593
|
+
fail(`the patch saved to ${saved} would not put the change back, nothing discarded:
|
|
1594
|
+
${reverts.stderr.trim()}`, 1);
|
|
1477
1595
|
await checked(["restore", "--", ...positionals]);
|
|
1478
1596
|
if (values.json === true)
|
|
1479
1597
|
printJson({ action: "discard", paths, saved });
|
|
@@ -1481,4 +1599,4 @@ async function main(argv) {
|
|
|
1481
1599
|
console.log(`discarded ${paths.join(", ")}, saved to ${saved} (git apply puts it back)`);
|
|
1482
1600
|
return 0;
|
|
1483
1601
|
}
|
|
1484
|
-
|
|
1602
|
+
process19.exitCode = await runMain({ name: "gu", run: main });
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-git",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "gst, gc, gb, gp, gf, gcl, gd and gu: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, a branch picked, nested repositories pushed or fetched, a clone into the workspace, the changes per file and an undo that keeps what it takes away.",
|
|
4
|
+
"version": "0.16.1",
|
|
5
|
+
"description": "gst, gc, gb, gp, gf, gm, gcl, gd and gu: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, a branch picked, nested repositories pushed or fetched, a branch merged with its conflicts listed, a clone into the workspace, the changes per file and an undo that keeps what it takes away.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/git#readme",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"gb": "./dist/gb.js",
|
|
29
29
|
"gp": "./dist/gp.js",
|
|
30
30
|
"gf": "./dist/gf.js",
|
|
31
|
+
"gm": "./dist/gm.js",
|
|
31
32
|
"gcl": "./dist/gcl.js",
|
|
32
33
|
"gd": "./dist/gd.js",
|
|
33
34
|
"gu": "./dist/gu.js"
|
|
@@ -43,17 +44,18 @@
|
|
|
43
44
|
"registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
|
|
44
45
|
},
|
|
45
46
|
"scripts": {
|
|
46
|
-
"build": "$npm_execpath build src/gst.ts src/gc.ts src/gb.ts src/gp.ts src/gf.ts src/gcl.ts src/gd.ts src/gu.ts --target bun --outdir dist",
|
|
47
|
+
"build": "$npm_execpath build src/gst.ts src/gc.ts src/gb.ts src/gp.ts src/gf.ts src/gm.ts src/gcl.ts src/gd.ts src/gu.ts --root src --target bun --outdir dist",
|
|
47
48
|
"gst": "$npm_execpath src/gst.ts",
|
|
48
49
|
"gc": "$npm_execpath src/gc.ts",
|
|
49
50
|
"gb": "$npm_execpath src/gb.ts",
|
|
50
51
|
"gp": "$npm_execpath src/gp.ts",
|
|
51
52
|
"gf": "$npm_execpath src/gf.ts",
|
|
53
|
+
"gm": "$npm_execpath src/gm.ts",
|
|
52
54
|
"gcl": "$npm_execpath src/gcl.ts",
|
|
53
55
|
"gd": "$npm_execpath src/gd.ts",
|
|
54
56
|
"gu": "$npm_execpath src/gu.ts"
|
|
55
57
|
},
|
|
56
58
|
"devDependencies": {
|
|
57
|
-
"@kaynooo/cli-kit": "0.
|
|
59
|
+
"@kaynooo/cli-kit": "0.41.0"
|
|
58
60
|
}
|
|
59
61
|
}
|