@kaynooo/cli-git 0.18.2 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/gb.js +15 -31
- package/dist/gc.js +10 -26
- package/dist/gcl.js +36 -44
- package/dist/gd.js +18 -34
- package/dist/gf.js +16 -32
- package/dist/gm.js +26 -42
- package/dist/gp.js +16 -32
- package/dist/gst.js +24 -40
- package/dist/gu.js +10 -26
- package/package.json +4 -4
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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -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();
|
|
@@ -2045,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2045
2045
|
`);
|
|
2046
2046
|
chmodSync(script, 448);
|
|
2047
2047
|
return {
|
|
2048
|
-
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" },
|
|
2049
2049
|
close: () => {
|
|
2050
2050
|
server.stop(true);
|
|
2051
2051
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2468,25 +2468,9 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2468
2468
|
}
|
|
2469
2469
|
// ../kit/src/workspace-root.ts
|
|
2470
2470
|
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
2471
|
// src/branch.ts
|
|
2488
2472
|
import { basename } from "path";
|
|
2489
|
-
import
|
|
2473
|
+
import process24 from "process";
|
|
2490
2474
|
|
|
2491
2475
|
// ../kit/src/picker.ts
|
|
2492
2476
|
init_folders();
|
|
@@ -2498,11 +2482,11 @@ init_job();
|
|
|
2498
2482
|
init_redraw();
|
|
2499
2483
|
init_style();
|
|
2500
2484
|
import { openSync } from "fs";
|
|
2501
|
-
import
|
|
2485
|
+
import process23 from "process";
|
|
2502
2486
|
import tty from "tty";
|
|
2503
2487
|
|
|
2504
2488
|
// ../kit/src/picker/preview.ts
|
|
2505
|
-
import
|
|
2489
|
+
import process22 from "process";
|
|
2506
2490
|
|
|
2507
2491
|
// ../kit/src/shell.ts
|
|
2508
2492
|
var SEPARATORS = new Set([`
|
|
@@ -2589,7 +2573,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
2589
2573
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
2590
2574
|
const stop = () => {
|
|
2591
2575
|
try {
|
|
2592
|
-
|
|
2576
|
+
process22.kill(-proc.pid, "SIGKILL");
|
|
2593
2577
|
} catch {
|
|
2594
2578
|
proc.kill();
|
|
2595
2579
|
}
|
|
@@ -2752,7 +2736,7 @@ function openTerminal() {
|
|
|
2752
2736
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
2753
2737
|
}
|
|
2754
2738
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
2755
|
-
const out =
|
|
2739
|
+
const out = process23.stderr;
|
|
2756
2740
|
let resize;
|
|
2757
2741
|
async function read(onChunk) {
|
|
2758
2742
|
const decoder = new TextDecoder;
|
|
@@ -2941,9 +2925,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2941
2925
|
const ended = new Promise((resolve) => {
|
|
2942
2926
|
finish = resolve;
|
|
2943
2927
|
});
|
|
2944
|
-
|
|
2928
|
+
process23.once("exit", restore);
|
|
2945
2929
|
for (const signal of SIGNALS2)
|
|
2946
|
-
|
|
2930
|
+
process23.once(signal, stop);
|
|
2947
2931
|
try {
|
|
2948
2932
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2949
2933
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -2956,8 +2940,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2956
2940
|
await ended;
|
|
2957
2941
|
} finally {
|
|
2958
2942
|
for (const signal of SIGNALS2)
|
|
2959
|
-
|
|
2960
|
-
|
|
2943
|
+
process23.off(signal, stop);
|
|
2944
|
+
process23.off("exit", restore);
|
|
2961
2945
|
restore();
|
|
2962
2946
|
}
|
|
2963
2947
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -3230,7 +3214,7 @@ async function gb(args) {
|
|
|
3230
3214
|
if (parsed.values.json === true)
|
|
3231
3215
|
printJson(all);
|
|
3232
3216
|
else
|
|
3233
|
-
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(`
|
|
3234
3218
|
`));
|
|
3235
3219
|
return 0;
|
|
3236
3220
|
}
|
|
@@ -3287,4 +3271,4 @@ async function finish(command, typed, emitting) {
|
|
|
3287
3271
|
}
|
|
3288
3272
|
|
|
3289
3273
|
// src/gb.ts
|
|
3290
|
-
|
|
3274
|
+
process25.exitCode = await runMain({ name: "gb", run: gb });
|
package/dist/gc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -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();
|
|
@@ -2047,7 +2047,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2047
2047
|
`);
|
|
2048
2048
|
chmodSync(script, 448);
|
|
2049
2049
|
return {
|
|
2050
|
-
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" },
|
|
2051
2051
|
close: () => {
|
|
2052
2052
|
server.stop(true);
|
|
2053
2053
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2470,22 +2470,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2470
2470
|
}
|
|
2471
2471
|
// ../kit/src/workspace-root.ts
|
|
2472
2472
|
init_user_config();
|
|
2473
|
-
import { homedir as homedir5 } from "os";
|
|
2474
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2475
|
-
import process21 from "process";
|
|
2476
|
-
function expandHome(path, home) {
|
|
2477
|
-
if (path === "~")
|
|
2478
|
-
return home;
|
|
2479
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2480
|
-
}
|
|
2481
|
-
function configured(env, home) {
|
|
2482
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2483
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2484
|
-
}
|
|
2485
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2486
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2487
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2488
|
-
}
|
|
2489
2473
|
// src/git.ts
|
|
2490
2474
|
async function git2(args, env) {
|
|
2491
2475
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2560,7 +2544,7 @@ var RENAME = /^[RC]\d*$/;
|
|
|
2560
2544
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
2561
2545
|
var TRAILING_SLASHES = /\/+$/;
|
|
2562
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"]];
|
|
2563
|
-
var LITERAL = { ...
|
|
2547
|
+
var LITERAL = { ...process22.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
2564
2548
|
function messageOf(title, lines, tickets) {
|
|
2565
2549
|
return [title, lines.join(`
|
|
2566
2550
|
`), tickets.join(`
|
|
@@ -2582,7 +2566,7 @@ async function stagedElsewhere(paths) {
|
|
|
2582
2566
|
}
|
|
2583
2567
|
function onDisk(path) {
|
|
2584
2568
|
try {
|
|
2585
|
-
return
|
|
2569
|
+
return join9(realpathSync3(dirname5(path)), basename(path));
|
|
2586
2570
|
} catch {
|
|
2587
2571
|
return path;
|
|
2588
2572
|
}
|
|
@@ -2590,7 +2574,7 @@ function onDisk(path) {
|
|
|
2590
2574
|
async function renameSources(paths) {
|
|
2591
2575
|
const [top = "", prefix = ""] = (await checked(["rev-parse", "--show-toplevel", "--show-prefix"])).split(`
|
|
2592
2576
|
`);
|
|
2593
|
-
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, "") || ".");
|
|
2594
2578
|
const covered = (name) => specs.some((spec) => spec === "." || name === spec || name.startsWith(`${spec}/`));
|
|
2595
2579
|
const fields = (await checked(["diff", "--cached", "-M", "--name-status", "--no-relative", "-z"])).split("\x00");
|
|
2596
2580
|
const sources = [];
|
|
@@ -2611,7 +2595,7 @@ async function inProgress() {
|
|
|
2611
2595
|
}
|
|
2612
2596
|
async function snapshotIndex() {
|
|
2613
2597
|
const index = (await checked(["rev-parse", "--path-format=absolute", "--git-path", "index"])).trim();
|
|
2614
|
-
const copy = `${index}.gc-${
|
|
2598
|
+
const copy = `${index}.gc-${process22.pid}`;
|
|
2615
2599
|
const existed = existsSync4(index);
|
|
2616
2600
|
if (existed)
|
|
2617
2601
|
copyFileSync(index, copy);
|
|
@@ -2701,4 +2685,4 @@ ${(commit.stderr + commit.stdout).trim()}`;
|
|
|
2701
2685
|
signals.release();
|
|
2702
2686
|
}
|
|
2703
2687
|
}
|
|
2704
|
-
|
|
2688
|
+
process22.exitCode = await runMain({ name: "gc", run: main });
|
package/dist/gcl.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -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();
|
|
@@ -2048,7 +2048,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2048
2048
|
`);
|
|
2049
2049
|
chmodSync(script, 448);
|
|
2050
2050
|
return {
|
|
2051
|
-
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" },
|
|
2052
2052
|
close: () => {
|
|
2053
2053
|
server.stop(true);
|
|
2054
2054
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2471,22 +2471,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2471
2471
|
}
|
|
2472
2472
|
// ../kit/src/workspace-root.ts
|
|
2473
2473
|
init_user_config();
|
|
2474
|
-
import { homedir as homedir5 } from "os";
|
|
2475
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2476
|
-
import process21 from "process";
|
|
2477
|
-
function expandHome(path, home) {
|
|
2478
|
-
if (path === "~")
|
|
2479
|
-
return home;
|
|
2480
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2481
|
-
}
|
|
2482
|
-
function configured(env, home) {
|
|
2483
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2484
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2485
|
-
}
|
|
2486
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2487
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2488
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2489
|
-
}
|
|
2490
2474
|
// src/git.ts
|
|
2491
2475
|
async function git2(args, env) {
|
|
2492
2476
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2496,8 +2480,8 @@ async function git2(args, env) {
|
|
|
2496
2480
|
|
|
2497
2481
|
// src/repos.ts
|
|
2498
2482
|
import { readdir } from "fs/promises";
|
|
2499
|
-
import { join as
|
|
2500
|
-
import
|
|
2483
|
+
import { join as join9, relative, resolve as resolve4 } from "path";
|
|
2484
|
+
import process22 from "process";
|
|
2501
2485
|
|
|
2502
2486
|
// src/status.ts
|
|
2503
2487
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -2593,9 +2577,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
2593
2577
|
found.push(dir);
|
|
2594
2578
|
if (left === 0)
|
|
2595
2579
|
return;
|
|
2596
|
-
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)));
|
|
2597
2581
|
}
|
|
2598
|
-
await walk(
|
|
2582
|
+
await walk(resolve4(root), depth);
|
|
2599
2583
|
return found.sort();
|
|
2600
2584
|
}
|
|
2601
2585
|
async function toplevelOf(dir) {
|
|
@@ -2603,14 +2587,14 @@ async function toplevelOf(dir) {
|
|
|
2603
2587
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
2604
2588
|
}
|
|
2605
2589
|
async function reposOf(roots) {
|
|
2606
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2590
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process22.cwd()];
|
|
2607
2591
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
2608
2592
|
return [...new Set(found.flat())].sort();
|
|
2609
2593
|
}
|
|
2610
2594
|
async function repoState(dir) {
|
|
2611
2595
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
2612
2596
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
2613
|
-
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 } };
|
|
2614
2598
|
}
|
|
2615
2599
|
function trackingOf(status) {
|
|
2616
2600
|
if (status.upstream === null)
|
|
@@ -2702,10 +2686,10 @@ async function sync(repo, { pull, env }) {
|
|
|
2702
2686
|
|
|
2703
2687
|
// src/gcl.ts
|
|
2704
2688
|
var DEFAULT_FORGE = "git.kaynooo.fr";
|
|
2705
|
-
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
|
|
2706
2690
|
|
|
2707
|
-
<repo> is a URL, an scp-style address
|
|
2708
|
-
|
|
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.
|
|
2709
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.`;
|
|
2710
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"]];
|
|
2711
2695
|
var OPTIONS = {
|
|
@@ -2713,6 +2697,7 @@ var OPTIONS = {
|
|
|
2713
2697
|
};
|
|
2714
2698
|
var SCHEME = /^[a-z][a-z\d+.-]*:\/\//i;
|
|
2715
2699
|
var SCP = /^[\w.-]+@[\w.-]+:/;
|
|
2700
|
+
var SCP_WITH_PORT = /^([\w.-]+@[\w.-]+):(\d+):\/?(.+)$/;
|
|
2716
2701
|
var OWNER_NAME = /^[\w.-]+\/[\w.-]+$/;
|
|
2717
2702
|
var GIT_SUFFIX = /\.git\/?$/;
|
|
2718
2703
|
var TRAILING_SLASH = /\/+$/;
|
|
@@ -2721,7 +2706,10 @@ var AUTH_REFUSED = /could not read Username|Authentication failed|terminal promp
|
|
|
2721
2706
|
var SSH_BASE_END = /[/:]$/;
|
|
2722
2707
|
function urlOf(repo, forge) {
|
|
2723
2708
|
if (repo.startsWith("~/"))
|
|
2724
|
-
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]}`;
|
|
2725
2713
|
if (SCHEME.test(repo) || SCP.test(repo) || repo.startsWith("/") || repo.startsWith("."))
|
|
2726
2714
|
return repo;
|
|
2727
2715
|
if (OWNER_NAME.test(repo))
|
|
@@ -2754,25 +2742,29 @@ async function update({ url, sshUrl, path }, env) {
|
|
|
2754
2742
|
return origin;
|
|
2755
2743
|
}
|
|
2756
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
|
+
}
|
|
2757
2756
|
const cloned = await git2(["clone", url, path], env);
|
|
2758
2757
|
if (cloned.code === 0)
|
|
2759
2758
|
return url;
|
|
2760
2759
|
if (sshUrl === undefined || !AUTH_REFUSED.test(cloned.stderr))
|
|
2761
2760
|
fail(`git clone failed:
|
|
2762
2761
|
${cloned.stderr.trim()}`, 1);
|
|
2763
|
-
|
|
2764
|
-
fail(`git clone failed:
|
|
2762
|
+
return fail(`git clone failed:
|
|
2765
2763
|
${cloned.stderr.trim()}
|
|
2766
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);
|
|
2767
|
-
console.error(`${url} wants a login, ${repo} may be private: cloning over ssh from ${sshUrl}`);
|
|
2768
|
-
const overSsh = await git2(["clone", sshUrl, path], env);
|
|
2769
|
-
if (overSsh.code !== 0)
|
|
2770
|
-
fail(`git clone failed over https and over ssh:
|
|
2771
|
-
${overSsh.stderr.trim()}`, 1);
|
|
2772
|
-
return sshUrl;
|
|
2773
2765
|
}
|
|
2774
2766
|
async function main(argv) {
|
|
2775
|
-
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"]] });
|
|
2776
2768
|
const [repo, given] = positionals;
|
|
2777
2769
|
if (repo === undefined)
|
|
2778
2770
|
fail("gcl needs the repository to clone: gcl owner/name", 2);
|
|
@@ -2785,11 +2777,11 @@ async function main(argv) {
|
|
|
2785
2777
|
const name = nameOf(url);
|
|
2786
2778
|
if (name === "")
|
|
2787
2779
|
fail(`no folder name can be taken from ${url}, give one: gcl ${repo} <dir>`, 2);
|
|
2788
|
-
const target = { repo, url, sshUrl, forgeSsh, path: given
|
|
2780
|
+
const target = { repo, url, sshUrl, forgeSsh, path: resolve5(given ?? name) };
|
|
2789
2781
|
const { path } = target;
|
|
2790
2782
|
const outcome = existsSync4(path) && (!statSync2(path).isDirectory() || readdirSync(path).length > 0) ? "existing" : "cloned";
|
|
2791
2783
|
const prompts = askpass();
|
|
2792
|
-
const env = { ...
|
|
2784
|
+
const env = { ...process23.env, ...prompts.env };
|
|
2793
2785
|
let from;
|
|
2794
2786
|
try {
|
|
2795
2787
|
from = outcome === "existing" ? await update(target, env) : await clone(target, env);
|
|
@@ -2807,7 +2799,7 @@ async function main(argv) {
|
|
|
2807
2799
|
return 0;
|
|
2808
2800
|
}
|
|
2809
2801
|
if (import.meta.main)
|
|
2810
|
-
|
|
2802
|
+
process23.exitCode = await runMain({ name: "gcl", run: main });
|
|
2811
2803
|
export {
|
|
2812
2804
|
nameOf,
|
|
2813
2805
|
sshUrlOf,
|
package/dist/gd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -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();
|
|
@@ -2045,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2045
2045
|
`);
|
|
2046
2046
|
chmodSync(script, 448);
|
|
2047
2047
|
return {
|
|
2048
|
-
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" },
|
|
2049
2049
|
close: () => {
|
|
2050
2050
|
server.stop(true);
|
|
2051
2051
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2468,22 +2468,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2468
2468
|
}
|
|
2469
2469
|
// ../kit/src/workspace-root.ts
|
|
2470
2470
|
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
2471
|
// src/git.ts
|
|
2488
2472
|
async function git2(args, env) {
|
|
2489
2473
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2493,8 +2477,8 @@ async function git2(args, env) {
|
|
|
2493
2477
|
|
|
2494
2478
|
// src/repos.ts
|
|
2495
2479
|
import { readdir } from "fs/promises";
|
|
2496
|
-
import { join as
|
|
2497
|
-
import
|
|
2480
|
+
import { join as join9, relative, resolve as resolve4 } from "path";
|
|
2481
|
+
import process22 from "process";
|
|
2498
2482
|
|
|
2499
2483
|
// src/status.ts
|
|
2500
2484
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -2590,9 +2574,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
2590
2574
|
found.push(dir);
|
|
2591
2575
|
if (left === 0)
|
|
2592
2576
|
return;
|
|
2593
|
-
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)));
|
|
2594
2578
|
}
|
|
2595
|
-
await walk(
|
|
2579
|
+
await walk(resolve4(root), depth);
|
|
2596
2580
|
return found.sort();
|
|
2597
2581
|
}
|
|
2598
2582
|
async function toplevelOf(dir) {
|
|
@@ -2600,14 +2584,14 @@ async function toplevelOf(dir) {
|
|
|
2600
2584
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
2601
2585
|
}
|
|
2602
2586
|
async function reposOf(roots) {
|
|
2603
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2587
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process22.cwd()];
|
|
2604
2588
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
2605
2589
|
return [...new Set(found.flat())].sort();
|
|
2606
2590
|
}
|
|
2607
2591
|
async function repoState(dir) {
|
|
2608
2592
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
2609
2593
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
2610
|
-
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 } };
|
|
2611
2595
|
}
|
|
2612
2596
|
function trackingOf(status) {
|
|
2613
2597
|
if (status.upstream === null)
|
|
@@ -2655,7 +2639,7 @@ var OPTIONS = {
|
|
|
2655
2639
|
stat: { type: "boolean", description: "list the files with their added and removed lines, the paths given too, never a patch" },
|
|
2656
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")
|
|
2657
2641
|
};
|
|
2658
|
-
var LITERAL = { ...
|
|
2642
|
+
var LITERAL = { ...process23.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
2659
2643
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
2660
2644
|
function parseNumstat(text) {
|
|
2661
2645
|
const fields = text.split("\x00");
|
|
@@ -2687,9 +2671,9 @@ ${ran.stderr.trim()}`, NOT_A_REPOSITORY.test(ran.stderr) ? 2 : 1);
|
|
|
2687
2671
|
return ran.stdout;
|
|
2688
2672
|
}
|
|
2689
2673
|
async function show(patch) {
|
|
2690
|
-
const viewer =
|
|
2674
|
+
const viewer = process23.stdout.isTTY ? Bun.which("view") : null;
|
|
2691
2675
|
if (viewer === null) {
|
|
2692
|
-
|
|
2676
|
+
process23.stdout.write(patch);
|
|
2693
2677
|
return;
|
|
2694
2678
|
}
|
|
2695
2679
|
const child = Bun.spawn([viewer, "--diff"], { stdin: new TextEncoder().encode(patch), stdout: "inherit", stderr: "inherit" });
|
|
@@ -2728,18 +2712,18 @@ async function main(argv) {
|
|
|
2728
2712
|
return 0;
|
|
2729
2713
|
}
|
|
2730
2714
|
const found = await Promise.all(wanted.map(async (each) => ({ ...each, files: parseNumstat(await diff([...each.args, "--numstat", "-z"], positionals)) })));
|
|
2731
|
-
const { dim } = paint(
|
|
2732
|
-
const green = role("ok",
|
|
2733
|
-
const red = role("problem",
|
|
2715
|
+
const { dim } = paint(process23.stdout);
|
|
2716
|
+
const green = role("ok", process23.stdout);
|
|
2717
|
+
const red = role("problem", process23.stdout);
|
|
2734
2718
|
const shown = found.filter((each) => each.files.length > 0);
|
|
2735
2719
|
if (shown.length === 0) {
|
|
2736
2720
|
console.log(dim("no change in the tracked files"));
|
|
2737
2721
|
return 0;
|
|
2738
2722
|
}
|
|
2739
2723
|
console.log(shown.map((each) => `${each.title}
|
|
2740
|
-
${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(`
|
|
2741
2725
|
|
|
2742
2726
|
`));
|
|
2743
2727
|
return 0;
|
|
2744
2728
|
}
|
|
2745
|
-
|
|
2729
|
+
process23.exitCode = await runMain({ name: "gd", run: main });
|
package/dist/gf.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -1552,7 +1552,7 @@ var init_prompt = __esm(() => {
|
|
|
1552
1552
|
});
|
|
1553
1553
|
|
|
1554
1554
|
// src/gf.ts
|
|
1555
|
-
import
|
|
1555
|
+
import process23 from "process";
|
|
1556
1556
|
|
|
1557
1557
|
// ../kit/src/index.ts
|
|
1558
1558
|
init_args();
|
|
@@ -2045,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2045
2045
|
`);
|
|
2046
2046
|
chmodSync(script, 448);
|
|
2047
2047
|
return {
|
|
2048
|
-
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" },
|
|
2049
2049
|
close: () => {
|
|
2050
2050
|
server.stop(true);
|
|
2051
2051
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2468,26 +2468,10 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2468
2468
|
}
|
|
2469
2469
|
// ../kit/src/workspace-root.ts
|
|
2470
2470
|
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
2471
|
// src/repos.ts
|
|
2488
2472
|
import { readdir } from "fs/promises";
|
|
2489
|
-
import { join as
|
|
2490
|
-
import
|
|
2473
|
+
import { join as join9, relative, resolve as resolve4 } from "path";
|
|
2474
|
+
import process22 from "process";
|
|
2491
2475
|
|
|
2492
2476
|
// src/git.ts
|
|
2493
2477
|
async function git2(args, env) {
|
|
@@ -2590,9 +2574,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
2590
2574
|
found.push(dir);
|
|
2591
2575
|
if (left === 0)
|
|
2592
2576
|
return;
|
|
2593
|
-
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)));
|
|
2594
2578
|
}
|
|
2595
|
-
await walk(
|
|
2579
|
+
await walk(resolve4(root), depth);
|
|
2596
2580
|
return found.sort();
|
|
2597
2581
|
}
|
|
2598
2582
|
async function toplevelOf(dir) {
|
|
@@ -2600,14 +2584,14 @@ async function toplevelOf(dir) {
|
|
|
2600
2584
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
2601
2585
|
}
|
|
2602
2586
|
async function reposOf(roots) {
|
|
2603
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2587
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process22.cwd()];
|
|
2604
2588
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
2605
2589
|
return [...new Set(found.flat())].sort();
|
|
2606
2590
|
}
|
|
2607
2591
|
async function repoState(dir) {
|
|
2608
2592
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
2609
2593
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
2610
|
-
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 } };
|
|
2611
2595
|
}
|
|
2612
2596
|
function trackingOf(status) {
|
|
2613
2597
|
if (status.upstream === null)
|
|
@@ -2709,16 +2693,16 @@ var OPTIONS = {
|
|
|
2709
2693
|
json: jsonOption("one {path, branch, upstream, commits, outcome, reason?} per repository, outcome being updated, current, fetched, skipped or refused")
|
|
2710
2694
|
};
|
|
2711
2695
|
function line(result) {
|
|
2712
|
-
const { dim } = paint(
|
|
2696
|
+
const { dim } = paint(process23.stdout);
|
|
2713
2697
|
const count = `${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
|
|
2714
2698
|
const said = {
|
|
2715
|
-
updated: () => marked("ok", `${result.branch} <- ${result.upstream}, ${count}`,
|
|
2699
|
+
updated: () => marked("ok", `${result.branch} <- ${result.upstream}, ${count}`, process23.stdout),
|
|
2716
2700
|
current: () => dim(`${result.branch} up to date`),
|
|
2717
2701
|
fetched: () => `${result.branch} is ${result.commits} behind ${result.upstream}`,
|
|
2718
2702
|
skipped: () => dim(`${result.branch ?? ""} ${result.reason ?? "skipped"}`.trim()),
|
|
2719
|
-
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`,
|
|
2703
|
+
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process23.stdout)
|
|
2720
2704
|
}[result.outcome];
|
|
2721
|
-
return [role("path",
|
|
2705
|
+
return [role("path", process23.stdout)(result.path), said()];
|
|
2722
2706
|
}
|
|
2723
2707
|
async function main(argv) {
|
|
2724
2708
|
const { values, positionals } = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], exits: EXITS, replaces: "git fetch --prune, git pull --ff-only and a git -C <repo> pull per nested repository", examples: ["gf", ["gf --repos", "every repository nested in this one"], ["gf --no-pull", "fetch and say how far behind the branch is"]] });
|
|
@@ -2726,7 +2710,7 @@ async function main(argv) {
|
|
|
2726
2710
|
const results = [];
|
|
2727
2711
|
const progress = progressLine();
|
|
2728
2712
|
const prompts = askpass(progress.pause);
|
|
2729
|
-
const env = { ...
|
|
2713
|
+
const env = { ...process23.env, ...prompts.env };
|
|
2730
2714
|
try {
|
|
2731
2715
|
for (const [at, repo] of repos.entries()) {
|
|
2732
2716
|
progress.update(repos.length > 1 ? { step: `fetching ${repo.path}`, done: at, total: repos.length, unit: "repositories" } : { step: `fetching ${repo.path}` });
|
|
@@ -2742,4 +2726,4 @@ async function main(argv) {
|
|
|
2742
2726
|
console.log(table(results.map(line)));
|
|
2743
2727
|
return results.some((result) => result.outcome === "refused") ? 1 : 0;
|
|
2744
2728
|
}
|
|
2745
|
-
|
|
2729
|
+
process23.exitCode = await runMain({ name: "gf", run: main });
|
package/dist/gm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -1553,8 +1553,8 @@ var init_prompt = __esm(() => {
|
|
|
1553
1553
|
|
|
1554
1554
|
// src/gm.ts
|
|
1555
1555
|
import { readFileSync as readFileSync7 } from "fs";
|
|
1556
|
-
import { join as
|
|
1557
|
-
import
|
|
1556
|
+
import { join as join9, relative } from "path";
|
|
1557
|
+
import process25 from "process";
|
|
1558
1558
|
|
|
1559
1559
|
// ../kit/src/index.ts
|
|
1560
1560
|
init_args();
|
|
@@ -2047,7 +2047,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2047
2047
|
`);
|
|
2048
2048
|
chmodSync(script, 448);
|
|
2049
2049
|
return {
|
|
2050
|
-
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" },
|
|
2051
2051
|
close: () => {
|
|
2052
2052
|
server.stop(true);
|
|
2053
2053
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2470,22 +2470,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2470
2470
|
}
|
|
2471
2471
|
// ../kit/src/workspace-root.ts
|
|
2472
2472
|
init_user_config();
|
|
2473
|
-
import { homedir as homedir5 } from "os";
|
|
2474
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2475
|
-
import process21 from "process";
|
|
2476
|
-
function expandHome(path, home) {
|
|
2477
|
-
if (path === "~")
|
|
2478
|
-
return home;
|
|
2479
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2480
|
-
}
|
|
2481
|
-
function configured(env, home) {
|
|
2482
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2483
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2484
|
-
}
|
|
2485
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2486
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2487
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2488
|
-
}
|
|
2489
2473
|
// ../kit/src/picker.ts
|
|
2490
2474
|
init_folders();
|
|
2491
2475
|
init_state();
|
|
@@ -2496,11 +2480,11 @@ init_job();
|
|
|
2496
2480
|
init_redraw();
|
|
2497
2481
|
init_style();
|
|
2498
2482
|
import { openSync } from "fs";
|
|
2499
|
-
import
|
|
2483
|
+
import process23 from "process";
|
|
2500
2484
|
import tty from "tty";
|
|
2501
2485
|
|
|
2502
2486
|
// ../kit/src/picker/preview.ts
|
|
2503
|
-
import
|
|
2487
|
+
import process22 from "process";
|
|
2504
2488
|
|
|
2505
2489
|
// ../kit/src/shell.ts
|
|
2506
2490
|
var SEPARATORS = new Set([`
|
|
@@ -2587,7 +2571,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
2587
2571
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
2588
2572
|
const stop = () => {
|
|
2589
2573
|
try {
|
|
2590
|
-
|
|
2574
|
+
process22.kill(-proc.pid, "SIGKILL");
|
|
2591
2575
|
} catch {
|
|
2592
2576
|
proc.kill();
|
|
2593
2577
|
}
|
|
@@ -2750,7 +2734,7 @@ function openTerminal() {
|
|
|
2750
2734
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
2751
2735
|
}
|
|
2752
2736
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
2753
|
-
const out =
|
|
2737
|
+
const out = process23.stderr;
|
|
2754
2738
|
let resize;
|
|
2755
2739
|
async function read(onChunk) {
|
|
2756
2740
|
const decoder = new TextDecoder;
|
|
@@ -2939,9 +2923,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2939
2923
|
const ended = new Promise((resolve) => {
|
|
2940
2924
|
finish = resolve;
|
|
2941
2925
|
});
|
|
2942
|
-
|
|
2926
|
+
process23.once("exit", restore);
|
|
2943
2927
|
for (const signal of SIGNALS2)
|
|
2944
|
-
|
|
2928
|
+
process23.once(signal, stop);
|
|
2945
2929
|
try {
|
|
2946
2930
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2947
2931
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -2954,8 +2938,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2954
2938
|
await ended;
|
|
2955
2939
|
} finally {
|
|
2956
2940
|
for (const signal of SIGNALS2)
|
|
2957
|
-
|
|
2958
|
-
|
|
2941
|
+
process23.off(signal, stop);
|
|
2942
|
+
process23.off("exit", restore);
|
|
2959
2943
|
restore();
|
|
2960
2944
|
}
|
|
2961
2945
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -3005,7 +2989,7 @@ function list(rows) {
|
|
|
3005
2989
|
|
|
3006
2990
|
// src/branch.ts
|
|
3007
2991
|
import { basename } from "path";
|
|
3008
|
-
import
|
|
2992
|
+
import process24 from "process";
|
|
3009
2993
|
var usage2 = `gb [branch]: picks a git branch and switches to it
|
|
3010
2994
|
gb -
|
|
3011
2995
|
gb -c <name>
|
|
@@ -3230,7 +3214,7 @@ async function gb(args) {
|
|
|
3230
3214
|
if (parsed.values.json === true)
|
|
3231
3215
|
printJson(all);
|
|
3232
3216
|
else
|
|
3233
|
-
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(`
|
|
3234
3218
|
`));
|
|
3235
3219
|
return 0;
|
|
3236
3220
|
}
|
|
@@ -3334,7 +3318,7 @@ var OPTIONS = {
|
|
|
3334
3318
|
};
|
|
3335
3319
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
3336
3320
|
var RENAME = /^[RC]\d*$/;
|
|
3337
|
-
var EDITOR_OFF = { ...
|
|
3321
|
+
var EDITOR_OFF = { ...process25.env, GIT_EDITOR: "true", GIT_MERGE_AUTOEDIT: "no" };
|
|
3338
3322
|
var BINARY_PROBE = 8000;
|
|
3339
3323
|
var SYMLINK_MODE = "120000";
|
|
3340
3324
|
async function ran(args, env) {
|
|
@@ -3375,7 +3359,7 @@ async function isMarkable(path, bytes, stages) {
|
|
|
3375
3359
|
async function conflicted() {
|
|
3376
3360
|
const top = (await ran(["rev-parse", "--show-toplevel"])).trim();
|
|
3377
3361
|
return Promise.all([...await unmergedStages()].map(async ([fromTop, stages]) => {
|
|
3378
|
-
const path = relative(
|
|
3362
|
+
const path = relative(process25.cwd(), join9(top, fromTop));
|
|
3379
3363
|
let bytes;
|
|
3380
3364
|
try {
|
|
3381
3365
|
bytes = readFileSync7(path);
|
|
@@ -3387,7 +3371,7 @@ async function conflicted() {
|
|
|
3387
3371
|
}));
|
|
3388
3372
|
}
|
|
3389
3373
|
function conflictLines(conflicts) {
|
|
3390
|
-
return conflicts.flatMap(({ path, hunks }) => hunks.length === 0 ? [`${role("path",
|
|
3374
|
+
return conflicts.flatMap(({ path, hunks }) => hunks.length === 0 ? [`${role("path", process25.stdout)(path)}: conflicted, no markers to show (deleted on a side, binary or a mode change)`] : hunks.flatMap((hunk) => [role("path", process25.stdout)(`${path}:${hunk.from}-${hunk.to}`), ...hunk.lines.map(({ line, text }) => `${line} ${text}`), ""]));
|
|
3391
3375
|
}
|
|
3392
3376
|
function fileLine(line) {
|
|
3393
3377
|
const [letter = "", from = "", to] = line.split("\t");
|
|
@@ -3405,7 +3389,7 @@ function conflictReport(branch, into, conflicts, json, squash = false) {
|
|
|
3405
3389
|
printJson({ outcome: "conflict", branch, into, conflicts: conflicts.map(({ path, hunks }) => ({ path, hunks })) });
|
|
3406
3390
|
return 1;
|
|
3407
3391
|
}
|
|
3408
|
-
console.log([marked("problem", `merging ${branch} into ${into} left ${conflicts.length} conflicted ${conflicts.length === 1 ? "file" : "files"}`,
|
|
3392
|
+
console.log([marked("problem", `merging ${branch} into ${into} left ${conflicts.length} conflicted ${conflicts.length === 1 ? "file" : "files"}`, process25.stdout), ...conflictLines(conflicts)].join(`
|
|
3409
3393
|
`).trimEnd());
|
|
3410
3394
|
console.log(squash ? `
|
|
3411
3395
|
resolve the files and commit them with gc, or git reset --merge to give up` : `
|
|
@@ -3426,7 +3410,7 @@ async function mergedReport(before, branch, into, json) {
|
|
|
3426
3410
|
const how = outcome === "merge" ? `merge commit ${sha.slice(0, 7)}` : "fast-forward";
|
|
3427
3411
|
const list = changed.split(`
|
|
3428
3412
|
`).filter(Boolean);
|
|
3429
|
-
console.log([marked("ok", `${into} <- ${branch}, ${how}, ${count}, ${list.length} ${list.length === 1 ? "file" : "files"} changed`,
|
|
3413
|
+
console.log([marked("ok", `${into} <- ${branch}, ${how}, ${count}, ${list.length} ${list.length === 1 ? "file" : "files"} changed`, process25.stdout), ...list.map(fileLine)].join(`
|
|
3430
3414
|
`));
|
|
3431
3415
|
return 0;
|
|
3432
3416
|
}
|
|
@@ -3441,7 +3425,7 @@ ${(stderr || stdout).trim()}`);
|
|
|
3441
3425
|
`);
|
|
3442
3426
|
return { outcome: code === 0 ? "clean" : "conflict", conflicts: [...new Set(rest.slice(0, Math.max(0, rest.indexOf(""))))] };
|
|
3443
3427
|
}
|
|
3444
|
-
function verdictText(verdict, tint = paint(
|
|
3428
|
+
function verdictText(verdict, tint = paint(process25.stdout)) {
|
|
3445
3429
|
if (verdict.outcome === "up-to-date")
|
|
3446
3430
|
return tint.dim("merged already");
|
|
3447
3431
|
return verdict.outcome === "clean" ? tint.green("clean") : tint.red(`conflicts: ${verdict.conflicts.join(", ")}`);
|
|
@@ -3455,7 +3439,7 @@ async function squashedReport(before, branch, into, json) {
|
|
|
3455
3439
|
}
|
|
3456
3440
|
const list = changed.split(`
|
|
3457
3441
|
`).filter(Boolean);
|
|
3458
|
-
console.log([marked("ok", `${branch} squashed into the index of ${into}: ${commits} ${commits === 1 ? "commit" : "commits"}, ${list.length} ${list.length === 1 ? "file" : "files"}, commit them with gc`,
|
|
3442
|
+
console.log([marked("ok", `${branch} squashed into the index of ${into}: ${commits} ${commits === 1 ? "commit" : "commits"}, ${list.length} ${list.length === 1 ? "file" : "files"}, commit them with gc`, process25.stdout), ...list.map(fileLine)].join(`
|
|
3459
3443
|
`));
|
|
3460
3444
|
return 0;
|
|
3461
3445
|
}
|
|
@@ -3469,9 +3453,9 @@ async function dryRun(branch, into, json) {
|
|
|
3469
3453
|
if (verdict.outcome === "up-to-date")
|
|
3470
3454
|
console.log(`${branch} is already merged into ${into}`);
|
|
3471
3455
|
else if (verdict.outcome === "clean")
|
|
3472
|
-
console.log(marked("ok", `merging ${branch} into ${into} would not conflict`,
|
|
3456
|
+
console.log(marked("ok", `merging ${branch} into ${into} would not conflict`, process25.stdout));
|
|
3473
3457
|
else
|
|
3474
|
-
console.log([marked("problem", `merging ${branch} into ${into} would conflict in ${verdict.conflicts.length} ${verdict.conflicts.length === 1 ? "file" : "files"}`,
|
|
3458
|
+
console.log([marked("problem", `merging ${branch} into ${into} would conflict in ${verdict.conflicts.length} ${verdict.conflicts.length === 1 ? "file" : "files"}`, process25.stdout), ...verdict.conflicts.map((path) => ` ${path}`)].join(`
|
|
3475
3459
|
`));
|
|
3476
3460
|
return code;
|
|
3477
3461
|
}
|
|
@@ -3546,7 +3530,7 @@ async function main(argv) {
|
|
|
3546
3530
|
if (json)
|
|
3547
3531
|
printJson({ outcome: "refused", into, conflicts: [...left, ...unpicked].map(({ path, hunks }) => ({ path, hunks })) });
|
|
3548
3532
|
else
|
|
3549
|
-
console.log([...problems.map((problem) => marked("problem", problem,
|
|
3533
|
+
console.log([...problems.map((problem) => marked("problem", problem, process25.stdout)), ...conflictLines([...left, ...unpicked])].join(`
|
|
3550
3534
|
`).trimEnd());
|
|
3551
3535
|
return 1;
|
|
3552
3536
|
}
|
|
@@ -3602,4 +3586,4 @@ ${USAGE}`);
|
|
|
3602
3586
|
return fail(`git merge failed:
|
|
3603
3587
|
${(merged.stderr || merged.stdout).trim()}`, NOT_A_REPOSITORY.test(merged.stderr) ? 2 : 1);
|
|
3604
3588
|
}
|
|
3605
|
-
|
|
3589
|
+
process25.exitCode = await runMain({ name: "gm", run: main });
|
package/dist/gp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -1552,7 +1552,7 @@ var init_prompt = __esm(() => {
|
|
|
1552
1552
|
});
|
|
1553
1553
|
|
|
1554
1554
|
// src/gp.ts
|
|
1555
|
-
import
|
|
1555
|
+
import process23 from "process";
|
|
1556
1556
|
|
|
1557
1557
|
// ../kit/src/index.ts
|
|
1558
1558
|
init_args();
|
|
@@ -2045,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2045
2045
|
`);
|
|
2046
2046
|
chmodSync(script, 448);
|
|
2047
2047
|
return {
|
|
2048
|
-
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" },
|
|
2049
2049
|
close: () => {
|
|
2050
2050
|
server.stop(true);
|
|
2051
2051
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2468,22 +2468,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2468
2468
|
}
|
|
2469
2469
|
// ../kit/src/workspace-root.ts
|
|
2470
2470
|
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
2471
|
// src/git.ts
|
|
2488
2472
|
async function git2(args, env) {
|
|
2489
2473
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2493,8 +2477,8 @@ async function git2(args, env) {
|
|
|
2493
2477
|
|
|
2494
2478
|
// src/repos.ts
|
|
2495
2479
|
import { readdir } from "fs/promises";
|
|
2496
|
-
import { join as
|
|
2497
|
-
import
|
|
2480
|
+
import { join as join9, relative, resolve as resolve4 } from "path";
|
|
2481
|
+
import process22 from "process";
|
|
2498
2482
|
|
|
2499
2483
|
// src/status.ts
|
|
2500
2484
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -2590,9 +2574,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
2590
2574
|
found.push(dir);
|
|
2591
2575
|
if (left === 0)
|
|
2592
2576
|
return;
|
|
2593
|
-
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)));
|
|
2594
2578
|
}
|
|
2595
|
-
await walk(
|
|
2579
|
+
await walk(resolve4(root), depth);
|
|
2596
2580
|
return found.sort();
|
|
2597
2581
|
}
|
|
2598
2582
|
async function toplevelOf(dir) {
|
|
@@ -2600,14 +2584,14 @@ async function toplevelOf(dir) {
|
|
|
2600
2584
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
2601
2585
|
}
|
|
2602
2586
|
async function reposOf(roots) {
|
|
2603
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2587
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process22.cwd()];
|
|
2604
2588
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
2605
2589
|
return [...new Set(found.flat())].sort();
|
|
2606
2590
|
}
|
|
2607
2591
|
async function repoState(dir) {
|
|
2608
2592
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
2609
2593
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
2610
|
-
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 } };
|
|
2611
2595
|
}
|
|
2612
2596
|
function trackingOf(status) {
|
|
2613
2597
|
if (status.upstream === null)
|
|
@@ -2724,16 +2708,16 @@ async function push(repo, asked, { dryRun, extra, env }) {
|
|
|
2724
2708
|
return pushed.code === 0 ? { path, branch, remote, commits, outcome: "pushed" } : { path, branch, remote, commits, outcome: "refused", reason: whyRefused(pushed.stderr) };
|
|
2725
2709
|
}
|
|
2726
2710
|
function line(result) {
|
|
2727
|
-
const { dim } = paint(
|
|
2711
|
+
const { dim } = paint(process23.stdout);
|
|
2728
2712
|
const sent = result.commits === null ? "" : `, ${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
|
|
2729
2713
|
const what = `${result.branch} -> ${result.remote}${sent}`;
|
|
2730
2714
|
const said = {
|
|
2731
|
-
pushed: () => marked("ok", `pushed ${what}`,
|
|
2715
|
+
pushed: () => marked("ok", `pushed ${what}`, process23.stdout),
|
|
2732
2716
|
"would-push": () => `would push ${what}`,
|
|
2733
2717
|
skipped: () => dim(result.reason ?? "skipped"),
|
|
2734
|
-
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`,
|
|
2718
|
+
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process23.stdout)
|
|
2735
2719
|
}[result.outcome];
|
|
2736
|
-
return [role("path",
|
|
2720
|
+
return [role("path", process23.stdout)(result.path), said()];
|
|
2737
2721
|
}
|
|
2738
2722
|
async function main(argv) {
|
|
2739
2723
|
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 -b feature", "a branch other than the current one"], ["gp -- --force-with-lease", "flags for git push"]] });
|
|
@@ -2744,7 +2728,7 @@ async function main(argv) {
|
|
|
2744
2728
|
const results = [];
|
|
2745
2729
|
const progress = progressLine();
|
|
2746
2730
|
const prompts = askpass(progress.pause);
|
|
2747
|
-
const env = { ...
|
|
2731
|
+
const env = { ...process23.env, ...prompts.env };
|
|
2748
2732
|
try {
|
|
2749
2733
|
for (const [at, { repo, branch }] of pushes.entries()) {
|
|
2750
2734
|
progress.update(pushes.length > 1 ? { step: `pushing ${repo.path}`, done: at, total: pushes.length, unit: "pushes" } : { step: `pushing ${repo.path}` });
|
|
@@ -2760,4 +2744,4 @@ async function main(argv) {
|
|
|
2760
2744
|
console.log(table(results.map(line)));
|
|
2761
2745
|
return results.some((result) => result.outcome === "refused") ? 1 : 0;
|
|
2762
2746
|
}
|
|
2763
|
-
|
|
2747
|
+
process23.exitCode = await runMain({ name: "gp", run: main });
|
package/dist/gst.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -1552,7 +1552,7 @@ var init_prompt = __esm(() => {
|
|
|
1552
1552
|
});
|
|
1553
1553
|
|
|
1554
1554
|
// src/gst.ts
|
|
1555
|
-
import
|
|
1555
|
+
import process24 from "process";
|
|
1556
1556
|
|
|
1557
1557
|
// ../kit/src/index.ts
|
|
1558
1558
|
init_args();
|
|
@@ -2045,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2045
2045
|
`);
|
|
2046
2046
|
chmodSync(script, 448);
|
|
2047
2047
|
return {
|
|
2048
|
-
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" },
|
|
2049
2049
|
close: () => {
|
|
2050
2050
|
server.stop(true);
|
|
2051
2051
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2468,25 +2468,9 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2468
2468
|
}
|
|
2469
2469
|
// ../kit/src/workspace-root.ts
|
|
2470
2470
|
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
2471
|
// src/colour.ts
|
|
2488
|
-
import
|
|
2489
|
-
function letter(status, stream =
|
|
2472
|
+
import process22 from "process";
|
|
2473
|
+
function letter(status, stream = process22.stdout) {
|
|
2490
2474
|
const colors = paint(stream);
|
|
2491
2475
|
const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
|
|
2492
2476
|
return tint(status);
|
|
@@ -2501,7 +2485,7 @@ async function git2(args, env) {
|
|
|
2501
2485
|
|
|
2502
2486
|
// src/operation.ts
|
|
2503
2487
|
import { existsSync as existsSync4, readFileSync as readFileSync7 } from "fs";
|
|
2504
|
-
import { join as
|
|
2488
|
+
import { join as join9 } from "path";
|
|
2505
2489
|
function numberIn(path) {
|
|
2506
2490
|
try {
|
|
2507
2491
|
const value = Number.parseInt(readFileSync7(path, "utf8"), 10);
|
|
@@ -2511,11 +2495,11 @@ function numberIn(path) {
|
|
|
2511
2495
|
}
|
|
2512
2496
|
}
|
|
2513
2497
|
function operationOf(gitDir) {
|
|
2514
|
-
const has = (name) => existsSync4(
|
|
2498
|
+
const has = (name) => existsSync4(join9(gitDir, name));
|
|
2515
2499
|
if (has("rebase-merge"))
|
|
2516
|
-
return { kind: "rebase", step: numberIn(
|
|
2500
|
+
return { kind: "rebase", step: numberIn(join9(gitDir, "rebase-merge/msgnum")), total: numberIn(join9(gitDir, "rebase-merge/end")) };
|
|
2517
2501
|
if (has("rebase-apply"))
|
|
2518
|
-
return { kind: "rebase", step: numberIn(
|
|
2502
|
+
return { kind: "rebase", step: numberIn(join9(gitDir, "rebase-apply/next")), total: numberIn(join9(gitDir, "rebase-apply/last")) };
|
|
2519
2503
|
for (const [file, kind] of [["MERGE_HEAD", "merge"], ["CHERRY_PICK_HEAD", "cherry-pick"], ["REVERT_HEAD", "revert"], ["BISECT_LOG", "bisect"]]) {
|
|
2520
2504
|
if (has(file))
|
|
2521
2505
|
return { kind };
|
|
@@ -2525,8 +2509,8 @@ function operationOf(gitDir) {
|
|
|
2525
2509
|
|
|
2526
2510
|
// src/repos.ts
|
|
2527
2511
|
import { readdir } from "fs/promises";
|
|
2528
|
-
import { join as
|
|
2529
|
-
import
|
|
2512
|
+
import { join as join10, relative, resolve as resolve4 } from "path";
|
|
2513
|
+
import process23 from "process";
|
|
2530
2514
|
|
|
2531
2515
|
// src/status.ts
|
|
2532
2516
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -2622,9 +2606,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
2622
2606
|
found.push(dir);
|
|
2623
2607
|
if (left === 0)
|
|
2624
2608
|
return;
|
|
2625
|
-
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(
|
|
2609
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join10(dir, entry.name), left - 1)));
|
|
2626
2610
|
}
|
|
2627
|
-
await walk(
|
|
2611
|
+
await walk(resolve4(root), depth);
|
|
2628
2612
|
return found.sort();
|
|
2629
2613
|
}
|
|
2630
2614
|
async function toplevelOf(dir) {
|
|
@@ -2632,14 +2616,14 @@ async function toplevelOf(dir) {
|
|
|
2632
2616
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
2633
2617
|
}
|
|
2634
2618
|
async function reposOf(roots) {
|
|
2635
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2619
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process23.cwd()];
|
|
2636
2620
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
2637
2621
|
return [...new Set(found.flat())].sort();
|
|
2638
2622
|
}
|
|
2639
2623
|
async function repoState(dir) {
|
|
2640
2624
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
2641
2625
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
2642
|
-
return { path: relative(
|
|
2626
|
+
return { path: relative(process23.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
2643
2627
|
}
|
|
2644
2628
|
function trackingOf(status) {
|
|
2645
2629
|
if (status.upstream === null)
|
|
@@ -2711,18 +2695,18 @@ async function listRepos(roots, json) {
|
|
|
2711
2695
|
printJson(repos.map(({ path, status, head }) => status === null ? { path, error: "git could not read it" } : { path, ...jsonOf(status, head) }));
|
|
2712
2696
|
return 0;
|
|
2713
2697
|
}
|
|
2714
|
-
const dim = paint(
|
|
2698
|
+
const dim = paint(process24.stdout).dim;
|
|
2715
2699
|
const cells = (repo) => {
|
|
2716
2700
|
if (repo.status === null)
|
|
2717
|
-
return [role("path",
|
|
2701
|
+
return [role("path", process24.stdout)(repo.path), "", "", "git could not read it"];
|
|
2718
2702
|
const changes = changesOf(repo.status);
|
|
2719
|
-
return [role("path",
|
|
2703
|
+
return [role("path", process24.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
|
|
2720
2704
|
};
|
|
2721
2705
|
console.log(table(repos.map(cells)));
|
|
2722
2706
|
return 0;
|
|
2723
2707
|
}
|
|
2724
2708
|
function group(title, lines) {
|
|
2725
|
-
return lines.length === 0 ? [] : [paint(
|
|
2709
|
+
return lines.length === 0 ? [] : [paint(process24.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
|
|
2726
2710
|
}
|
|
2727
2711
|
function staged({ index, from, path }) {
|
|
2728
2712
|
return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
|
|
@@ -2762,12 +2746,12 @@ ${USAGE}`);
|
|
|
2762
2746
|
summary(status, head.code === 0 ? head.stdout : "", extra),
|
|
2763
2747
|
...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
|
|
2764
2748
|
...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${letter(change.worktree)} ${change.path}`)),
|
|
2765
|
-
...group("untracked", status.untracked.map((file) => paint(
|
|
2766
|
-
...group("conflicted", status.conflicted.map((file) => paint(
|
|
2767
|
-
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id",
|
|
2749
|
+
...group("untracked", status.untracked.map((file) => paint(process24.stdout).dim(file))),
|
|
2750
|
+
...group("conflicted", status.conflicted.map((file) => paint(process24.stdout).red(file))),
|
|
2751
|
+
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process24.stdout)(commitSha)} ${commitTitle}`))
|
|
2768
2752
|
];
|
|
2769
2753
|
console.log(lines.join(`
|
|
2770
2754
|
`));
|
|
2771
2755
|
return 0;
|
|
2772
2756
|
}
|
|
2773
|
-
|
|
2757
|
+
process24.exitCode = await runMain({ name: "gst", run: main });
|
package/dist/gu.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -1553,8 +1553,8 @@ var init_prompt = __esm(() => {
|
|
|
1553
1553
|
|
|
1554
1554
|
// src/gu.ts
|
|
1555
1555
|
import { mkdirSync as mkdirSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
1556
|
-
import { join as
|
|
1557
|
-
import
|
|
1556
|
+
import { join as join9, resolve as resolve4 } from "path";
|
|
1557
|
+
import process22 from "process";
|
|
1558
1558
|
|
|
1559
1559
|
// ../kit/src/index.ts
|
|
1560
1560
|
init_args();
|
|
@@ -2047,7 +2047,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
|
|
|
2047
2047
|
`);
|
|
2048
2048
|
chmodSync(script, 448);
|
|
2049
2049
|
return {
|
|
2050
|
-
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" },
|
|
2051
2051
|
close: () => {
|
|
2052
2052
|
server.stop(true);
|
|
2053
2053
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -2470,22 +2470,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
|
|
|
2470
2470
|
}
|
|
2471
2471
|
// ../kit/src/workspace-root.ts
|
|
2472
2472
|
init_user_config();
|
|
2473
|
-
import { homedir as homedir5 } from "os";
|
|
2474
|
-
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2475
|
-
import process21 from "process";
|
|
2476
|
-
function expandHome(path, home) {
|
|
2477
|
-
if (path === "~")
|
|
2478
|
-
return home;
|
|
2479
|
-
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
2480
|
-
}
|
|
2481
|
-
function configured(env, home) {
|
|
2482
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2483
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2484
|
-
}
|
|
2485
|
-
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
2486
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2487
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
2488
|
-
}
|
|
2489
2473
|
// src/git.ts
|
|
2490
2474
|
async function git2(args, env) {
|
|
2491
2475
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -2504,7 +2488,7 @@ var OPTIONS = {
|
|
|
2504
2488
|
commit: { type: "boolean", short: "c", description: "undo the last commit, keeping its changes staged" },
|
|
2505
2489
|
json: jsonOption("{action, paths?, saved?, commit?} of what was undone, saved being the patch of a discard")
|
|
2506
2490
|
};
|
|
2507
|
-
var LITERAL = { ...
|
|
2491
|
+
var LITERAL = { ...process22.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
2508
2492
|
var PLAIN_PATCH = ["--binary", "--no-ext-diff", "--no-textconv", "--no-color", "--no-relative", "--submodule=short", "--src-prefix=a/", "--dst-prefix=b/"];
|
|
2509
2493
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
2510
2494
|
async function checked(args, standing = "nothing undone") {
|
|
@@ -2562,8 +2546,8 @@ async function main(argv) {
|
|
|
2562
2546
|
return 0;
|
|
2563
2547
|
}
|
|
2564
2548
|
const patch = await checked(["diff", ...PLAIN_PATCH, "--", ...positionals]);
|
|
2565
|
-
const folder =
|
|
2566
|
-
const saved =
|
|
2549
|
+
const folder = join9(resolve4((await checked(["rev-parse", "--git-dir"])).trim()), "gu");
|
|
2550
|
+
const saved = join9(folder, `${new Date().toISOString().replaceAll(":", "-")}.patch`);
|
|
2567
2551
|
const top = (await checked(["rev-parse", "--show-toplevel"])).trim();
|
|
2568
2552
|
mkdirSync3(folder, { recursive: true });
|
|
2569
2553
|
writeFileSync3(saved, patch);
|
|
@@ -2577,7 +2561,7 @@ ${reverts.stderr.trim()}`, 1);
|
|
|
2577
2561
|
if (intended.length > 0) {
|
|
2578
2562
|
await checked(["-C", top, "rm", "--cached", "--quiet", "--", ...intended], standing);
|
|
2579
2563
|
for (const path of intended)
|
|
2580
|
-
rmSync2(
|
|
2564
|
+
rmSync2(join9(top, path), { force: true });
|
|
2581
2565
|
}
|
|
2582
2566
|
if (tracked.length > 0)
|
|
2583
2567
|
await checked(["-C", top, "restore", "--", ...tracked], standing);
|
|
@@ -2587,4 +2571,4 @@ ${reverts.stderr.trim()}`, 1);
|
|
|
2587
2571
|
console.log(`discarded ${paths.join(", ")}, saved to ${saved} (git apply puts it back)`);
|
|
2588
2572
|
return 0;
|
|
2589
2573
|
}
|
|
2590
|
-
|
|
2574
|
+
process22.exitCode = await runMain({ name: "gu", run: main });
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-git",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "gst, gc, gb, gp, gf, gm, gcl, gd and gu: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, a branch picked, nested repositories pushed or fetched, a branch merged with its conflicts listed, a clone
|
|
4
|
+
"version": "0.19.1",
|
|
5
|
+
"description": "gst, gc, gb, gp, gf, gm, gcl, gd and gu: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, a branch picked, nested repositories pushed or fetched, a branch merged with its conflicts listed, a clone over ssh first, the changes per file and an undo that keeps what it takes away.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/Kayno0o/cli/tree/main/packages/git#readme",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"build": "$npm_execpath build src/gst.ts src/gc.ts src/gb.ts src/gp.ts src/gf.ts src/gm.ts src/gcl.ts src/gd.ts src/gu.ts --root src --target bun --outdir dist",
|
|
47
|
+
"build": "$npm_execpath build src/gst.ts src/gc.ts src/gb.ts src/gp.ts src/gf.ts src/gm.ts src/gcl.ts src/gd.ts src/gu.ts --root src --target bun --outdir dist && $npm_execpath ../../scripts/shell-shebang.ts",
|
|
48
48
|
"gst": "$npm_execpath src/gst.ts",
|
|
49
49
|
"gc": "$npm_execpath src/gc.ts",
|
|
50
50
|
"gb": "$npm_execpath src/gb.ts",
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"gu": "$npm_execpath src/gu.ts"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@kaynooo/cli-kit": "0.46.
|
|
59
|
+
"@kaynooo/cli-kit": "0.46.4"
|
|
60
60
|
}
|
|
61
61
|
}
|