gwqadd 0.3.1 → 0.3.3

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.
Files changed (2) hide show
  1. package/bin/gwqadd.mjs +64 -4
  2. package/package.json +1 -1
package/bin/gwqadd.mjs CHANGED
@@ -266,6 +266,18 @@ __${slug}_exec() {
266
266
  # ${desc}.
267
267
  ${fnName}() {
268
268
  emulate -L zsh
269
+ # These print to stdout for the caller — help text, a list, JSON — and one of
270
+ # them, --json, would collide with the --quiet added below. Capturing that and
271
+ # handing it to cd produced "file name too long" on --help. Pass them through.
272
+ local __a
273
+ for __a in "$@"; do
274
+ case $__a in
275
+ -h|--help|-V|--version|--init|--init=*|--json)
276
+ __${slug}_exec "$@"
277
+ return $?
278
+ ;;
279
+ esac
280
+ done
269
281
  local __dir
270
282
  __dir=$(__${slug}_exec --quiet "$@") || return $?
271
283
  # Empty is not a failure: --no-cd, --help and --version all succeed without
@@ -296,6 +308,18 @@ __${slug}_exec() {
296
308
 
297
309
  # ${desc}.
298
310
  ${fnName}() {
311
+ # These print to stdout for the caller — help text, a list, JSON — and one of
312
+ # them, --json, would collide with the --quiet added below. Capturing that and
313
+ # handing it to cd produced "file name too long" on --help. Pass them through.
314
+ local __a
315
+ for __a in "$@"; do
316
+ case "$__a" in
317
+ -h|--help|-V|--version|--init|--init=*|--json)
318
+ __${slug}_exec "$@"
319
+ return $?
320
+ ;;
321
+ esac
322
+ done
299
323
  local __dir
300
324
  __dir=$(__${slug}_exec --quiet "$@") || return $?
301
325
  [ -n "$__dir" ] || return 0
@@ -322,6 +346,15 @@ function __${slug}_exec
322
346
  end
323
347
 
324
348
  function ${fnName} --description ${fishq(desc)}
349
+ # Help text, a list or JSON goes to the caller, not to cd. --json would also
350
+ # collide with the --quiet added below.
351
+ for __a in $argv
352
+ switch $__a
353
+ case -h --help -V --version --init '--init=*' --json
354
+ __${slug}_exec $argv
355
+ return $status
356
+ end
357
+ end
325
358
  set -l __dir (__${slug}_exec --quiet $argv)
326
359
  # \`set\` reports the command substitution's status, but not every fish
327
360
  # release agrees on that. Capturing it keeps a failed run from cd'ing,
@@ -941,9 +974,36 @@ function copyToClipboard(text) {
941
974
 
942
975
  // ── worktree creation ────────────────────────────────────────────────────────
943
976
 
944
- // gwq reports the git command it ran, so a collision's destination can be read
945
- // back out of its error text.
946
- const COLLISION = /git worktree add (?:-b [^ ]* )?(\/[^ :]*)/;
977
+ // A collision's destination has to be recovered from gwq's error text. Two
978
+ // sources, in order of reliability:
979
+ //
980
+ // fatal: '<path>' already exists <- git, quoted, unambiguous
981
+ // ...: git worktree add [-b <branch>] <path>: ...
982
+ //
983
+ // The quoted form is preferred because the command echo is not parseable in
984
+ // general: `-b` swaps the argument order (`add -b <branch> <path>` versus
985
+ // `add <path> <branch>`), and a path containing a space silently truncated the
986
+ // old pattern — a gwq basedir under a directory with a space made `-f` do
987
+ // nothing at all, without saying so.
988
+ const COLLISION_QUOTED = /fatal: '([^']+)' already exists/;
989
+
990
+ // The command echo needs to know which form was used, because `-b` swaps the
991
+ // argument order and both a path and a branch can follow `add`:
992
+ //
993
+ // gwq add -b <branch> -> git worktree add -b <branch> <path>: …
994
+ // gwq add <branch> -> git worktree add <path> <branch>: …
995
+ //
996
+ // Guessing cost real time once already: a pattern that stopped at the first
997
+ // space read the path-first form correctly by accident, and a pattern that ran
998
+ // to the colon swallowed the branch with it.
999
+ const collisionFromCmd = (out, withB) => (withB
1000
+ ? out.match(/git worktree add -b \S+ (.+?): /)
1001
+ : out.match(/git worktree add (.+?) \S+: /))?.[1];
1002
+
1003
+ function collisionPath(out, withB) {
1004
+ const quoted = out.match(COLLISION_QUOTED)?.[1];
1005
+ return (quoted ?? collisionFromCmd(out, withB) ?? '').trim();
1006
+ }
947
1007
 
948
1008
  function timestamp() {
949
1009
  const d = new Date();
@@ -1054,7 +1114,7 @@ async function main() {
1054
1114
  };
1055
1115
 
1056
1116
  if (status !== 0) {
1057
- const collide = out.match(COLLISION)?.[1] ?? '';
1117
+ const collide = collisionPath(out, addArgs[0] === '-b');
1058
1118
  // gwq's own -f does not reach `git worktree add` (verified against v0.1.1),
1059
1119
  // so a collision has to be cleared here or not at all.
1060
1120
  if (collide && existsSync(collide) && force) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gwqadd",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Create a branch and its gwq worktree in the repository you are in, and cd there.",
5
5
  "type": "module",
6
6
  "bin": {