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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, A as AuditConfig, R as RuntimeAdapters, i as ExecutionContext, j 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-BEKkCViX.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-Bpuvmw9y.cjs';
2
2
 
3
3
  /**
4
4
  * stdout parsing utilities for Git output
@@ -3940,6 +3940,16 @@ type CliRunnerOptions = {
3940
3940
  gitBinary?: string;
3941
3941
  /** Additional environment variables */
3942
3942
  env?: Record<string, string>;
3943
+ /**
3944
+ * Controls how the parent process environment is inherited by spawned Git commands.
3945
+ *
3946
+ * By default, only a curated allowlist of variables that Git needs to operate is
3947
+ * inherited (environment variable traversal prevention); the full parent environment is
3948
+ * NOT forwarded. See {@link EnvInheritance} for all options.
3949
+ *
3950
+ * @default undefined (inherit the default allowlist)
3951
+ */
3952
+ inheritEnv?: EnvInheritance;
3943
3953
  /** Directories to prepend to PATH */
3944
3954
  pathPrefix?: string[];
3945
3955
  /** Custom HOME directory for git config isolation */
@@ -3962,6 +3972,7 @@ declare class CliRunner {
3962
3972
  private readonly exec;
3963
3973
  private readonly gitBinary;
3964
3974
  private readonly baseEnv;
3975
+ private readonly inheritEnv;
3965
3976
  private readonly pathPrefix;
3966
3977
  private readonly home;
3967
3978
  private readonly credential;
@@ -3980,7 +3991,10 @@ declare class CliRunner {
3980
3991
  /**
3981
3992
  * Build the effective environment for command execution
3982
3993
  *
3983
- * Applies home directory and PATH prefix overrides
3994
+ * Seeds the environment from the inherited (allowlisted) parent variables, then layers
3995
+ * the configured `env`, home directory, and PATH prefix overrides on top. The parent
3996
+ * process environment is never forwarded wholesale unless `inheritEnv: true` is set
3997
+ * (environment variable traversal prevention).
3984
3998
  */
3985
3999
  private buildEnv;
3986
4000
  /**
@@ -1,4 +1,4 @@
1
- import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, A as AuditConfig, R as RuntimeAdapters, i as ExecutionContext, j 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-BEKkCViX.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-Bpuvmw9y.js';
2
2
 
3
3
  /**
4
4
  * stdout parsing utilities for Git output
@@ -3940,6 +3940,16 @@ type CliRunnerOptions = {
3940
3940
  gitBinary?: string;
3941
3941
  /** Additional environment variables */
3942
3942
  env?: Record<string, string>;
3943
+ /**
3944
+ * Controls how the parent process environment is inherited by spawned Git commands.
3945
+ *
3946
+ * By default, only a curated allowlist of variables that Git needs to operate is
3947
+ * inherited (environment variable traversal prevention); the full parent environment is
3948
+ * NOT forwarded. See {@link EnvInheritance} for all options.
3949
+ *
3950
+ * @default undefined (inherit the default allowlist)
3951
+ */
3952
+ inheritEnv?: EnvInheritance;
3943
3953
  /** Directories to prepend to PATH */
3944
3954
  pathPrefix?: string[];
3945
3955
  /** Custom HOME directory for git config isolation */
@@ -3962,6 +3972,7 @@ declare class CliRunner {
3962
3972
  private readonly exec;
3963
3973
  private readonly gitBinary;
3964
3974
  private readonly baseEnv;
3975
+ private readonly inheritEnv;
3965
3976
  private readonly pathPrefix;
3966
3977
  private readonly home;
3967
3978
  private readonly credential;
@@ -3980,7 +3991,10 @@ declare class CliRunner {
3980
3991
  /**
3981
3992
  * Build the effective environment for command execution
3982
3993
  *
3983
- * Applies home directory and PATH prefix overrides
3994
+ * Seeds the environment from the inherited (allowlisted) parent variables, then layers
3995
+ * the configured `env`, home directory, and PATH prefix overrides on top. The parent
3996
+ * process environment is never forwarded wholesale unless `inheritEnv: true` is set
3997
+ * (environment variable traversal prevention).
3984
3998
  */
3985
3999
  private buildEnv;
3986
4000
  /**
@@ -417,6 +417,99 @@ function detectErrorCategory(stderr) {
417
417
 
418
418
  // src/runner/cli-runner.ts
419
419
  import process2 from "process";
420
+
421
+ // src/core/env.ts
422
+ var DEFAULT_ENV_ALLOWLIST = [
423
+ // Executable resolution
424
+ "PATH",
425
+ "PATHEXT",
426
+ // User home / identity
427
+ "HOME",
428
+ "USER",
429
+ "LOGNAME",
430
+ // Locale and time
431
+ "LANG",
432
+ "LANGUAGE",
433
+ "LC_ALL",
434
+ "LC_CTYPE",
435
+ "LC_MESSAGES",
436
+ "LC_NUMERIC",
437
+ "LC_TIME",
438
+ "LC_COLLATE",
439
+ "LC_MONETARY",
440
+ "TZ",
441
+ // Temporary directories
442
+ "TMPDIR",
443
+ "TMP",
444
+ "TEMP",
445
+ // Terminal
446
+ "TERM",
447
+ "COLORTERM",
448
+ // SSH agent (required for Git-over-SSH authentication)
449
+ "SSH_AUTH_SOCK",
450
+ "SSH_AGENT_PID",
451
+ // HTTP(S) proxy configuration (required for Git network operations behind a proxy)
452
+ "HTTP_PROXY",
453
+ "HTTPS_PROXY",
454
+ "http_proxy",
455
+ "https_proxy",
456
+ "ALL_PROXY",
457
+ "all_proxy",
458
+ "NO_PROXY",
459
+ "no_proxy",
460
+ // Windows essentials
461
+ "USERPROFILE",
462
+ "HOMEDRIVE",
463
+ "HOMEPATH",
464
+ "APPDATA",
465
+ "LOCALAPPDATA",
466
+ "PROGRAMDATA",
467
+ "ALLUSERSPROFILE",
468
+ "PROGRAMFILES",
469
+ "PROGRAMFILES(X86)",
470
+ "PROGRAMW6432",
471
+ "PUBLIC",
472
+ "SYSTEMROOT",
473
+ "SYSTEMDRIVE",
474
+ "WINDIR",
475
+ "COMSPEC",
476
+ "COMPUTERNAME",
477
+ "USERDOMAIN",
478
+ "NUMBER_OF_PROCESSORS",
479
+ "PROCESSOR_ARCHITECTURE"
480
+ ];
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
+ }
488
+ }
489
+ return all;
490
+ }
491
+ const allow = new Set(inheritEnv === false ? [] : DEFAULT_ENV_ALLOWLIST);
492
+ if (Array.isArray(inheritEnv)) {
493
+ for (const name of inheritEnv) {
494
+ allow.add(name);
495
+ }
496
+ }
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
+ }
508
+ }
509
+ return result;
510
+ }
511
+
512
+ // src/runner/cli-runner.ts
420
513
  var FATAL_ERROR_PATTERN = /fatal:\s*(.+)/i;
421
514
  var ERROR_PATTERN = /error:\s*(.+)/i;
422
515
  var LINE_SEPARATOR_PATTERN = /\r|\n/;
@@ -470,6 +563,7 @@ var CliRunner = class _CliRunner {
470
563
  exec;
471
564
  gitBinary;
472
565
  baseEnv;
566
+ inheritEnv;
473
567
  pathPrefix;
474
568
  home;
475
569
  credential;
@@ -478,6 +572,7 @@ var CliRunner = class _CliRunner {
478
572
  this.exec = adapters.exec;
479
573
  this.gitBinary = options?.gitBinary ?? "git";
480
574
  this.baseEnv = options?.env ?? {};
575
+ this.inheritEnv = options?.inheritEnv;
481
576
  this.pathPrefix = options?.pathPrefix ?? [];
482
577
  this.home = options?.home;
483
578
  this.credential = options?.credential;
@@ -491,6 +586,7 @@ var CliRunner = class _CliRunner {
491
586
  withOptions(options) {
492
587
  const mergedEnv = { ...this.baseEnv, ...options.env };
493
588
  const mergedPathPrefix = [...this.pathPrefix, ...options.pathPrefix ?? []];
589
+ const inheritEnv = options.inheritEnv ?? this.inheritEnv;
494
590
  const home = options.home ?? this.home;
495
591
  const credential = options.credential ?? this.credential;
496
592
  const audit = options.audit ?? this.audit;
@@ -508,6 +604,7 @@ var CliRunner = class _CliRunner {
508
604
  {
509
605
  gitBinary: options.gitBinary ?? this.gitBinary,
510
606
  env: mergedEnv,
607
+ inheritEnv,
511
608
  pathPrefix: mergedPathPrefix,
512
609
  home,
513
610
  credential,
@@ -539,10 +636,16 @@ var CliRunner = class _CliRunner {
539
636
  /**
540
637
  * Build the effective environment for command execution
541
638
  *
542
- * Applies home directory and PATH prefix overrides
639
+ * Seeds the environment from the inherited (allowlisted) parent variables, then layers
640
+ * the configured `env`, home directory, and PATH prefix overrides on top. The parent
641
+ * process environment is never forwarded wholesale unless `inheritEnv: true` is set
642
+ * (environment variable traversal prevention).
543
643
  */
544
644
  buildEnv() {
545
- const env = { ...this.baseEnv };
645
+ const env = {
646
+ ...resolveInheritedEnv(process2.env, this.inheritEnv, process2.platform),
647
+ ...this.baseEnv
648
+ };
546
649
  if (this.home) {
547
650
  env.HOME = this.home;
548
651
  env.USERPROFILE = this.home;
@@ -555,9 +658,11 @@ var CliRunner = class _CliRunner {
555
658
  }
556
659
  }
557
660
  if (allPathPrefixes.length > 0) {
558
- const separator = process2.platform === "win32" ? ";" : ":";
559
- const currentPath = process2.env.PATH ?? "";
560
- env.PATH = [...allPathPrefixes, currentPath].join(separator);
661
+ const isWindows = process2.platform === "win32";
662
+ const separator = isWindows ? ";" : ":";
663
+ const pathKey = isWindows ? Object.keys(env).find((key) => key.toLowerCase() === "path") ?? "PATH" : "PATH";
664
+ const currentPath = env[pathKey] ?? "";
665
+ env[pathKey] = [...allPathPrefixes, currentPath].join(separator);
561
666
  }
562
667
  if (this.audit?.onTrace) {
563
668
  if (env.GIT_TRACE === void 0) {
@@ -608,6 +713,9 @@ var CliRunner = class _CliRunner {
608
713
  {
609
714
  argv,
610
715
  env,
716
+ // The env above is already fully resolved (including any inherited variables),
717
+ // so the adapter must not merge the parent environment on top of it.
718
+ inheritEnv: false,
611
719
  cwd: context.type === "worktree" ? context.workdir : void 0,
612
720
  signal
613
721
  },
@@ -5382,6 +5490,7 @@ function toCliRunnerOptions(opts) {
5382
5490
  }
5383
5491
  return {
5384
5492
  env: opts.env,
5493
+ inheritEnv: opts.inheritEnv,
5385
5494
  pathPrefix: opts.pathPrefix,
5386
5495
  home: opts.home,
5387
5496
  credential: opts.credential ? {
@@ -5825,6 +5934,12 @@ async function createGit(options) {
5825
5934
 
5826
5935
  // src/adapters/node/exec.ts
5827
5936
  import { spawn } from "child_process";
5937
+ function resolveChildEnv(env, inheritEnv) {
5938
+ if (inheritEnv === false) {
5939
+ return env ?? {};
5940
+ }
5941
+ return env ? { ...process.env, ...env } : process.env;
5942
+ }
5828
5943
  async function* streamToAsyncIterable(stream) {
5829
5944
  let buffer = "";
5830
5945
  for await (const chunk of stream) {
@@ -5851,7 +5966,7 @@ var NodeExecAdapter = class {
5851
5966
  };
5852
5967
  }
5853
5968
  spawn(options, handlers) {
5854
- const { argv, env, cwd, signal } = options;
5969
+ const { argv, env, inheritEnv, cwd, signal } = options;
5855
5970
  const command = argv[0];
5856
5971
  if (command === void 0) {
5857
5972
  throw new Error("argv must not be empty");
@@ -5860,7 +5975,7 @@ var NodeExecAdapter = class {
5860
5975
  return new Promise((resolve, reject) => {
5861
5976
  const child = spawn(command, args, {
5862
5977
  cwd,
5863
- env: env ? { ...process.env, ...env } : process.env,
5978
+ env: resolveChildEnv(env, inheritEnv),
5864
5979
  stdio: ["ignore", "pipe", "pipe"]
5865
5980
  });
5866
5981
  let stdout = "";
@@ -5908,7 +6023,7 @@ var NodeExecAdapter = class {
5908
6023
  });
5909
6024
  }
5910
6025
  spawnStreaming(options) {
5911
- const { argv, env, cwd, signal } = options;
6026
+ const { argv, env, inheritEnv, cwd, signal } = options;
5912
6027
  const command = argv[0];
5913
6028
  if (command === void 0) {
5914
6029
  throw new Error("argv must not be empty");
@@ -5916,7 +6031,7 @@ var NodeExecAdapter = class {
5916
6031
  const args = argv.slice(1);
5917
6032
  const child = spawn(command, args, {
5918
6033
  cwd,
5919
- env: env ? { ...process.env, ...env } : process.env,
6034
+ env: resolveChildEnv(env, inheritEnv),
5920
6035
  stdio: ["ignore", "pipe", "pipe"]
5921
6036
  });
5922
6037
  let aborted = false;