@kaynooo/cli-git 0.14.0 → 0.15.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/dist/gb.js +251 -28
- package/dist/gc.js +239 -16
- package/dist/gp.js +250 -23
- package/dist/gst.js +250 -27
- package/package.json +1 -1
package/dist/gp.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gp.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -141,7 +141,39 @@ function userConfigPath(bin, where = {}) {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
// ../kit/src/theme.ts
|
|
144
|
+
function toLinear(channel) {
|
|
145
|
+
const value = channel / 255;
|
|
146
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
147
|
+
}
|
|
148
|
+
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055)));
|
|
149
|
+
function toOklab(hex) {
|
|
150
|
+
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
151
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
152
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
153
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
154
|
+
return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
|
|
155
|
+
}
|
|
156
|
+
function fromOklab([lightness, a, b]) {
|
|
157
|
+
const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
158
|
+
const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
159
|
+
const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
160
|
+
const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
|
|
161
|
+
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
162
|
+
}
|
|
144
163
|
var ENDS = new Map;
|
|
164
|
+
function gradientAt(theme, ratio) {
|
|
165
|
+
if (theme.gradient === undefined)
|
|
166
|
+
return;
|
|
167
|
+
const key = theme.gradient.join();
|
|
168
|
+
let ends = ENDS.get(key);
|
|
169
|
+
if (ends === undefined) {
|
|
170
|
+
ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
|
|
171
|
+
ENDS.set(key, ends);
|
|
172
|
+
}
|
|
173
|
+
const at = Math.min(1, Math.max(0, ratio));
|
|
174
|
+
const [from, to] = ends;
|
|
175
|
+
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
176
|
+
}
|
|
145
177
|
var DEFAULT = {
|
|
146
178
|
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
147
179
|
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
@@ -193,6 +225,9 @@ function tinted(colors, spec, env = process5.env) {
|
|
|
193
225
|
return chain[token] ?? chain;
|
|
194
226
|
}, colors);
|
|
195
227
|
}
|
|
228
|
+
function shaded(theme, colors, glyph, cells, width, env = process5.env) {
|
|
229
|
+
return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
|
|
230
|
+
}
|
|
196
231
|
function isRecord(value) {
|
|
197
232
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
198
233
|
}
|
|
@@ -366,6 +401,12 @@ function formatSeconds(total) {
|
|
|
366
401
|
const next = amounts[first + 1];
|
|
367
402
|
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
368
403
|
}
|
|
404
|
+
function formatDuration(ms) {
|
|
405
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
406
|
+
}
|
|
407
|
+
function formatElapsed(ms) {
|
|
408
|
+
return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
|
|
409
|
+
}
|
|
369
410
|
function upTo(text, separator) {
|
|
370
411
|
const end = text.indexOf(separator);
|
|
371
412
|
return end === -1 ? text : text.slice(0, end);
|
|
@@ -770,6 +811,9 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
770
811
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
771
812
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
772
813
|
}
|
|
814
|
+
// ../kit/src/progress.ts
|
|
815
|
+
import process12 from "process";
|
|
816
|
+
|
|
773
817
|
// ../kit/src/process.ts
|
|
774
818
|
import { constants } from "os";
|
|
775
819
|
import process11 from "process";
|
|
@@ -893,20 +937,199 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
893
937
|
}
|
|
894
938
|
|
|
895
939
|
// ../kit/src/progress.ts
|
|
940
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
941
|
+
var FRAME_MS = 200;
|
|
942
|
+
var BAR_WIDTH = 20;
|
|
943
|
+
var CLEAR_BELOW = "\r\x1B[J";
|
|
896
944
|
var ESC = String.fromCharCode(27);
|
|
897
945
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
898
946
|
var RESET_STYLE = `${ESC}[0m`;
|
|
947
|
+
var CTRL_C = 3;
|
|
899
948
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
949
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
950
|
+
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
951
|
+
if (!takesControlCodes(stream, env))
|
|
952
|
+
return { redraw: () => {
|
|
953
|
+
return;
|
|
954
|
+
}, print: (text) => void stream.write(`${text}
|
|
955
|
+
`), stop: () => {
|
|
956
|
+
return;
|
|
957
|
+
} };
|
|
958
|
+
const write = stream.write.bind(stream);
|
|
959
|
+
let frame = 0;
|
|
960
|
+
let drawn = false;
|
|
961
|
+
const columns = () => {
|
|
962
|
+
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
963
|
+
return now === undefined || now === 0 ? 80 : now;
|
|
964
|
+
};
|
|
965
|
+
const clear = () => {
|
|
966
|
+
if (drawn)
|
|
967
|
+
write(CLEAR_BELOW);
|
|
968
|
+
drawn = false;
|
|
969
|
+
};
|
|
970
|
+
const draw = () => {
|
|
971
|
+
const width = columns() - 1;
|
|
972
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
973
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
974
|
+
if (lines.length === 0) {
|
|
975
|
+
clear();
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
write(`${CLEAR_BELOW}${lines.join(`
|
|
979
|
+
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
980
|
+
drawn = true;
|
|
981
|
+
};
|
|
982
|
+
const timer = setInterval(draw, FRAME_MS);
|
|
983
|
+
stream.on?.("resize", draw);
|
|
984
|
+
const restore = interceptOutput(clear);
|
|
985
|
+
const release = swallowInput();
|
|
986
|
+
const onExit = () => {
|
|
987
|
+
clear();
|
|
988
|
+
release();
|
|
989
|
+
};
|
|
990
|
+
const signals = holdSignals(stop);
|
|
991
|
+
function stop() {
|
|
992
|
+
clearInterval(timer);
|
|
993
|
+
stream.off?.("resize", draw);
|
|
994
|
+
clear();
|
|
995
|
+
restore();
|
|
996
|
+
release();
|
|
997
|
+
process12.off("exit", onExit);
|
|
998
|
+
signals.release();
|
|
999
|
+
}
|
|
1000
|
+
timer.unref();
|
|
1001
|
+
process12.on("exit", onExit);
|
|
1002
|
+
return {
|
|
1003
|
+
redraw: draw,
|
|
1004
|
+
print: (text) => {
|
|
1005
|
+
clear();
|
|
1006
|
+
write(`${text}
|
|
1007
|
+
`);
|
|
1008
|
+
draw();
|
|
1009
|
+
},
|
|
1010
|
+
stop
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
1014
|
+
const colors = paint(stream, env);
|
|
1015
|
+
const write = stream.write.bind(stream);
|
|
1016
|
+
const begun = performance.now();
|
|
1017
|
+
let started = begun;
|
|
1018
|
+
let current;
|
|
1019
|
+
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
1020
|
+
const end = (line) => {
|
|
1021
|
+
region.stop();
|
|
1022
|
+
write(`${line}
|
|
1023
|
+
`);
|
|
1024
|
+
};
|
|
1025
|
+
return {
|
|
1026
|
+
update: (progress) => {
|
|
1027
|
+
const step = current?.step;
|
|
1028
|
+
current = progress;
|
|
1029
|
+
if (progress.step !== step) {
|
|
1030
|
+
started = performance.now();
|
|
1031
|
+
region.redraw();
|
|
1032
|
+
}
|
|
1033
|
+
},
|
|
1034
|
+
stop: region.stop,
|
|
1035
|
+
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1036
|
+
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1040
|
+
const { theme } = activeTheme();
|
|
1041
|
+
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1042
|
+
if (total !== undefined && total > 0) {
|
|
1043
|
+
const counted = Math.min(done ?? 0, total);
|
|
1044
|
+
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1045
|
+
parts.push({ text: " ", tint: () => plain }, { text: theme.glyphs.bar.repeat(filled), tint: (colors) => () => shaded(theme, colors, theme.glyphs.bar, filled, BAR_WIDTH) }, { text: theme.glyphs.bar.repeat(BAR_WIDTH - filled), tint: (colors) => colors.dim }, { text: ` ${counted}/${total}${unit === undefined ? "" : ` ${unit}`}`, tint: (colors) => colors.dim });
|
|
1046
|
+
}
|
|
1047
|
+
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1048
|
+
return parts;
|
|
1049
|
+
}
|
|
1050
|
+
function plain(text) {
|
|
1051
|
+
return text;
|
|
1052
|
+
}
|
|
1053
|
+
function tintedParts(parts, colors) {
|
|
1054
|
+
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1055
|
+
}
|
|
1056
|
+
function cutToWidth(line, width) {
|
|
1057
|
+
if (Bun.stringWidth(line) <= width)
|
|
1058
|
+
return line;
|
|
1059
|
+
let room = width;
|
|
1060
|
+
let kept = "";
|
|
1061
|
+
let index = 0;
|
|
1062
|
+
let linked = false;
|
|
1063
|
+
while (index < line.length) {
|
|
1064
|
+
ESCAPE_CODE.lastIndex = index;
|
|
1065
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
1066
|
+
if (escape !== null) {
|
|
1067
|
+
kept += escape[0];
|
|
1068
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1069
|
+
index = ESCAPE_CODE.lastIndex;
|
|
1070
|
+
continue;
|
|
1071
|
+
}
|
|
1072
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1073
|
+
const columns = Bun.stringWidth(char);
|
|
1074
|
+
if (columns > room)
|
|
1075
|
+
break;
|
|
1076
|
+
kept += char;
|
|
1077
|
+
room -= columns;
|
|
1078
|
+
index += char.length;
|
|
1079
|
+
}
|
|
1080
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1081
|
+
}
|
|
1082
|
+
function swallowInput() {
|
|
1083
|
+
const input = process12.stdin;
|
|
1084
|
+
if (!input.isTTY)
|
|
1085
|
+
return () => {
|
|
1086
|
+
return;
|
|
1087
|
+
};
|
|
1088
|
+
const onData = (data) => {
|
|
1089
|
+
if (data.includes(CTRL_C))
|
|
1090
|
+
process12.kill(process12.pid, "SIGINT");
|
|
1091
|
+
};
|
|
1092
|
+
input.setRawMode(true);
|
|
1093
|
+
input.on("data", onData);
|
|
1094
|
+
input.resume();
|
|
1095
|
+
let released = false;
|
|
1096
|
+
return () => {
|
|
1097
|
+
if (released)
|
|
1098
|
+
return;
|
|
1099
|
+
released = true;
|
|
1100
|
+
input.off("data", onData);
|
|
1101
|
+
input.pause();
|
|
1102
|
+
input.setRawMode(false);
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
function interceptOutput(clear) {
|
|
1106
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
|
|
1107
|
+
const wrapped = targets.map(([target, name]) => {
|
|
1108
|
+
const original = Reflect.get(target, name);
|
|
1109
|
+
const wrapper = (...args) => {
|
|
1110
|
+
clear();
|
|
1111
|
+
return original.apply(target, args);
|
|
1112
|
+
};
|
|
1113
|
+
Reflect.set(target, name, wrapper);
|
|
1114
|
+
return { target, name, original, wrapper };
|
|
1115
|
+
});
|
|
1116
|
+
return () => {
|
|
1117
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
1118
|
+
if (Reflect.get(target, name) === wrapper)
|
|
1119
|
+
Reflect.set(target, name, original);
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
900
1123
|
// ../kit/src/cli.ts
|
|
901
1124
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
902
1125
|
import { dirname as dirname3, join as join5 } from "path";
|
|
903
|
-
import
|
|
1126
|
+
import process14 from "process";
|
|
904
1127
|
|
|
905
1128
|
// ../kit/src/usage.ts
|
|
906
1129
|
import { appendFileSync, mkdirSync } from "fs";
|
|
907
1130
|
import { homedir as homedir3 } from "os";
|
|
908
1131
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
909
|
-
import
|
|
1132
|
+
import process13 from "process";
|
|
910
1133
|
|
|
911
1134
|
// ../kit/src/logs.ts
|
|
912
1135
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -920,14 +1143,14 @@ var usageError;
|
|
|
920
1143
|
function noteUsageError(message) {
|
|
921
1144
|
usageError = message;
|
|
922
1145
|
}
|
|
923
|
-
function stateHome(env =
|
|
1146
|
+
function stateHome(env = process13.env) {
|
|
924
1147
|
const dir = env.XDG_STATE_HOME;
|
|
925
1148
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
926
1149
|
}
|
|
927
|
-
function usagePath(env =
|
|
1150
|
+
function usagePath(env = process13.env) {
|
|
928
1151
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
929
1152
|
}
|
|
930
|
-
function usageRecorded(env =
|
|
1153
|
+
function usageRecorded(env = process13.env) {
|
|
931
1154
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
932
1155
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
933
1156
|
}
|
|
@@ -941,7 +1164,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
941
1164
|
usageError = undefined;
|
|
942
1165
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
943
1166
|
}
|
|
944
|
-
function recordUsage(entry, env =
|
|
1167
|
+
function recordUsage(entry, env = process13.env) {
|
|
945
1168
|
if (!usageRecorded(env))
|
|
946
1169
|
return;
|
|
947
1170
|
try {
|
|
@@ -959,8 +1182,8 @@ var LEVEL_OPTIONS = {
|
|
|
959
1182
|
};
|
|
960
1183
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
961
1184
|
function printError(prefix, message, hint, cause) {
|
|
962
|
-
const colors = paint(
|
|
963
|
-
const styled = takesControlCodes(
|
|
1185
|
+
const colors = paint(process14.stderr);
|
|
1186
|
+
const styled = takesControlCodes(process14.stderr);
|
|
964
1187
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
965
1188
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
966
1189
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1085,7 +1308,7 @@ var {Glob } = globalThis.Bun;
|
|
|
1085
1308
|
var SESSION_FILES = new Glob("*.json");
|
|
1086
1309
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1087
1310
|
// ../kit/src/watch.ts
|
|
1088
|
-
import
|
|
1311
|
+
import process15 from "process";
|
|
1089
1312
|
import { format } from "util";
|
|
1090
1313
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1091
1314
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1107,7 +1330,7 @@ function withoutWatch(args) {
|
|
|
1107
1330
|
}
|
|
1108
1331
|
return rest;
|
|
1109
1332
|
}
|
|
1110
|
-
async function watching(value, step, stream =
|
|
1333
|
+
async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1111
1334
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1112
1335
|
if (!takesControlCodes(stream))
|
|
1113
1336
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1115,12 +1338,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1115
1338
|
for (let round = 0;round < rounds; round++) {
|
|
1116
1339
|
const held = [];
|
|
1117
1340
|
const { log, info } = console;
|
|
1118
|
-
const write =
|
|
1341
|
+
const write = process15.stdout.write.bind(process15.stdout);
|
|
1119
1342
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1120
1343
|
`);
|
|
1121
1344
|
console.log = hold;
|
|
1122
1345
|
console.info = hold;
|
|
1123
|
-
|
|
1346
|
+
process15.stdout.write = (text) => {
|
|
1124
1347
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1125
1348
|
return true;
|
|
1126
1349
|
};
|
|
@@ -1129,7 +1352,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1129
1352
|
} finally {
|
|
1130
1353
|
console.log = log;
|
|
1131
1354
|
console.info = info;
|
|
1132
|
-
|
|
1355
|
+
process15.stdout.write = write;
|
|
1133
1356
|
}
|
|
1134
1357
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1135
1358
|
await sleep(interval);
|
|
@@ -1146,7 +1369,7 @@ async function git2(args, env) {
|
|
|
1146
1369
|
// src/repos.ts
|
|
1147
1370
|
import { readdir } from "fs/promises";
|
|
1148
1371
|
import { join as join6, relative, resolve as resolve4 } from "path";
|
|
1149
|
-
import
|
|
1372
|
+
import process17 from "process";
|
|
1150
1373
|
|
|
1151
1374
|
// src/status.ts
|
|
1152
1375
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -1246,14 +1469,14 @@ async function toplevelOf(dir) {
|
|
|
1246
1469
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1247
1470
|
}
|
|
1248
1471
|
async function reposOf(roots) {
|
|
1249
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
1472
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process17.cwd()];
|
|
1250
1473
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1251
1474
|
return [...new Set(found.flat())].sort();
|
|
1252
1475
|
}
|
|
1253
1476
|
async function repoState(dir) {
|
|
1254
1477
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1255
1478
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1256
|
-
return { path: relative(
|
|
1479
|
+
return { path: relative(process17.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1257
1480
|
}
|
|
1258
1481
|
function trackingOf(status) {
|
|
1259
1482
|
if (status.upstream === null)
|
|
@@ -1332,16 +1555,16 @@ async function push(repo, { dryRun, extra }) {
|
|
|
1332
1555
|
return pushed.code === 0 ? { path, branch, remote, commits, outcome: "pushed" } : { path, branch, remote, commits, outcome: "refused", reason: whyRefused(pushed.stderr) };
|
|
1333
1556
|
}
|
|
1334
1557
|
function line(result) {
|
|
1335
|
-
const { dim } = paint(
|
|
1558
|
+
const { dim } = paint(process18.stdout);
|
|
1336
1559
|
const sent = result.commits === null ? "" : `, ${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
|
|
1337
1560
|
const what = `${result.branch} -> ${result.remote}${sent}`;
|
|
1338
1561
|
const said = {
|
|
1339
|
-
pushed: () => marked("ok", `pushed ${what}`,
|
|
1562
|
+
pushed: () => marked("ok", `pushed ${what}`, process18.stdout),
|
|
1340
1563
|
"would-push": () => `would push ${what}`,
|
|
1341
1564
|
skipped: () => dim(result.reason ?? "skipped"),
|
|
1342
|
-
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`,
|
|
1565
|
+
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process18.stdout)
|
|
1343
1566
|
}[result.outcome];
|
|
1344
|
-
return [role("path",
|
|
1567
|
+
return [role("path", process18.stdout)(result.path), said()];
|
|
1345
1568
|
}
|
|
1346
1569
|
async function main(argv) {
|
|
1347
1570
|
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"]] });
|
|
@@ -1358,12 +1581,16 @@ async function main(argv) {
|
|
|
1358
1581
|
fail(`no git repository at or below ${positionals.length === 0 ? "the current directory" : positionals.join(", ")}`);
|
|
1359
1582
|
const repos = await Promise.all(dirs.map(repoState));
|
|
1360
1583
|
const results = [];
|
|
1361
|
-
|
|
1584
|
+
const progress = progressLine();
|
|
1585
|
+
for (const [at, repo] of repos.entries()) {
|
|
1586
|
+
progress.update(repos.length > 1 ? { step: `pushing ${repo.path}`, done: at, total: repos.length, unit: "repositories" } : { step: `pushing ${repo.path}` });
|
|
1362
1587
|
results.push(await push(repo, { dryRun: values["dry-run"] === true, extra: rest }));
|
|
1588
|
+
}
|
|
1589
|
+
progress.stop();
|
|
1363
1590
|
if (values.json === true)
|
|
1364
1591
|
printJson(results);
|
|
1365
1592
|
else
|
|
1366
1593
|
console.log(table(results.map(line)));
|
|
1367
1594
|
return results.some((result) => result.outcome === "refused") ? 1 : 0;
|
|
1368
1595
|
}
|
|
1369
|
-
|
|
1596
|
+
process18.exitCode = await runMain({ name: "gp", run: main });
|