@kaynooo/cli-git 0.17.3 → 0.18.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 CHANGED
@@ -18,6 +18,7 @@ Prints one line with the branch, its upstream and how far ahead and behind it is
18
18
 
19
19
  `gp [dir]...` pushes the current branch of the repository, or of each dir's, when it is ahead of its upstream as of the last fetch, and with `-u` to origin (the only remote when there is no origin) when it has no upstream yet. `--repos` (`-r`) pushes every repository `gst --repos` lists, one after another.
20
20
 
21
+ - `--branch <name>` (`-b`, repeatable) pushes that local branch instead of the current one: to the upstream it tracks, under its name there, else with `-u` to origin; a repository without it is skipped.
21
22
  - A detached HEAD, a branch with nothing ahead and a repository with no remote are skipped, saying so; a refused push shows git's reason and the next repository is still pushed.
22
23
  - What follows `--` goes to each `git push` (`gp -- --tags`, `gp -- --force-with-lease`), and a branch with nothing ahead is then pushed too.
23
24
  - `--dry-run` says what would be pushed; `--json` prints `{path, branch, remote, commits, outcome, reason?}` per repository, `outcome` being `pushed`, `would-push`, `skipped` or `refused`.
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
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
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
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
@@ -2638,6 +2649,7 @@ var OPTIONS = {
2638
2649
  staged: { type: "boolean", short: "s", description: "only what is staged" },
2639
2650
  ref: { type: "string", description: "compare to this commit, branch or tag, or a..b, instead of the index" },
2640
2651
  patch: { type: "boolean", short: "p", description: "print the patch of every file listed, not just of the paths given" },
2652
+ stat: { type: "boolean", description: "list the files with their added and removed lines, the paths given too, never a patch" },
2641
2653
  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
2654
  };
2643
2655
  var LITERAL = { ...process24.env, GIT_LITERAL_PATHSPECS: "1" };
@@ -2693,10 +2705,12 @@ async function main(argv) {
2693
2705
  badUsage(`--ref takes a commit, branch or tag, not ${values.ref}`);
2694
2706
  if (values.ref !== undefined && values.staged === true)
2695
2707
  badUsage("--ref and --staged exclude each other: --ref compares the working tree");
2708
+ if (values.stat === true && values.patch === true)
2709
+ badUsage("--stat and --patch exclude each other");
2696
2710
  if (await toplevelOf(".") === undefined)
2697
2711
  fail("not inside a git repository", 2);
2698
2712
  const wanted = sections(values);
2699
- const patched = positionals.length > 0 || values.patch === true;
2713
+ const patched = (positionals.length > 0 || values.patch === true) && values.stat !== true;
2700
2714
  if (values.json === true) {
2701
2715
  printJson(await Promise.all(wanted.map(async ({ title, args }) => ({
2702
2716
  title,
@@ -2710,7 +2724,7 @@ async function main(argv) {
2710
2724
  await show(patches.join(""));
2711
2725
  return 0;
2712
2726
  }
2713
- const found = await Promise.all(wanted.map(async (each) => ({ ...each, files: parseNumstat(await diff([...each.args, "--numstat", "-z"], [])) })));
2727
+ const found = await Promise.all(wanted.map(async (each) => ({ ...each, files: parseNumstat(await diff([...each.args, "--numstat", "-z"], positionals)) })));
2714
2728
  const { dim } = paint(process24.stdout);
2715
2729
  const green = role("ok", process24.stdout);
2716
2730
  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
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
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
@@ -2631,10 +2642,12 @@ async function dirsOf(positionals, all) {
2631
2642
  // src/gp.ts
2632
2643
  var USAGE = `gp [dir]...: pushes the current branch of the repository, or of each dir, when it is ahead of its upstream or has none yet
2633
2644
 
2645
+ --branch pushes that local branch instead, to its upstream or with -u to origin, whichever branch is checked out; given several times, each is pushed, and a repository without it is skipped.
2634
2646
  --repos pushes every repository at and below the current one's toplevel, or below each dir given, the way gst --repos lists them. A detached HEAD, a branch with nothing to push and a repository with no remote are skipped, saying so; the pushes run one after another.
2635
2647
  What follows -- goes to every git push as is (gp -- --tags, gp -- --force-with-lease), and a branch with nothing ahead is then pushed too.`;
2636
2648
  var EXITS = [[0, "every push went through, or there was nothing to push"], [1, "a push was refused or a repository could not be read"], [2, "outside a git repository or a usage error"]];
2637
2649
  var OPTIONS = {
2650
+ branch: { type: "string", short: "b", multiple: true, description: "push this local branch instead of the current one" },
2638
2651
  repos: { type: "boolean", short: "r", description: "every repository nested below too" },
2639
2652
  "dry-run": { type: "boolean", description: "say what would be pushed, pushing nothing" },
2640
2653
  json: jsonOption("one {path, branch, remote, commits, outcome, reason?} per repository, outcome being pushed, would-push, skipped or refused")
@@ -2656,19 +2669,38 @@ async function unpushed(dir, branch) {
2656
2669
  const count = await git2(["-C", dir, "rev-list", "--count", branch, "--not", "--remotes"]);
2657
2670
  return count.code === 0 ? Number(count.stdout.trim()) : null;
2658
2671
  }
2659
- async function push(repo, { dryRun, extra, env }) {
2672
+ var AHEAD = /ahead (\d+)/;
2673
+ async function namedTarget(dir, branch) {
2674
+ const read = await git2(["-C", dir, "for-each-ref", "--format=%(upstream:short)%00%(upstream:remotename)%00%(upstream:remoteref)%00%(upstream:track,nobracket)", `refs/heads/${branch}`]);
2675
+ const line = read.stdout.trim();
2676
+ if (read.code !== 0 || line === "")
2677
+ return;
2678
+ const [upstream = "", remote = "", ref = "", track = ""] = line.split("\x00");
2679
+ if (upstream === "")
2680
+ return { branch, upstream: null, ahead: null, refspec: [] };
2681
+ return { branch, upstream, ahead: track === "gone" ? null : Number(AHEAD.exec(track)?.[1] ?? 0), refspec: [remote, `${branch}:${ref}`] };
2682
+ }
2683
+ async function push(repo, asked, { dryRun, extra, env }) {
2660
2684
  const { path, dir, status } = repo;
2661
2685
  const skipped = (reason, branch = null) => ({ path, branch, remote: null, commits: null, outcome: "skipped", reason });
2662
2686
  if (status === null)
2663
2687
  return { path, branch: null, remote: null, commits: null, outcome: "refused", reason: "git could not read it" };
2664
- const { branch, upstream, aheadBehind } = status;
2665
- if (branch === "(detached)")
2666
- return skipped("detached HEAD");
2688
+ let target;
2689
+ if (asked !== undefined) {
2690
+ target = await namedTarget(dir, asked);
2691
+ if (target === undefined)
2692
+ return skipped(`no branch ${asked}`, asked);
2693
+ } else {
2694
+ if (status.branch === "(detached)")
2695
+ return skipped("detached HEAD");
2696
+ target = { branch: status.branch, upstream: status.upstream, ahead: status.aheadBehind?.ahead ?? null, refspec: [] };
2697
+ }
2698
+ const { branch, upstream, ahead, refspec } = target;
2667
2699
  let args;
2668
2700
  let remote;
2669
2701
  let commits;
2670
2702
  if (upstream === null) {
2671
- if ((await git2(["-C", dir, "rev-parse", "--verify", "--quiet", "HEAD"])).code !== 0)
2703
+ if ((await git2(["-C", dir, "rev-parse", "--verify", "--quiet", `refs/heads/${branch}`])).code !== 0)
2672
2704
  return skipped("no commit yet, nothing to push", branch);
2673
2705
  const name = await remoteFor(dir);
2674
2706
  if (name === undefined)
@@ -2677,11 +2709,11 @@ async function push(repo, { dryRun, extra, env }) {
2677
2709
  remote = `${name}/${branch}`;
2678
2710
  commits = await unpushed(dir, branch);
2679
2711
  } else {
2680
- if (aheadBehind !== null && aheadBehind.ahead === 0 && extra.length === 0)
2712
+ if (ahead === 0 && extra.length === 0)
2681
2713
  return skipped("nothing to push", branch);
2682
- args = ["push", ...extra];
2714
+ args = ["push", ...extra, ...refspec];
2683
2715
  remote = upstream;
2684
- commits = aheadBehind?.ahead ?? await unpushed(dir, branch);
2716
+ commits = ahead ?? await unpushed(dir, branch);
2685
2717
  }
2686
2718
  if (dryRun)
2687
2719
  return { path, branch, remote, commits, outcome: "would-push" };
@@ -2701,17 +2733,19 @@ function line(result) {
2701
2733
  return [role("path", process24.stdout)(result.path), said()];
2702
2734
  }
2703
2735
  async function main(argv) {
2704
- 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 -- --force-with-lease", "flags for git push"]] });
2736
+ 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"]] });
2705
2737
  const dirs = await dirsOf(positionals, values.repos === true);
2706
2738
  const repos = await Promise.all(dirs.map(repoState));
2739
+ const branches = values.branch ?? [undefined];
2740
+ const pushes = repos.flatMap((repo) => branches.map((branch) => ({ repo, branch })));
2707
2741
  const results = [];
2708
2742
  const progress = progressLine();
2709
2743
  const prompts = askpass(progress.pause);
2710
2744
  const env = prompts === undefined ? undefined : { ...process24.env, ...prompts.env };
2711
2745
  try {
2712
- for (const [at, repo] of repos.entries()) {
2713
- progress.update(repos.length > 1 ? { step: `pushing ${repo.path}`, done: at, total: repos.length, unit: "repositories" } : { step: `pushing ${repo.path}` });
2714
- results.push(await push(repo, { dryRun: values["dry-run"] === true, extra: rest, env }));
2746
+ for (const [at, { repo, branch }] of pushes.entries()) {
2747
+ progress.update(pushes.length > 1 ? { step: `pushing ${repo.path}`, done: at, total: pushes.length, unit: "pushes" } : { step: `pushing ${repo.path}` });
2748
+ results.push(await push(repo, branch, { dryRun: values["dry-run"] === true, extra: rest, env }));
2715
2749
  }
2716
2750
  } finally {
2717
2751
  prompts?.close();
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
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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-git",
3
3
  "type": "module",
4
- "version": "0.17.3",
4
+ "version": "0.18.1",
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.0"
59
+ "@kaynooo/cli-kit": "0.46.2"
60
60
  }
61
61
  }