@simple-git/argv-parser 3.0.0 → 3.1.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/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { isPathSpec as b, toPaths as _ } from "@simple-git/args-pathspec";
2
- function* L(e, t) {
2
+ function* F(e, t) {
3
3
  const n = t === "global";
4
4
  for (const o of e)
5
5
  o.isGlobal === n && (yield o);
6
6
  }
7
- const K = /* @__PURE__ */ new Set([
7
+ const W = /* @__PURE__ */ new Set([
8
8
  "--add",
9
9
  "--edit",
10
10
  "--remove-section",
@@ -13,7 +13,7 @@ const K = /* @__PURE__ */ new Set([
13
13
  "--unset",
14
14
  "--unset-all",
15
15
  "-e"
16
- ]), I = /* @__PURE__ */ new Set([
16
+ ]), K = /* @__PURE__ */ new Set([
17
17
  "--get",
18
18
  "--get-all",
19
19
  "--get-color",
@@ -29,17 +29,17 @@ const K = /* @__PURE__ */ new Set([
29
29
  "set",
30
30
  "unset"
31
31
  ]), D = /* @__PURE__ */ new Set(["get", "get-color", "get-colorbool", "list"]);
32
- function B(e, t) {
33
- for (const { name: o } of L(e, "task")) {
32
+ function I(e, t) {
33
+ for (const { name: o } of F(e, "task")) {
34
+ if (W.has(o))
35
+ return v(!0, t, o === "--rename-section");
34
36
  if (K.has(o))
35
- return w(!0, t, o === "--rename-section");
36
- if (I.has(o))
37
- return w(!1, t);
37
+ return v(!1, t);
38
38
  }
39
39
  const n = t.at(0)?.toLowerCase();
40
- return n === void 0 ? null : j.has(n) ? w(!0, t.slice(1), n === "rename-section") : D.has(n) ? w(!1, t.slice(1)) : t.length === 1 ? w(!1, t) : w(!0, t);
40
+ return n === void 0 ? null : j.has(n) ? v(!0, t.slice(1), n === "rename-section") : D.has(n) ? v(!1, t.slice(1)) : t.length === 1 ? v(!1, t) : v(!0, t);
41
41
  }
42
- function w(e = !1, t = [], n = !1) {
42
+ function v(e = !1, t = [], n = !1) {
43
43
  const o = t.at(0)?.toLowerCase();
44
44
  return o === void 0 ? null : {
45
45
  isWrite: e,
@@ -49,7 +49,7 @@ function w(e = !1, t = [], n = !1) {
49
49
  rename: n
50
50
  };
51
51
  }
52
- function V(e, t) {
52
+ function B(e, t) {
53
53
  return t.isWrite && t.value !== void 0 ? {
54
54
  scope: e,
55
55
  key: t.key,
@@ -57,15 +57,15 @@ function V(e, t) {
57
57
  rename: t.rename
58
58
  } : { key: t.key, scope: e };
59
59
  }
60
- function q(e) {
60
+ function V(e) {
61
61
  const t = e?.indexOf("=") || -1;
62
62
  return !e || t < 0 ? null : {
63
63
  key: e.slice(0, t).trim().toLowerCase(),
64
64
  value: e.slice(t + 1)
65
65
  };
66
66
  }
67
- function z(e) {
68
- for (const { name: t } of L(e, "task"))
67
+ function q(e) {
68
+ for (const { name: t } of F(e, "task"))
69
69
  switch (t) {
70
70
  case "--global":
71
71
  return "global";
@@ -81,7 +81,7 @@ function z(e) {
81
81
  }
82
82
  return "local";
83
83
  }
84
- function Y({ name: e }) {
84
+ function z({ name: e }) {
85
85
  if (e === "-c" || e === "--config")
86
86
  return "inline";
87
87
  if (e === "--config-env")
@@ -89,37 +89,32 @@ function Y({ name: e }) {
89
89
  }
90
90
  function* H(e) {
91
91
  for (const t of e) {
92
- const n = Y(t), o = n && q(t.value);
92
+ const n = z(t), o = n && V(t.value);
93
93
  o && (yield {
94
94
  ...o,
95
95
  scope: n
96
96
  });
97
97
  }
98
98
  }
99
- function J(e, t, n) {
99
+ function Y(e, t, n) {
100
100
  const o = {
101
101
  read: [],
102
102
  write: [...H(t)]
103
103
  };
104
- return e === "config" && X(
104
+ return e === "config" && J(
105
105
  o,
106
- z(t),
107
- B(t, n)
106
+ q(t),
107
+ I(t, n)
108
108
  ), o;
109
109
  }
110
- function X(e, t, n) {
110
+ function J(e, t, n) {
111
111
  if (n === null)
112
112
  return;
113
- const o = V(t, n);
113
+ const o = B(t, n);
114
114
  n.isWrite ? e.write.push(o) : e.read.push(o);
115
115
  }
116
- const R = {
116
+ const S = {
117
117
  short: /* @__PURE__ */ new Map([
118
- ["c", !0]
119
- // -c <k=v> set config key for this invocation
120
- ])
121
- }, S = {
122
- short: new Map([
123
118
  ["C", !0],
124
119
  // -C <path> change working directory
125
120
  ["P", !1],
@@ -130,7 +125,8 @@ const R = {
130
125
  // -p paginate
131
126
  ["v", !1],
132
127
  // -v version
133
- ...R.short.entries()
128
+ ["c", !0]
129
+ // -c <k=v> set config key for this invocation
134
130
  ]),
135
131
  long: /* @__PURE__ */ new Set([
136
132
  "attr-source",
@@ -142,11 +138,20 @@ const R = {
142
138
  "super-prefix",
143
139
  "work-tree"
144
140
  ])
145
- }, Q = {
141
+ }, X = {
142
+ archive: {
143
+ short: /* @__PURE__ */ new Map([
144
+ ["c", !1]
145
+ // no `-c` of its own, with `--remote` unknown options are sent to the remote
146
+ ]),
147
+ long: /* @__PURE__ */ new Set()
148
+ },
146
149
  clone: {
147
150
  short: /* @__PURE__ */ new Map([
148
151
  ["b", !0],
149
152
  // -b <branch>
153
+ ["c", !0],
154
+ // -c <k=v> set config key in the new repository
150
155
  ["j", !0],
151
156
  // -j <n> parallel jobs
152
157
  ["l", !1],
@@ -190,14 +195,51 @@ const R = {
190
195
  ]),
191
196
  long: /* @__PURE__ */ new Set(["blob", "comment", "default", "file", "type", "value"])
192
197
  },
198
+ difftool: {
199
+ short: /* @__PURE__ */ new Map([
200
+ ["d", !1],
201
+ // -d dir-diff
202
+ ["g", !1],
203
+ // -g gui
204
+ ["h", !1],
205
+ // -h help
206
+ ["t", !0],
207
+ // -t <tool>
208
+ ["x", !0],
209
+ // -x <command>
210
+ ["y", !1]
211
+ // -y no-prompt
212
+ ]),
213
+ long: /* @__PURE__ */ new Set(["extcmd", "tool"])
214
+ },
193
215
  fetch: {
194
216
  short: /* @__PURE__ */ new Map(),
195
217
  long: /* @__PURE__ */ new Set(["upload-pack"])
196
218
  },
219
+ grep: {
220
+ short: /* @__PURE__ */ new Map([
221
+ ["c", !1]
222
+ // -c count
223
+ ]),
224
+ long: /* @__PURE__ */ new Set()
225
+ },
197
226
  init: {
198
227
  short: /* @__PURE__ */ new Map(),
199
228
  long: /* @__PURE__ */ new Set(["template"])
200
229
  },
230
+ notes: {
231
+ short: /* @__PURE__ */ new Map([
232
+ ["C", !0],
233
+ // -C <object> reuse message
234
+ ["F", !0],
235
+ // -F <file> read message from file
236
+ ["c", !0],
237
+ // -c <object> reedit message
238
+ ["m", !0]
239
+ // -m <msg>
240
+ ]),
241
+ long: /* @__PURE__ */ new Set(["file", "message", "reedit-message", "reuse-message"])
242
+ },
201
243
  pull: {
202
244
  short: /* @__PURE__ */ new Map(),
203
245
  long: /* @__PURE__ */ new Set(["upload-pack"])
@@ -232,16 +274,29 @@ const R = {
232
274
  // -x <cmd> exec
233
275
  ]),
234
276
  long: /* @__PURE__ */ new Set(["exec", "onto", "strategy", "strategy-option"])
277
+ },
278
+ "send-email": {
279
+ short: /* @__PURE__ */ new Map(),
280
+ long: /* @__PURE__ */ new Set(["cc-cmd", "header-cmd", "sendmail-cmd", "to-cmd"])
281
+ },
282
+ switch: {
283
+ short: /* @__PURE__ */ new Map([
284
+ ["C", !0],
285
+ // -C <branch> force create
286
+ ["c", !0]
287
+ // -c <branch> create
288
+ ]),
289
+ long: /* @__PURE__ */ new Set(["create", "force-create", "orphan"])
235
290
  }
236
- }, Z = { short: /* @__PURE__ */ new Map(), long: /* @__PURE__ */ new Set() };
237
- function ee(e) {
238
- const t = Q[e ?? ""] ?? Z;
291
+ }, Q = { short: /* @__PURE__ */ new Map(), long: /* @__PURE__ */ new Set() };
292
+ function Z(e) {
293
+ const t = X[e ?? ""] ?? Q;
239
294
  return {
240
- short: new Map([...R.short.entries(), ...t.short.entries()]),
295
+ short: new Map([["c", !1], ...t.short.entries()]),
241
296
  long: t.long
242
297
  };
243
298
  }
244
- function F(e, t = S) {
299
+ function L(e, t = S) {
245
300
  if (e.startsWith("--")) {
246
301
  const n = e.indexOf("=");
247
302
  if (n > 2)
@@ -253,56 +308,56 @@ function F(e, t = S) {
253
308
  const n = e.charAt(1), o = t.short.get(n);
254
309
  return [{ name: e, needsNext: o === !0 }];
255
310
  }
256
- return te(e, t.short);
311
+ return ee(e, t.short);
257
312
  }
258
- function te(e, t) {
313
+ function ee(e, t) {
259
314
  const n = e.slice(1).split(""), o = [];
260
315
  for (let a = 0; a < n.length; a++) {
261
316
  const s = n[a], r = t.get(s);
262
317
  if (r === void 0)
263
318
  return [{ name: e, needsNext: !1 }];
264
319
  if (r) {
265
- const f = n.slice(a + 1).join("");
266
- if (f && ![...f].every((v) => t.has(v)))
267
- return o.push({ name: `-${s}`, value: f, needsNext: !1 }), o;
320
+ const u = n.slice(a + 1).join("");
321
+ if (u && ![...u].every((w) => t.has(w)))
322
+ return o.push({ name: `-${s}`, value: u, needsNext: !1 }), o;
268
323
  }
269
324
  o.push({ name: `-${s}`, needsNext: r });
270
325
  }
271
326
  return o;
272
327
  }
273
- function ne(e, t = []) {
328
+ function te(e, t = []) {
274
329
  let n = 0;
275
330
  for (; n < e.length; ) {
276
331
  const o = String(e[n]);
277
332
  if (!o.startsWith("-") || o.length < 2) break;
278
- const a = F(o);
333
+ const a = L(o);
279
334
  let s = n + 1;
280
335
  for (const r of a) {
281
- const f = {
336
+ const u = {
282
337
  name: r.name,
283
338
  value: r.value,
284
339
  absorbedNext: !1,
285
340
  isGlobal: !0
286
341
  };
287
- r.needsNext && f.value === void 0 && s < e.length && (f.value = String(e[s]), f.absorbedNext = !0, s++), t.push(f);
342
+ r.needsNext && u.value === void 0 && s < e.length && (u.value = String(e[s]), u.absorbedNext = !0, s++), t.push(u);
288
343
  }
289
344
  n = s;
290
345
  }
291
346
  return { flags: t, taskIndex: n };
292
347
  }
293
- function oe(e, t, n = []) {
294
- const o = ee(t), a = [], s = [];
348
+ function ne(e, t, n = []) {
349
+ const o = Z(t), a = [], s = [];
295
350
  let r = 0;
296
351
  for (; r < e.length; ) {
297
- const f = e[r];
298
- if (b(f)) {
299
- s.push(..._(f)), r++;
352
+ const u = e[r];
353
+ if (b(u)) {
354
+ s.push(..._(u)), r++;
300
355
  continue;
301
356
  }
302
- const p = String(f);
357
+ const p = String(u);
303
358
  if (p === "--") {
304
- for (let i = r + 1; i < e.length; i++) {
305
- const d = e[i];
359
+ for (let c = r + 1; c < e.length; c++) {
360
+ const d = e[c];
306
361
  b(d) ? s.push(..._(d)) : s.push(String(d));
307
362
  }
308
363
  break;
@@ -311,21 +366,24 @@ function oe(e, t, n = []) {
311
366
  a.push(p), r++;
312
367
  continue;
313
368
  }
314
- const v = F(p, o);
369
+ const w = L(p, o);
315
370
  let h = r + 1;
316
- for (const i of v) {
371
+ for (const c of w) {
317
372
  const d = {
318
- name: i.name,
319
- value: i.value,
373
+ name: c.name,
374
+ value: c.value,
320
375
  absorbedNext: !1,
321
376
  isGlobal: !1
322
377
  };
323
- i.needsNext && d.value === void 0 && h < e.length && !b(e[h]) && (d.value = String(e[h]), d.absorbedNext = !0, h++), n.push(d);
378
+ c.needsNext && d.value === void 0 && h < e.length && !b(e[h]) ? (d.value = String(e[h]), d.absorbedNext = !0, h++) : oe(c, d, e[h]) && (d.value = String(e[h])), n.push(d);
324
379
  }
325
380
  r = h;
326
381
  }
327
382
  return { flags: n, positionals: a, pathspecs: s };
328
383
  }
384
+ function oe(e, t, n) {
385
+ return e.name === "-c" && !e.needsNext && t.value === void 0 && typeof n == "string" && !n.startsWith("-") && n.includes("=");
386
+ }
329
387
  function* ae({
330
388
  write: e
331
389
  }) {
@@ -347,7 +405,7 @@ function* ae({
347
405
  }
348
406
  }
349
407
  }
350
- function u(e, t, n = String(e), o = "default") {
408
+ function i(e, t, n = String(e), o = "default") {
351
409
  const a = typeof e == "string" ? new RegExp(`\\s*${e.toLowerCase()}`) : e;
352
410
  return function(r) {
353
411
  if (a.test(r))
@@ -359,57 +417,59 @@ function u(e, t, n = String(e), o = "default") {
359
417
  };
360
418
  };
361
419
  }
362
- function c(e, t) {
420
+ function f(e, t) {
363
421
  const n = new RegExp(`\\s*${e.toLowerCase().replace(/\./g, "(..+)?.")}`);
364
- return u(n, t, e);
422
+ return i(n, t, e);
365
423
  }
366
424
  const se = /^sendemail\.(.+\.)?(sendmailcmd|tocmd|cccmd|headercmd|smtpserver|smtpserveroption|smtpsslcertpath|smtpsslclientcert|smtpsslclientkey|aliasesfile|mailmap\.file)$/, re = /^imap\.(tunnel|host|sslverify)$/, le = /^instaweb\.(httpd|modulepath|gitwebdir)$/, ie = /^(browser|man)\..+\.(path|cmd)$/, ce = /^gpg\.(ssh\.(allowedsignersfile|revocationfile)|mintrustlevel)$/, fe = [
367
- u(se, "allowUnsafeSendEmailConfig", "sendemail.*"),
368
- u(re, "allowUnsafeSendEmailConfig", "imap.*"),
369
- u(le, "allowUnsafeWebServerConfig", "instaweb.*"),
370
- u(ie, "allowUnsafeBrowser", "browser.* / man.*"),
371
- u(ce, "allowUnsafeSignatureTrust", "gpg.* signature trust"),
372
- u("alias", "allowUnsafeAlias"),
373
- u("core.askPass", "allowUnsafeAskPass"),
374
- u("core.editor", "allowUnsafeEditor"),
375
- u("core.fsmonitor", "allowUnsafeFsMonitor"),
376
- u("core.gitProxy", "allowUnsafeGitProxy"),
377
- u("core.hooksPath", "allowUnsafeHooksPath"),
378
- u("core.pager", "allowUnsafePager"),
379
- u("core.sshCommand", "allowUnsafeSshCommand"),
380
- c("credential.helper", "allowUnsafeCredentialHelper"),
381
- c("diff.command", "allowUnsafeDiffExternal"),
382
- u("diff.external", "allowUnsafeDiffExternal"),
383
- c("difftool.cmd", "allowUnsafeDiffExternal"),
384
- c("difftool.path", "allowUnsafeDiffExternal"),
385
- c("diff.textconv", "allowUnsafeDiffTextConv"),
386
- c("filter.clean", "allowUnsafeFilter"),
387
- c("filter.process", "allowUnsafeFilter"),
388
- c("filter.smudge", "allowUnsafeFilter"),
389
- c("gpg.program", "allowUnsafeGpgProgram"),
390
- c("gpg.defaultKeyCommand", "allowUnsafeGpgProgram"),
391
- u("include.path", "allowUnsafeInclude"),
392
- c("includeIf", "allowUnsafeInclude"),
393
- u("init.templateDir", "allowUnsafeTemplateDir"),
394
- u("interactive.diffFilter", "allowUnsafePager"),
395
- c("pager.", "allowUnsafePager"),
396
- c("merge.driver", "allowUnsafeMergeDriver"),
397
- c("mergetool.path", "allowUnsafeMergeDriver"),
398
- c("mergetool.cmd", "allowUnsafeMergeDriver"),
399
- c("protocol.allow", "allowUnsafeProtocolOverride"),
400
- c("remote.receivepack", "allowUnsafePack"),
401
- c("remote.uploadpack", "allowUnsafePack"),
402
- u("uploadpack.packObjectsHook", "allowUnsafePack"),
403
- u("sequence.editor", "allowUnsafeEditor"),
404
- c("submodule.update", "allowUnsafeSubmodule"),
405
- c("tar.command", "allowUnsafeCommandBinaries"),
406
- c("trailer.cmd", "allowUnsafeCommandBinaries"),
407
- c("trailer.command", "allowUnsafeCommandBinaries"),
408
- c("url.insteadOf", "allowUnsafeUrlRewrite"),
409
- // catch-all configuration using the "foo.command" or "bar.cmd" naming convention, only blocked
410
- // when the `recommended` checks are enabled
411
- u(/command$/, "allowUnsafeCommandBinaries", "/command$/", "recommended"),
412
- u(/\.cmd$/, "allowUnsafeCommandBinaries", "/\\.cmd$/", "recommended")
425
+ i(se, "allowUnsafeSendEmailConfig", "sendemail.*"),
426
+ i(re, "allowUnsafeSendEmailConfig", "imap.*"),
427
+ i(le, "allowUnsafeWebServerConfig", "instaweb.*"),
428
+ i(ie, "allowUnsafeBrowser", "browser.* / man.*"),
429
+ i(ce, "allowUnsafeSignatureTrust", "gpg.* signature trust"),
430
+ i("alias", "allowUnsafeAlias"),
431
+ i("core.askPass", "allowUnsafeAskPass"),
432
+ i("core.editor", "allowUnsafeEditor"),
433
+ i("core.fsmonitor", "allowUnsafeFsMonitor"),
434
+ i("core.gitProxy", "allowUnsafeGitProxy"),
435
+ i("core.hooksPath", "allowUnsafeHooksPath"),
436
+ i("core.pager", "allowUnsafePager"),
437
+ i("core.sshCommand", "allowUnsafeSshCommand"),
438
+ f("credential.helper", "allowUnsafeCredentialHelper"),
439
+ f("diff.command", "allowUnsafeDiffExternal"),
440
+ i("diff.external", "allowUnsafeDiffExternal"),
441
+ f("difftool.cmd", "allowUnsafeDiffExternal"),
442
+ f("difftool.path", "allowUnsafeDiffExternal"),
443
+ f("diff.textconv", "allowUnsafeDiffTextConv"),
444
+ f("filter.clean", "allowUnsafeFilter"),
445
+ f("filter.process", "allowUnsafeFilter"),
446
+ f("filter.smudge", "allowUnsafeFilter"),
447
+ f("gpg.program", "allowUnsafeGpgProgram"),
448
+ f("gpg.defaultKeyCommand", "allowUnsafeGpgProgram"),
449
+ i("gc.recentObjectsHook", "allowUnsafeExec"),
450
+ i("include.path", "allowUnsafeInclude"),
451
+ f("includeIf", "allowUnsafeInclude"),
452
+ i("init.templateDir", "allowUnsafeTemplateDir"),
453
+ i("interactive.diffFilter", "allowUnsafePager"),
454
+ f("pager.", "allowUnsafePager"),
455
+ f("merge.driver", "allowUnsafeMergeDriver"),
456
+ f("mergetool.path", "allowUnsafeMergeDriver"),
457
+ f("mergetool.cmd", "allowUnsafeMergeDriver"),
458
+ f("protocol.allow", "allowUnsafeProtocolOverride"),
459
+ f("remote.receivepack", "allowUnsafePack"),
460
+ f("remote.uploadpack", "allowUnsafePack"),
461
+ i("uploadpack.packObjectsHook", "allowUnsafePack"),
462
+ i("sequence.editor", "allowUnsafeEditor"),
463
+ f("submodule.update", "allowUnsafeSubmodule"),
464
+ f("tar.command", "allowUnsafeCommandBinaries"),
465
+ f("trailer.cmd", "allowUnsafeCommandBinaries"),
466
+ f("trailer.command", "allowUnsafeCommandBinaries"),
467
+ f("url.insteadOf", "allowUnsafeUrlRewrite"),
468
+ // catch-all configuration using the "foo.command", "bar.cmd" or "baz.someHook" naming conventions,
469
+ // only blocked when the `recommended` checks are enabled
470
+ i(/command$/, "allowUnsafeCommandBinaries", "/command$/", "recommended"),
471
+ i(/\.cmd$/, "allowUnsafeCommandBinaries", "/\\.cmd$/", "recommended"),
472
+ i(/hook$/, "allowUnsafeCommandBinaries", "/hook$/", "recommended")
413
473
  ];
414
474
  function* ue(e, t) {
415
475
  for (const n of t)
@@ -418,66 +478,95 @@ function* ue(e, t) {
418
478
  a && (yield a);
419
479
  }
420
480
  }
421
- function g(e, t, n, {
481
+ function m(e, t, n, {
422
482
  name: o = String(t),
423
483
  exceptTask: a,
424
484
  globalOnly: s = !1,
425
- withValue: r = !1
485
+ withValue: r = !1,
486
+ level: u = "default"
426
487
  } = {}) {
427
- const f = typeof t == "string" ? new RegExp(`\\s*${t.toLowerCase()}`) : t, p = `Use of ${e ? `${e} with option ` : ""}${o} is not permitted without enabling ${n}`;
428
- return function(h, i) {
429
- if (!(e && h !== e) && !(a && h === a) && !(s && !i.isGlobal) && !(r && i.value === void 0) && f.test(i.name))
488
+ const p = typeof t == "string" ? new RegExp(`\\s*${t.toLowerCase()}`) : t, w = `Use of ${e ? `${e} with option ` : ""}${o} is not permitted without enabling ${n}`;
489
+ return function(c, d) {
490
+ if (!(e && c !== e) && !(a && c === a) && !(s && !d.isGlobal) && !(r && d.value === void 0) && p.test(d.name))
430
491
  return {
431
492
  category: n,
432
- level: "default",
433
- message: p
493
+ level: u,
494
+ message: w
434
495
  };
435
496
  };
436
497
  }
437
498
  const y = { globalOnly: !0, withValue: !0 }, de = [
438
- g(null, /--(upload|receive)-pack/, "allowUnsafePack", {
499
+ m(null, /--(upload|receive)-pack/, "allowUnsafePack", {
439
500
  name: "--upload-pack or --receive-pack"
440
501
  }),
441
- g("clone", /^-\w*u/, "allowUnsafePack"),
442
- g("clone", "--u", "allowUnsafePack"),
502
+ m("clone", /^-\w*u/, "allowUnsafePack"),
503
+ m("clone", "--u", "allowUnsafePack"),
443
504
  // `--exec` names the program run on the remote end of `push`, `send-pack`, `fetch-pack`, `archive` and
444
505
  // (undocumented) `ls-remote`, `rebase` uses it for a command run after each commit
445
- g(null, /^--exec$/, "allowUnsafePack", {
506
+ m(null, /^--exec$/, "allowUnsafePack", {
446
507
  name: "--exec",
447
508
  exceptTask: "rebase"
448
509
  }),
449
510
  // `git` accepts unambiguous abbreviations of long options, so `--ex` and `--exe` are `--exec`
450
- g("rebase", /^(-x|--ex(ec?)?)$/, "allowUnsafeExec", { name: "-x or --exec" }),
511
+ m("rebase", /^(-x|--ex(ec?)?)$/, "allowUnsafeExec", { name: "-x or --exec" }),
451
512
  // `git filter-branch` runs the value of each of these through `eval`
452
- g(
513
+ m(
453
514
  "filter-branch",
454
515
  /^--(setup|(env|tree|index|parent|msg|commit|tag-name)-filter)$/,
455
516
  "allowUnsafeExec",
456
517
  { name: "--setup or --<type>-filter" }
457
518
  ),
519
+ // `git send-email` runs the value of each of these as a shell command. It reads its options with Perl's
520
+ // Getopt::Long, which accepts unambiguous abbreviations (`--to-cm`, `--sendm`) and a single leading dash.
521
+ m("send-email", /^--?(to-cm|cc-cm|hea|sendm)[a-z-]*(=|$)/, "allowUnsafeExec", {
522
+ name: "--to-cmd, --cc-cmd, --header-cmd or --sendmail-cmd"
523
+ }),
524
+ // `git difftool` runs the value of `-x` / `--extcmd` as the diff command. It passes options it doesn't
525
+ // know on to `git diff`, so an abbreviation such as `--extc` is never read as `--extcmd`, and in a short
526
+ // cluster `x` is only `-x` when it follows difftool's own switches (`-d`, `-g`, `-h`, `-y`): in `-tlinux`
527
+ // it is part of the tool name, and a cluster such as `-px` is handed to `git diff` as a whole.
528
+ m("difftool", /^(-[dghy]*x|--extcmd$)/, "allowUnsafeExec", {
529
+ name: "-x or --extcmd"
530
+ }),
458
531
  // `git grep` configures a pager with `-O<cmd>` (potentially clustered as `-iO<cmd>`), or through the long-form
459
532
  // `--open-files-in-pager`. Without a value both use the configured pager, so are permitted.
460
- g("grep", /^-\w*O./, "allowUnsafePager", { name: "-O" }),
461
- g("grep", "--open-files-in-pager", "allowUnsafePager", { withValue: !0 }),
462
- g(null, "--template", "allowUnsafeTemplateDir"),
463
- g(null, "--exec-path", "allowUnsafeExec", y),
533
+ m("grep", /^-\w*O./, "allowUnsafePager", { name: "-O" }),
534
+ m("grep", "--open-files-in-pager", "allowUnsafePager", { withValue: !0 }),
535
+ // options that write their output to a path named in the command, enforced with the recommended checks:
536
+ // `--output=<file>` is a diff option (`diff`, `log`, `show`, `format-patch`, ...) and an `archive` option,
537
+ // `format-patch -o <dir>` / `--output-directory` and `archive -o <file>` are their short / directory forms.
538
+ // `--output-indicator-*` are unrelated diff options and remain permitted.
539
+ m(null, /^--output$/, "allowUnsafeOutputPath", {
540
+ name: "--output",
541
+ level: "recommended"
542
+ }),
543
+ m("format-patch", /^(-\w*o|--output-directory$)/, "allowUnsafeOutputPath", {
544
+ name: "-o or --output-directory",
545
+ level: "recommended"
546
+ }),
547
+ m("archive", /^-\w*o/, "allowUnsafeOutputPath", {
548
+ name: "-o",
549
+ level: "recommended"
550
+ }),
551
+ m(null, "--template", "allowUnsafeTemplateDir"),
552
+ m(null, "--exec-path", "allowUnsafeExec", y),
464
553
  // `git` reads the configuration of whichever repository these name, so the
465
554
  // directory alone is enough to deliver config the argv guards never see
466
- g(null, "--git-dir", "allowUnsafeConfigPaths", y),
467
- g(null, "--work-tree", "allowUnsafeConfigPaths", y),
468
- g(null, /^-C$/, "allowUnsafeConfigPaths", { ...y, name: "-C" })
555
+ m(null, "--git-dir", "allowUnsafeConfigPaths", y),
556
+ m(null, "--work-tree", "allowUnsafeConfigPaths", y),
557
+ m(null, /^-C$/, "allowUnsafeConfigPaths", { ...y, name: "-C" })
469
558
  ];
470
- function G(e, t, n) {
559
+ function R(e, t, n) {
471
560
  return [...ue(e, t), ...ae(n)];
472
561
  }
473
562
  function Ae(...e) {
474
- const { flags: t, taskIndex: n } = ne(e), o = n < e.length ? String(e[n]).toLowerCase() : null, a = o !== null ? e.slice(n + 1) : [], { positionals: s, pathspecs: r } = oe(a, o, t), f = J(o, t, s);
563
+ const { flags: t, taskIndex: n } = te(e), o = n < e.length ? String(e[n]).toLowerCase() : null, a = o !== null ? e.slice(n + 1) : [], { positionals: s, pathspecs: r } = ne(a, o, t), u = Y(o, t, s);
475
564
  return {
476
565
  task: o,
477
566
  flags: t.map(ge),
478
567
  paths: r,
479
- config: f,
480
- vulnerabilities: me(G(o, t, f))
568
+ config: u,
569
+ vulnerabilities: me(R(o, t, u))
481
570
  };
482
571
  }
483
572
  function me(e) {
@@ -598,7 +687,7 @@ function he(e) {
598
687
  return t.has(a) || n.some((s) => s.test(a));
599
688
  };
600
689
  }
601
- const Le = he(pe), N = {
690
+ const Fe = he(pe), M = {
602
691
  editor: "allowUnsafeEditor",
603
692
  git_askpass: "allowUnsafeAskPass",
604
693
  git_config_global: "allowUnsafeConfigPaths",
@@ -619,12 +708,12 @@ const Le = he(pe), N = {
619
708
  prefix: "allowUnsafeConfigPaths",
620
709
  ssh_askpass: "allowUnsafeAskPass",
621
710
  visual: "allowUnsafeEditor"
622
- }, T = {
711
+ }, G = {
623
712
  home: "allowUnsafeConfigPaths",
624
713
  xdg_config_home: "allowUnsafeConfigPaths"
625
714
  };
626
- function W(e) {
627
- return Object.hasOwn(T, e);
715
+ function N(e) {
716
+ return Object.hasOwn(G, e);
628
717
  }
629
718
  function* we(e) {
630
719
  const t = parseInt(e.git_config_count ?? "0", 10);
@@ -635,8 +724,8 @@ function* we(e) {
635
724
  }
636
725
  function* ve(e, t) {
637
726
  for (const n of Object.keys(e))
638
- if (W(n) && e[n] !== t[n]) {
639
- const o = T[n];
727
+ if (N(n) && e[n] !== t[n]) {
728
+ const o = G[n];
640
729
  yield {
641
730
  category: o,
642
731
  level: "recommended",
@@ -647,8 +736,8 @@ function* ve(e, t) {
647
736
  }
648
737
  function* be(e) {
649
738
  for (const t of Object.keys(e))
650
- if (M(t)) {
651
- const n = N[t];
739
+ if (T(t)) {
740
+ const n = M[t];
652
741
  yield {
653
742
  category: n,
654
743
  level: "default",
@@ -657,42 +746,42 @@ function* be(e) {
657
746
  };
658
747
  }
659
748
  }
660
- function M(e) {
661
- return Object.hasOwn(N, e);
749
+ function T(e) {
750
+ return Object.hasOwn(M, e);
662
751
  }
663
752
  function Ue(e) {
664
753
  const t = String(e).toLowerCase().trim();
665
- return t.startsWith("git_") || M(t);
754
+ return t.startsWith("git_") || T(t);
666
755
  }
667
756
  function $(e) {
668
757
  const t = {};
669
758
  for (const [n, o] of Object.entries(e)) {
670
759
  const a = n.toLowerCase().trim();
671
- (Ue(a) || W(a)) && (t[a] = String(o));
760
+ (Ue(a) || N(a)) && (t[a] = String(o));
672
761
  }
673
762
  return t;
674
763
  }
675
- function Re(e, t = {}) {
764
+ function Le(e, t = {}) {
676
765
  const n = $(e), o = {
677
766
  read: [],
678
767
  write: [...we(n)]
679
768
  }, a = [
680
769
  ...be(n),
681
770
  ...ve(n, $(t)),
682
- ...G(null, [], o)
771
+ ...R(null, [], o)
683
772
  ];
684
773
  return {
685
774
  config: o,
686
775
  vulnerabilities: a
687
776
  };
688
777
  }
689
- class k {
778
+ class E {
690
779
  constructor(t, n) {
691
780
  this.value = t, this.validate = n;
692
781
  }
693
782
  }
694
- function Fe(e) {
695
- return new k(String(e), (t) => {
783
+ function Re(e) {
784
+ return new E(String(e), (t) => {
696
785
  if (!t || t === "@" || t.includes("..") || t.includes("@{") || t.includes("//") || /[\s~^:?*[\\]/.test(t) || t.endsWith("/") || t.endsWith(".") || t.split("/").some((n) => n.startsWith(".") || n.endsWith(".lock")))
697
786
  return "not a valid ref name";
698
787
  });
@@ -708,9 +797,9 @@ const ye = [
708
797
  "scp",
709
798
  "local"
710
799
  ], xe = new Set(ye), Ce = /^([a-z][a-z0-9+.-]*):\/\//i, Se = /^(?:([^@/]+)@)?([^/:]+):(?!\/\/)/;
711
- function Ge(e, { protocols: t } = {}) {
800
+ function Me(e, { protocols: t } = {}) {
712
801
  const n = t ? new Set(t) : xe;
713
- return new k(String(e), (o) => {
802
+ return new E(String(e), (o) => {
714
803
  const a = Ce.exec(o)?.[1]?.toLowerCase();
715
804
  if (a !== void 0) {
716
805
  if (!n.has(a))
@@ -727,14 +816,14 @@ function Ge(e, { protocols: t } = {}) {
727
816
  return s && !/^[a-z]:[\\/]/i.test(o) ? n.has("scp") ? s[1]?.startsWith("-") || s[2].startsWith("-") ? 'host and user names must not start with "-"' : void 0 : "scp-like urls are not permitted" : n.has("local") ? void 0 : "local paths are not permitted";
728
817
  });
729
818
  }
730
- class ke extends Error {
819
+ class Ee extends Error {
731
820
  }
732
- const Ee = /[\u0000-\u001f\u007f]/, _e = /^[a-z][a-z0-9+.-]*::/i, P = /* @__PURE__ */ new Set(["-c", "--config", "--config-env"]), O = /* @__PURE__ */ new Set([
821
+ const ke = /[\u0000-\u001f\u007f]/, _e = /^[a-z][a-z0-9+.-]*::/i, P = /* @__PURE__ */ new Set(["-c", "--config", "--config-env"]), O = /* @__PURE__ */ new Set([
733
822
  ...[...S.short].filter(([, e]) => e).map(([e]) => `-${e}`),
734
823
  ...[...S.long].map((e) => `--${e}`)
735
824
  ]);
736
- function m(e) {
737
- throw new ke(e);
825
+ function g(e) {
826
+ throw new Ee(e);
738
827
  }
739
828
  function $e(e) {
740
829
  return Array.isArray(e) && Array.isArray(e.raw) && Object.isFrozen(e);
@@ -744,14 +833,14 @@ function U(e) {
744
833
  }
745
834
  function A(e) {
746
835
  let t;
747
- if (e instanceof k) {
836
+ if (e instanceof E) {
748
837
  t = e.value;
749
838
  const n = e.validate(t);
750
- n && m(`interpolated value ${U(t)} is rejected: ${n}`);
751
- } else typeof e == "string" ? t = e : typeof e == "number" && Number.isFinite(e) ? t = String(e) : m(
839
+ n && g(`interpolated value ${U(t)} is rejected: ${n}`);
840
+ } else typeof e == "string" ? t = e : typeof e == "number" && Number.isFinite(e) ? t = String(e) : g(
752
841
  `interpolated values must be strings, finite numbers or arrays of them, received ${typeof e}`
753
842
  );
754
- return Ee.test(t) && m(`interpolated value ${U(t)} contains control characters`), _e.test(t) && m(`interpolated value ${U(t)} would select a git remote helper transport`), t;
843
+ return ke.test(t) && g(`interpolated value ${U(t)} contains control characters`), _e.test(t) && g(`interpolated value ${U(t)} would select a git remote helper transport`), t;
755
844
  }
756
845
  function Pe(e, t) {
757
846
  const n = [];
@@ -760,13 +849,13 @@ function Pe(e, t) {
760
849
  o.length && (n.push(o), o = []);
761
850
  };
762
851
  return e.forEach((s, r) => {
763
- for (const f of s.split(/(\s+)/))
764
- /^\s+$/.test(f) ? a() : f && o.push({ text: f });
852
+ for (const u of s.split(/(\s+)/))
853
+ /^\s+$/.test(u) ? a() : u && o.push({ text: u });
765
854
  r < t.length && o.push({ text: "", value: t[r] });
766
855
  }), a(), n;
767
856
  }
768
- function Ne(e, t) {
769
- $e(e) || m("must be used as a tagged template literal");
857
+ function Ge(e, t) {
858
+ $e(e) || g("must be used as a tagged template literal");
770
859
  const n = [];
771
860
  let o, a = !1, s;
772
861
  for (const r of Pe(e, t)) {
@@ -776,11 +865,11 @@ function Ne(e, t) {
776
865
  continue;
777
866
  }
778
867
  const p = !("value" in r[0]);
779
- s !== void 0 && P.has(s) && !p && m(
868
+ s !== void 0 && P.has(s) && !p && g(
780
869
  'configuration keys must be written literally, use "-c some.key=${value}" rather than "-c ${value}"'
781
870
  );
782
871
  const h = p && (r[0].text.startsWith("-") || s !== void 0 && O.has(s));
783
- if (o === void 0 && !h && m(
872
+ if (o === void 0 && !h && g(
784
873
  'the git sub-command must be written literally, interpolated values before it can only be used as option values, for example "-c user.name=${name}"'
785
874
  ), r.length === 1) {
786
875
  const { value: l } = r[0];
@@ -789,50 +878,50 @@ function Ne(e, t) {
789
878
  else
790
879
  for (const x of Array.isArray(l) ? l : [l]) {
791
880
  const C = A(x);
792
- C.startsWith("-") && !a && m(
881
+ C.startsWith("-") && !a && g(
793
882
  `interpolated value ${U(C)} would be read as an option, values that may start with "-" must follow "--" or be wrapped with pathspec()`
794
883
  ), n.push(C);
795
884
  }
796
885
  s = void 0;
797
886
  continue;
798
887
  }
799
- let i = "", d = -1;
888
+ let c = "", d = -1;
800
889
  for (const l of r)
801
- "value" in l ? ((Array.isArray(l.value) || b(l.value)) && m("arrays and pathspecs must be interpolated as a standalone argument"), d < 0 && (d = i.length), i += A(l.value)) : i += l.text;
802
- if (d === 0 && i.startsWith("-") && !a && m(`interpolated value ${U(i)} would be read as an option`), d > 0 && i.startsWith("-") && !a) {
803
- const l = i.indexOf("=");
804
- (l < 0 || l >= d) && m(
890
+ "value" in l ? ((Array.isArray(l.value) || b(l.value)) && g("arrays and pathspecs must be interpolated as a standalone argument"), d < 0 && (d = c.length), c += A(l.value)) : c += l.text;
891
+ if (d === 0 && c.startsWith("-") && !a && g(`interpolated value ${U(c)} would be read as an option`), d > 0 && c.startsWith("-") && !a) {
892
+ const l = c.indexOf("=");
893
+ (l < 0 || l >= d) && g(
805
894
  'interpolated values in options must follow "=", for example "--message=${value}"'
806
895
  );
807
896
  }
808
897
  if (s !== void 0 && P.has(s)) {
809
- const l = i.indexOf("=");
810
- (l < 0 || l >= d) && m(
898
+ const l = c.indexOf("=");
899
+ (l < 0 || l >= d) && g(
811
900
  'configuration keys must be written literally, use "-c some.key=${value}" rather than "-c ${value}"'
812
901
  );
813
902
  }
814
- const E = /^(?:--config(?:-env)?=|-c(?=.))/.exec(i)?.[0];
815
- if (E && !a) {
816
- const l = i.indexOf("=", E.length);
817
- (l < 0 || l >= d) && m('configuration keys must be written literally, use "--config=some.key=${value}"');
903
+ const k = /^(?:--config(?:-env)?=|-c(?=.))/.exec(c)?.[0];
904
+ if (k && !a) {
905
+ const l = c.indexOf("=", k.length);
906
+ (l < 0 || l >= d) && g('configuration keys must be written literally, use "--config=some.key=${value}"');
818
907
  }
819
- n.push(i), s = void 0;
908
+ n.push(c), s = void 0;
820
909
  }
821
- return o === void 0 && m("no git sub-command supplied"), n;
910
+ return o === void 0 && g("no git sub-command supplied"), n;
822
911
  }
823
912
  export {
824
- ke as GitTemplateError,
913
+ Ee as GitTemplateError,
825
914
  pe as SAFE_CONFIG_KEYS,
826
- k as TemplateValue,
915
+ E as TemplateValue,
827
916
  he as configKeyMatcher,
828
- M as isGitEnvKey,
917
+ T as isGitEnvKey,
829
918
  Ue as isGuardedEnvKey,
830
- Le as isSafeConfigKey,
919
+ Fe as isSafeConfigKey,
831
920
  $e as isTemplateStringsArray,
832
921
  Ae as parseArgv,
833
- Re as parseEnv,
834
- Fe as refName,
835
- Ge as remoteUrl,
836
- Ne as templateArgv
922
+ Le as parseEnv,
923
+ Re as refName,
924
+ Me as remoteUrl,
925
+ Ge as templateArgv
837
926
  };
838
927
  //# sourceMappingURL=index.mjs.map