@kaynooo/cli-git 0.18.0 → 0.19.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 +1 -1
- package/dist/gb.js +33 -35
- package/dist/gc.js +28 -30
- package/dist/gcl.js +103 -59
- package/dist/gd.js +41 -40
- package/dist/gf.js +35 -37
- package/dist/gm.js +44 -46
- package/dist/gp.js +35 -37
- package/dist/gst.js +42 -44
- package/dist/gu.js +28 -30
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ Prints one line with the branch, its upstream and how far ahead and behind it is
|
|
|
64
64
|
|
|
65
65
|
## gcl
|
|
66
66
|
|
|
67
|
-
`gcl <repo> [dir]` clones into
|
|
67
|
+
`gcl <repo> [dir]` clones into `./<name>`, as git clone does, or into `dir`, and prints the path on stdout, so `cd (gcl kaynooo/cli)` lands in it. `<repo>` is a URL, an scp-style address (`git@host:22022:owner/name` is read as `ssh://git@host:22022/owner/name`), a local path or `owner/name`. With the `forgeSsh` key of `~/.config/kaynooo-cli/config.json` set to the forge's ssh address (`git@git.example.org`, `ssh://git@git.example.org:22022`), `owner/name` is cloned over ssh, then anonymously over https when ssh fails. Without it `owner/name` is read as `https://git.kaynooo.fr/owner/name.git` (the `forge` key names another host, `http://host:port` for another scheme), and a private repository's refusal names the ssh address to give. Off a terminal, gcl, gf and gp keep git and ssh from asking for a password, on the terminal or through the desktop's askpass window: they fail at once instead.
|
|
68
68
|
|
|
69
69
|
- A folder that already holds the repository is not cloned again: it is fetched and fast-forwarded as `gf` does. A folder holding anything else is refused, exit 1.
|
|
70
70
|
- `--json` prints `{url, path, branch, head, outcome}`, `outcome` being `cloned` or `existing`.
|
package/dist/gb.js
CHANGED
|
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
652
652
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
653
653
|
return number;
|
|
654
654
|
}
|
|
655
|
+
function durationMs(text, unit) {
|
|
656
|
+
if (BARE_DURATION.test(text))
|
|
657
|
+
return Number(text) * UNIT_MS[unit];
|
|
658
|
+
if (!DURATION.test(text))
|
|
659
|
+
return 0;
|
|
660
|
+
let ms = 0;
|
|
661
|
+
for (const [, amount, part] of text.matchAll(DURATION_PART))
|
|
662
|
+
ms += Number(amount) * UNIT_MS[part];
|
|
663
|
+
return ms;
|
|
664
|
+
}
|
|
655
665
|
function duration(value, name, fallback, unit = "s") {
|
|
656
666
|
if (value === undefined)
|
|
657
667
|
return fallback;
|
|
658
|
-
const
|
|
659
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
668
|
+
const ms = durationMs(value.trim(), unit);
|
|
660
669
|
if (ms < 1)
|
|
661
670
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
662
671
|
return ms;
|
|
663
672
|
}
|
|
664
|
-
var WHOLE, DURATION, UNIT_MS;
|
|
673
|
+
var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
|
|
665
674
|
var init_input = __esm(() => {
|
|
666
675
|
init_args();
|
|
667
676
|
WHOLE = /^\d+$/;
|
|
668
|
-
|
|
669
|
-
|
|
677
|
+
BARE_DURATION = /^\d+(?:\.\d+)?$/;
|
|
678
|
+
DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
|
|
679
|
+
DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
|
|
680
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
|
|
670
681
|
});
|
|
671
682
|
|
|
672
683
|
// ../kit/src/args.ts
|
|
@@ -1541,7 +1552,7 @@ var init_prompt = __esm(() => {
|
|
|
1541
1552
|
});
|
|
1542
1553
|
|
|
1543
1554
|
// src/gb.ts
|
|
1544
|
-
import
|
|
1555
|
+
import process25 from "process";
|
|
1545
1556
|
|
|
1546
1557
|
// ../kit/src/index.ts
|
|
1547
1558
|
init_args();
|
|
@@ -1971,12 +1982,15 @@ import { join as join6 } from "path";
|
|
|
1971
1982
|
import process16 from "process";
|
|
1972
1983
|
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1973
1984
|
var ECHOED = /username|yes\/no/i;
|
|
1985
|
+
var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
|
|
1974
1986
|
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1975
1987
|
function askpass(pause = () => () => {
|
|
1976
1988
|
return;
|
|
1977
1989
|
}) {
|
|
1978
1990
|
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1979
|
-
return
|
|
1991
|
+
return { env: { ...NO_PROMPTS }, close: () => {
|
|
1992
|
+
return;
|
|
1993
|
+
} };
|
|
1980
1994
|
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1981
1995
|
const socketPath = join6(dir, "socket");
|
|
1982
1996
|
const script = join6(dir, "askpass");
|
|
@@ -2031,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2031
2045
|
`);
|
|
2032
2046
|
chmodSync(script, 448);
|
|
2033
2047
|
return {
|
|
2034
|
-
env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
2048
|
+
env: { GIT_ASKPASS: script, GIT_TERMINAL_PROMPT: "0", SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
2035
2049
|
close: () => {
|
|
2036
2050
|
server.stop(true);
|
|
2037
2051
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2454,25 +2468,9 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2454
2468
|
}
|
|
2455
2469
|
// ../kit/src/workspace-root.ts
|
|
2456
2470
|
init_user_config();
|
|
2457
|
-
import { homedir as homedir5 } from "os";
|
|
2458
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2459
|
-
import process21 from "process";
|
|
2460
|
-
function expandHome(path, home) {
|
|
2461
|
-
if (path === "~")
|
|
2462
|
-
return home;
|
|
2463
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2464
|
-
}
|
|
2465
|
-
function configured(env, home) {
|
|
2466
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2467
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2468
|
-
}
|
|
2469
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2470
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2471
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2472
|
-
}
|
|
2473
2471
|
// src/branch.ts
|
|
2474
2472
|
import { basename } from "path";
|
|
2475
|
-
import
|
|
2473
|
+
import process24 from "process";
|
|
2476
2474
|
|
|
2477
2475
|
// ../kit/src/picker.ts
|
|
2478
2476
|
init_folders();
|
|
@@ -2484,11 +2482,11 @@ init_job();
|
|
|
2484
2482
|
init_redraw();
|
|
2485
2483
|
init_style();
|
|
2486
2484
|
import { openSync } from "fs";
|
|
2487
|
-
import
|
|
2485
|
+
import process23 from "process";
|
|
2488
2486
|
import tty from "tty";
|
|
2489
2487
|
|
|
2490
2488
|
// ../kit/src/picker/preview.ts
|
|
2491
|
-
import
|
|
2489
|
+
import process22 from "process";
|
|
2492
2490
|
|
|
2493
2491
|
// ../kit/src/shell.ts
|
|
2494
2492
|
var SEPARATORS = new Set([`
|
|
@@ -2575,7 +2573,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
2575
2573
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
2576
2574
|
const stop = () => {
|
|
2577
2575
|
try {
|
|
2578
|
-
|
|
2576
|
+
process22.kill(-proc.pid, "SIGKILL");
|
|
2579
2577
|
} catch {
|
|
2580
2578
|
proc.kill();
|
|
2581
2579
|
}
|
|
@@ -2738,7 +2736,7 @@ function openTerminal() {
|
|
|
2738
2736
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
2739
2737
|
}
|
|
2740
2738
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
2741
|
-
const out =
|
|
2739
|
+
const out = process23.stderr;
|
|
2742
2740
|
let resize;
|
|
2743
2741
|
async function read(onChunk) {
|
|
2744
2742
|
const decoder = new TextDecoder;
|
|
@@ -2927,9 +2925,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2927
2925
|
const ended = new Promise((resolve) => {
|
|
2928
2926
|
finish = resolve;
|
|
2929
2927
|
});
|
|
2930
|
-
|
|
2928
|
+
process23.once("exit", restore);
|
|
2931
2929
|
for (const signal of SIGNALS2)
|
|
2932
|
-
|
|
2930
|
+
process23.once(signal, stop);
|
|
2933
2931
|
try {
|
|
2934
2932
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2935
2933
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -2942,8 +2940,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2942
2940
|
await ended;
|
|
2943
2941
|
} finally {
|
|
2944
2942
|
for (const signal of SIGNALS2)
|
|
2945
|
-
|
|
2946
|
-
|
|
2943
|
+
process23.off(signal, stop);
|
|
2944
|
+
process23.off("exit", restore);
|
|
2947
2945
|
restore();
|
|
2948
2946
|
}
|
|
2949
2947
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -3216,7 +3214,7 @@ async function gb(args) {
|
|
|
3216
3214
|
if (parsed.values.json === true)
|
|
3217
3215
|
printJson(all);
|
|
3218
3216
|
else
|
|
3219
|
-
console.log(table2(all.map(row)).map((line) => takesControlCodes(
|
|
3217
|
+
console.log(table2(all.map(row)).map((line) => takesControlCodes(process24.stdout) ? line : Bun.stripANSI(line)).join(`
|
|
3220
3218
|
`));
|
|
3221
3219
|
return 0;
|
|
3222
3220
|
}
|
|
@@ -3273,4 +3271,4 @@ async function finish(command, typed, emitting) {
|
|
|
3273
3271
|
}
|
|
3274
3272
|
|
|
3275
3273
|
// src/gb.ts
|
|
3276
|
-
|
|
3274
|
+
process25.exitCode = await runMain({ name: "gb", run: gb });
|
package/dist/gc.js
CHANGED
|
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
652
652
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
653
653
|
return number;
|
|
654
654
|
}
|
|
655
|
+
function durationMs(text, unit) {
|
|
656
|
+
if (BARE_DURATION.test(text))
|
|
657
|
+
return Number(text) * UNIT_MS[unit];
|
|
658
|
+
if (!DURATION.test(text))
|
|
659
|
+
return 0;
|
|
660
|
+
let ms = 0;
|
|
661
|
+
for (const [, amount, part] of text.matchAll(DURATION_PART))
|
|
662
|
+
ms += Number(amount) * UNIT_MS[part];
|
|
663
|
+
return ms;
|
|
664
|
+
}
|
|
655
665
|
function duration(value, name, fallback, unit = "s") {
|
|
656
666
|
if (value === undefined)
|
|
657
667
|
return fallback;
|
|
658
|
-
const
|
|
659
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
668
|
+
const ms = durationMs(value.trim(), unit);
|
|
660
669
|
if (ms < 1)
|
|
661
670
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
662
671
|
return ms;
|
|
663
672
|
}
|
|
664
|
-
var WHOLE, DURATION, UNIT_MS;
|
|
673
|
+
var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
|
|
665
674
|
var init_input = __esm(() => {
|
|
666
675
|
init_args();
|
|
667
676
|
WHOLE = /^\d+$/;
|
|
668
|
-
|
|
669
|
-
|
|
677
|
+
BARE_DURATION = /^\d+(?:\.\d+)?$/;
|
|
678
|
+
DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
|
|
679
|
+
DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
|
|
680
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
|
|
670
681
|
});
|
|
671
682
|
|
|
672
683
|
// ../kit/src/args.ts
|
|
@@ -1542,8 +1553,8 @@ var init_prompt = __esm(() => {
|
|
|
1542
1553
|
|
|
1543
1554
|
// src/gc.ts
|
|
1544
1555
|
import { copyFileSync, existsSync as existsSync4, realpathSync as realpathSync3, renameSync, rmSync as rmSync2 } from "fs";
|
|
1545
|
-
import { basename, dirname as
|
|
1546
|
-
import
|
|
1556
|
+
import { basename, dirname as dirname5, isAbsolute as isAbsolute2, join as join9, relative } from "path";
|
|
1557
|
+
import process22 from "process";
|
|
1547
1558
|
|
|
1548
1559
|
// ../kit/src/index.ts
|
|
1549
1560
|
init_args();
|
|
@@ -1973,12 +1984,15 @@ import { join as join6 } from "path";
|
|
|
1973
1984
|
import process16 from "process";
|
|
1974
1985
|
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1975
1986
|
var ECHOED = /username|yes\/no/i;
|
|
1987
|
+
var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
|
|
1976
1988
|
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1977
1989
|
function askpass(pause = () => () => {
|
|
1978
1990
|
return;
|
|
1979
1991
|
}) {
|
|
1980
1992
|
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1981
|
-
return
|
|
1993
|
+
return { env: { ...NO_PROMPTS }, close: () => {
|
|
1994
|
+
return;
|
|
1995
|
+
} };
|
|
1982
1996
|
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1983
1997
|
const socketPath = join6(dir, "socket");
|
|
1984
1998
|
const script = join6(dir, "askpass");
|
|
@@ -2033,7 +2047,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2033
2047
|
`);
|
|
2034
2048
|
chmodSync(script, 448);
|
|
2035
2049
|
return {
|
|
2036
|
-
env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
2050
|
+
env: { GIT_ASKPASS: script, GIT_TERMINAL_PROMPT: "0", SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
2037
2051
|
close: () => {
|
|
2038
2052
|
server.stop(true);
|
|
2039
2053
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2456,22 +2470,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2456
2470
|
}
|
|
2457
2471
|
// ../kit/src/workspace-root.ts
|
|
2458
2472
|
init_user_config();
|
|
2459
|
-
import { homedir as homedir5 } from "os";
|
|
2460
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2461
|
-
import process21 from "process";
|
|
2462
|
-
function expandHome(path, home) {
|
|
2463
|
-
if (path === "~")
|
|
2464
|
-
return home;
|
|
2465
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2466
|
-
}
|
|
2467
|
-
function configured(env, home) {
|
|
2468
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2469
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2470
|
-
}
|
|
2471
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2472
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2473
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2474
|
-
}
|
|
2475
2473
|
// src/git.ts
|
|
2476
2474
|
async function git2(args, env) {
|
|
2477
2475
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2546,7 +2544,7 @@ var RENAME = /^[RC]\d*$/;
|
|
|
2546
2544
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
2547
2545
|
var TRAILING_SLASHES = /\/+$/;
|
|
2548
2546
|
var SEQUENCES = [["MERGE_HEAD", "a merge", "gm --continue"], ["CHERRY_PICK_HEAD", "a cherry-pick", "git cherry-pick --continue"], ["REVERT_HEAD", "a revert", "git revert --continue"]];
|
|
2549
|
-
var LITERAL = { ...
|
|
2547
|
+
var LITERAL = { ...process22.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
2550
2548
|
function messageOf(title, lines, tickets) {
|
|
2551
2549
|
return [title, lines.join(`
|
|
2552
2550
|
`), tickets.join(`
|
|
@@ -2568,7 +2566,7 @@ async function stagedElsewhere(paths) {
|
|
|
2568
2566
|
}
|
|
2569
2567
|
function onDisk(path) {
|
|
2570
2568
|
try {
|
|
2571
|
-
return
|
|
2569
|
+
return join9(realpathSync3(dirname5(path)), basename(path));
|
|
2572
2570
|
} catch {
|
|
2573
2571
|
return path;
|
|
2574
2572
|
}
|
|
@@ -2576,7 +2574,7 @@ function onDisk(path) {
|
|
|
2576
2574
|
async function renameSources(paths) {
|
|
2577
2575
|
const [top = "", prefix = ""] = (await checked(["rev-parse", "--show-toplevel", "--show-prefix"])).split(`
|
|
2578
2576
|
`);
|
|
2579
|
-
const specs = paths.map((path) => (isAbsolute2(path) ? relative(top, onDisk(path)) :
|
|
2577
|
+
const specs = paths.map((path) => (isAbsolute2(path) ? relative(top, onDisk(path)) : join9(prefix, path)).replace(TRAILING_SLASHES, "") || ".");
|
|
2580
2578
|
const covered = (name) => specs.some((spec) => spec === "." || name === spec || name.startsWith(`${spec}/`));
|
|
2581
2579
|
const fields = (await checked(["diff", "--cached", "-M", "--name-status", "--no-relative", "-z"])).split("\x00");
|
|
2582
2580
|
const sources = [];
|
|
@@ -2597,7 +2595,7 @@ async function inProgress() {
|
|
|
2597
2595
|
}
|
|
2598
2596
|
async function snapshotIndex() {
|
|
2599
2597
|
const index = (await checked(["rev-parse", "--path-format=absolute", "--git-path", "index"])).trim();
|
|
2600
|
-
const copy = `${index}.gc-${
|
|
2598
|
+
const copy = `${index}.gc-${process22.pid}`;
|
|
2601
2599
|
const existed = existsSync4(index);
|
|
2602
2600
|
if (existed)
|
|
2603
2601
|
copyFileSync(index, copy);
|
|
@@ -2687,4 +2685,4 @@ ${(commit.stderr + commit.stdout).trim()}`;
|
|
|
2687
2685
|
signals.release();
|
|
2688
2686
|
}
|
|
2689
2687
|
}
|
|
2690
|
-
|
|
2688
|
+
process22.exitCode = await runMain({ name: "gc", run: main });
|
package/dist/gcl.js
CHANGED
|
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
652
652
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
653
653
|
return number;
|
|
654
654
|
}
|
|
655
|
+
function durationMs(text, unit) {
|
|
656
|
+
if (BARE_DURATION.test(text))
|
|
657
|
+
return Number(text) * UNIT_MS[unit];
|
|
658
|
+
if (!DURATION.test(text))
|
|
659
|
+
return 0;
|
|
660
|
+
let ms = 0;
|
|
661
|
+
for (const [, amount, part] of text.matchAll(DURATION_PART))
|
|
662
|
+
ms += Number(amount) * UNIT_MS[part];
|
|
663
|
+
return ms;
|
|
664
|
+
}
|
|
655
665
|
function duration(value, name, fallback, unit = "s") {
|
|
656
666
|
if (value === undefined)
|
|
657
667
|
return fallback;
|
|
658
|
-
const
|
|
659
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
668
|
+
const ms = durationMs(value.trim(), unit);
|
|
660
669
|
if (ms < 1)
|
|
661
670
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
662
671
|
return ms;
|
|
663
672
|
}
|
|
664
|
-
var WHOLE, DURATION, UNIT_MS;
|
|
673
|
+
var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
|
|
665
674
|
var init_input = __esm(() => {
|
|
666
675
|
init_args();
|
|
667
676
|
WHOLE = /^\d+$/;
|
|
668
|
-
|
|
669
|
-
|
|
677
|
+
BARE_DURATION = /^\d+(?:\.\d+)?$/;
|
|
678
|
+
DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
|
|
679
|
+
DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
|
|
680
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
|
|
670
681
|
});
|
|
671
682
|
|
|
672
683
|
// ../kit/src/args.ts
|
|
@@ -1542,9 +1553,9 @@ var init_prompt = __esm(() => {
|
|
|
1542
1553
|
|
|
1543
1554
|
// src/gcl.ts
|
|
1544
1555
|
import { existsSync as existsSync4, readdirSync, realpathSync as realpathSync3, statSync as statSync2 } from "fs";
|
|
1545
|
-
import { homedir as
|
|
1546
|
-
import { basename, join as
|
|
1547
|
-
import
|
|
1556
|
+
import { homedir as homedir5 } from "os";
|
|
1557
|
+
import { basename, join as join10, resolve as resolve5 } from "path";
|
|
1558
|
+
import process23 from "process";
|
|
1548
1559
|
|
|
1549
1560
|
// ../kit/src/index.ts
|
|
1550
1561
|
init_args();
|
|
@@ -1974,12 +1985,15 @@ import { join as join6 } from "path";
|
|
|
1974
1985
|
import process16 from "process";
|
|
1975
1986
|
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1976
1987
|
var ECHOED = /username|yes\/no/i;
|
|
1988
|
+
var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
|
|
1977
1989
|
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1978
1990
|
function askpass(pause = () => () => {
|
|
1979
1991
|
return;
|
|
1980
1992
|
}) {
|
|
1981
1993
|
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1982
|
-
return
|
|
1994
|
+
return { env: { ...NO_PROMPTS }, close: () => {
|
|
1995
|
+
return;
|
|
1996
|
+
} };
|
|
1983
1997
|
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1984
1998
|
const socketPath = join6(dir, "socket");
|
|
1985
1999
|
const script = join6(dir, "askpass");
|
|
@@ -2034,7 +2048,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2034
2048
|
`);
|
|
2035
2049
|
chmodSync(script, 448);
|
|
2036
2050
|
return {
|
|
2037
|
-
env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
2051
|
+
env: { GIT_ASKPASS: script, GIT_TERMINAL_PROMPT: "0", SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
2038
2052
|
close: () => {
|
|
2039
2053
|
server.stop(true);
|
|
2040
2054
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2457,22 +2471,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2457
2471
|
}
|
|
2458
2472
|
// ../kit/src/workspace-root.ts
|
|
2459
2473
|
init_user_config();
|
|
2460
|
-
import { homedir as homedir5 } from "os";
|
|
2461
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2462
|
-
import process21 from "process";
|
|
2463
|
-
function expandHome(path, home) {
|
|
2464
|
-
if (path === "~")
|
|
2465
|
-
return home;
|
|
2466
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2467
|
-
}
|
|
2468
|
-
function configured(env, home) {
|
|
2469
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2470
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2471
|
-
}
|
|
2472
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2473
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2474
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2475
|
-
}
|
|
2476
2474
|
// src/git.ts
|
|
2477
2475
|
async function git2(args, env) {
|
|
2478
2476
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2482,8 +2480,8 @@ async function git2(args, env) {
|
|
|
2482
2480
|
|
|
2483
2481
|
// src/repos.ts
|
|
2484
2482
|
import { readdir } from "fs/promises";
|
|
2485
|
-
import { join as
|
|
2486
|
-
import
|
|
2483
|
+
import { join as join9, relative, resolve as resolve4 } from "path";
|
|
2484
|
+
import process22 from "process";
|
|
2487
2485
|
|
|
2488
2486
|
// src/status.ts
|
|
2489
2487
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -2579,9 +2577,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
2579
2577
|
found.push(dir);
|
|
2580
2578
|
if (left === 0)
|
|
2581
2579
|
return;
|
|
2582
|
-
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(
|
|
2580
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join9(dir, entry.name), left - 1)));
|
|
2583
2581
|
}
|
|
2584
|
-
await walk(
|
|
2582
|
+
await walk(resolve4(root), depth);
|
|
2585
2583
|
return found.sort();
|
|
2586
2584
|
}
|
|
2587
2585
|
async function toplevelOf(dir) {
|
|
@@ -2589,14 +2587,14 @@ async function toplevelOf(dir) {
|
|
|
2589
2587
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
2590
2588
|
}
|
|
2591
2589
|
async function reposOf(roots) {
|
|
2592
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2590
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process22.cwd()];
|
|
2593
2591
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
2594
2592
|
return [...new Set(found.flat())].sort();
|
|
2595
2593
|
}
|
|
2596
2594
|
async function repoState(dir) {
|
|
2597
2595
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
2598
2596
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
2599
|
-
return { path: relative(
|
|
2597
|
+
return { path: relative(process22.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
2600
2598
|
}
|
|
2601
2599
|
function trackingOf(status) {
|
|
2602
2600
|
if (status.upstream === null)
|
|
@@ -2688,9 +2686,10 @@ async function sync(repo, { pull, env }) {
|
|
|
2688
2686
|
|
|
2689
2687
|
// src/gcl.ts
|
|
2690
2688
|
var DEFAULT_FORGE = "git.kaynooo.fr";
|
|
2691
|
-
var USAGE = `gcl <repo> [dir]: clones a repository into the
|
|
2689
|
+
var USAGE = `gcl <repo> [dir]: clones a repository into the current folder and prints where it landed
|
|
2692
2690
|
|
|
2693
|
-
<repo> is a URL, an scp-style address
|
|
2691
|
+
<repo> is a URL, an scp-style address (\`git@host:port:owner/name\` read as \`ssh://git@host:port/owner/name\`), a local path or \`owner/name\`. Without <dir> the clone goes to ./<name>, as git clone does.
|
|
2692
|
+
\`owner/name\` is cloned over ssh from the \`forgeSsh\` config key (\`git@host\` or \`ssh://git@host:port\`), anonymously over https from \`https://${DEFAULT_FORGE}/owner/name.git\` (the \`forge\` config key names another host) when ssh fails or forgeSsh is unset. Off a terminal git never asks for a password, through the terminal or a desktop window: it fails instead.
|
|
2694
2693
|
A folder that already holds the repository is fetched and fast-forwarded as gf does, not cloned again; one holding anything else is refused.`;
|
|
2695
2694
|
var EXITS = [[0, "it cloned the repository, or found it and brought it up to date"], [1, "git could not clone it, or the folder is taken"], [2, "a usage error"]];
|
|
2696
2695
|
var OPTIONS = {
|
|
@@ -2698,66 +2697,111 @@ var OPTIONS = {
|
|
|
2698
2697
|
};
|
|
2699
2698
|
var SCHEME = /^[a-z][a-z\d+.-]*:\/\//i;
|
|
2700
2699
|
var SCP = /^[\w.-]+@[\w.-]+:/;
|
|
2700
|
+
var SCP_WITH_PORT = /^([\w.-]+@[\w.-]+):(\d+):\/?(.+)$/;
|
|
2701
2701
|
var OWNER_NAME = /^[\w.-]+\/[\w.-]+$/;
|
|
2702
2702
|
var GIT_SUFFIX = /\.git\/?$/;
|
|
2703
2703
|
var TRAILING_SLASH = /\/+$/;
|
|
2704
2704
|
var LAST_SEGMENT = /[/:]/;
|
|
2705
|
+
var AUTH_REFUSED = /could not read Username|Authentication failed|terminal prompts disabled|\b40[13]\b/i;
|
|
2706
|
+
var SSH_BASE_END = /[/:]$/;
|
|
2705
2707
|
function urlOf(repo, forge) {
|
|
2706
2708
|
if (repo.startsWith("~/"))
|
|
2707
|
-
return
|
|
2709
|
+
return join10(homedir5(), repo.slice(2));
|
|
2710
|
+
const withPort = SCP_WITH_PORT.exec(repo);
|
|
2711
|
+
if (withPort !== null)
|
|
2712
|
+
return `ssh://${withPort[1]}:${withPort[2]}/${withPort[3]}`;
|
|
2708
2713
|
if (SCHEME.test(repo) || SCP.test(repo) || repo.startsWith("/") || repo.startsWith("."))
|
|
2709
2714
|
return repo;
|
|
2710
2715
|
if (OWNER_NAME.test(repo))
|
|
2711
|
-
return `https://${forge}/${repo.replace(GIT_SUFFIX, "")}.git`;
|
|
2716
|
+
return `${SCHEME.test(forge) ? forge.replace(TRAILING_SLASH, "") : `https://${forge}`}/${repo.replace(GIT_SUFFIX, "")}.git`;
|
|
2712
2717
|
return fail(`${repo} is no URL and no owner/name`, 2);
|
|
2713
2718
|
}
|
|
2719
|
+
function sshUrlOf(repo, base) {
|
|
2720
|
+
const separator = SCHEME.test(base) ? "/" : ":";
|
|
2721
|
+
return `${base}${SSH_BASE_END.test(base) ? "" : separator}${repo.replace(GIT_SUFFIX, "")}.git`;
|
|
2722
|
+
}
|
|
2723
|
+
function setting(config, key) {
|
|
2724
|
+
const value = config[key];
|
|
2725
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
2726
|
+
}
|
|
2714
2727
|
function nameOf(url) {
|
|
2715
2728
|
return basename(url.replace(TRAILING_SLASH, "").split(LAST_SEGMENT).at(-1) ?? "").replace(GIT_SUFFIX, "");
|
|
2716
2729
|
}
|
|
2717
2730
|
function same(url) {
|
|
2718
2731
|
return url.replace(TRAILING_SLASH, "").replace(GIT_SUFFIX, "").toLowerCase();
|
|
2719
2732
|
}
|
|
2733
|
+
async function update({ url, sshUrl, path }, env) {
|
|
2734
|
+
if (!statSync2(path).isDirectory() || await toplevelOf(path) !== realpathSync3(path))
|
|
2735
|
+
fail(`${path} exists and is not a repository, nothing cloned`, 1);
|
|
2736
|
+
const origin = (await git2(["-C", path, "remote", "get-url", "origin"])).stdout.trim();
|
|
2737
|
+
if (same(origin) !== same(url) && (sshUrl === undefined || same(origin) !== same(sshUrl)))
|
|
2738
|
+
fail(`${path} is a clone of ${origin === "" ? "nothing (no origin)" : origin}, not ${url}, nothing cloned`, 1);
|
|
2739
|
+
const synced = await sync(await repoState(path), { pull: true, env });
|
|
2740
|
+
if (synced.outcome === "refused")
|
|
2741
|
+
fail(`${path} is already cloned but could not be brought up to date: ${synced.reason}`, 1);
|
|
2742
|
+
return origin;
|
|
2743
|
+
}
|
|
2744
|
+
async function clone({ repo, url, sshUrl, forgeSsh, path }, env) {
|
|
2745
|
+
if (forgeSsh !== undefined && sshUrl !== undefined) {
|
|
2746
|
+
const overSsh = await git2(["clone", sshUrl, path], env);
|
|
2747
|
+
if (overSsh.code === 0)
|
|
2748
|
+
return sshUrl;
|
|
2749
|
+
const overHttps = await git2(["clone", url, path], { ...env, ...NO_PROMPTS });
|
|
2750
|
+
if (overHttps.code !== 0)
|
|
2751
|
+
fail(`git clone failed over ssh and over https:
|
|
2752
|
+
${overSsh.stderr.trim()}
|
|
2753
|
+
${overHttps.stderr.trim()}`, 1);
|
|
2754
|
+
return url;
|
|
2755
|
+
}
|
|
2756
|
+
const cloned = await git2(["clone", url, path], env);
|
|
2757
|
+
if (cloned.code === 0)
|
|
2758
|
+
return url;
|
|
2759
|
+
if (sshUrl === undefined || !AUTH_REFUSED.test(cloned.stderr))
|
|
2760
|
+
fail(`git clone failed:
|
|
2761
|
+
${cloned.stderr.trim()}`, 1);
|
|
2762
|
+
return fail(`git clone failed:
|
|
2763
|
+
${cloned.stderr.trim()}
|
|
2764
|
+
${repo} may be private, which https refuses without a login: clone it over ssh, as gcl ${sshUrl}, or set forgeSsh in ~/.config/kaynooo-cli/config.json to the forge's ssh address so that owner/name does`, 1);
|
|
2765
|
+
}
|
|
2720
2766
|
async function main(argv) {
|
|
2721
|
-
const { values, positionals } = parse(argv, USAGE, OPTIONS, { positionals: ["<repo>", "[dir]"], exits: EXITS, replaces: "git clone with the url
|
|
2767
|
+
const { values, positionals } = parse(argv, USAGE, OPTIONS, { positionals: ["<repo>", "[dir]"], exits: EXITS, replaces: "git clone with the url typed out, then a cd", examples: ["gcl kaynooo/cli", ["gcl git@github.com:oven-sh/bun.git", "an scp address"], ["gcl git@git.example.org:22022:kaynooo/cli", "an scp address with a port"], ["gcl kaynooo/cli ~/tmp/cli", "a folder of your own"]] });
|
|
2722
2768
|
const [repo, given] = positionals;
|
|
2723
2769
|
if (repo === undefined)
|
|
2724
2770
|
fail("gcl needs the repository to clone: gcl owner/name", 2);
|
|
2725
|
-
const
|
|
2726
|
-
const
|
|
2771
|
+
const config = readUserConfig("config");
|
|
2772
|
+
const forge = setting(config, "forge") ?? DEFAULT_FORGE;
|
|
2773
|
+
const url = urlOf(repo, forge);
|
|
2774
|
+
const isOwnerName = OWNER_NAME.test(repo) && !repo.startsWith(".");
|
|
2775
|
+
const forgeSsh = setting(config, "forgeSsh");
|
|
2776
|
+
const sshUrl = isOwnerName ? sshUrlOf(repo, forgeSsh ?? `git@${SCHEME.test(forge) ? new URL(forge).hostname : forge}`) : undefined;
|
|
2727
2777
|
const name = nameOf(url);
|
|
2728
2778
|
if (name === "")
|
|
2729
2779
|
fail(`no folder name can be taken from ${url}, give one: gcl ${repo} <dir>`, 2);
|
|
2730
|
-
const
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
fail(`${path} is already cloned but could not be brought up to date: ${synced.reason}`, 1);
|
|
2741
|
-
outcome = "existing";
|
|
2742
|
-
} else {
|
|
2743
|
-
const cloned = await git2(["clone", url, path]);
|
|
2744
|
-
if (cloned.code !== 0)
|
|
2745
|
-
fail(`git clone failed:
|
|
2746
|
-
${cloned.stderr.trim()}`, 1);
|
|
2780
|
+
const target = { repo, url, sshUrl, forgeSsh, path: resolve5(given ?? name) };
|
|
2781
|
+
const { path } = target;
|
|
2782
|
+
const outcome = existsSync4(path) && (!statSync2(path).isDirectory() || readdirSync(path).length > 0) ? "existing" : "cloned";
|
|
2783
|
+
const prompts = askpass();
|
|
2784
|
+
const env = { ...process23.env, ...prompts.env };
|
|
2785
|
+
let from;
|
|
2786
|
+
try {
|
|
2787
|
+
from = outcome === "existing" ? await update(target, env) : await clone(target, env);
|
|
2788
|
+
} finally {
|
|
2789
|
+
prompts.close();
|
|
2747
2790
|
}
|
|
2748
2791
|
const { status, head } = await repoState(path);
|
|
2749
|
-
const result = { url, path, branch: status?.branch ?? null, head: head?.sha ?? null, outcome };
|
|
2792
|
+
const result = { url: from, path, branch: status?.branch ?? null, head: head?.sha ?? null, outcome };
|
|
2750
2793
|
if (values.json === true)
|
|
2751
2794
|
printJson(result);
|
|
2752
2795
|
else
|
|
2753
2796
|
console.log(path);
|
|
2754
2797
|
if (values.json !== true)
|
|
2755
|
-
console.error(`${outcome === "cloned" ? "cloned" : "already cloned"} ${
|
|
2798
|
+
console.error(`${outcome === "cloned" ? "cloned" : "already cloned"} ${from}${result.branch === null ? "" : ` on ${result.branch}`}${result.head === null ? "" : ` at ${result.head}`}`);
|
|
2756
2799
|
return 0;
|
|
2757
2800
|
}
|
|
2758
2801
|
if (import.meta.main)
|
|
2759
|
-
|
|
2802
|
+
process23.exitCode = await runMain({ name: "gcl", run: main });
|
|
2760
2803
|
export {
|
|
2761
2804
|
nameOf,
|
|
2805
|
+
sshUrlOf,
|
|
2762
2806
|
urlOf
|
|
2763
2807
|
};
|