@kaynooo/cli-git 0.18.1 → 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 +17 -30
- package/dist/gc.js +12 -25
- package/dist/gcl.js +87 -54
- package/dist/gd.js +20 -33
- package/dist/gf.js +19 -32
- package/dist/gm.js +28 -41
- package/dist/gp.js +19 -32
- package/dist/gst.js +26 -39
- package/dist/gu.js +12 -25
- 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
|
@@ -1552,7 +1552,7 @@ var init_prompt = __esm(() => {
|
|
|
1552
1552
|
});
|
|
1553
1553
|
|
|
1554
1554
|
// src/gb.ts
|
|
1555
|
-
import
|
|
1555
|
+
import process25 from "process";
|
|
1556
1556
|
|
|
1557
1557
|
// ../kit/src/index.ts
|
|
1558
1558
|
init_args();
|
|
@@ -1982,12 +1982,15 @@ import { join as join6 } from "path";
|
|
|
1982
1982
|
import process16 from "process";
|
|
1983
1983
|
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1984
1984
|
var ECHOED = /username|yes\/no/i;
|
|
1985
|
+
var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
|
|
1985
1986
|
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1986
1987
|
function askpass(pause = () => () => {
|
|
1987
1988
|
return;
|
|
1988
1989
|
}) {
|
|
1989
1990
|
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1990
|
-
return
|
|
1991
|
+
return { env: { ...NO_PROMPTS }, close: () => {
|
|
1992
|
+
return;
|
|
1993
|
+
} };
|
|
1991
1994
|
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1992
1995
|
const socketPath = join6(dir, "socket");
|
|
1993
1996
|
const script = join6(dir, "askpass");
|
|
@@ -2042,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2042
2045
|
`);
|
|
2043
2046
|
chmodSync(script, 448);
|
|
2044
2047
|
return {
|
|
2045
|
-
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" },
|
|
2046
2049
|
close: () => {
|
|
2047
2050
|
server.stop(true);
|
|
2048
2051
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2465,25 +2468,9 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2465
2468
|
}
|
|
2466
2469
|
// ../kit/src/workspace-root.ts
|
|
2467
2470
|
init_user_config();
|
|
2468
|
-
import { homedir as homedir5 } from "os";
|
|
2469
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2470
|
-
import process21 from "process";
|
|
2471
|
-
function expandHome(path, home) {
|
|
2472
|
-
if (path === "~")
|
|
2473
|
-
return home;
|
|
2474
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2475
|
-
}
|
|
2476
|
-
function configured(env, home) {
|
|
2477
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2478
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2479
|
-
}
|
|
2480
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2481
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2482
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2483
|
-
}
|
|
2484
2471
|
// src/branch.ts
|
|
2485
2472
|
import { basename } from "path";
|
|
2486
|
-
import
|
|
2473
|
+
import process24 from "process";
|
|
2487
2474
|
|
|
2488
2475
|
// ../kit/src/picker.ts
|
|
2489
2476
|
init_folders();
|
|
@@ -2495,11 +2482,11 @@ init_job();
|
|
|
2495
2482
|
init_redraw();
|
|
2496
2483
|
init_style();
|
|
2497
2484
|
import { openSync } from "fs";
|
|
2498
|
-
import
|
|
2485
|
+
import process23 from "process";
|
|
2499
2486
|
import tty from "tty";
|
|
2500
2487
|
|
|
2501
2488
|
// ../kit/src/picker/preview.ts
|
|
2502
|
-
import
|
|
2489
|
+
import process22 from "process";
|
|
2503
2490
|
|
|
2504
2491
|
// ../kit/src/shell.ts
|
|
2505
2492
|
var SEPARATORS = new Set([`
|
|
@@ -2586,7 +2573,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
2586
2573
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
2587
2574
|
const stop = () => {
|
|
2588
2575
|
try {
|
|
2589
|
-
|
|
2576
|
+
process22.kill(-proc.pid, "SIGKILL");
|
|
2590
2577
|
} catch {
|
|
2591
2578
|
proc.kill();
|
|
2592
2579
|
}
|
|
@@ -2749,7 +2736,7 @@ function openTerminal() {
|
|
|
2749
2736
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
2750
2737
|
}
|
|
2751
2738
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
2752
|
-
const out =
|
|
2739
|
+
const out = process23.stderr;
|
|
2753
2740
|
let resize;
|
|
2754
2741
|
async function read(onChunk) {
|
|
2755
2742
|
const decoder = new TextDecoder;
|
|
@@ -2938,9 +2925,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2938
2925
|
const ended = new Promise((resolve) => {
|
|
2939
2926
|
finish = resolve;
|
|
2940
2927
|
});
|
|
2941
|
-
|
|
2928
|
+
process23.once("exit", restore);
|
|
2942
2929
|
for (const signal of SIGNALS2)
|
|
2943
|
-
|
|
2930
|
+
process23.once(signal, stop);
|
|
2944
2931
|
try {
|
|
2945
2932
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2946
2933
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -2953,8 +2940,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2953
2940
|
await ended;
|
|
2954
2941
|
} finally {
|
|
2955
2942
|
for (const signal of SIGNALS2)
|
|
2956
|
-
|
|
2957
|
-
|
|
2943
|
+
process23.off(signal, stop);
|
|
2944
|
+
process23.off("exit", restore);
|
|
2958
2945
|
restore();
|
|
2959
2946
|
}
|
|
2960
2947
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -3227,7 +3214,7 @@ async function gb(args) {
|
|
|
3227
3214
|
if (parsed.values.json === true)
|
|
3228
3215
|
printJson(all);
|
|
3229
3216
|
else
|
|
3230
|
-
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(`
|
|
3231
3218
|
`));
|
|
3232
3219
|
return 0;
|
|
3233
3220
|
}
|
|
@@ -3284,4 +3271,4 @@ async function finish(command, typed, emitting) {
|
|
|
3284
3271
|
}
|
|
3285
3272
|
|
|
3286
3273
|
// src/gb.ts
|
|
3287
|
-
|
|
3274
|
+
process25.exitCode = await runMain({ name: "gb", run: gb });
|
package/dist/gc.js
CHANGED
|
@@ -1553,8 +1553,8 @@ var init_prompt = __esm(() => {
|
|
|
1553
1553
|
|
|
1554
1554
|
// src/gc.ts
|
|
1555
1555
|
import { copyFileSync, existsSync as existsSync4, realpathSync as realpathSync3, renameSync, rmSync as rmSync2 } from "fs";
|
|
1556
|
-
import { basename, dirname as
|
|
1557
|
-
import
|
|
1556
|
+
import { basename, dirname as dirname5, isAbsolute as isAbsolute2, join as join9, relative } from "path";
|
|
1557
|
+
import process22 from "process";
|
|
1558
1558
|
|
|
1559
1559
|
// ../kit/src/index.ts
|
|
1560
1560
|
init_args();
|
|
@@ -1984,12 +1984,15 @@ import { join as join6 } from "path";
|
|
|
1984
1984
|
import process16 from "process";
|
|
1985
1985
|
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1986
1986
|
var ECHOED = /username|yes\/no/i;
|
|
1987
|
+
var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
|
|
1987
1988
|
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1988
1989
|
function askpass(pause = () => () => {
|
|
1989
1990
|
return;
|
|
1990
1991
|
}) {
|
|
1991
1992
|
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1992
|
-
return
|
|
1993
|
+
return { env: { ...NO_PROMPTS }, close: () => {
|
|
1994
|
+
return;
|
|
1995
|
+
} };
|
|
1993
1996
|
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1994
1997
|
const socketPath = join6(dir, "socket");
|
|
1995
1998
|
const script = join6(dir, "askpass");
|
|
@@ -2044,7 +2047,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2044
2047
|
`);
|
|
2045
2048
|
chmodSync(script, 448);
|
|
2046
2049
|
return {
|
|
2047
|
-
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" },
|
|
2048
2051
|
close: () => {
|
|
2049
2052
|
server.stop(true);
|
|
2050
2053
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2467,22 +2470,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2467
2470
|
}
|
|
2468
2471
|
// ../kit/src/workspace-root.ts
|
|
2469
2472
|
init_user_config();
|
|
2470
|
-
import { homedir as homedir5 } from "os";
|
|
2471
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2472
|
-
import process21 from "process";
|
|
2473
|
-
function expandHome(path, home) {
|
|
2474
|
-
if (path === "~")
|
|
2475
|
-
return home;
|
|
2476
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2477
|
-
}
|
|
2478
|
-
function configured(env, home) {
|
|
2479
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2480
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2481
|
-
}
|
|
2482
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2483
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2484
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2485
|
-
}
|
|
2486
2473
|
// src/git.ts
|
|
2487
2474
|
async function git2(args, env) {
|
|
2488
2475
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2557,7 +2544,7 @@ var RENAME = /^[RC]\d*$/;
|
|
|
2557
2544
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
2558
2545
|
var TRAILING_SLASHES = /\/+$/;
|
|
2559
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"]];
|
|
2560
|
-
var LITERAL = { ...
|
|
2547
|
+
var LITERAL = { ...process22.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
2561
2548
|
function messageOf(title, lines, tickets) {
|
|
2562
2549
|
return [title, lines.join(`
|
|
2563
2550
|
`), tickets.join(`
|
|
@@ -2579,7 +2566,7 @@ async function stagedElsewhere(paths) {
|
|
|
2579
2566
|
}
|
|
2580
2567
|
function onDisk(path) {
|
|
2581
2568
|
try {
|
|
2582
|
-
return
|
|
2569
|
+
return join9(realpathSync3(dirname5(path)), basename(path));
|
|
2583
2570
|
} catch {
|
|
2584
2571
|
return path;
|
|
2585
2572
|
}
|
|
@@ -2587,7 +2574,7 @@ function onDisk(path) {
|
|
|
2587
2574
|
async function renameSources(paths) {
|
|
2588
2575
|
const [top = "", prefix = ""] = (await checked(["rev-parse", "--show-toplevel", "--show-prefix"])).split(`
|
|
2589
2576
|
`);
|
|
2590
|
-
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, "") || ".");
|
|
2591
2578
|
const covered = (name) => specs.some((spec) => spec === "." || name === spec || name.startsWith(`${spec}/`));
|
|
2592
2579
|
const fields = (await checked(["diff", "--cached", "-M", "--name-status", "--no-relative", "-z"])).split("\x00");
|
|
2593
2580
|
const sources = [];
|
|
@@ -2608,7 +2595,7 @@ async function inProgress() {
|
|
|
2608
2595
|
}
|
|
2609
2596
|
async function snapshotIndex() {
|
|
2610
2597
|
const index = (await checked(["rev-parse", "--path-format=absolute", "--git-path", "index"])).trim();
|
|
2611
|
-
const copy = `${index}.gc-${
|
|
2598
|
+
const copy = `${index}.gc-${process22.pid}`;
|
|
2612
2599
|
const existed = existsSync4(index);
|
|
2613
2600
|
if (existed)
|
|
2614
2601
|
copyFileSync(index, copy);
|
|
@@ -2698,4 +2685,4 @@ ${(commit.stderr + commit.stdout).trim()}`;
|
|
|
2698
2685
|
signals.release();
|
|
2699
2686
|
}
|
|
2700
2687
|
}
|
|
2701
|
-
|
|
2688
|
+
process22.exitCode = await runMain({ name: "gc", run: main });
|
package/dist/gcl.js
CHANGED
|
@@ -1553,9 +1553,9 @@ var init_prompt = __esm(() => {
|
|
|
1553
1553
|
|
|
1554
1554
|
// src/gcl.ts
|
|
1555
1555
|
import { existsSync as existsSync4, readdirSync, realpathSync as realpathSync3, statSync as statSync2 } from "fs";
|
|
1556
|
-
import { homedir as
|
|
1557
|
-
import { basename, join as
|
|
1558
|
-
import
|
|
1556
|
+
import { homedir as homedir5 } from "os";
|
|
1557
|
+
import { basename, join as join10, resolve as resolve5 } from "path";
|
|
1558
|
+
import process23 from "process";
|
|
1559
1559
|
|
|
1560
1560
|
// ../kit/src/index.ts
|
|
1561
1561
|
init_args();
|
|
@@ -1985,12 +1985,15 @@ import { join as join6 } from "path";
|
|
|
1985
1985
|
import process16 from "process";
|
|
1986
1986
|
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1987
1987
|
var ECHOED = /username|yes\/no/i;
|
|
1988
|
+
var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
|
|
1988
1989
|
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1989
1990
|
function askpass(pause = () => () => {
|
|
1990
1991
|
return;
|
|
1991
1992
|
}) {
|
|
1992
1993
|
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1993
|
-
return
|
|
1994
|
+
return { env: { ...NO_PROMPTS }, close: () => {
|
|
1995
|
+
return;
|
|
1996
|
+
} };
|
|
1994
1997
|
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1995
1998
|
const socketPath = join6(dir, "socket");
|
|
1996
1999
|
const script = join6(dir, "askpass");
|
|
@@ -2045,7 +2048,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2045
2048
|
`);
|
|
2046
2049
|
chmodSync(script, 448);
|
|
2047
2050
|
return {
|
|
2048
|
-
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" },
|
|
2049
2052
|
close: () => {
|
|
2050
2053
|
server.stop(true);
|
|
2051
2054
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2468,22 +2471,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2468
2471
|
}
|
|
2469
2472
|
// ../kit/src/workspace-root.ts
|
|
2470
2473
|
init_user_config();
|
|
2471
|
-
import { homedir as homedir5 } from "os";
|
|
2472
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2473
|
-
import process21 from "process";
|
|
2474
|
-
function expandHome(path, home) {
|
|
2475
|
-
if (path === "~")
|
|
2476
|
-
return home;
|
|
2477
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2478
|
-
}
|
|
2479
|
-
function configured(env, home) {
|
|
2480
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2481
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2482
|
-
}
|
|
2483
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2484
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2485
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2486
|
-
}
|
|
2487
2474
|
// src/git.ts
|
|
2488
2475
|
async function git2(args, env) {
|
|
2489
2476
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2493,8 +2480,8 @@ async function git2(args, env) {
|
|
|
2493
2480
|
|
|
2494
2481
|
// src/repos.ts
|
|
2495
2482
|
import { readdir } from "fs/promises";
|
|
2496
|
-
import { join as
|
|
2497
|
-
import
|
|
2483
|
+
import { join as join9, relative, resolve as resolve4 } from "path";
|
|
2484
|
+
import process22 from "process";
|
|
2498
2485
|
|
|
2499
2486
|
// src/status.ts
|
|
2500
2487
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -2590,9 +2577,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
2590
2577
|
found.push(dir);
|
|
2591
2578
|
if (left === 0)
|
|
2592
2579
|
return;
|
|
2593
|
-
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)));
|
|
2594
2581
|
}
|
|
2595
|
-
await walk(
|
|
2582
|
+
await walk(resolve4(root), depth);
|
|
2596
2583
|
return found.sort();
|
|
2597
2584
|
}
|
|
2598
2585
|
async function toplevelOf(dir) {
|
|
@@ -2600,14 +2587,14 @@ async function toplevelOf(dir) {
|
|
|
2600
2587
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
2601
2588
|
}
|
|
2602
2589
|
async function reposOf(roots) {
|
|
2603
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2590
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process22.cwd()];
|
|
2604
2591
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
2605
2592
|
return [...new Set(found.flat())].sort();
|
|
2606
2593
|
}
|
|
2607
2594
|
async function repoState(dir) {
|
|
2608
2595
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
2609
2596
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
2610
|
-
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 } };
|
|
2611
2598
|
}
|
|
2612
2599
|
function trackingOf(status) {
|
|
2613
2600
|
if (status.upstream === null)
|
|
@@ -2699,9 +2686,10 @@ async function sync(repo, { pull, env }) {
|
|
|
2699
2686
|
|
|
2700
2687
|
// src/gcl.ts
|
|
2701
2688
|
var DEFAULT_FORGE = "git.kaynooo.fr";
|
|
2702
|
-
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
|
|
2703
2690
|
|
|
2704
|
-
<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.
|
|
2705
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.`;
|
|
2706
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"]];
|
|
2707
2695
|
var OPTIONS = {
|
|
@@ -2709,66 +2697,111 @@ var OPTIONS = {
|
|
|
2709
2697
|
};
|
|
2710
2698
|
var SCHEME = /^[a-z][a-z\d+.-]*:\/\//i;
|
|
2711
2699
|
var SCP = /^[\w.-]+@[\w.-]+:/;
|
|
2700
|
+
var SCP_WITH_PORT = /^([\w.-]+@[\w.-]+):(\d+):\/?(.+)$/;
|
|
2712
2701
|
var OWNER_NAME = /^[\w.-]+\/[\w.-]+$/;
|
|
2713
2702
|
var GIT_SUFFIX = /\.git\/?$/;
|
|
2714
2703
|
var TRAILING_SLASH = /\/+$/;
|
|
2715
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 = /[/:]$/;
|
|
2716
2707
|
function urlOf(repo, forge) {
|
|
2717
2708
|
if (repo.startsWith("~/"))
|
|
2718
|
-
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]}`;
|
|
2719
2713
|
if (SCHEME.test(repo) || SCP.test(repo) || repo.startsWith("/") || repo.startsWith("."))
|
|
2720
2714
|
return repo;
|
|
2721
2715
|
if (OWNER_NAME.test(repo))
|
|
2722
|
-
return `https://${forge}/${repo.replace(GIT_SUFFIX, "")}.git`;
|
|
2716
|
+
return `${SCHEME.test(forge) ? forge.replace(TRAILING_SLASH, "") : `https://${forge}`}/${repo.replace(GIT_SUFFIX, "")}.git`;
|
|
2723
2717
|
return fail(`${repo} is no URL and no owner/name`, 2);
|
|
2724
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
|
+
}
|
|
2725
2727
|
function nameOf(url) {
|
|
2726
2728
|
return basename(url.replace(TRAILING_SLASH, "").split(LAST_SEGMENT).at(-1) ?? "").replace(GIT_SUFFIX, "");
|
|
2727
2729
|
}
|
|
2728
2730
|
function same(url) {
|
|
2729
2731
|
return url.replace(TRAILING_SLASH, "").replace(GIT_SUFFIX, "").toLowerCase();
|
|
2730
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
|
+
}
|
|
2731
2766
|
async function main(argv) {
|
|
2732
|
-
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"]] });
|
|
2733
2768
|
const [repo, given] = positionals;
|
|
2734
2769
|
if (repo === undefined)
|
|
2735
2770
|
fail("gcl needs the repository to clone: gcl owner/name", 2);
|
|
2736
|
-
const
|
|
2737
|
-
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;
|
|
2738
2777
|
const name = nameOf(url);
|
|
2739
2778
|
if (name === "")
|
|
2740
2779
|
fail(`no folder name can be taken from ${url}, give one: gcl ${repo} <dir>`, 2);
|
|
2741
|
-
const
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
fail(`${path} is already cloned but could not be brought up to date: ${synced.reason}`, 1);
|
|
2752
|
-
outcome = "existing";
|
|
2753
|
-
} else {
|
|
2754
|
-
const cloned = await git2(["clone", url, path]);
|
|
2755
|
-
if (cloned.code !== 0)
|
|
2756
|
-
fail(`git clone failed:
|
|
2757
|
-
${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();
|
|
2758
2790
|
}
|
|
2759
2791
|
const { status, head } = await repoState(path);
|
|
2760
|
-
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 };
|
|
2761
2793
|
if (values.json === true)
|
|
2762
2794
|
printJson(result);
|
|
2763
2795
|
else
|
|
2764
2796
|
console.log(path);
|
|
2765
2797
|
if (values.json !== true)
|
|
2766
|
-
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}`}`);
|
|
2767
2799
|
return 0;
|
|
2768
2800
|
}
|
|
2769
2801
|
if (import.meta.main)
|
|
2770
|
-
|
|
2802
|
+
process23.exitCode = await runMain({ name: "gcl", run: main });
|
|
2771
2803
|
export {
|
|
2772
2804
|
nameOf,
|
|
2805
|
+
sshUrlOf,
|
|
2773
2806
|
urlOf
|
|
2774
2807
|
};
|
package/dist/gd.js
CHANGED
|
@@ -1552,7 +1552,7 @@ var init_prompt = __esm(() => {
|
|
|
1552
1552
|
});
|
|
1553
1553
|
|
|
1554
1554
|
// src/gd.ts
|
|
1555
|
-
import
|
|
1555
|
+
import process23 from "process";
|
|
1556
1556
|
|
|
1557
1557
|
// ../kit/src/index.ts
|
|
1558
1558
|
init_args();
|
|
@@ -1982,12 +1982,15 @@ import { join as join6 } from "path";
|
|
|
1982
1982
|
import process16 from "process";
|
|
1983
1983
|
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1984
1984
|
var ECHOED = /username|yes\/no/i;
|
|
1985
|
+
var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
|
|
1985
1986
|
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1986
1987
|
function askpass(pause = () => () => {
|
|
1987
1988
|
return;
|
|
1988
1989
|
}) {
|
|
1989
1990
|
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1990
|
-
return
|
|
1991
|
+
return { env: { ...NO_PROMPTS }, close: () => {
|
|
1992
|
+
return;
|
|
1993
|
+
} };
|
|
1991
1994
|
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1992
1995
|
const socketPath = join6(dir, "socket");
|
|
1993
1996
|
const script = join6(dir, "askpass");
|
|
@@ -2042,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2042
2045
|
`);
|
|
2043
2046
|
chmodSync(script, 448);
|
|
2044
2047
|
return {
|
|
2045
|
-
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" },
|
|
2046
2049
|
close: () => {
|
|
2047
2050
|
server.stop(true);
|
|
2048
2051
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2465,22 +2468,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2465
2468
|
}
|
|
2466
2469
|
// ../kit/src/workspace-root.ts
|
|
2467
2470
|
init_user_config();
|
|
2468
|
-
import { homedir as homedir5 } from "os";
|
|
2469
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2470
|
-
import process21 from "process";
|
|
2471
|
-
function expandHome(path, home) {
|
|
2472
|
-
if (path === "~")
|
|
2473
|
-
return home;
|
|
2474
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2475
|
-
}
|
|
2476
|
-
function configured(env, home) {
|
|
2477
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2478
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2479
|
-
}
|
|
2480
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2481
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2482
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2483
|
-
}
|
|
2484
2471
|
// src/git.ts
|
|
2485
2472
|
async function git2(args, env) {
|
|
2486
2473
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2490,8 +2477,8 @@ async function git2(args, env) {
|
|
|
2490
2477
|
|
|
2491
2478
|
// src/repos.ts
|
|
2492
2479
|
import { readdir } from "fs/promises";
|
|
2493
|
-
import { join as
|
|
2494
|
-
import
|
|
2480
|
+
import { join as join9, relative, resolve as resolve4 } from "path";
|
|
2481
|
+
import process22 from "process";
|
|
2495
2482
|
|
|
2496
2483
|
// src/status.ts
|
|
2497
2484
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -2587,9 +2574,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
2587
2574
|
found.push(dir);
|
|
2588
2575
|
if (left === 0)
|
|
2589
2576
|
return;
|
|
2590
|
-
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(
|
|
2577
|
+
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)));
|
|
2591
2578
|
}
|
|
2592
|
-
await walk(
|
|
2579
|
+
await walk(resolve4(root), depth);
|
|
2593
2580
|
return found.sort();
|
|
2594
2581
|
}
|
|
2595
2582
|
async function toplevelOf(dir) {
|
|
@@ -2597,14 +2584,14 @@ async function toplevelOf(dir) {
|
|
|
2597
2584
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
2598
2585
|
}
|
|
2599
2586
|
async function reposOf(roots) {
|
|
2600
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2587
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process22.cwd()];
|
|
2601
2588
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
2602
2589
|
return [...new Set(found.flat())].sort();
|
|
2603
2590
|
}
|
|
2604
2591
|
async function repoState(dir) {
|
|
2605
2592
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
2606
2593
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
2607
|
-
return { path: relative(
|
|
2594
|
+
return { path: relative(process22.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
2608
2595
|
}
|
|
2609
2596
|
function trackingOf(status) {
|
|
2610
2597
|
if (status.upstream === null)
|
|
@@ -2652,7 +2639,7 @@ var OPTIONS = {
|
|
|
2652
2639
|
stat: { type: "boolean", description: "list the files with their added and removed lines, the paths given too, never a patch" },
|
|
2653
2640
|
json: jsonOption("[{title, files: [{path, added, removed}], patch?}] per section, added and removed being null for a binary file, patch there with paths or --patch, the files then those of the paths")
|
|
2654
2641
|
};
|
|
2655
|
-
var LITERAL = { ...
|
|
2642
|
+
var LITERAL = { ...process23.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
2656
2643
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
2657
2644
|
function parseNumstat(text) {
|
|
2658
2645
|
const fields = text.split("\x00");
|
|
@@ -2684,9 +2671,9 @@ ${ran.stderr.trim()}`, NOT_A_REPOSITORY.test(ran.stderr) ? 2 : 1);
|
|
|
2684
2671
|
return ran.stdout;
|
|
2685
2672
|
}
|
|
2686
2673
|
async function show(patch) {
|
|
2687
|
-
const viewer =
|
|
2674
|
+
const viewer = process23.stdout.isTTY ? Bun.which("view") : null;
|
|
2688
2675
|
if (viewer === null) {
|
|
2689
|
-
|
|
2676
|
+
process23.stdout.write(patch);
|
|
2690
2677
|
return;
|
|
2691
2678
|
}
|
|
2692
2679
|
const child = Bun.spawn([viewer, "--diff"], { stdin: new TextEncoder().encode(patch), stdout: "inherit", stderr: "inherit" });
|
|
@@ -2725,18 +2712,18 @@ async function main(argv) {
|
|
|
2725
2712
|
return 0;
|
|
2726
2713
|
}
|
|
2727
2714
|
const found = await Promise.all(wanted.map(async (each) => ({ ...each, files: parseNumstat(await diff([...each.args, "--numstat", "-z"], positionals)) })));
|
|
2728
|
-
const { dim } = paint(
|
|
2729
|
-
const green = role("ok",
|
|
2730
|
-
const red = role("problem",
|
|
2715
|
+
const { dim } = paint(process23.stdout);
|
|
2716
|
+
const green = role("ok", process23.stdout);
|
|
2717
|
+
const red = role("problem", process23.stdout);
|
|
2731
2718
|
const shown = found.filter((each) => each.files.length > 0);
|
|
2732
2719
|
if (shown.length === 0) {
|
|
2733
2720
|
console.log(dim("no change in the tracked files"));
|
|
2734
2721
|
return 0;
|
|
2735
2722
|
}
|
|
2736
2723
|
console.log(shown.map((each) => `${each.title}
|
|
2737
|
-
${table(each.files.map((file) => [role("path",
|
|
2724
|
+
${table(each.files.map((file) => [role("path", process23.stdout)(file.path), file.added === null ? dim("binary") : green(`+${file.added}`), file.removed === null ? "" : red(`-${file.removed}`)]))}`).join(`
|
|
2738
2725
|
|
|
2739
2726
|
`));
|
|
2740
2727
|
return 0;
|
|
2741
2728
|
}
|
|
2742
|
-
|
|
2729
|
+
process23.exitCode = await runMain({ name: "gd", run: main });
|