@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/dist/gst.js
CHANGED
|
@@ -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();
|
|
@@ -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/colour.ts
|
|
2485
|
-
import
|
|
2486
|
-
function letter(status, stream =
|
|
2472
|
+
import process22 from "process";
|
|
2473
|
+
function letter(status, stream = process22.stdout) {
|
|
2487
2474
|
const colors = paint(stream);
|
|
2488
2475
|
const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
|
|
2489
2476
|
return tint(status);
|
|
@@ -2498,7 +2485,7 @@ async function git2(args, env) {
|
|
|
2498
2485
|
|
|
2499
2486
|
// src/operation.ts
|
|
2500
2487
|
import { existsSync as existsSync4, readFileSync as readFileSync7 } from "fs";
|
|
2501
|
-
import { join as
|
|
2488
|
+
import { join as join9 } from "path";
|
|
2502
2489
|
function numberIn(path) {
|
|
2503
2490
|
try {
|
|
2504
2491
|
const value = Number.parseInt(readFileSync7(path, "utf8"), 10);
|
|
@@ -2508,11 +2495,11 @@ function numberIn(path) {
|
|
|
2508
2495
|
}
|
|
2509
2496
|
}
|
|
2510
2497
|
function operationOf(gitDir) {
|
|
2511
|
-
const has = (name) => existsSync4(
|
|
2498
|
+
const has = (name) => existsSync4(join9(gitDir, name));
|
|
2512
2499
|
if (has("rebase-merge"))
|
|
2513
|
-
return { kind: "rebase", step: numberIn(
|
|
2500
|
+
return { kind: "rebase", step: numberIn(join9(gitDir, "rebase-merge/msgnum")), total: numberIn(join9(gitDir, "rebase-merge/end")) };
|
|
2514
2501
|
if (has("rebase-apply"))
|
|
2515
|
-
return { kind: "rebase", step: numberIn(
|
|
2502
|
+
return { kind: "rebase", step: numberIn(join9(gitDir, "rebase-apply/next")), total: numberIn(join9(gitDir, "rebase-apply/last")) };
|
|
2516
2503
|
for (const [file, kind] of [["MERGE_HEAD", "merge"], ["CHERRY_PICK_HEAD", "cherry-pick"], ["REVERT_HEAD", "revert"], ["BISECT_LOG", "bisect"]]) {
|
|
2517
2504
|
if (has(file))
|
|
2518
2505
|
return { kind };
|
|
@@ -2522,8 +2509,8 @@ function operationOf(gitDir) {
|
|
|
2522
2509
|
|
|
2523
2510
|
// src/repos.ts
|
|
2524
2511
|
import { readdir } from "fs/promises";
|
|
2525
|
-
import { join as
|
|
2526
|
-
import
|
|
2512
|
+
import { join as join10, relative, resolve as resolve4 } from "path";
|
|
2513
|
+
import process23 from "process";
|
|
2527
2514
|
|
|
2528
2515
|
// src/status.ts
|
|
2529
2516
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -2619,9 +2606,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
2619
2606
|
found.push(dir);
|
|
2620
2607
|
if (left === 0)
|
|
2621
2608
|
return;
|
|
2622
|
-
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)));
|
|
2623
2610
|
}
|
|
2624
|
-
await walk(
|
|
2611
|
+
await walk(resolve4(root), depth);
|
|
2625
2612
|
return found.sort();
|
|
2626
2613
|
}
|
|
2627
2614
|
async function toplevelOf(dir) {
|
|
@@ -2629,14 +2616,14 @@ async function toplevelOf(dir) {
|
|
|
2629
2616
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
2630
2617
|
}
|
|
2631
2618
|
async function reposOf(roots) {
|
|
2632
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2619
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process23.cwd()];
|
|
2633
2620
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
2634
2621
|
return [...new Set(found.flat())].sort();
|
|
2635
2622
|
}
|
|
2636
2623
|
async function repoState(dir) {
|
|
2637
2624
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
2638
2625
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
2639
|
-
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 } };
|
|
2640
2627
|
}
|
|
2641
2628
|
function trackingOf(status) {
|
|
2642
2629
|
if (status.upstream === null)
|
|
@@ -2708,18 +2695,18 @@ async function listRepos(roots, json) {
|
|
|
2708
2695
|
printJson(repos.map(({ path, status, head }) => status === null ? { path, error: "git could not read it" } : { path, ...jsonOf(status, head) }));
|
|
2709
2696
|
return 0;
|
|
2710
2697
|
}
|
|
2711
|
-
const dim = paint(
|
|
2698
|
+
const dim = paint(process24.stdout).dim;
|
|
2712
2699
|
const cells = (repo) => {
|
|
2713
2700
|
if (repo.status === null)
|
|
2714
|
-
return [role("path",
|
|
2701
|
+
return [role("path", process24.stdout)(repo.path), "", "", "git could not read it"];
|
|
2715
2702
|
const changes = changesOf(repo.status);
|
|
2716
|
-
return [role("path",
|
|
2703
|
+
return [role("path", process24.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
|
|
2717
2704
|
};
|
|
2718
2705
|
console.log(table(repos.map(cells)));
|
|
2719
2706
|
return 0;
|
|
2720
2707
|
}
|
|
2721
2708
|
function group(title, lines) {
|
|
2722
|
-
return lines.length === 0 ? [] : [paint(
|
|
2709
|
+
return lines.length === 0 ? [] : [paint(process24.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
|
|
2723
2710
|
}
|
|
2724
2711
|
function staged({ index, from, path }) {
|
|
2725
2712
|
return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
|
|
@@ -2759,12 +2746,12 @@ ${USAGE}`);
|
|
|
2759
2746
|
summary(status, head.code === 0 ? head.stdout : "", extra),
|
|
2760
2747
|
...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
|
|
2761
2748
|
...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${letter(change.worktree)} ${change.path}`)),
|
|
2762
|
-
...group("untracked", status.untracked.map((file) => paint(
|
|
2763
|
-
...group("conflicted", status.conflicted.map((file) => paint(
|
|
2764
|
-
...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}`))
|
|
2765
2752
|
];
|
|
2766
2753
|
console.log(lines.join(`
|
|
2767
2754
|
`));
|
|
2768
2755
|
return 0;
|
|
2769
2756
|
}
|
|
2770
|
-
|
|
2757
|
+
process24.exitCode = await runMain({ name: "gst", run: main });
|
package/dist/gu.js
CHANGED
|
@@ -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();
|
|
@@ -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 });
|
|
@@ -2501,7 +2488,7 @@ var OPTIONS = {
|
|
|
2501
2488
|
commit: { type: "boolean", short: "c", description: "undo the last commit, keeping its changes staged" },
|
|
2502
2489
|
json: jsonOption("{action, paths?, saved?, commit?} of what was undone, saved being the patch of a discard")
|
|
2503
2490
|
};
|
|
2504
|
-
var LITERAL = { ...
|
|
2491
|
+
var LITERAL = { ...process22.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
2505
2492
|
var PLAIN_PATCH = ["--binary", "--no-ext-diff", "--no-textconv", "--no-color", "--no-relative", "--submodule=short", "--src-prefix=a/", "--dst-prefix=b/"];
|
|
2506
2493
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
2507
2494
|
async function checked(args, standing = "nothing undone") {
|
|
@@ -2559,8 +2546,8 @@ async function main(argv) {
|
|
|
2559
2546
|
return 0;
|
|
2560
2547
|
}
|
|
2561
2548
|
const patch = await checked(["diff", ...PLAIN_PATCH, "--", ...positionals]);
|
|
2562
|
-
const folder =
|
|
2563
|
-
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`);
|
|
2564
2551
|
const top = (await checked(["rev-parse", "--show-toplevel"])).trim();
|
|
2565
2552
|
mkdirSync3(folder, { recursive: true });
|
|
2566
2553
|
writeFileSync3(saved, patch);
|
|
@@ -2574,7 +2561,7 @@ ${reverts.stderr.trim()}`, 1);
|
|
|
2574
2561
|
if (intended.length > 0) {
|
|
2575
2562
|
await checked(["-C", top, "rm", "--cached", "--quiet", "--", ...intended], standing);
|
|
2576
2563
|
for (const path of intended)
|
|
2577
|
-
rmSync2(
|
|
2564
|
+
rmSync2(join9(top, path), { force: true });
|
|
2578
2565
|
}
|
|
2579
2566
|
if (tracked.length > 0)
|
|
2580
2567
|
await checked(["-C", top, "restore", "--", ...tracked], standing);
|
|
@@ -2584,4 +2571,4 @@ ${reverts.stderr.trim()}`, 1);
|
|
|
2584
2571
|
console.log(`discarded ${paths.join(", ")}, saved to ${saved} (git apply puts it back)`);
|
|
2585
2572
|
return 0;
|
|
2586
2573
|
}
|
|
2587
|
-
|
|
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.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 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",
|
|
@@ -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
|
}
|