type-git 0.8.2 → 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.
@@ -1,4 +1,4 @@
1
- import { k as CompoundDecimalParser, l as COMPOUND_DECIMALS, m as GitDecimalParser, n as GitDecimalLiteral, o as GitDecimalValue, p as AtMost$1, D as Digit$1, q as AddDigit, F as FastImportUnsignedParser, T as Trim, U as UrlBytes, r as GitIntegerValue, N as NumberLiteralOrder, S as SafeIntegerAtLeast, s as GitScalarParser, t as Evidence, u as Constraint, P as Predicate, a as CompanionExecutable, v as GitBooleanSource, w as GitDecimalCallbacks, x as GitIntegerProfile, y as GitNumericParser, z as Constrained, H as GitNumericLiteral, J as GitBooleanCallback, K as GitBooleanCallbackLiteral, O as ObjectFilterLiteral, M as AsciiUpper, Q as StringCallbackParser, V as StringCallbackLiteral, X as AsciiLower, Y as GitNumericValue, Z as GitBooleanCallbackValue, _ as StringCallbackValue, $ as ConstraintRequirement, a0 as GitTimestampParser, a1 as GitDecimalCallback, a2 as LegacyGitDecimal, a3 as GitIntegerParser, a4 as GitOutputMode, h as CommandExecOpts, R as RawResult, G as Git, W as WorktreeRepo, B as BareRepo } from '../git.d-CJUJ4264.cjs';
1
+ import { k as CompoundDecimalParser, l as COMPOUND_DECIMALS, m as GitDecimalParser, n as GitDecimalLiteral, o as GitDecimalValue, p as AtMost$1, D as Digit$1, q as AddDigit, F as FastImportUnsignedParser, T as Trim, U as UrlBytes, r as GitIntegerValue, N as NumberLiteralOrder, S as SafeIntegerAtLeast, s as GitScalarParser, t as Evidence, u as Constraint, P as Predicate, a as CompanionExecutable, v as GitBooleanSource, w as GitDecimalCallbacks, x as GitIntegerProfile, y as GitNumericParser, z as Constrained, H as GitNumericLiteral, J as GitBooleanCallback, K as GitBooleanCallbackLiteral, O as ObjectFilterLiteral, M as AsciiUpper, Q as StringCallbackParser, V as StringCallbackLiteral, X as AsciiLower, Y as GitNumericValue, Z as GitBooleanCallbackValue, _ as StringCallbackValue, $ as ConstraintRequirement, a0 as GitTimestampParser, a1 as GitDecimalCallback, a2 as LegacyGitDecimal, a3 as GitIntegerParser, a4 as GitOutputMode, a5 as CommandExecOpts, R as RawResult, G as Git, W as WorktreeRepo, B as BareRepo } from '../git.d-BTNkPofF.cjs';
2
2
 
3
3
  type Profile<P extends CompoundDecimalParser> = (typeof COMPOUND_DECIMALS)[P];
4
4
  type DecimalProfile<P extends CompoundDecimalParser, Bits extends 32 | 64, NegateOverflow extends boolean> = Omit<Profile<P>['decimal'], 'longBits'> & {
@@ -21,7 +21,7 @@ import {
21
21
  parseGitScalar,
22
22
  validateIO,
23
23
  violations
24
- } from "../chunk-SXHFNCJZ.js";
24
+ } from "../chunk-V4ZRQG3O.js";
25
25
 
26
26
  // src/strict/command-runner.ts
27
27
  import process from "process";
package/docs/adapters.md CHANGED
@@ -20,10 +20,16 @@ The built-in adapters are `NodeExecAdapter` (`type-git/node`), `BunExecAdapter`
20
20
  ## `SpawnOptions` as the runner sends them
21
21
 
22
22
  - `argv`: `[gitBinary, ...]` (or a companion program path). The first element is the program;
23
- arguments are never passed through a shell. Do not join them into a command line.
23
+ arguments are never passed through a shell. Do not join them into a command line. When a Git
24
+ command also gets `cwd` (see below) and `gitBinary` is a relative path such as `./tools/git`,
25
+ the runner prefixes the host process's current directory, so the program is the same one a
26
+ call without `cwd` would run. A bare name such as `git` is left for `PATH` lookup.
24
27
  - `env`: the **complete** environment for the child. The runner has already resolved the
25
28
  inherited variables (see `inheritEnv` on `createGit`/`open`), layered `env`, `home` and
26
- `pathPrefix` on top, and applied any per-call overrides.
29
+ `pathPrefix` on top, and applied any per-call overrides. When the spawn also gets `cwd`, every
30
+ relative or empty `PATH` entry (from `pathPrefix`, `env`, a per-call override, or the inherited
31
+ value) is anchored to the host process's current directory, so the program search does not
32
+ look inside the repository. Rooted entries, and quoted entries on Windows, are unchanged.
27
33
  - `inheritEnv`: always `false` from the runner. The adapter must not merge the parent process
28
34
  environment underneath `env`; doing so would defeat the environment allowlist.
29
35
  - `stdin`: `undefined`, a UTF-8 `string`, or a `Uint8Array`. When present, write all of it and
@@ -43,8 +49,8 @@ Git commands select the repository with an explicit flag. Companion programs (`s
43
49
  | Context | argv | `cwd` sent to the adapter |
44
50
  | --- | --- | --- |
45
51
  | Repository-agnostic (`git.raw`, `git.version`, `clone`, `init`, …) | `git …` | `undefined` |
46
- | Worktree repository | `git -C <workdir> …` | `<workdir>` |
47
- | Bare repository | `git --git-dir <gitDir> …` | `undefined` |
52
+ | Worktree repository | `git -C <workdir> …` | `<workdir>` if absolute, else `undefined` |
53
+ | Bare repository | `git --git-dir <gitDir> …` | `<gitDir>` if absolute, else `undefined` |
48
54
  | Companion program, repository-agnostic | `<program> …` | `undefined` |
49
55
  | Companion program, worktree repository | `<program> …` | `<workdir>` |
50
56
  | Companion program, bare repository | `<program> …` | `<gitDir>` |
@@ -53,15 +59,22 @@ When a credential helper is configured, Git argv starts with
53
59
  `git -c credential.helper=<helper>` before the context flag.
54
60
 
55
61
  `undefined` means "do not set one"; the child then inherits the host process's current
56
- directory. The runner passes repository paths unchanged, as the table shows: worktree Git
57
- commands get the path in `-C` and as `cwd`, worktree companion programs only as `cwd`, bare Git
58
- commands only in `--git-dir` (`cwd: undefined`), and bare companion programs only as `cwd`.
59
- `clone` and `init` are repository-agnostic: the destination is a positional argument. For
60
- worktree calls, use absolute worktree paths: then the selected repository does not depend on the
61
- inherited directory. A relative worktree path is resolved twice (once by `cwd`, again by `-C`),
62
- so it can fail even with the built-in adapters: `'.'` works, but `'repo'` resolves to
63
- `repo/repo` (#329). Bare Git commands, `clone`, `init` and repository-agnostic calls get
64
- `cwd: undefined` whatever path is used, so an adapter that requires a working directory must
62
+ directory. The runner passes repository paths unchanged, as the table shows. Git commands get the
63
+ path in `-C` / `--git-dir` and, when the path is absolute on the host platform, also as `cwd`
64
+ (on POSIX a path starting with `/`; on Windows also `\x`, `C:\x`, `C:/x`, and UNC paths, but not
65
+ drive-relative `C:x`). A relative path is not sent as `cwd`, because Git resolves `-C` / `--git-dir`
66
+ against the working directory and would otherwise look in `<path>/<path>`; Git then resolves it
67
+ against the host process's current directory, as the Git CLI would. Companion programs get the
68
+ path only as `cwd`, whether absolute or not. Relative path arguments of a repository command
69
+ (for example `repo.raw(['archive', '-o', 'out.tar', 'HEAD'])`) resolve inside the worktree for
70
+ a worktree repository, whether it was opened by an absolute or a relative path, because `-C`
71
+ changes Git's directory. For a bare repository they resolve inside the repository directory
72
+ when it was opened by an absolute path, and against the host process's current directory when
73
+ it was opened by a relative path, because `--git-dir` does not change Git's directory. `clone` and `init` are repository-agnostic: the
74
+ destination is a positional argument. Use absolute repository paths so that the selected
75
+ repository does not depend on the inherited directory and the adapter always receives `cwd` for
76
+ repository calls. `clone`, `init`, repository-agnostic calls, and calls on a repository opened by
77
+ a relative path get `cwd: undefined`, so an adapter that requires a working directory must
65
78
  handle `undefined` (for example by using the host's current directory) instead of rejecting
66
79
  these calls. Repository-agnostic calls are different: `git.raw()`, `strict(git).command()`
67
80
  and repository-agnostic companion programs run with `cwd: undefined`, so a command that needs a
@@ -75,11 +88,20 @@ directory, as the Git CLI would. Open a repository and use `repo.raw()` to avoid
75
88
  - `git.open(path)`, `git.openBare(path)`, `git.openRaw(path)`:
76
89
  1. `git -C <path> rev-parse --is-bare-repository` with `cwd: <path>`.
77
90
  2. Only if step 1 exits non-zero: `git --git-dir <path> rev-parse --is-bare-repository` with
78
- no `cwd`. The error thrown when both fail carries step 2's exit code and stderr.
79
-
80
- If `<path>` does not exist, step 1 fails to start (the built-in Node adapter reports
81
- `spawn git ENOENT` because the working directory is missing) and `open` throws a
82
- `GitError` with kind `SpawnFailed`; step 2 does not run.
91
+ `cwd: <path>`.
92
+
93
+ Both steps follow the `cwd` rule above, so a relative `<path>` runs with `cwd: undefined`.
94
+ When both steps fail, the `GitError` (kind `NonZeroExit`) carries step 2's `exitCode` and
95
+ `stderr`, and `context.firstProbe` carries step 1's `argv`, `exitCode` and `stderr`. Step 1
96
+ usually names the cause (for example `detected dubious ownership` when `safe.directory` does
97
+ not allow the repository), while step 2 only says `not a git repository`, so the message also
98
+ ends with step 1's first `fatal:` line when there is one.
99
+
100
+ If an absolute `<path>` does not exist, step 1 fails to start (the built-in Node adapter
101
+ reports `spawn git ENOENT` because the working directory is missing) and `open` throws a
102
+ `GitError` with kind `SpawnFailed`; step 2 does not run. A relative `<path>` that does not
103
+ exist runs without `cwd`, so both steps run and fail, and `open` throws the `NonZeroExit`
104
+ error above with `firstProbe` (step 1 says `cannot change to '<path>'`).
83
105
  - Typed `strict(...).command()` calls may start **internal probes** before the real command when the
84
106
  result depends on how the installed Git parses an argument (for example `git <command> -h`,
85
107
  `git --exec-path`, or a probe inside a throwaway bare repository created with
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-git",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Type-safe Git wrapper library with LFS support, progress tracking, and abort control for Node.js/Deno/Bun",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",