type-git 0.1.1 → 0.3.0-alpha.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.d.cts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { Z as AddOpts, bC as BareRepo, a0 as BranchCreateOpts, a1 as BranchDeleteOpts, _ as BranchInfo, bh as BranchOperations, $ as BranchOpts, a2 as CheckoutBranchOpts, a4 as CheckoutOpts, a3 as CheckoutPathOpts, am as CherryPickOpts, an as CleanOpts, v as CliRunner, w as CliRunnerOptions, x as CloneOpts, U as Commit, a5 as CommitOpts, a6 as CommitResult, bt as ConfigEntry, bu as ConfigGetOpts, by as ConfigKey, bw as ConfigListOpts, bz as ConfigOperations, bx as ConfigSchema, bv as ConfigSetOpts, C as CreateGitOptions, a8 as DiffEntry, a7 as DiffOpts, a9 as DiffResult, W as FetchOpts, X as ForceWithLeaseOpts, G as GIT_LOG_FORMAT, H as Git, b as GitProgressInfo, E as GlobalConfigListOpts, F as GlobalConfigOperations, A as GlobalLfsInstallOpts, D as GlobalLfsOperations, B as GlobalLfsUninstallOpts, I as InitOpts, L as LEGACY_GIT_VERSION, a_ as LfsCheckoutOpts, b2 as LfsEnvInfo, bg as LfsExtraOperations, aP as LfsFetchOpts, aS as LfsFileEntry, aW as LfsLockEntry, aX as LfsLockOpts, aZ as LfsLocksOpts, aT as LfsLsFilesOpts, b1 as LfsMigrateExportOpts, b0 as LfsMigrateImportOpts, a$ as LfsMigrateInfoOpts, bf as LfsOperations, b5 as LfsPreDownloadOpts, b6 as LfsPreDownloadResult, b3 as LfsPreUploadOpts, b4 as LfsPreUploadResult, e as LfsProgressInfo, aO as LfsPruneOpts, aL as LfsPullOpts, aM as LfsPushOpts, aK as LfsStatus, aN as LfsStatusOpts, aU as LfsTrackEntry, aV as LfsTrackOpts, aY as LfsUnlockOpts, V as LogOpts, y as LsRemoteOpts, f as LsRemoteRef, z as LsRemoteResult, N as LsTreeEntry, g as LsTreeObjectType, O as LsTreeOpts, M as MIN_GIT_VERSION, aa as MergeOpts, ab as MergeResult, ao as MvOpts, NodeExecAdapter, NodeFsAdapter, P as ParsedCommit, h as ParsedLsTreeEntry, i as ParsedWorktree, j as PorcelainV2Entry, ac as PullOpts, Y as PushOpts, ap as RebaseOpts, bl as RemoteAddOpts, bk as RemoteInfo, bs as RemoteOperations, bo as RemotePruneOpts, bq as RemoteSetBranchesOpts, bm as RemoteSetHeadOpts, bn as RemoteShowOpts, bp as RemoteUpdateOpts, br as RemoteUrlOpts, R as RepoBase, aQ as RepoLfsInstallOpts, aR as RepoLfsUninstallOpts, J as RepoLsRemoteOpts, K as RepoLsRemoteResult, ad as ResetOpts, aq as RestoreOpts, au as RevParseBooleanQuery, av as RevParseListOpts, aw as RevParseListQuery, ay as RevParseOtherQuery, az as RevParsePathFormat, aA as RevParsePathOpts, at as RevParsePathQuery, ax as RevParseRefOpts, ar as RevertOpts, ae as RmOpts, as as ShowOpts, ah as StashApplyOpts, af as StashEntry, bi as StashOperations, ag as StashPushOpts, S as StatusEntry, T as StatusOpts, Q as StatusPorcelain, aC as SubmoduleAddOpts, aD as SubmoduleDeinitOpts, aG as SubmoduleForeachOpts, aJ as SubmoduleInfo, bA as SubmoduleOperations, aB as SubmoduleOpts, aI as SubmoduleSetBranchOpts, aE as SubmoduleStatusOpts, aF as SubmoduleSummaryOpts, aH as SubmoduleSyncOpts, ai as SwitchOpts, al as TagCreateOpts, aj as TagInfo, ak as TagListOpts, bj as TagOperations, TypeGit, TypeGitOptions, b7 as Worktree, b8 as WorktreeAddOpts, bd as WorktreeLockOpts, bb as WorktreeMoveOpts, be as WorktreeOperations, ba as WorktreePruneOpts, b9 as WorktreeRemoveOpts, bc as WorktreeRepairOpts, bB as WorktreeRepo, c as createGit, a as createGitSync, createNodeAdapters, d as detectErrorCategory, p as parseGitLog, k as parseGitProgress, l as parseJson, m as parseKeyValue, n as parseLfsProgress, o as parseLines, q as parseLsRemote, r as parseLsTree, s as parsePorcelainV2, t as parseRecords, u as parseWorktreeList } from './adapters/node/index.cjs';
2
- export { A as AdapterFactory, C as Capabilities, q as CommandSpec, s as Credential, t as CredentialConfig, r as CredentialRequest, E as ExecAdapter, e as ExecOpts, i as ExecutionContext, F as FsAdapter, o as GitArgumentError, j as GitError, G as GitErrorCategory, m as GitErrorKind, h as GitOpenOptions, g as GitProgress, L as LfsMode, l as LfsProgress, N as NonEmptyString, O as OutputContract, f as RawResult, p as Runtime, R as RuntimeAdapters, c as SpawnHandle, S as SpawnOptions, b as SpawnResult, a as StreamHandler, d as TailHandle, T as TailOptions, k as isNonEmpty, n as nonEmpty } from './adapters-DehG3CsV.cjs';
2
+ export { k as AdapterFactory, A as AuditConfig, x as AuditEvent, w as AuditEventEnd, v as AuditEventStart, C as Capabilities, r as CommandSpec, t as Credential, u as CredentialConfig, s as CredentialRequest, E as ExecAdapter, e as ExecOpts, i as ExecutionContext, F as FsAdapter, p as GitArgumentError, j as GitError, G as GitErrorCategory, o as GitErrorKind, h as GitOpenOptions, g as GitProgress, L as LfsMode, m as LfsProgress, N as NonEmptyString, O as OutputContract, f as RawResult, q as Runtime, R as RuntimeAdapters, c as SpawnHandle, S as SpawnOptions, b as SpawnResult, a as StreamHandler, d as TailHandle, T as TailOptions, y as TraceEvent, l as isNonEmpty, n as nonEmpty } from './adapters-BEKkCViX.cjs';
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { Z as AddOpts, bC as BareRepo, a0 as BranchCreateOpts, a1 as BranchDeleteOpts, _ as BranchInfo, bh as BranchOperations, $ as BranchOpts, a2 as CheckoutBranchOpts, a4 as CheckoutOpts, a3 as CheckoutPathOpts, am as CherryPickOpts, an as CleanOpts, v as CliRunner, w as CliRunnerOptions, x as CloneOpts, U as Commit, a5 as CommitOpts, a6 as CommitResult, bt as ConfigEntry, bu as ConfigGetOpts, by as ConfigKey, bw as ConfigListOpts, bz as ConfigOperations, bx as ConfigSchema, bv as ConfigSetOpts, C as CreateGitOptions, a8 as DiffEntry, a7 as DiffOpts, a9 as DiffResult, W as FetchOpts, X as ForceWithLeaseOpts, G as GIT_LOG_FORMAT, H as Git, b as GitProgressInfo, E as GlobalConfigListOpts, F as GlobalConfigOperations, A as GlobalLfsInstallOpts, D as GlobalLfsOperations, B as GlobalLfsUninstallOpts, I as InitOpts, L as LEGACY_GIT_VERSION, a_ as LfsCheckoutOpts, b2 as LfsEnvInfo, bg as LfsExtraOperations, aP as LfsFetchOpts, aS as LfsFileEntry, aW as LfsLockEntry, aX as LfsLockOpts, aZ as LfsLocksOpts, aT as LfsLsFilesOpts, b1 as LfsMigrateExportOpts, b0 as LfsMigrateImportOpts, a$ as LfsMigrateInfoOpts, bf as LfsOperations, b5 as LfsPreDownloadOpts, b6 as LfsPreDownloadResult, b3 as LfsPreUploadOpts, b4 as LfsPreUploadResult, e as LfsProgressInfo, aO as LfsPruneOpts, aL as LfsPullOpts, aM as LfsPushOpts, aK as LfsStatus, aN as LfsStatusOpts, aU as LfsTrackEntry, aV as LfsTrackOpts, aY as LfsUnlockOpts, V as LogOpts, y as LsRemoteOpts, f as LsRemoteRef, z as LsRemoteResult, N as LsTreeEntry, g as LsTreeObjectType, O as LsTreeOpts, M as MIN_GIT_VERSION, aa as MergeOpts, ab as MergeResult, ao as MvOpts, NodeExecAdapter, NodeFsAdapter, P as ParsedCommit, h as ParsedLsTreeEntry, i as ParsedWorktree, j as PorcelainV2Entry, ac as PullOpts, Y as PushOpts, ap as RebaseOpts, bl as RemoteAddOpts, bk as RemoteInfo, bs as RemoteOperations, bo as RemotePruneOpts, bq as RemoteSetBranchesOpts, bm as RemoteSetHeadOpts, bn as RemoteShowOpts, bp as RemoteUpdateOpts, br as RemoteUrlOpts, R as RepoBase, aQ as RepoLfsInstallOpts, aR as RepoLfsUninstallOpts, J as RepoLsRemoteOpts, K as RepoLsRemoteResult, ad as ResetOpts, aq as RestoreOpts, au as RevParseBooleanQuery, av as RevParseListOpts, aw as RevParseListQuery, ay as RevParseOtherQuery, az as RevParsePathFormat, aA as RevParsePathOpts, at as RevParsePathQuery, ax as RevParseRefOpts, ar as RevertOpts, ae as RmOpts, as as ShowOpts, ah as StashApplyOpts, af as StashEntry, bi as StashOperations, ag as StashPushOpts, S as StatusEntry, T as StatusOpts, Q as StatusPorcelain, aC as SubmoduleAddOpts, aD as SubmoduleDeinitOpts, aG as SubmoduleForeachOpts, aJ as SubmoduleInfo, bA as SubmoduleOperations, aB as SubmoduleOpts, aI as SubmoduleSetBranchOpts, aE as SubmoduleStatusOpts, aF as SubmoduleSummaryOpts, aH as SubmoduleSyncOpts, ai as SwitchOpts, al as TagCreateOpts, aj as TagInfo, ak as TagListOpts, bj as TagOperations, TypeGit, TypeGitOptions, b7 as Worktree, b8 as WorktreeAddOpts, bd as WorktreeLockOpts, bb as WorktreeMoveOpts, be as WorktreeOperations, ba as WorktreePruneOpts, b9 as WorktreeRemoveOpts, bc as WorktreeRepairOpts, bB as WorktreeRepo, c as createGit, a as createGitSync, createNodeAdapters, d as detectErrorCategory, p as parseGitLog, k as parseGitProgress, l as parseJson, m as parseKeyValue, n as parseLfsProgress, o as parseLines, q as parseLsRemote, r as parseLsTree, s as parsePorcelainV2, t as parseRecords, u as parseWorktreeList } from './adapters/node/index.js';
2
- export { A as AdapterFactory, C as Capabilities, q as CommandSpec, s as Credential, t as CredentialConfig, r as CredentialRequest, E as ExecAdapter, e as ExecOpts, i as ExecutionContext, F as FsAdapter, o as GitArgumentError, j as GitError, G as GitErrorCategory, m as GitErrorKind, h as GitOpenOptions, g as GitProgress, L as LfsMode, l as LfsProgress, N as NonEmptyString, O as OutputContract, f as RawResult, p as Runtime, R as RuntimeAdapters, c as SpawnHandle, S as SpawnOptions, b as SpawnResult, a as StreamHandler, d as TailHandle, T as TailOptions, k as isNonEmpty, n as nonEmpty } from './adapters-DehG3CsV.js';
2
+ export { k as AdapterFactory, A as AuditConfig, x as AuditEvent, w as AuditEventEnd, v as AuditEventStart, C as Capabilities, r as CommandSpec, t as Credential, u as CredentialConfig, s as CredentialRequest, E as ExecAdapter, e as ExecOpts, i as ExecutionContext, F as FsAdapter, p as GitArgumentError, j as GitError, G as GitErrorCategory, o as GitErrorKind, h as GitOpenOptions, g as GitProgress, L as LfsMode, m as LfsProgress, N as NonEmptyString, O as OutputContract, f as RawResult, q as Runtime, R as RuntimeAdapters, c as SpawnHandle, S as SpawnOptions, b as SpawnResult, a as StreamHandler, d as TailHandle, T as TailOptions, y as TraceEvent, l as isNonEmpty, n as nonEmpty } from './adapters-BEKkCViX.js';
package/dist/index.js CHANGED
@@ -505,6 +505,7 @@ import process2 from "process";
505
505
  var FATAL_ERROR_PATTERN = /fatal:\s*(.+)/i;
506
506
  var ERROR_PATTERN = /error:\s*(.+)/i;
507
507
  var LINE_SEPARATOR_PATTERN = /\r|\n/;
508
+ var GIT_TRACE_PATTERN = /^\d{2}:\d{2}:\d{2}\.\d+\s+(?:trace:|[A-Za-z0-9_.-]+\.c:)/;
508
509
  function toLfsProgress(info) {
509
510
  if (!info) {
510
511
  return null;
@@ -557,6 +558,7 @@ var CliRunner = class _CliRunner {
557
558
  pathPrefix;
558
559
  home;
559
560
  credential;
561
+ audit;
560
562
  constructor(adapters, options) {
561
563
  this.exec = adapters.exec;
562
564
  this.gitBinary = options?.gitBinary ?? "git";
@@ -564,6 +566,7 @@ var CliRunner = class _CliRunner {
564
566
  this.pathPrefix = options?.pathPrefix ?? [];
565
567
  this.home = options?.home;
566
568
  this.credential = options?.credential;
569
+ this.audit = options?.audit;
567
570
  }
568
571
  /**
569
572
  * Create a new CliRunner with additional options merged
@@ -575,6 +578,7 @@ var CliRunner = class _CliRunner {
575
578
  const mergedPathPrefix = [...this.pathPrefix, ...options.pathPrefix ?? []];
576
579
  const home = options.home ?? this.home;
577
580
  const credential = options.credential ?? this.credential;
581
+ const audit = options.audit ?? this.audit;
578
582
  return new _CliRunner(
579
583
  {
580
584
  exec: this.exec,
@@ -591,7 +595,8 @@ var CliRunner = class _CliRunner {
591
595
  env: mergedEnv,
592
596
  pathPrefix: mergedPathPrefix,
593
597
  home,
594
- credential
598
+ credential,
599
+ audit
595
600
  }
596
601
  );
597
602
  }
@@ -639,6 +644,15 @@ var CliRunner = class _CliRunner {
639
644
  const currentPath = process2.env.PATH ?? "";
640
645
  env.PATH = [...allPathPrefixes, currentPath].join(separator);
641
646
  }
647
+ if (this.audit?.onTrace) {
648
+ if (env.GIT_TRACE === void 0) {
649
+ env.GIT_TRACE = "1";
650
+ } else if (!env.GIT_TRACE || env.GIT_TRACE === "0") {
651
+ console.warn(
652
+ "type-git: onTrace callback provided but GIT_TRACE is disabled. Trace events will not be emitted."
653
+ );
654
+ }
655
+ }
642
656
  return env;
643
657
  }
644
658
  /**
@@ -662,27 +676,70 @@ var CliRunner = class _CliRunner {
662
676
  if (onLfsProgress) {
663
677
  env.GIT_LFS_FORCE_PROGRESS = "1";
664
678
  }
665
- let stderrBuffer = "";
666
- const result = await this.exec.spawn(
667
- {
679
+ const startTimestamp = Date.now();
680
+ if (this.audit?.onAudit) {
681
+ this.audit.onAudit({
682
+ type: "start",
683
+ timestamp: startTimestamp,
668
684
  argv,
669
- env,
670
- cwd: context.type === "worktree" ? context.workdir : void 0,
671
- signal
672
- },
673
- onProgress || onLfsProgress ? {
674
- onStderr: (chunk) => {
675
- stderrBuffer += chunk;
676
- const lines = stderrBuffer.split(LINE_SEPARATOR_PATTERN);
677
- stderrBuffer = lines.pop() ?? "";
678
- for (const line of lines) {
679
- processProgressLine(line, onProgress, onLfsProgress);
685
+ context
686
+ });
687
+ }
688
+ let stderrBuffer = "";
689
+ const needsStderrStreaming = onProgress || onLfsProgress || this.audit?.onTrace;
690
+ let result;
691
+ try {
692
+ result = await this.exec.spawn(
693
+ {
694
+ argv,
695
+ env,
696
+ cwd: context.type === "worktree" ? context.workdir : void 0,
697
+ signal
698
+ },
699
+ needsStderrStreaming ? {
700
+ onStderr: (chunk) => {
701
+ stderrBuffer += chunk;
702
+ const lines = stderrBuffer.split(LINE_SEPARATOR_PATTERN);
703
+ stderrBuffer = lines.pop() ?? "";
704
+ for (const line of lines) {
705
+ this.processStderrLine(line, onProgress, onLfsProgress);
706
+ }
680
707
  }
681
- }
682
- } : void 0
683
- );
684
- if (stderrBuffer.trim() && (onProgress || onLfsProgress)) {
685
- processProgressLine(stderrBuffer, onProgress, onLfsProgress);
708
+ } : void 0
709
+ );
710
+ if (stderrBuffer.trim() && needsStderrStreaming) {
711
+ this.processStderrLine(stderrBuffer, onProgress, onLfsProgress);
712
+ }
713
+ } catch (error) {
714
+ if (this.audit?.onAudit) {
715
+ const endTimestamp = Date.now();
716
+ this.audit.onAudit({
717
+ type: "end",
718
+ timestamp: endTimestamp,
719
+ argv,
720
+ context,
721
+ stdout: "",
722
+ stderr: error instanceof Error ? error.message : String(error),
723
+ exitCode: -1,
724
+ aborted: signal?.aborted ?? false,
725
+ duration: endTimestamp - startTimestamp
726
+ });
727
+ }
728
+ throw error;
729
+ }
730
+ if (this.audit?.onAudit) {
731
+ const endTimestamp = Date.now();
732
+ this.audit.onAudit({
733
+ type: "end",
734
+ timestamp: endTimestamp,
735
+ argv,
736
+ context,
737
+ stdout: result.stdout,
738
+ stderr: result.stderr,
739
+ exitCode: result.exitCode,
740
+ aborted: result.aborted,
741
+ duration: endTimestamp - startTimestamp
742
+ });
686
743
  }
687
744
  return {
688
745
  stdout: result.stdout,
@@ -691,6 +748,23 @@ var CliRunner = class _CliRunner {
691
748
  aborted: result.aborted
692
749
  };
693
750
  }
751
+ /**
752
+ * Process a single line from stderr for progress and trace callbacks
753
+ */
754
+ processStderrLine(line, onProgress, onLfsProgress) {
755
+ const trimmed = line.trim();
756
+ if (!trimmed) {
757
+ return;
758
+ }
759
+ if (this.audit?.onTrace && GIT_TRACE_PATTERN.test(trimmed)) {
760
+ this.audit.onTrace({
761
+ timestamp: Date.now(),
762
+ line: trimmed
763
+ });
764
+ return;
765
+ }
766
+ processProgressLine(line, onProgress, onLfsProgress);
767
+ }
694
768
  /**
695
769
  * Map Git result to GitError if needed
696
770
  */
@@ -1184,7 +1258,8 @@ var BareRepoImpl = class {
1184
1258
  }
1185
1259
  await this.runner.runOrThrow(this.context, args, {
1186
1260
  signal: opts?.signal,
1187
- onProgress: opts?.onProgress
1261
+ onProgress: opts?.onProgress,
1262
+ onLfsProgress: opts?.onLfsProgress
1188
1263
  });
1189
1264
  }
1190
1265
  // ==========================================================================
@@ -2155,7 +2230,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2155
2230
  }
2156
2231
  await this.runner.runOrThrow(this.context, args, {
2157
2232
  signal: opts?.signal,
2158
- onProgress: opts?.onProgress
2233
+ onProgress: opts?.onProgress,
2234
+ onLfsProgress: opts?.onLfsProgress
2159
2235
  });
2160
2236
  }
2161
2237
  /**
@@ -5499,7 +5575,8 @@ var GitImpl = class {
5499
5575
  try {
5500
5576
  await this.runner.runOrThrow({ type: "global" }, args, {
5501
5577
  signal: opts?.signal,
5502
- onProgress: opts?.onProgress
5578
+ onProgress: opts?.onProgress,
5579
+ onLfsProgress: opts?.onLfsProgress
5503
5580
  });
5504
5581
  } catch (error) {
5505
5582
  if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
@@ -5979,6 +6056,13 @@ var NodeExecAdapter = class {
5979
6056
  wait: () => waitPromise,
5980
6057
  kill: (sig) => {
5981
6058
  child.kill(sig ?? "SIGTERM");
6059
+ },
6060
+ [Symbol.asyncDispose]: async () => {
6061
+ if (child.exitCode === null) {
6062
+ child.kill("SIGTERM");
6063
+ }
6064
+ await waitPromise.catch(() => {
6065
+ });
5982
6066
  }
5983
6067
  };
5984
6068
  }
@@ -6026,7 +6110,8 @@ function createTailPolling(options) {
6026
6110
  state.resolveNext = null;
6027
6111
  }
6028
6112
  };
6029
- startPollingLoop(adapter, state, signal, pollInterval, stop).catch(() => {
6113
+ const pollingPromise = startPollingLoop(adapter, state, signal, pollInterval, stop);
6114
+ pollingPromise.catch(() => {
6030
6115
  });
6031
6116
  const lines = {
6032
6117
  [Symbol.asyncIterator]() {
@@ -6048,7 +6133,15 @@ function createTailPolling(options) {
6048
6133
  };
6049
6134
  }
6050
6135
  };
6051
- return { lines, stop };
6136
+ return {
6137
+ lines,
6138
+ stop,
6139
+ [Symbol.asyncDispose]: async () => {
6140
+ stop();
6141
+ await pollingPromise.catch(() => {
6142
+ });
6143
+ }
6144
+ };
6052
6145
  }
6053
6146
  async function startPollingLoop(adapter, state, signal, pollInterval, stop) {
6054
6147
  let position = 0;
@@ -6072,6 +6165,9 @@ async function startPollingLoop(adapter, state, signal, pollInterval, stop) {
6072
6165
  }
6073
6166
  }
6074
6167
  }
6168
+ if (state.stopped || signal?.aborted) {
6169
+ break;
6170
+ }
6075
6171
  await adapter.sleep(pollInterval);
6076
6172
  }
6077
6173
  stop();
@@ -6160,16 +6256,26 @@ var NodeFsAdapter = class {
6160
6256
  sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
6161
6257
  };
6162
6258
  const polling = createTailPolling({ adapter, signal, pollInterval });
6163
- const originalStop = polling.stop;
6164
- const enhancedStop = () => {
6165
- originalStop();
6259
+ const closeFileHandle = async () => {
6166
6260
  if (state.file) {
6167
- state.file.close().catch(() => {
6261
+ await state.file.close().catch(() => {
6168
6262
  });
6169
6263
  state.file = null;
6170
6264
  }
6171
6265
  };
6172
- return { lines: polling.lines, stop: enhancedStop };
6266
+ const originalStop = polling.stop;
6267
+ const enhancedStop = () => {
6268
+ originalStop();
6269
+ void closeFileHandle();
6270
+ };
6271
+ return {
6272
+ lines: polling.lines,
6273
+ stop: enhancedStop,
6274
+ [Symbol.asyncDispose]: async () => {
6275
+ await polling[Symbol.asyncDispose]();
6276
+ await closeFileHandle();
6277
+ }
6278
+ };
6173
6279
  }
6174
6280
  };
6175
6281