type-git 0.3.0-alpha.1 → 0.3.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, i as EnvInheritance, A as AuditConfig, R as RuntimeAdapters, j as ExecutionContext, k as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-Bpuvmw9y.cjs';
1
+ import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, i as EnvInheritance, A as AuditConfig, R as RuntimeAdapters, j as ExecutionContext, k as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-sSzx9O1u.cjs';
2
2
 
3
3
  /**
4
4
  * stdout parsing utilities for Git output
@@ -3959,6 +3959,23 @@ type CliRunnerOptions = {
3959
3959
  /** Audit configuration for command tracking and tracing */
3960
3960
  audit?: AuditConfig;
3961
3961
  };
3962
+ /**
3963
+ * Per-call options for {@link CliRunner.run} / {@link CliRunner.runOrThrow}.
3964
+ *
3965
+ * Extends {@link ExecOpts} with an `env` overlay so callers (e.g. the repository
3966
+ * implementations) can inject command-specific environment variables — such as
3967
+ * `GIT_LFS_SKIP_SMUDGE` for an LFS skip-smudge mode. This keeps `env` out of the
3968
+ * public `ExecOpts` / repository operation option types, scoping it to the
3969
+ * runner's own `run` / `runOrThrow` entry points.
3970
+ */
3971
+ type RunOptions = ExecOpts & {
3972
+ /**
3973
+ * Extra environment variables merged on top of the resolved environment for
3974
+ * this single command. Values here take precedence over the configured
3975
+ * environment but do not persist across calls.
3976
+ */
3977
+ env?: Record<string, string>;
3978
+ };
3962
3979
  /**
3963
3980
  * CLI Runner for executing Git commands
3964
3981
  *
@@ -4004,7 +4021,7 @@ declare class CliRunner {
4004
4021
  /**
4005
4022
  * Run a Git command
4006
4023
  */
4007
- run(context: ExecutionContext, args: string[], opts?: ExecOpts): Promise<RawResult>;
4024
+ run(context: ExecutionContext, args: string[], opts?: RunOptions): Promise<RawResult>;
4008
4025
  /**
4009
4026
  * Process a single line from stderr for progress and trace callbacks
4010
4027
  */
@@ -4024,7 +4041,7 @@ declare class CliRunner {
4024
4041
  /**
4025
4042
  * Run a command and throw on error
4026
4043
  */
4027
- runOrThrow(context: ExecutionContext, args: string[], opts?: ExecOpts): Promise<RawResult>;
4044
+ runOrThrow(context: ExecutionContext, args: string[], opts?: RunOptions): Promise<RawResult>;
4028
4045
  }
4029
4046
 
4030
4047
  /**
@@ -1,4 +1,4 @@
1
- import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, i as EnvInheritance, A as AuditConfig, R as RuntimeAdapters, j as ExecutionContext, k as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-Bpuvmw9y.js';
1
+ import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, i as EnvInheritance, A as AuditConfig, R as RuntimeAdapters, j as ExecutionContext, k as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-sSzx9O1u.js';
2
2
 
3
3
  /**
4
4
  * stdout parsing utilities for Git output
@@ -3959,6 +3959,23 @@ type CliRunnerOptions = {
3959
3959
  /** Audit configuration for command tracking and tracing */
3960
3960
  audit?: AuditConfig;
3961
3961
  };
3962
+ /**
3963
+ * Per-call options for {@link CliRunner.run} / {@link CliRunner.runOrThrow}.
3964
+ *
3965
+ * Extends {@link ExecOpts} with an `env` overlay so callers (e.g. the repository
3966
+ * implementations) can inject command-specific environment variables — such as
3967
+ * `GIT_LFS_SKIP_SMUDGE` for an LFS skip-smudge mode. This keeps `env` out of the
3968
+ * public `ExecOpts` / repository operation option types, scoping it to the
3969
+ * runner's own `run` / `runOrThrow` entry points.
3970
+ */
3971
+ type RunOptions = ExecOpts & {
3972
+ /**
3973
+ * Extra environment variables merged on top of the resolved environment for
3974
+ * this single command. Values here take precedence over the configured
3975
+ * environment but do not persist across calls.
3976
+ */
3977
+ env?: Record<string, string>;
3978
+ };
3962
3979
  /**
3963
3980
  * CLI Runner for executing Git commands
3964
3981
  *
@@ -4004,7 +4021,7 @@ declare class CliRunner {
4004
4021
  /**
4005
4022
  * Run a Git command
4006
4023
  */
4007
- run(context: ExecutionContext, args: string[], opts?: ExecOpts): Promise<RawResult>;
4024
+ run(context: ExecutionContext, args: string[], opts?: RunOptions): Promise<RawResult>;
4008
4025
  /**
4009
4026
  * Process a single line from stderr for progress and trace callbacks
4010
4027
  */
@@ -4024,7 +4041,7 @@ declare class CliRunner {
4024
4041
  /**
4025
4042
  * Run a command and throw on error
4026
4043
  */
4027
- runOrThrow(context: ExecutionContext, args: string[], opts?: ExecOpts): Promise<RawResult>;
4044
+ runOrThrow(context: ExecutionContext, args: string[], opts?: RunOptions): Promise<RawResult>;
4028
4045
  }
4029
4046
 
4030
4047
  /**
@@ -448,6 +448,22 @@ var DEFAULT_ENV_ALLOWLIST = [
448
448
  // SSH agent (required for Git-over-SSH authentication)
449
449
  "SSH_AUTH_SOCK",
450
450
  "SSH_AGENT_PID",
451
+ // Git SSH transport and TLS configuration. These are commonly required for
452
+ // fetch/push to keep working under the default allowlist. They are transport
453
+ // configuration rather than credential stores, but note they can still carry
454
+ // sensitive data depending on local setup (e.g. GIT_SSH_COMMAND can name a command
455
+ // Git executes). The most credential-prone / askpass variables (GIT_ASKPASS,
456
+ // SSH_ASKPASS, GIT_PROXY_COMMAND) are intentionally NOT inherited by default — they
457
+ // can carry inline credentials or run a helper that reads secrets from the
458
+ // environment, which would weaken the traversal-prevention model. Opt into those
459
+ // explicitly via `inheritEnv` when needed.
460
+ "GIT_SSH",
461
+ "GIT_SSH_COMMAND",
462
+ "GIT_SSH_VARIANT",
463
+ "GIT_SSL_CAINFO",
464
+ "GIT_SSL_CAPATH",
465
+ "GIT_TERMINAL_PROMPT",
466
+ "GIT_CONFIG_NOSYSTEM",
451
467
  // HTTP(S) proxy configuration (required for Git network operations behind a proxy)
452
468
  "HTTP_PROXY",
453
469
  "HTTPS_PROXY",
@@ -478,35 +494,52 @@ var DEFAULT_ENV_ALLOWLIST = [
478
494
  "NUMBER_OF_PROCESSORS",
479
495
  "PROCESSOR_ARCHITECTURE"
480
496
  ];
481
- function resolveInheritedEnv(parentEnv, inheritEnv, platform = "") {
482
- if (inheritEnv === true) {
483
- const all = {};
484
- for (const [key, value] of Object.entries(parentEnv)) {
485
- if (value !== void 0) {
486
- all[key] = value;
487
- }
497
+ function pickEnv(parentEnv, predicate) {
498
+ const result = {};
499
+ for (const [key, value] of Object.entries(parentEnv)) {
500
+ if (value !== void 0 && predicate(key)) {
501
+ result[key] = value;
488
502
  }
489
- return all;
490
503
  }
504
+ return result;
505
+ }
506
+ function buildAllowlist(inheritEnv) {
491
507
  const allow = new Set(inheritEnv === false ? [] : DEFAULT_ENV_ALLOWLIST);
492
508
  if (Array.isArray(inheritEnv)) {
493
509
  for (const name of inheritEnv) {
494
510
  allow.add(name);
495
511
  }
512
+ return { allow, remove: void 0 };
496
513
  }
497
- const isWindows = platform === "win32";
498
- const allowLower = isWindows ? new Set([...allow].map((name) => name.toLowerCase())) : null;
499
- const result = {};
500
- for (const [key, value] of Object.entries(parentEnv)) {
501
- if (value === void 0) {
502
- continue;
503
- }
504
- const allowed = allowLower ? allowLower.has(key.toLowerCase()) : allow.has(key);
505
- if (allowed) {
506
- result[key] = value;
507
- }
514
+ if (inheritEnv === false) {
515
+ return { allow, remove: void 0 };
508
516
  }
509
- return result;
517
+ for (const name of inheritEnv.add ?? []) {
518
+ allow.add(name);
519
+ }
520
+ const hasRemove = inheritEnv.remove !== void 0 && inheritEnv.remove.length > 0;
521
+ const remove = hasRemove ? new Set(inheritEnv.remove) : void 0;
522
+ return { allow, remove };
523
+ }
524
+ function makeNameMatcher(names, isWindows) {
525
+ if (!isWindows) {
526
+ return (name) => names.has(name);
527
+ }
528
+ const lower = new Set([...names].map((name) => name.toLowerCase()));
529
+ return (name) => lower.has(name.toLowerCase());
530
+ }
531
+ function resolveInheritedEnv(parentEnv, inheritEnv, platform = "") {
532
+ if (inheritEnv === true) {
533
+ return pickEnv(parentEnv, () => true);
534
+ }
535
+ if (typeof inheritEnv === "function") {
536
+ return pickEnv(parentEnv, inheritEnv);
537
+ }
538
+ const { allow, remove } = buildAllowlist(inheritEnv ?? []);
539
+ const isWindows = platform === "win32";
540
+ const isAllowed = makeNameMatcher(allow, isWindows);
541
+ const isRemoved = remove ? makeNameMatcher(remove, isWindows) : () => false;
542
+ return pickEnv(parentEnv, (name) => isAllowed(name) && !isRemoved(name));
510
543
  }
511
544
 
512
545
  // src/runner/cli-runner.ts
@@ -691,8 +724,11 @@ var CliRunner = class _CliRunner {
691
724
  */
692
725
  async run(context, args, opts) {
693
726
  const argv = this.buildArgv(context, args);
694
- const { signal, onProgress, onLfsProgress } = opts ?? {};
727
+ const { signal, onProgress, onLfsProgress, env: envOverride } = opts ?? {};
695
728
  const env = this.buildEnv();
729
+ if (envOverride) {
730
+ Object.assign(env, envOverride);
731
+ }
696
732
  if (onLfsProgress) {
697
733
  env.GIT_LFS_FORCE_PROGRESS = "1";
698
734
  }
@@ -1260,7 +1296,7 @@ var BareRepoImpl = class {
1260
1296
  */
1261
1297
  async push(opts) {
1262
1298
  const args = ["push"];
1263
- if (opts?.onProgress) {
1299
+ if (opts?.onProgress || opts?.onLfsProgress) {
1264
1300
  args.push("--progress");
1265
1301
  }
1266
1302
  if (opts?.force) {
@@ -2158,7 +2194,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2158
2194
  */
2159
2195
  async push(opts) {
2160
2196
  const args = ["push"];
2161
- if (opts?.onProgress) {
2197
+ if (opts?.onProgress || opts?.onLfsProgress) {
2162
2198
  args.push("--progress");
2163
2199
  }
2164
2200
  if (opts?.verbose) {
@@ -2263,6 +2299,29 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2263
2299
  setLfsMode(mode) {
2264
2300
  this._lfsMode = mode;
2265
2301
  }
2302
+ /**
2303
+ * Per-command environment overrides derived from the configured LFS mode.
2304
+ *
2305
+ * When the repository was opened (or reconfigured) with an object-form LFS
2306
+ * mode requesting `skipSmudge` and/or `skipDownload`, working-tree-populating
2307
+ * operations (checkout, switch, reset, merge, pull, rebase, restore) run with
2308
+ * `GIT_LFS_SKIP_SMUDGE=1`. Git then leaves LFS pointer files in place instead
2309
+ * of downloading their contents during the implicit checkout.
2310
+ *
2311
+ * The objects can be materialized later via the explicit `repo.lfs.pull()` /
2312
+ * `repo.lfs.checkout()` helpers, which use dedicated git-lfs commands and are
2313
+ * not affected by `GIT_LFS_SKIP_SMUDGE`.
2314
+ *
2315
+ * Returns `undefined` for the `'enabled'` / `'disabled'` string modes so the
2316
+ * runner environment is left untouched.
2317
+ */
2318
+ lfsModeEnv() {
2319
+ const mode = this._lfsMode;
2320
+ if (typeof mode === "object" && (mode.skipSmudge === true || mode.skipDownload === true)) {
2321
+ return { GIT_LFS_SKIP_SMUDGE: "1" };
2322
+ }
2323
+ return void 0;
2324
+ }
2266
2325
  // ==========================================================================
2267
2326
  // LFS Operations
2268
2327
  // ==========================================================================
@@ -2285,7 +2344,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2285
2344
  }
2286
2345
  await this.runner.runOrThrow(this.context, args, {
2287
2346
  signal: opts?.signal,
2288
- onProgress: opts?.onProgress
2347
+ onProgress: opts?.onProgress,
2348
+ onLfsProgress: opts?.onLfsProgress
2289
2349
  });
2290
2350
  }
2291
2351
  async lfsPush(opts) {
@@ -2314,7 +2374,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2314
2374
  }
2315
2375
  await this.runner.runOrThrow(this.context, args, {
2316
2376
  signal: opts?.signal,
2317
- onProgress: opts?.onProgress
2377
+ onProgress: opts?.onProgress,
2378
+ onLfsProgress: opts?.onLfsProgress
2318
2379
  });
2319
2380
  }
2320
2381
  async lfsStatus(opts) {
@@ -2397,7 +2458,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2397
2458
  const args = ["lfs", "push", remote, "--object-id", ...batch];
2398
2459
  const result = await this.runner.run(this.context, args, {
2399
2460
  signal: opts?.signal,
2400
- onProgress: opts?.onProgress
2461
+ onProgress: opts?.onProgress,
2462
+ onLfsProgress: opts?.onLfsProgress
2401
2463
  });
2402
2464
  if (result.exitCode === 0) {
2403
2465
  uploadedCount += batch.length;
@@ -2474,7 +2536,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2474
2536
  const args = ["lfs", "fetch", remote, "--", ...batch];
2475
2537
  const result = await this.runner.run(this.context, args, {
2476
2538
  signal: opts?.signal,
2477
- onProgress: opts?.onProgress
2539
+ onProgress: opts?.onProgress,
2540
+ onLfsProgress: opts?.onLfsProgress
2478
2541
  });
2479
2542
  if (result.exitCode === 0) {
2480
2543
  downloadedCount += batch.length;
@@ -2539,7 +2602,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2539
2602
  return;
2540
2603
  }
2541
2604
  const args = ["lfs", "fetch"];
2542
- if (opts?.onProgress) {
2605
+ if (opts?.onProgress || opts?.onLfsProgress) {
2543
2606
  args.push("--progress");
2544
2607
  }
2545
2608
  if (opts?.all) {
@@ -2572,7 +2635,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2572
2635
  }
2573
2636
  await this.runner.runOrThrow(this.context, args, {
2574
2637
  signal: opts?.signal,
2575
- onProgress: opts?.onProgress
2638
+ onProgress: opts?.onProgress,
2639
+ onLfsProgress: opts?.onLfsProgress
2576
2640
  });
2577
2641
  }
2578
2642
  async lfsInstall(opts) {
@@ -3334,7 +3398,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3334
3398
  }
3335
3399
  }
3336
3400
  await this.runner.runOrThrow(this.context, args, {
3337
- signal: opts?.signal
3401
+ signal: opts?.signal,
3402
+ env: this.lfsModeEnv()
3338
3403
  });
3339
3404
  }
3340
3405
  // ==========================================================================
@@ -3691,7 +3756,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3691
3756
  }
3692
3757
  args.push(branch);
3693
3758
  const result = await this.runner.run(this.context, args, {
3694
- signal: opts?.signal
3759
+ signal: opts?.signal,
3760
+ env: this.lfsModeEnv()
3695
3761
  });
3696
3762
  if (result.exitCode !== 0) {
3697
3763
  const statusResult = await this.runner.runOrThrow(this.context, ["status", "--porcelain"], {
@@ -3720,7 +3786,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3720
3786
  // ==========================================================================
3721
3787
  async pull(opts) {
3722
3788
  const args = ["pull"];
3723
- if (opts?.onProgress) {
3789
+ if (opts?.onProgress || opts?.onLfsProgress) {
3724
3790
  args.push("--progress");
3725
3791
  }
3726
3792
  if (opts?.rebase === true) {
@@ -3868,7 +3934,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3868
3934
  }
3869
3935
  await this.runner.runOrThrow(this.context, args, {
3870
3936
  signal: opts?.signal,
3871
- onProgress: opts?.onProgress
3937
+ onProgress: opts?.onProgress,
3938
+ onLfsProgress: opts?.onLfsProgress,
3939
+ env: this.lfsModeEnv()
3872
3940
  });
3873
3941
  }
3874
3942
  // ==========================================================================
@@ -3898,7 +3966,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
3898
3966
  args.push(target);
3899
3967
  }
3900
3968
  await this.runner.runOrThrow(this.context, args, {
3901
- signal: opts?.signal
3969
+ signal: opts?.signal,
3970
+ env: this.lfsModeEnv()
3902
3971
  });
3903
3972
  }
3904
3973
  // ==========================================================================
@@ -4094,7 +4163,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4094
4163
  args.push(opts.startPoint);
4095
4164
  }
4096
4165
  await this.runner.runOrThrow(this.context, args, {
4097
- signal: opts?.signal
4166
+ signal: opts?.signal,
4167
+ env: this.lfsModeEnv()
4098
4168
  });
4099
4169
  }
4100
4170
  // ==========================================================================
@@ -4521,7 +4591,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4521
4591
  args.push(opts.upstream);
4522
4592
  }
4523
4593
  await this.runner.runOrThrow(this.context, args, {
4524
- signal: opts?.signal
4594
+ signal: opts?.signal,
4595
+ env: this.lfsModeEnv()
4525
4596
  });
4526
4597
  }
4527
4598
  // ==========================================================================
@@ -4579,7 +4650,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
4579
4650
  const pathList = Array.isArray(paths) ? paths : [paths];
4580
4651
  args.push("--", ...pathList);
4581
4652
  await this.runner.runOrThrow(this.context, args, {
4582
- signal: opts?.signal
4653
+ signal: opts?.signal,
4654
+ env: this.lfsModeEnv()
4583
4655
  });
4584
4656
  }
4585
4657
  // ==========================================================================
@@ -5592,7 +5664,7 @@ var GitImpl = class {
5592
5664
  }
5593
5665
  async clone(url, path, opts) {
5594
5666
  const args = buildCloneArgs(opts);
5595
- if (opts?.onProgress) {
5667
+ if (opts?.onProgress || opts?.onLfsProgress) {
5596
5668
  args.push("--progress");
5597
5669
  }
5598
5670
  args.push(url, path);