@kaynooo/cli-git 0.18.0 → 0.18.2

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 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 `<workspace>/<name>` (the workspace `cli config` reports) 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, a local path or `owner/name`, read as `https://git.kaynooo.fr/owner/name.git`; the `forge` key of `~/.config/kaynooo-cli/config.json` names another host.
67
+ `gcl <repo> [dir]` clones into `<workspace>/<name>` (the workspace `cli config` reports) 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, a local path or `owner/name`, read as `https://git.kaynooo.fr/owner/name.git`; the `forge` key of `~/.config/kaynooo-cli/config.json` names another host (`http://host:port` for another scheme). A private repository refuses that anonymous https clone: with the `forgeSsh` key set to the forge's ssh address (`git@git.example.org`, `ssh://git@git.example.org:22022`) gcl clones it over ssh instead, else the error names the ssh address to give. Off a terminal, gcl, gf and gp keep git and ssh from asking for a password, on the terminal or through the desktop's askpass window: they fail at once instead.
68
68
 
69
69
  - A folder that already holds the repository is not cloned again: it is fetched and fast-forwarded as `gf` does. A folder holding anything else is refused, exit 1.
70
70
  - `--json` prints `{url, path, branch, head, outcome}`, `outcome` being `cloned` or `existing`.
package/dist/gb.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1971,12 +1982,15 @@ import { join as join6 } from "path";
1971
1982
  import process16 from "process";
1972
1983
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1973
1984
  var ECHOED = /username|yes\/no/i;
1985
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1974
1986
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1975
1987
  function askpass(pause = () => () => {
1976
1988
  return;
1977
1989
  }) {
1978
1990
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1979
- return;
1991
+ return { env: { ...NO_PROMPTS }, close: () => {
1992
+ return;
1993
+ } };
1980
1994
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1981
1995
  const socketPath = join6(dir, "socket");
1982
1996
  const script = join6(dir, "askpass");
package/dist/gc.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1973,12 +1984,15 @@ import { join as join6 } from "path";
1973
1984
  import process16 from "process";
1974
1985
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1975
1986
  var ECHOED = /username|yes\/no/i;
1987
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1976
1988
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1977
1989
  function askpass(pause = () => () => {
1978
1990
  return;
1979
1991
  }) {
1980
1992
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1981
- return;
1993
+ return { env: { ...NO_PROMPTS }, close: () => {
1994
+ return;
1995
+ } };
1982
1996
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1983
1997
  const socketPath = join6(dir, "socket");
1984
1998
  const script = join6(dir, "askpass");
package/dist/gcl.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1974,12 +1985,15 @@ import { join as join6 } from "path";
1974
1985
  import process16 from "process";
1975
1986
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1976
1987
  var ECHOED = /username|yes\/no/i;
1988
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1977
1989
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1978
1990
  function askpass(pause = () => () => {
1979
1991
  return;
1980
1992
  }) {
1981
1993
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1982
- return;
1994
+ return { env: { ...NO_PROMPTS }, close: () => {
1995
+ return;
1996
+ } };
1983
1997
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1984
1998
  const socketPath = join6(dir, "socket");
1985
1999
  const script = join6(dir, "askpass");
@@ -2691,6 +2705,7 @@ var DEFAULT_FORGE = "git.kaynooo.fr";
2691
2705
  var USAGE = `gcl <repo> [dir]: clones a repository into the workspace folder and prints where it landed
2692
2706
 
2693
2707
  <repo> is a URL, an scp-style address, a local path or \`owner/name\`, read as \`https://${DEFAULT_FORGE}/owner/name.git\` (the \`forge\` config key names another host). Without <dir> the clone goes to <workspace>/<name>, the workspace \`cli config\` reports.
2708
+ A private repository refuses an \`owner/name\` clone over https: with the \`forgeSsh\` config key set to the forge's ssh address (\`git@host\` or \`ssh://git@host:port\`) it is cloned over ssh instead, else the error names the ssh address to give. Off a terminal git never asks for a password, through the terminal or a desktop window: it fails instead.
2694
2709
  A folder that already holds the repository is fetched and fast-forwarded as gf does, not cloned again; one holding anything else is refused.`;
2695
2710
  var EXITS = [[0, "it cloned the repository, or found it and brought it up to date"], [1, "git could not clone it, or the folder is taken"], [2, "a usage error"]];
2696
2711
  var OPTIONS = {
@@ -2702,62 +2717,99 @@ var OWNER_NAME = /^[\w.-]+\/[\w.-]+$/;
2702
2717
  var GIT_SUFFIX = /\.git\/?$/;
2703
2718
  var TRAILING_SLASH = /\/+$/;
2704
2719
  var LAST_SEGMENT = /[/:]/;
2720
+ var AUTH_REFUSED = /could not read Username|Authentication failed|terminal prompts disabled|\b40[13]\b/i;
2721
+ var SSH_BASE_END = /[/:]$/;
2705
2722
  function urlOf(repo, forge) {
2706
2723
  if (repo.startsWith("~/"))
2707
2724
  return join11(homedir6(), repo.slice(2));
2708
2725
  if (SCHEME.test(repo) || SCP.test(repo) || repo.startsWith("/") || repo.startsWith("."))
2709
2726
  return repo;
2710
2727
  if (OWNER_NAME.test(repo))
2711
- return `https://${forge}/${repo.replace(GIT_SUFFIX, "")}.git`;
2728
+ return `${SCHEME.test(forge) ? forge.replace(TRAILING_SLASH, "") : `https://${forge}`}/${repo.replace(GIT_SUFFIX, "")}.git`;
2712
2729
  return fail(`${repo} is no URL and no owner/name`, 2);
2713
2730
  }
2731
+ function sshUrlOf(repo, base) {
2732
+ const separator = SCHEME.test(base) ? "/" : ":";
2733
+ return `${base}${SSH_BASE_END.test(base) ? "" : separator}${repo.replace(GIT_SUFFIX, "")}.git`;
2734
+ }
2735
+ function setting(config, key) {
2736
+ const value = config[key];
2737
+ return typeof value === "string" && value !== "" ? value : undefined;
2738
+ }
2714
2739
  function nameOf(url) {
2715
2740
  return basename(url.replace(TRAILING_SLASH, "").split(LAST_SEGMENT).at(-1) ?? "").replace(GIT_SUFFIX, "");
2716
2741
  }
2717
2742
  function same(url) {
2718
2743
  return url.replace(TRAILING_SLASH, "").replace(GIT_SUFFIX, "").toLowerCase();
2719
2744
  }
2745
+ async function update({ url, sshUrl, path }, env) {
2746
+ if (!statSync2(path).isDirectory() || await toplevelOf(path) !== realpathSync3(path))
2747
+ fail(`${path} exists and is not a repository, nothing cloned`, 1);
2748
+ const origin = (await git2(["-C", path, "remote", "get-url", "origin"])).stdout.trim();
2749
+ if (same(origin) !== same(url) && (sshUrl === undefined || same(origin) !== same(sshUrl)))
2750
+ fail(`${path} is a clone of ${origin === "" ? "nothing (no origin)" : origin}, not ${url}, nothing cloned`, 1);
2751
+ const synced = await sync(await repoState(path), { pull: true, env });
2752
+ if (synced.outcome === "refused")
2753
+ fail(`${path} is already cloned but could not be brought up to date: ${synced.reason}`, 1);
2754
+ return origin;
2755
+ }
2756
+ async function clone({ repo, url, sshUrl, forgeSsh, path }, env) {
2757
+ const cloned = await git2(["clone", url, path], env);
2758
+ if (cloned.code === 0)
2759
+ return url;
2760
+ if (sshUrl === undefined || !AUTH_REFUSED.test(cloned.stderr))
2761
+ fail(`git clone failed:
2762
+ ${cloned.stderr.trim()}`, 1);
2763
+ if (forgeSsh === undefined)
2764
+ fail(`git clone failed:
2765
+ ${cloned.stderr.trim()}
2766
+ ${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
+ }
2720
2774
  async function main(argv) {
2721
2775
  const { values, positionals } = parse(argv, USAGE, OPTIONS, { positionals: ["<repo>", "[dir]"], exits: EXITS, replaces: "git clone with the url and the folder typed out, then a cd", examples: ["gcl kaynooo/cli", ["gcl git@github.com:oven-sh/bun.git", "an scp address"], ["gcl kaynooo/cli ~/tmp/cli", "a folder of your own"]] });
2722
2776
  const [repo, given] = positionals;
2723
2777
  if (repo === undefined)
2724
2778
  fail("gcl needs the repository to clone: gcl owner/name", 2);
2725
- const configured = readUserConfig("config").forge;
2726
- const url = urlOf(repo, typeof configured === "string" && configured !== "" ? configured : DEFAULT_FORGE);
2779
+ const config = readUserConfig("config");
2780
+ const forge = setting(config, "forge") ?? DEFAULT_FORGE;
2781
+ const url = urlOf(repo, forge);
2782
+ const isOwnerName = OWNER_NAME.test(repo) && !repo.startsWith(".");
2783
+ const forgeSsh = setting(config, "forgeSsh");
2784
+ const sshUrl = isOwnerName ? sshUrlOf(repo, forgeSsh ?? `git@${SCHEME.test(forge) ? new URL(forge).hostname : forge}`) : undefined;
2727
2785
  const name = nameOf(url);
2728
2786
  if (name === "")
2729
2787
  fail(`no folder name can be taken from ${url}, give one: gcl ${repo} <dir>`, 2);
2730
- const path = given === undefined ? join11(workspaceRoot(), name) : resolve6(given);
2731
- let outcome = "cloned";
2732
- if (existsSync4(path) && (!statSync2(path).isDirectory() || readdirSync(path).length > 0)) {
2733
- if (!statSync2(path).isDirectory() || await toplevelOf(path) !== realpathSync3(path))
2734
- fail(`${path} exists and is not a repository, nothing cloned`, 1);
2735
- const origin = (await git2(["-C", path, "remote", "get-url", "origin"])).stdout.trim();
2736
- if (same(origin) !== same(url))
2737
- fail(`${path} is a clone of ${origin === "" ? "nothing (no origin)" : origin}, not ${url}, nothing cloned`, 1);
2738
- const synced = await sync(await repoState(path), { pull: true });
2739
- if (synced.outcome === "refused")
2740
- fail(`${path} is already cloned but could not be brought up to date: ${synced.reason}`, 1);
2741
- outcome = "existing";
2742
- } else {
2743
- const cloned = await git2(["clone", url, path]);
2744
- if (cloned.code !== 0)
2745
- fail(`git clone failed:
2746
- ${cloned.stderr.trim()}`, 1);
2788
+ const target = { repo, url, sshUrl, forgeSsh, path: given === undefined ? join11(workspaceRoot(), name) : resolve6(given) };
2789
+ const { path } = target;
2790
+ const outcome = existsSync4(path) && (!statSync2(path).isDirectory() || readdirSync(path).length > 0) ? "existing" : "cloned";
2791
+ const prompts = askpass();
2792
+ const env = { ...process24.env, ...prompts.env };
2793
+ let from;
2794
+ try {
2795
+ from = outcome === "existing" ? await update(target, env) : await clone(target, env);
2796
+ } finally {
2797
+ prompts.close();
2747
2798
  }
2748
2799
  const { status, head } = await repoState(path);
2749
- const result = { url, path, branch: status?.branch ?? null, head: head?.sha ?? null, outcome };
2800
+ const result = { url: from, path, branch: status?.branch ?? null, head: head?.sha ?? null, outcome };
2750
2801
  if (values.json === true)
2751
2802
  printJson(result);
2752
2803
  else
2753
2804
  console.log(path);
2754
2805
  if (values.json !== true)
2755
- console.error(`${outcome === "cloned" ? "cloned" : "already cloned"} ${url}${result.branch === null ? "" : ` on ${result.branch}`}${result.head === null ? "" : ` at ${result.head}`}`);
2806
+ console.error(`${outcome === "cloned" ? "cloned" : "already cloned"} ${from}${result.branch === null ? "" : ` on ${result.branch}`}${result.head === null ? "" : ` at ${result.head}`}`);
2756
2807
  return 0;
2757
2808
  }
2758
2809
  if (import.meta.main)
2759
2810
  process24.exitCode = await runMain({ name: "gcl", run: main });
2760
2811
  export {
2761
2812
  nameOf,
2813
+ sshUrlOf,
2762
2814
  urlOf
2763
2815
  };
package/dist/gd.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1971,12 +1982,15 @@ import { join as join6 } from "path";
1971
1982
  import process16 from "process";
1972
1983
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1973
1984
  var ECHOED = /username|yes\/no/i;
1985
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1974
1986
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1975
1987
  function askpass(pause = () => () => {
1976
1988
  return;
1977
1989
  }) {
1978
1990
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1979
- return;
1991
+ return { env: { ...NO_PROMPTS }, close: () => {
1992
+ return;
1993
+ } };
1980
1994
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1981
1995
  const socketPath = join6(dir, "socket");
1982
1996
  const script = join6(dir, "askpass");
@@ -2638,6 +2652,7 @@ var OPTIONS = {
2638
2652
  staged: { type: "boolean", short: "s", description: "only what is staged" },
2639
2653
  ref: { type: "string", description: "compare to this commit, branch or tag, or a..b, instead of the index" },
2640
2654
  patch: { type: "boolean", short: "p", description: "print the patch of every file listed, not just of the paths given" },
2655
+ stat: { type: "boolean", description: "list the files with their added and removed lines, the paths given too, never a patch" },
2641
2656
  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")
2642
2657
  };
2643
2658
  var LITERAL = { ...process24.env, GIT_LITERAL_PATHSPECS: "1" };
@@ -2693,10 +2708,12 @@ async function main(argv) {
2693
2708
  badUsage(`--ref takes a commit, branch or tag, not ${values.ref}`);
2694
2709
  if (values.ref !== undefined && values.staged === true)
2695
2710
  badUsage("--ref and --staged exclude each other: --ref compares the working tree");
2711
+ if (values.stat === true && values.patch === true)
2712
+ badUsage("--stat and --patch exclude each other");
2696
2713
  if (await toplevelOf(".") === undefined)
2697
2714
  fail("not inside a git repository", 2);
2698
2715
  const wanted = sections(values);
2699
- const patched = positionals.length > 0 || values.patch === true;
2716
+ const patched = (positionals.length > 0 || values.patch === true) && values.stat !== true;
2700
2717
  if (values.json === true) {
2701
2718
  printJson(await Promise.all(wanted.map(async ({ title, args }) => ({
2702
2719
  title,
@@ -2710,7 +2727,7 @@ async function main(argv) {
2710
2727
  await show(patches.join(""));
2711
2728
  return 0;
2712
2729
  }
2713
- const found = await Promise.all(wanted.map(async (each) => ({ ...each, files: parseNumstat(await diff([...each.args, "--numstat", "-z"], [])) })));
2730
+ const found = await Promise.all(wanted.map(async (each) => ({ ...each, files: parseNumstat(await diff([...each.args, "--numstat", "-z"], positionals)) })));
2714
2731
  const { dim } = paint(process24.stdout);
2715
2732
  const green = role("ok", process24.stdout);
2716
2733
  const red = role("problem", process24.stdout);
package/dist/gf.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1971,12 +1982,15 @@ import { join as join6 } from "path";
1971
1982
  import process16 from "process";
1972
1983
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1973
1984
  var ECHOED = /username|yes\/no/i;
1985
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1974
1986
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1975
1987
  function askpass(pause = () => () => {
1976
1988
  return;
1977
1989
  }) {
1978
1990
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1979
- return;
1991
+ return { env: { ...NO_PROMPTS }, close: () => {
1992
+ return;
1993
+ } };
1980
1994
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1981
1995
  const socketPath = join6(dir, "socket");
1982
1996
  const script = join6(dir, "askpass");
@@ -2712,14 +2726,14 @@ async function main(argv) {
2712
2726
  const results = [];
2713
2727
  const progress = progressLine();
2714
2728
  const prompts = askpass(progress.pause);
2715
- const env = prompts === undefined ? undefined : { ...process24.env, ...prompts.env };
2729
+ const env = { ...process24.env, ...prompts.env };
2716
2730
  try {
2717
2731
  for (const [at, repo] of repos.entries()) {
2718
2732
  progress.update(repos.length > 1 ? { step: `fetching ${repo.path}`, done: at, total: repos.length, unit: "repositories" } : { step: `fetching ${repo.path}` });
2719
2733
  results.push(await sync(repo, { pull: values["no-pull"] !== true, env }));
2720
2734
  }
2721
2735
  } finally {
2722
- prompts?.close();
2736
+ prompts.close();
2723
2737
  progress.stop();
2724
2738
  }
2725
2739
  if (values.json === true)
package/dist/gm.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1973,12 +1984,15 @@ import { join as join6 } from "path";
1973
1984
  import process16 from "process";
1974
1985
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1975
1986
  var ECHOED = /username|yes\/no/i;
1987
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1976
1988
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1977
1989
  function askpass(pause = () => () => {
1978
1990
  return;
1979
1991
  }) {
1980
1992
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1981
- return;
1993
+ return { env: { ...NO_PROMPTS }, close: () => {
1994
+ return;
1995
+ } };
1982
1996
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1983
1997
  const socketPath = join6(dir, "socket");
1984
1998
  const script = join6(dir, "askpass");
package/dist/gp.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1971,12 +1982,15 @@ import { join as join6 } from "path";
1971
1982
  import process16 from "process";
1972
1983
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1973
1984
  var ECHOED = /username|yes\/no/i;
1985
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1974
1986
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1975
1987
  function askpass(pause = () => () => {
1976
1988
  return;
1977
1989
  }) {
1978
1990
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1979
- return;
1991
+ return { env: { ...NO_PROMPTS }, close: () => {
1992
+ return;
1993
+ } };
1980
1994
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1981
1995
  const socketPath = join6(dir, "socket");
1982
1996
  const script = join6(dir, "askpass");
@@ -2730,14 +2744,14 @@ async function main(argv) {
2730
2744
  const results = [];
2731
2745
  const progress = progressLine();
2732
2746
  const prompts = askpass(progress.pause);
2733
- const env = prompts === undefined ? undefined : { ...process24.env, ...prompts.env };
2747
+ const env = { ...process24.env, ...prompts.env };
2734
2748
  try {
2735
2749
  for (const [at, { repo, branch }] of pushes.entries()) {
2736
2750
  progress.update(pushes.length > 1 ? { step: `pushing ${repo.path}`, done: at, total: pushes.length, unit: "pushes" } : { step: `pushing ${repo.path}` });
2737
2751
  results.push(await push(repo, branch, { dryRun: values["dry-run"] === true, extra: rest, env }));
2738
2752
  }
2739
2753
  } finally {
2740
- prompts?.close();
2754
+ prompts.close();
2741
2755
  progress.stop();
2742
2756
  }
2743
2757
  if (values.json === true)
package/dist/gst.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1971,12 +1982,15 @@ import { join as join6 } from "path";
1971
1982
  import process16 from "process";
1972
1983
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1973
1984
  var ECHOED = /username|yes\/no/i;
1985
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1974
1986
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1975
1987
  function askpass(pause = () => () => {
1976
1988
  return;
1977
1989
  }) {
1978
1990
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1979
- return;
1991
+ return { env: { ...NO_PROMPTS }, close: () => {
1992
+ return;
1993
+ } };
1980
1994
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1981
1995
  const socketPath = join6(dir, "socket");
1982
1996
  const script = join6(dir, "askpass");
package/dist/gu.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1973,12 +1984,15 @@ import { join as join6 } from "path";
1973
1984
  import process16 from "process";
1974
1985
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1975
1986
  var ECHOED = /username|yes\/no/i;
1987
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1976
1988
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1977
1989
  function askpass(pause = () => () => {
1978
1990
  return;
1979
1991
  }) {
1980
1992
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1981
- return;
1993
+ return { env: { ...NO_PROMPTS }, close: () => {
1994
+ return;
1995
+ } };
1982
1996
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1983
1997
  const socketPath = join6(dir, "socket");
1984
1998
  const script = join6(dir, "askpass");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-git",
3
3
  "type": "module",
4
- "version": "0.18.0",
4
+ "version": "0.18.2",
5
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 into the workspace, the changes per file and an undo that keeps what it takes away.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -56,6 +56,6 @@
56
56
  "gu": "$npm_execpath src/gu.ts"
57
57
  },
58
58
  "devDependencies": {
59
- "@kaynooo/cli-kit": "0.46.1"
59
+ "@kaynooo/cli-kit": "0.46.2"
60
60
  }
61
61
  }