type-git 0.8.1 → 0.8.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.
@@ -19,7 +19,7 @@ import {
19
19
  validatePathInput,
20
20
  validateRevParseQuery,
21
21
  validateRevParseRefOpts
22
- } from "./chunk-UAKOSACD.js";
22
+ } from "./chunk-V4ZRQG3O.js";
23
23
 
24
24
  // src/core/clone-config.ts
25
25
  var HTTP_VARIABLES = [
@@ -159,6 +159,22 @@ function checkedRefSortKey(command, value) {
159
159
  }
160
160
  return value;
161
161
  }
162
+ function checkedRevision(command, name, value) {
163
+ if (value === "") {
164
+ throw new GitArgumentError(
165
+ `${command}: ${name} must not be empty; Git rejects an empty revision.`
166
+ );
167
+ }
168
+ return checkedOperand(command, name, value);
169
+ }
170
+ function checkedOptionValue(command, name, value) {
171
+ if (value === "") {
172
+ throw new GitArgumentError(
173
+ `${command}: ${name} must not be empty; Git rejects an empty value here.`
174
+ );
175
+ }
176
+ return value;
177
+ }
162
178
 
163
179
  // src/core/untrusted-repo.ts
164
180
  var UNTRUSTED_REPO_MIN_GIT_VERSION = "2.38.0";
@@ -701,6 +717,16 @@ async function push(runner, context, opts) {
701
717
  });
702
718
  }
703
719
 
720
+ // src/impl/raw-opts.ts
721
+ function splitRawOpts(opts) {
722
+ const throwOnNonZero = opts?.throwOnNonZero;
723
+ if (throwOnNonZero !== void 0 && typeof throwOnNonZero !== "boolean") {
724
+ const got = throwOnNonZero === null ? "null" : typeof throwOnNonZero;
725
+ throw new GitArgumentError(`throwOnNonZero must be a boolean, got ${got}`);
726
+ }
727
+ return { throwOnNonZero: throwOnNonZero === true, runOpts: opts ?? {} };
728
+ }
729
+
704
730
  // src/impl/bare-repo-impl.ts
705
731
  var REMOTE_LINE_PATTERN = /^(\S+)\t(.+?)\s+\((fetch|push)\)$/;
706
732
  var PRUNED_REF_PATTERN = /\* \[pruned\] (.+)/;
@@ -937,8 +963,9 @@ var BareRepoImpl = class {
937
963
  return { type: "bare", gitDir: this.gitDir };
938
964
  }
939
965
  /** Execute a raw Git command without typed argument validation. */
940
- raw(argv, opts) {
941
- return this.runner.run(this.context, argv, opts);
966
+ async raw(argv, opts) {
967
+ const { throwOnNonZero, runOpts } = splitRawOpts(opts);
968
+ return throwOnNonZero ? await this.runner.runOrThrow(this.context, argv, runOpts) : await this.runner.run(this.context, argv, runOpts);
942
969
  }
943
970
  /**
944
971
  * Check if this repository is a worktree repository (has working directory)
@@ -973,8 +1000,8 @@ var BareRepoImpl = class {
973
1000
  if (opts?.refsOnly) {
974
1001
  args.push("--refs");
975
1002
  }
976
- if (opts?.sort) {
977
- args.push("--sort", opts.sort);
1003
+ if (opts?.sort !== void 0) {
1004
+ args.push("--sort", checkedOptionValue("lsRemote", "sort", opts.sort));
978
1005
  }
979
1006
  args.push(checkedOperand("lsRemote", "remote", remote));
980
1007
  if (opts?.refs && opts.refs.length > 0) {
@@ -1091,7 +1118,7 @@ var BareRepoImpl = class {
1091
1118
  async remoteAdd(name, url, opts) {
1092
1119
  validateOptions("remoteAdd", opts);
1093
1120
  const args = ["remote", "add"];
1094
- if (opts?.track) {
1121
+ if (opts?.track !== void 0) {
1095
1122
  args.push("-t", opts.track);
1096
1123
  }
1097
1124
  if (opts?.fetch) {
@@ -1166,8 +1193,14 @@ var BareRepoImpl = class {
1166
1193
  args.push("--delete");
1167
1194
  }
1168
1195
  args.push(checkedOperand("remote.setHead", "remote", remote));
1169
- if (branch && !opts?.auto && !opts?.delete) {
1170
- args.push(checkedOperand("remote.setHead", "branch", branch));
1196
+ if (branch !== void 0 && !opts?.auto && !opts?.delete) {
1197
+ args.push(
1198
+ checkedOperand(
1199
+ "remote.setHead",
1200
+ "branch",
1201
+ checkedOptionValue("remote.setHead", "branch", branch)
1202
+ )
1203
+ );
1171
1204
  }
1172
1205
  await this.runner.runOrThrow(this.context, args, {
1173
1206
  signal: opts?.signal
@@ -1581,7 +1614,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
1581
1614
  }
1582
1615
  /** Execute a raw Git command without typed argument validation. */
1583
1616
  async raw(argv, opts) {
1584
- return this.runner.run(this.context, argv, opts);
1617
+ const { throwOnNonZero, runOpts } = splitRawOpts(opts);
1618
+ return throwOnNonZero ? await this.runner.runOrThrow(this.context, argv, runOpts) : await this.runner.run(this.context, argv, runOpts);
1585
1619
  }
1586
1620
  /**
1587
1621
  * Check if this repository is a worktree repository (has working directory)
@@ -1616,8 +1650,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
1616
1650
  if (opts?.refsOnly) {
1617
1651
  args.push("--refs");
1618
1652
  }
1619
- if (opts?.sort) {
1620
- args.push("--sort", opts.sort);
1653
+ if (opts?.sort !== void 0) {
1654
+ args.push("--sort", checkedOptionValue("lsRemote", "sort", opts.sort));
1621
1655
  }
1622
1656
  args.push(checkedOperand("lsRemote", "remote", remote));
1623
1657
  if (opts?.refs && opts.refs.length > 0) {
@@ -1792,19 +1826,19 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
1792
1826
  if (opts?.skip !== void 0) {
1793
1827
  args.push(`--skip=${opts.skip}`);
1794
1828
  }
1795
- if (opts?.since) {
1829
+ if (opts?.since !== void 0) {
1796
1830
  const since = opts.since instanceof Date ? opts.since.toISOString() : opts.since;
1797
1831
  args.push(`--since=${since}`);
1798
1832
  }
1799
- if (opts?.after) {
1833
+ if (opts?.after !== void 0) {
1800
1834
  const after = opts.after instanceof Date ? opts.after.toISOString() : opts.after;
1801
1835
  args.push(`--after=${after}`);
1802
1836
  }
1803
- if (opts?.until) {
1837
+ if (opts?.until !== void 0) {
1804
1838
  const until = opts.until instanceof Date ? opts.until.toISOString() : opts.until;
1805
1839
  args.push(`--until=${until}`);
1806
1840
  }
1807
- if (opts?.before) {
1841
+ if (opts?.before !== void 0) {
1808
1842
  const before = opts.before instanceof Date ? opts.before.toISOString() : opts.before;
1809
1843
  args.push(`--before=${before}`);
1810
1844
  }
@@ -1835,8 +1869,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
1835
1869
  if (opts?.reverse) {
1836
1870
  args.push("--reverse");
1837
1871
  }
1838
- if (opts?.ref) {
1839
- args.push(checkedOperand("log", "ref", opts.ref));
1872
+ if (opts?.ref !== void 0) {
1873
+ args.push(checkedRevision("log", "ref", opts.ref));
1840
1874
  }
1841
1875
  const result = await this.runner.runOrThrow(this.context, args, {
1842
1876
  signal: opts?.signal
@@ -2288,8 +2322,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2288
2322
  const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
2289
2323
  args.push("--exclude", patterns.join(","));
2290
2324
  }
2291
- if (opts?.ref) {
2292
- args.push(checkedOperand("lfs.lsFiles", "ref", opts.ref));
2325
+ if (opts?.ref !== void 0) {
2326
+ args.push(checkedRevision("lfs.lsFiles", "ref", opts.ref));
2293
2327
  }
2294
2328
  const result = await this.runner.runOrThrow(this.context, args, {
2295
2329
  signal: opts?.signal
@@ -2675,8 +2709,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2675
2709
  args.push("-b", opts.branch);
2676
2710
  }
2677
2711
  args.push(checkedOperand("worktree.add", "path", path));
2678
- if (opts?.commitish) {
2679
- args.push(checkedOperand("worktree.add", "commitish", opts.commitish));
2712
+ if (opts?.commitish !== void 0) {
2713
+ args.push(checkedRevision("worktree.add", "commitish", opts.commitish));
2680
2714
  }
2681
2715
  await this.runner.runOrThrow(this.context, args, {
2682
2716
  signal: opts?.signal,
@@ -2702,8 +2736,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2702
2736
  if (opts?.verbose) {
2703
2737
  args.push("--verbose");
2704
2738
  }
2705
- if (opts?.expire) {
2706
- args.push(`--expire=${opts.expire}`);
2739
+ if (opts?.expire !== void 0) {
2740
+ args.push(`--expire=${checkedOptionValue("worktree.prune", "expire", opts.expire)}`);
2707
2741
  }
2708
2742
  const result = await this.runner.runOrThrow(this.context, args, {
2709
2743
  signal: opts?.signal
@@ -2795,7 +2829,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2795
2829
  if (opts?.chmod) {
2796
2830
  args.push(`--chmod=${opts.chmod}`);
2797
2831
  }
2798
- if (opts?.pathspecFromFile) {
2832
+ if (opts?.pathspecFromFile !== void 0) {
2799
2833
  args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
2800
2834
  }
2801
2835
  const pathList = Array.isArray(paths) ? paths : [paths];
@@ -2822,26 +2856,28 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2822
2856
  if (opts?.quiet) {
2823
2857
  args.push("--quiet");
2824
2858
  }
2825
- if (opts?.contains) {
2826
- args.push(`--contains=${opts.contains}`);
2859
+ if (opts?.contains !== void 0) {
2860
+ args.push(`--contains=${checkedOptionValue("branch.list", "contains", opts.contains)}`);
2827
2861
  }
2828
- if (opts?.noContains) {
2829
- args.push(`--no-contains=${opts.noContains}`);
2862
+ if (opts?.noContains !== void 0) {
2863
+ args.push(
2864
+ `--no-contains=${checkedOptionValue("branch.list", "noContains", opts.noContains)}`
2865
+ );
2830
2866
  }
2831
2867
  if (opts?.abbrev !== void 0) {
2832
2868
  args.push(`--abbrev=${opts.abbrev}`);
2833
2869
  }
2834
- if (opts?.merged) {
2835
- args.push(`--merged=${opts.merged}`);
2870
+ if (opts?.merged !== void 0) {
2871
+ args.push(`--merged=${checkedOptionValue("branch.list", "merged", opts.merged)}`);
2836
2872
  }
2837
- if (opts?.noMerged) {
2838
- args.push(`--no-merged=${opts.noMerged}`);
2873
+ if (opts?.noMerged !== void 0) {
2874
+ args.push(`--no-merged=${checkedOptionValue("branch.list", "noMerged", opts.noMerged)}`);
2839
2875
  }
2840
2876
  if (opts?.sort !== void 0) {
2841
2877
  args.push(`--sort=${checkedRefSortKey("branch.list", opts.sort)}`);
2842
2878
  }
2843
- if (opts?.pointsAt) {
2844
- args.push(`--points-at=${opts.pointsAt}`);
2879
+ if (opts?.pointsAt !== void 0) {
2880
+ args.push(`--points-at=${checkedOptionValue("branch.list", "pointsAt", opts.pointsAt)}`);
2845
2881
  }
2846
2882
  if (opts?.ignoreCase) {
2847
2883
  args.push("--ignore-case");
@@ -2899,8 +2935,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2899
2935
  }
2900
2936
  args.push(checkedOperand("branch.create", "name", name));
2901
2937
  checkedNewBranchName("branch.create", "name", name);
2902
- if (opts?.startPoint) {
2903
- args.push(checkedOperand("branch.create", "startPoint", opts.startPoint));
2938
+ if (opts?.startPoint !== void 0) {
2939
+ args.push(checkedRevision("branch.create", "startPoint", opts.startPoint));
2904
2940
  }
2905
2941
  await this.runner.runOrThrow(this.context, args, {
2906
2942
  signal: opts?.signal
@@ -2973,11 +3009,11 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2973
3009
  if (pathOpts?.theirs) {
2974
3010
  args.push("--theirs");
2975
3011
  }
2976
- if (pathOpts?.pathspecFromFile) {
3012
+ if (pathOpts?.pathspecFromFile !== void 0) {
2977
3013
  args.push(`--pathspec-from-file=${pathOpts.pathspecFromFile}`);
2978
3014
  }
2979
- if (pathOpts?.source) {
2980
- args.push(checkedOperand("checkout", "source", pathOpts.source));
3015
+ if (pathOpts?.source !== void 0) {
3016
+ args.push(checkedRevision("checkout", "source", pathOpts.source));
2981
3017
  }
2982
3018
  args.push("--");
2983
3019
  args.push(...targetOrPaths);
@@ -3025,8 +3061,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3025
3061
  args.push("--ignore-other-worktrees");
3026
3062
  }
3027
3063
  args.push(checkedOperand("checkout", "target", targetOrPaths));
3028
- if (branchOpts?.startPoint) {
3029
- args.push(checkedOperand("checkout", "startPoint", branchOpts.startPoint));
3064
+ if (branchOpts?.startPoint !== void 0) {
3065
+ args.push(checkedRevision("checkout", "startPoint", branchOpts.startPoint));
3030
3066
  }
3031
3067
  }
3032
3068
  await this.runner.runOrThrow(this.context, args, {
@@ -3041,7 +3077,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3041
3077
  validateOptions("commit", opts);
3042
3078
  validateInput("commitPaths", { ...opts }, "commit");
3043
3079
  const args = ["commit"];
3044
- if (opts?.message) {
3080
+ if (opts?.message !== void 0) {
3045
3081
  args.push("-m", opts.message);
3046
3082
  }
3047
3083
  if (opts?.allowEmpty) {
@@ -3053,12 +3089,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3053
3089
  if (opts?.all) {
3054
3090
  args.push("-a");
3055
3091
  }
3056
- if (opts?.author) {
3092
+ if (opts?.author !== void 0) {
3057
3093
  args.push("--author", opts.author);
3058
3094
  }
3059
- if (opts?.date) {
3095
+ if (opts?.date !== void 0) {
3060
3096
  const date = opts.date instanceof Date ? opts.date.toISOString() : opts.date;
3061
- args.push("--date", date);
3097
+ args.push("--date", checkedOptionValue("commit", "date", date));
3062
3098
  }
3063
3099
  if (opts?.noVerify) {
3064
3100
  args.push("--no-verify");
@@ -3075,17 +3111,17 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3075
3111
  if (opts?.verbose) {
3076
3112
  args.push("--verbose");
3077
3113
  }
3078
- if (opts?.file) {
3079
- args.push("--file", opts.file);
3114
+ if (opts?.file !== void 0) {
3115
+ args.push("--file", checkedOptionValue("commit", "file", opts.file));
3080
3116
  }
3081
- if (opts?.reuseMessage) {
3082
- args.push("--reuse-message", opts.reuseMessage);
3117
+ if (opts?.reuseMessage !== void 0) {
3118
+ args.push("--reuse-message", checkedOptionValue("commit", "reuseMessage", opts.reuseMessage));
3083
3119
  }
3084
- if (opts?.fixup) {
3085
- args.push("--fixup", opts.fixup);
3120
+ if (opts?.fixup !== void 0) {
3121
+ args.push("--fixup", checkedOptionValue("commit", "fixup", opts.fixup));
3086
3122
  }
3087
- if (opts?.squash) {
3088
- args.push("--squash", opts.squash);
3123
+ if (opts?.squash !== void 0) {
3124
+ args.push("--squash", checkedOptionValue("commit", "squash", opts.squash));
3089
3125
  }
3090
3126
  if (opts?.resetAuthor) {
3091
3127
  args.push("--reset-author");
@@ -3114,7 +3150,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3114
3150
  if (opts?.untrackedFiles) {
3115
3151
  args.push(`--untracked-files=${opts.untrackedFiles}`);
3116
3152
  }
3117
- if (opts?.pathspecFromFile) {
3153
+ if (opts?.pathspecFromFile !== void 0) {
3118
3154
  args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
3119
3155
  }
3120
3156
  if (opts?.allowEmptyMessage) {
@@ -3245,8 +3281,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3245
3281
  if (opts?.renameLimit !== void 0) {
3246
3282
  args.push(`-l${opts.renameLimit}`);
3247
3283
  }
3248
- if (opts?.pickaxe) {
3249
- args.push(`-S${opts.pickaxe}`);
3284
+ if (opts?.pickaxe !== void 0) {
3285
+ args.push(...opts.pickaxe === "" ? ["-S", ""] : [`-S${opts.pickaxe}`]);
3250
3286
  }
3251
3287
  if (opts?.pickaxeAll) {
3252
3288
  args.push("--pickaxe-all");
@@ -3260,8 +3296,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3260
3296
  if (opts?.wordDiff) {
3261
3297
  args.push(`--word-diff=${opts.wordDiff}`);
3262
3298
  }
3263
- if (target) {
3264
- args.push(checkedOperand("diff", "target", target));
3299
+ if (target !== void 0) {
3300
+ args.push(checkedRevision("diff", "target", target));
3265
3301
  }
3266
3302
  if (opts?.paths && opts.paths.length > 0) {
3267
3303
  args.push("--", ...opts.paths);
@@ -3319,7 +3355,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3319
3355
  return { success: true };
3320
3356
  }
3321
3357
  const args = ["merge"];
3322
- if (opts?.message) {
3358
+ if (opts?.message !== void 0) {
3323
3359
  args.push("-m", opts.message);
3324
3360
  }
3325
3361
  if (opts?.ff === "only") {
@@ -3333,8 +3369,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3333
3369
  if (opts?.noCommit) {
3334
3370
  args.push("--no-commit");
3335
3371
  }
3336
- if (opts?.strategy) {
3337
- args.push("-s", opts.strategy);
3372
+ if (opts?.strategy !== void 0) {
3373
+ args.push("-s", checkedOptionValue("merge", "strategy", opts.strategy));
3338
3374
  }
3339
3375
  if (opts?.strategyOption) {
3340
3376
  const strategyOpts = Array.isArray(opts.strategyOption) ? opts.strategyOption : [opts.strategyOption];
@@ -3394,7 +3430,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3394
3430
  if (opts?.signoff) {
3395
3431
  args.push("--signoff");
3396
3432
  }
3397
- if (opts?.intoName) {
3433
+ if (opts?.intoName !== void 0) {
3398
3434
  args.push(`--into-name=${opts.intoName}`);
3399
3435
  }
3400
3436
  args.push(checkedOperand("merge", "branch", branch));
@@ -3505,8 +3541,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3505
3541
  if (opts?.autostash) {
3506
3542
  args.push("--autostash");
3507
3543
  }
3508
- if (opts?.strategy) {
3509
- args.push(`--strategy=${opts.strategy}`);
3544
+ if (opts?.strategy !== void 0) {
3545
+ args.push(`--strategy=${checkedOptionValue("pull", "strategy", opts.strategy)}`);
3510
3546
  }
3511
3547
  if (opts?.strategyOption) {
3512
3548
  const strategyOpts = Array.isArray(opts.strategyOption) ? opts.strategyOption : [opts.strategyOption];
@@ -3573,10 +3609,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3573
3609
  if (opts?.setUpstream) {
3574
3610
  args.push("--set-upstream");
3575
3611
  }
3576
- if (opts?.remote) {
3577
- args.push(checkedOperand("pull", "remote", opts.remote));
3612
+ if (opts?.remote !== void 0) {
3613
+ args.push(
3614
+ checkedOperand("pull", "remote", checkedOptionValue("pull", "remote", opts.remote))
3615
+ );
3578
3616
  }
3579
- if (opts?.branch) {
3617
+ if (opts?.branch !== void 0) {
3580
3618
  args.push(checkedOperand("pull", "branch", opts.branch));
3581
3619
  }
3582
3620
  await this.runner.runOrThrow(this.context, args, {
@@ -3612,11 +3650,11 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3612
3650
  if (opts?.intentToAdd) {
3613
3651
  args.push("--intent-to-add");
3614
3652
  }
3615
- if (opts?.pathspecFromFile) {
3653
+ if (opts?.pathspecFromFile !== void 0) {
3616
3654
  args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
3617
3655
  }
3618
- if (target) {
3619
- args.push(checkedOperand("reset", "target", target), "--");
3656
+ if (target !== void 0) {
3657
+ args.push(checkedRevision("reset", "target", target), "--");
3620
3658
  }
3621
3659
  await this.runner.runOrThrow(this.context, args, {
3622
3660
  signal: opts?.signal,
@@ -3647,7 +3685,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3647
3685
  if (opts?.sparse) {
3648
3686
  args.push("--sparse");
3649
3687
  }
3650
- if (opts?.pathspecFromFile) {
3688
+ if (opts?.pathspecFromFile !== void 0) {
3651
3689
  args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
3652
3690
  }
3653
3691
  const pathList = Array.isArray(paths) ? paths : [paths];
@@ -3707,7 +3745,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3707
3745
  if (opts?.all) {
3708
3746
  args.push("--all");
3709
3747
  }
3710
- if (opts?.pathspecFromFile) {
3748
+ if (opts?.pathspecFromFile !== void 0) {
3711
3749
  args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
3712
3750
  }
3713
3751
  if (opts?.paths && opts.paths.length > 0) {
@@ -3819,8 +3857,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3819
3857
  } else {
3820
3858
  args.push(target);
3821
3859
  }
3822
- if (opts?.startPoint) {
3823
- args.push(checkedOperand("switch", "startPoint", opts.startPoint));
3860
+ if (opts?.startPoint !== void 0) {
3861
+ args.push(checkedRevision("switch", "startPoint", opts.startPoint));
3824
3862
  }
3825
3863
  await this.runner.runOrThrow(this.context, args, {
3826
3864
  signal: opts?.signal,
@@ -3832,31 +3870,31 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3832
3870
  // ==========================================================================
3833
3871
  async tagList(opts) {
3834
3872
  const args = ["tag", "--list"];
3835
- if (opts?.sort) {
3836
- args.push(`--sort=${opts.sort}`);
3873
+ if (opts?.sort !== void 0) {
3874
+ args.push(`--sort=${checkedOptionValue("tag.list", "sort", opts.sort)}`);
3837
3875
  }
3838
3876
  if (opts?.lines !== void 0) {
3839
3877
  args.push(`-n${opts.lines}`);
3840
3878
  }
3841
- if (opts?.contains) {
3842
- args.push(`--contains=${opts.contains}`);
3879
+ if (opts?.contains !== void 0) {
3880
+ args.push(`--contains=${checkedOptionValue("tag.list", "contains", opts.contains)}`);
3843
3881
  }
3844
- if (opts?.noContains) {
3845
- args.push(`--no-contains=${opts.noContains}`);
3882
+ if (opts?.noContains !== void 0) {
3883
+ args.push(`--no-contains=${checkedOptionValue("tag.list", "noContains", opts.noContains)}`);
3846
3884
  }
3847
- if (opts?.merged) {
3848
- args.push(`--merged=${opts.merged}`);
3885
+ if (opts?.merged !== void 0) {
3886
+ args.push(`--merged=${checkedOptionValue("tag.list", "merged", opts.merged)}`);
3849
3887
  }
3850
- if (opts?.noMerged) {
3851
- args.push(`--no-merged=${opts.noMerged}`);
3888
+ if (opts?.noMerged !== void 0) {
3889
+ args.push(`--no-merged=${checkedOptionValue("tag.list", "noMerged", opts.noMerged)}`);
3852
3890
  }
3853
- if (opts?.pointsAt) {
3854
- args.push(`--points-at=${opts.pointsAt}`);
3891
+ if (opts?.pointsAt !== void 0) {
3892
+ args.push(`--points-at=${checkedOptionValue("tag.list", "pointsAt", opts.pointsAt)}`);
3855
3893
  }
3856
3894
  if (opts?.ignoreCase) {
3857
3895
  args.push("--ignore-case");
3858
3896
  }
3859
- if (opts?.pattern) {
3897
+ if (opts?.pattern !== void 0) {
3860
3898
  args.push(checkedOperand("tag.list", "pattern", opts.pattern));
3861
3899
  }
3862
3900
  const result = await this.runner.runOrThrow(this.context, args, {
@@ -3894,15 +3932,15 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3894
3932
  if (opts?.cleanup) {
3895
3933
  args.push(`--cleanup=${opts.cleanup}`);
3896
3934
  }
3897
- if (opts?.localUser) {
3935
+ if (opts?.localUser !== void 0) {
3898
3936
  args.push(`--local-user=${opts.localUser}`);
3899
3937
  }
3900
3938
  if (opts?.createReflog) {
3901
3939
  args.push("--create-reflog");
3902
3940
  }
3903
3941
  args.push(checkedOperand("tag.create", "name", name));
3904
- if (opts?.commit) {
3905
- args.push(checkedOperand("tag.create", "commit", opts.commit));
3942
+ if (opts?.commit !== void 0) {
3943
+ args.push(checkedRevision("tag.create", "commit", opts.commit));
3906
3944
  }
3907
3945
  await this.runner.runOrThrow(this.context, args, {
3908
3946
  signal: opts?.signal
@@ -3986,6 +4024,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3986
4024
  async cherryPick(commits, opts) {
3987
4025
  const control = opts?.abort || opts?.continue || opts?.skip;
3988
4026
  const commitList = control ? [] : checkedOperands("cherryPick", "commits", Array.isArray(commits) ? commits : [commits]);
4027
+ if (opts?.strategy !== void 0) {
4028
+ checkedOptionValue("cherryPick", "strategy", opts.strategy);
4029
+ }
3989
4030
  await this.runner.validateMainlineOptions(this.context, "cherryPick", opts, {
3990
4031
  signal: opts?.signal
3991
4032
  });
@@ -4011,7 +4052,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4011
4052
  if (opts?.mainline !== void 0) {
4012
4053
  args.push("-m", opts.mainline.toString());
4013
4054
  }
4014
- if (opts?.strategy) {
4055
+ if (opts?.strategy !== void 0) {
4015
4056
  args.push("--strategy", opts.strategy);
4016
4057
  }
4017
4058
  if (opts?.cleanup) {
@@ -4144,8 +4185,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4144
4185
  if (opts?.skip) {
4145
4186
  args.push("--skip");
4146
4187
  }
4147
- if (opts?.onto) {
4148
- args.push("--onto", opts.onto);
4188
+ if (opts?.onto !== void 0) {
4189
+ args.push("--onto", checkedOptionValue("rebase", "onto", opts.onto));
4149
4190
  }
4150
4191
  if (opts?.rebaseMerges) {
4151
4192
  args.push("--rebase-merges");
@@ -4230,8 +4271,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4230
4271
  } else if (opts?.forkPoint === false) {
4231
4272
  args.push("--no-fork-point");
4232
4273
  }
4233
- if (opts?.strategy) {
4234
- args.push("--strategy", opts.strategy);
4274
+ if (opts?.strategy !== void 0) {
4275
+ args.push("--strategy", checkedOptionValue("rebase", "strategy", opts.strategy));
4235
4276
  }
4236
4277
  if (opts?.strategyOption) {
4237
4278
  const strategyOptions = Array.isArray(opts.strategyOption) ? opts.strategyOption : [opts.strategyOption];
@@ -4252,8 +4293,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4252
4293
  } else if (opts?.reapplyCherryPicks === false) {
4253
4294
  args.push("--no-reapply-cherry-picks");
4254
4295
  }
4255
- if (opts?.upstream) {
4256
- args.push(checkedOperand("rebase", "upstream", opts.upstream));
4296
+ if (opts?.upstream !== void 0) {
4297
+ args.push(checkedRevision("rebase", "upstream", opts.upstream));
4257
4298
  }
4258
4299
  await this.runner.runOrThrow(this.context, args, {
4259
4300
  signal: opts?.signal,
@@ -4279,8 +4320,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4279
4320
  if (opts?.worktree) {
4280
4321
  args.push("--worktree");
4281
4322
  }
4282
- if (opts?.source) {
4283
- args.push("--source", opts.source);
4323
+ if (opts?.source !== void 0) {
4324
+ args.push("--source", checkedOptionValue("restore", "source", opts.source));
4284
4325
  }
4285
4326
  if (opts?.ours) {
4286
4327
  args.push("--ours");
@@ -4318,7 +4359,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4318
4359
  if (opts?.ignoreSkipWorktreeBits) {
4319
4360
  args.push("--ignore-skip-worktree-bits");
4320
4361
  }
4321
- if (opts?.pathspecFromFile) {
4362
+ if (opts?.pathspecFromFile !== void 0) {
4322
4363
  args.push("--pathspec-from-file", opts.pathspecFromFile);
4323
4364
  }
4324
4365
  const pathList = Array.isArray(paths) ? paths : [paths];
@@ -4334,6 +4375,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4334
4375
  async revert(commits, opts) {
4335
4376
  const control = opts?.abort || opts?.continue || opts?.skip;
4336
4377
  const commitList = control ? [] : checkedOperands("revert", "commits", Array.isArray(commits) ? commits : [commits]);
4378
+ if (opts?.strategy !== void 0) {
4379
+ checkedOptionValue("revert", "strategy", opts.strategy);
4380
+ }
4337
4381
  await this.runner.validateMainlineOptions(this.context, "revert", opts, {
4338
4382
  signal: opts?.signal
4339
4383
  });
@@ -4367,7 +4411,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4367
4411
  } else if (opts?.rerereAutoupdate === false) {
4368
4412
  args.push("--no-rerere-autoupdate");
4369
4413
  }
4370
- if (opts?.strategy) {
4414
+ if (opts?.strategy !== void 0) {
4371
4415
  args.push("--strategy", opts.strategy);
4372
4416
  }
4373
4417
  if (opts?.strategyOption) {
@@ -4406,7 +4450,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4406
4450
  if (opts?.nameStatus) {
4407
4451
  args.push("--name-status");
4408
4452
  }
4409
- if (opts?.format) {
4453
+ if (opts?.format !== void 0) {
4410
4454
  args.push(`--format=${opts.format}`);
4411
4455
  }
4412
4456
  if (opts?.quiet) {
@@ -4418,10 +4462,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4418
4462
  if (opts?.useMailmap) {
4419
4463
  args.push("--use-mailmap");
4420
4464
  }
4421
- if (opts?.decorateRefs) {
4465
+ if (opts?.decorateRefs !== void 0) {
4422
4466
  args.push("--decorate-refs", opts.decorateRefs);
4423
4467
  }
4424
- if (opts?.decorateRefsExclude) {
4468
+ if (opts?.decorateRefsExclude !== void 0) {
4425
4469
  args.push("--decorate-refs-exclude", opts.decorateRefsExclude);
4426
4470
  }
4427
4471
  if (opts?.decorate) {
@@ -4588,8 +4632,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4588
4632
  */
4589
4633
  async revListCount(ref, opts) {
4590
4634
  const args = ["rev-list", "--count"];
4591
- if (ref) {
4592
- args.push(checkedOperand("revListCount", "ref", ref));
4635
+ if (ref !== void 0) {
4636
+ args.push(checkedRevision("revListCount", "ref", ref));
4593
4637
  } else {
4594
4638
  args.push("HEAD");
4595
4639
  }
@@ -4708,14 +4752,14 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4708
4752
  if (opts?.recommendShallow) {
4709
4753
  args.push("--recommend-shallow");
4710
4754
  }
4711
- if (opts?.reference) {
4755
+ if (opts?.reference !== void 0) {
4712
4756
  args.push(`--reference=${opts.reference}`);
4713
4757
  }
4714
4758
  if (opts?.singleBranch) {
4715
4759
  args.push("--single-branch");
4716
4760
  }
4717
- if (opts?.filter) {
4718
- args.push(`--filter=${opts.filter}`);
4761
+ if (opts?.filter !== void 0) {
4762
+ args.push(`--filter=${checkedOptionValue("submodule.update", "filter", opts.filter)}`);
4719
4763
  }
4720
4764
  await this.runner.runOrThrow(this.context, args, {
4721
4765
  signal: opts?.signal
@@ -4723,17 +4767,17 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4723
4767
  }
4724
4768
  async submoduleAdd(url, path, opts) {
4725
4769
  const args = ["submodule", "add"];
4726
- if (opts?.branch) {
4727
- args.push("-b", opts.branch);
4770
+ if (opts?.branch !== void 0) {
4771
+ args.push("-b", checkedOptionValue("submodule.add", "branch", opts.branch));
4728
4772
  }
4729
4773
  if (opts?.force) {
4730
4774
  args.push("--force");
4731
4775
  }
4732
- if (opts?.name) {
4733
- args.push("--name", opts.name);
4776
+ if (opts?.name !== void 0) {
4777
+ args.push("--name", checkedOptionValue("submodule.add", "name", opts.name));
4734
4778
  }
4735
- if (opts?.reference) {
4736
- args.push("--reference", opts.reference);
4779
+ if (opts?.reference !== void 0) {
4780
+ args.push("--reference", checkedOptionValue("submodule.add", "reference", opts.reference));
4737
4781
  }
4738
4782
  if (opts?.depth !== void 0) {
4739
4783
  args.push("--depth", String(opts.depth));
@@ -4876,7 +4920,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4876
4920
  async remoteAdd(name, url, opts) {
4877
4921
  validateOptions("remoteAdd", opts);
4878
4922
  const args = ["remote", "add"];
4879
- if (opts?.track) {
4923
+ if (opts?.track !== void 0) {
4880
4924
  args.push("-t", opts.track);
4881
4925
  }
4882
4926
  if (opts?.fetch) {
@@ -4953,8 +4997,14 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4953
4997
  args.push("--delete");
4954
4998
  }
4955
4999
  args.push(checkedOperand("remote.setHead", "remote", remote));
4956
- if (branch && !opts?.auto && !opts?.delete) {
4957
- args.push(checkedOperand("remote.setHead", "branch", branch));
5000
+ if (branch !== void 0 && !opts?.auto && !opts?.delete) {
5001
+ args.push(
5002
+ checkedOperand(
5003
+ "remote.setHead",
5004
+ "branch",
5005
+ checkedOptionValue("remote.setHead", "branch", branch)
5006
+ )
5007
+ );
4958
5008
  }
4959
5009
  await this.runner.runOrThrow(this.context, args, {
4960
5010
  signal: opts?.signal
@@ -5359,6 +5409,26 @@ async function assertDataOnlySubmoduleConfigs(runner, fs, workdir, label, expect
5359
5409
  await assertDataOnlySubmoduleConfigs(runner, fs, subdir, sublabel, subdir);
5360
5410
  }
5361
5411
  }
5412
+ var FATAL_LINE_PATTERN = /^fatal: [^\r\n]*/m;
5413
+ function notARepository(path, worktreeArgv, worktreeResult, bareResult) {
5414
+ const cause = worktreeResult.stderr.match(FATAL_LINE_PATTERN)?.[0];
5415
+ return new GitError(
5416
+ "NonZeroExit",
5417
+ `Not a git repository: ${path}${cause === void 0 ? "" : ` (${cause})`}`,
5418
+ {
5419
+ gitDir: path,
5420
+ exitCode: bareResult.exitCode,
5421
+ ...bareResult.signal ? { signal: bareResult.signal } : {},
5422
+ stderr: bareResult.stderr,
5423
+ firstProbe: {
5424
+ argv: ["-C", path, ...worktreeArgv],
5425
+ exitCode: worktreeResult.exitCode,
5426
+ ...worktreeResult.signal ? { signal: worktreeResult.signal } : {},
5427
+ stderr: worktreeResult.stderr
5428
+ }
5429
+ }
5430
+ );
5431
+ }
5362
5432
  function gitDirRefusal(path, exitCode, stderr) {
5363
5433
  return new GitError(
5364
5434
  "NonZeroExit",
@@ -5447,21 +5517,19 @@ var GitImpl = class {
5447
5517
  }
5448
5518
  const repoRunner = opts ? this.runner.withOptions(toCliRunnerOptions(opts)) : this.runner;
5449
5519
  const untrusted = opts?.untrusted === true;
5450
- const result = await repoRunner.run({ type: "worktree", workdir: path }, [
5520
+ const worktreeArgv = [
5451
5521
  "rev-parse",
5452
5522
  "--is-bare-repository",
5453
5523
  ...untrusted ? ["--is-inside-git-dir"] : []
5454
- ]);
5524
+ ];
5525
+ const result = await repoRunner.run({ type: "worktree", workdir: path }, worktreeArgv);
5455
5526
  if (result.exitCode !== 0) {
5456
5527
  const bareResult = await repoRunner.run({ type: "bare", gitDir: path }, [
5457
5528
  "rev-parse",
5458
5529
  "--is-bare-repository"
5459
5530
  ]);
5460
5531
  if (bareResult.exitCode !== 0) {
5461
- throw new GitError("NonZeroExit", `Not a git repository: ${path}`, {
5462
- exitCode: bareResult.exitCode,
5463
- stderr: bareResult.stderr
5464
- });
5532
+ throw notARepository(path, worktreeArgv, result, bareResult);
5465
5533
  }
5466
5534
  if (bareResult.stdout.trim() === "true") {
5467
5535
  if (opts?.untrusted === true) {
@@ -5538,7 +5606,7 @@ var GitImpl = class {
5538
5606
  if (opts?.bare) {
5539
5607
  args.push("--bare");
5540
5608
  }
5541
- if (opts?.template) {
5609
+ if (opts?.template !== void 0) {
5542
5610
  args.push("--template", opts.template);
5543
5611
  }
5544
5612
  if (opts?.shared !== void 0) {
@@ -5552,14 +5620,22 @@ var GitImpl = class {
5552
5620
  args.push(`--shared=${opts.shared}`);
5553
5621
  }
5554
5622
  }
5555
- if (opts?.initialBranch && await this.supportsInitialBranch()) {
5556
- args.push("--initial-branch", opts.initialBranch);
5623
+ const initialBranch = opts?.initialBranch;
5624
+ const separateGitDir = opts?.separateGitDir;
5625
+ if (initialBranch !== void 0) {
5626
+ checkedOptionValue("init", "initialBranch", initialBranch);
5627
+ }
5628
+ if (separateGitDir !== void 0) {
5629
+ checkedOptionValue("init", "separateGitDir", separateGitDir);
5630
+ }
5631
+ if (initialBranch && await this.supportsInitialBranch()) {
5632
+ args.push("--initial-branch", initialBranch);
5557
5633
  }
5558
5634
  if (opts?.objectFormat) {
5559
5635
  args.push("--object-format", opts.objectFormat);
5560
5636
  }
5561
- if (opts?.separateGitDir) {
5562
- args.push("--separate-git-dir", opts.separateGitDir);
5637
+ if (separateGitDir !== void 0) {
5638
+ args.push("--separate-git-dir", separateGitDir);
5563
5639
  }
5564
5640
  args.push(checkedOperand("init", "path", path));
5565
5641
  const destinationExisted = await this.adapters.fs.exists(path);
@@ -5569,11 +5645,11 @@ var GitImpl = class {
5569
5645
  signal: opts?.signal,
5570
5646
  onProgress: opts?.onProgress
5571
5647
  });
5572
- if (opts?.initialBranch && !await this.supportsInitialBranch()) {
5648
+ if (initialBranch && !await this.supportsInitialBranch()) {
5573
5649
  const context = opts?.bare ? { type: "bare", gitDir: path } : { type: "worktree", workdir: path };
5574
5650
  await this.runner.runOrThrow(
5575
5651
  context,
5576
- ["symbolic-ref", "HEAD", `refs/heads/${opts.initialBranch}`],
5652
+ ["symbolic-ref", "HEAD", `refs/heads/${initialBranch}`],
5577
5653
  {
5578
5654
  signal: opts?.signal
5579
5655
  }
@@ -5605,8 +5681,8 @@ var GitImpl = class {
5605
5681
  if (opts?.refs) {
5606
5682
  args.push("--refs");
5607
5683
  }
5608
- if (opts?.sort) {
5609
- args.push("--sort", opts.sort);
5684
+ if (opts?.sort !== void 0) {
5685
+ args.push("--sort", checkedOptionValue("lsRemote", "sort", opts.sort));
5610
5686
  }
5611
5687
  args.push(checkedOperand("lsRemote", "url", url));
5612
5688
  const result = await this.runner.runOrThrow({ type: "global" }, args, {
@@ -5639,8 +5715,9 @@ var GitImpl = class {
5639
5715
  return compareVersions(version, "2.28.0") >= 0;
5640
5716
  }
5641
5717
  /** Execute a raw Git command without typed argument validation. */
5642
- raw(argv, opts) {
5643
- return this.runner.run({ type: "global" }, argv, opts);
5718
+ async raw(argv, opts) {
5719
+ const { throwOnNonZero, runOpts } = splitRawOpts(opts);
5720
+ return throwOnNonZero ? await this.runner.runOrThrow({ type: "global" }, argv, runOpts) : await this.runner.run({ type: "global" }, argv, runOpts);
5644
5721
  }
5645
5722
  // ==========================================================================
5646
5723
  // Global Config Operations