@osdlc/typed-git 0.19.0 → 0.22.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @osdlc/typed-git
2
2
 
3
+ ## 0.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ebdb5ad: `diffText` and `diffAddedFile` pass `--inter-hunk-context=0` and remove `GIT_DIFF_OPTS` from git's environment, so `diff.interHunkContext` and a `-u<n>` in `GIT_DIFF_OPTS` no longer change the lines of context: `diffText(rev, { context: 0 })` gives the changed lines alone. `GitVerb.env` values may be `undefined`, which removes the variable from the child's environment, as command-seam's `env` does. The docs now list every git setting that still changes the patch text (`diff.algorithm`, `diff.indentHeuristic`, `diff.renames` without `findRenames`, `diff.renameLimit`, `diff.ignoreSubmodules`, `core.quotePath`, `diff.orderFile`, `diff.suppressBlankEmpty`, `core.abbrev`, a funcname driver and binary attributes), say that `findRenames` also overrides `diff.renames=copies`, and say that `context` does not change `diffAddedFile`'s text. A bad `context`, `depth` or `jobs` of `NaN` or `Infinity` now names that value in the `TypeError`, not `null`.
8
+
9
+ ## 0.21.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 3f84b08: `update` rebases with `--fork-point` when it does not know the parent's old head. A child of a PR rebased in an earlier run, without `--restack`, now leaves the parent's old commits behind when the clone's reflog still holds them, instead of replaying them onto their new versions. A fresh clone has no such reflog and rebases as before. `git.rebase(onto, { forkPoint: true })` in typed-git passes `--fork-point`.
14
+
15
+ ## 0.20.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 1ba6088: `diffText` takes `context` (`--unified=<n>`, default 3) and `findRenames` (`-M`, off by default, so `diff.renames` still applies); `diffAddedFile` takes `context`. A negative or non-integer `context` throws a `TypeError`.
20
+
3
21
  ## 0.19.0
4
22
 
5
23
  ### Minor Changes
package/README.md CHANGED
@@ -318,16 +318,47 @@ prints `-` there and a fabricated `0` would be worse than nothing.
318
318
  ## Diff output and the user's git configuration
319
319
 
320
320
  `diffText` and `diffAddedFile` return a plain unified diff with `a/` and `b/`
321
- prefixes and three lines of context. Both always pass `--no-color`,
321
+ prefixes and, by default, three lines of context. Both always pass `--no-color`,
322
322
  `--no-ext-diff`, `--no-textconv`, `--src-prefix=a/`, `--dst-prefix=b/`,
323
- `--no-relative`, `--submodule=short` and `--unified=3`. So `color.ui`,
324
- `color.diff`, `diff.external`, a `diff.<driver>.command` or textconv driver,
325
- `diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`, `diff.dstPrefix`,
326
- `diff.relative`, `diff.submodule` and `diff.context` do not change the text,
327
- and none of them stops `git apply` taking it. Other settings still apply:
328
- rename detection (`diff.renames`), `diff.ignoreSubmodules` and
329
- `diff.algorithm`. The `GIT_DIFF_OPTS` environment variable also still applies:
330
- `-u0` there overrides the three lines of context.
323
+ `--no-relative`, `--submodule=short`, `--inter-hunk-context=0` and
324
+ `--unified=3`, and both remove `GIT_DIFF_OPTS` from git's environment.
325
+ `context: n` changes the last flag to `--unified=<n>`, so `diffText` with
326
+ `context: 0` gives the changed lines alone. `diffAddedFile` takes `context` too,
327
+ so a caller can pass the same options to both verbs, but it changes nothing
328
+ there: a diff from `/dev/null` is one all-added hunk with no context lines.
329
+ `diffText` also takes `findRenames: true` (`-M`), which reads a moved file as
330
+ one rename patch whatever `diff.renames` says. It also turns
331
+ `diff.renames=copies` off, so a new file that copies a changed one is a plain
332
+ add, not a `copy from`/`copy to` patch.
333
+
334
+ So `color.ui`, `color.diff`, `diff.external`, a `diff.<driver>.command` or
335
+ textconv driver, `diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`,
336
+ `diff.dstPrefix`, `diff.relative`, `diff.submodule`, `diff.context`,
337
+ `diff.interHunkContext` and `GIT_DIFF_OPTS` do not change the text, and none
338
+ of them stops `git apply` taking it.
339
+
340
+ Other settings still change the text:
341
+
342
+ - rename detection: `diff.renames`, unless `findRenames` is set, and
343
+ `diff.renameLimit`, past which git stops looking for renames and only warns
344
+ on stderr;
345
+ - `diff.algorithm`, which changes which lines read as changed, and so the line
346
+ counts, not just the layout;
347
+ - `diff.indentHeuristic`, which moves where a hunk starts;
348
+ - `diff.ignoreSubmodules` and `submodule.<name>.ignore`, which can hide a
349
+ submodule change;
350
+ - `core.quotePath`: with `false`, a non-ASCII path is printed raw, not
351
+ C-quoted;
352
+ - `diff.orderFile`, which changes the order of the files;
353
+ - `diff.suppressBlankEmpty`, under which a blank context line loses its
354
+ leading space;
355
+ - `core.abbrev`, which changes the length of the hashes on the `index` line;
356
+ - a `diff.<driver>.xfuncname`, which changes the function name after `@@`;
357
+ - a `-diff` or `binary` attribute, which prints `Binary files … differ` in
358
+ place of a patch (`binary: true` writes a binary patch instead);
359
+ - clean filters and end-of-line conversion (`core.autocrlf`, and the `text`,
360
+ `eol` and `filter` attributes), which change the working-tree content git
361
+ compares.
331
362
 
332
363
  `diffNameStatus` passes `--no-relative`, so its paths are relative to the
333
364
  repository root and cover the whole repository when the cwd is below the
@@ -763,8 +794,8 @@ exit throws the classified failure.
763
794
  | `diffNameStatus({ cached, range, noRenames, paths })` | `diff --no-color --no-relative --name-status -z [--cached] [--no-renames] [range] [--] [paths]` | none — `--` is passed once, when there is a range or a path, so git never reads the range as a path |
764
795
  | `diffStat({ rangeArgs, paths })` | `diff --stat` | none — raw stdout |
765
796
  | `diffCheck({ paths })` | `diff --check` | `1`, `2` → `{ ok: false, output }` |
766
- | `diffText(rev?, { staged, binary, paths })` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=3 [--cached] [--binary] [rev] [--] [paths]` | none — empty string only when nothing differs; a bad rev or a non-repository throws; `--` is passed once, when there is a rev or a path, so git never reads the rev as a path; the text is plain under the [settings the flags pin](#diff-output-and-the-users-git-configuration); `binary` writes a binary file's change as a patch `git apply` replays |
767
- | `diffAddedFile(relPath)` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=3 --no-index -- /dev/null <path>` | none — exit 1 with output is success; exit 1 with no output, or exit 2, throws; the text is plain, as for `diffText` |
797
+ | `diffText(rev?, { staged, binary, context, findRenames, paths })` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --inter-hunk-context=0 --unified=<context, default 3> [--cached] [--binary] [-M] [rev] [--] [paths]`, without `GIT_DIFF_OPTS` | none — empty string only when nothing differs; a bad rev or a non-repository throws; `--` is passed once, when there is a rev or a path, so git never reads the rev as a path; the text is plain under the [settings the flags pin](#diff-output-and-the-users-git-configuration); `binary` writes a binary file's change as a patch `git apply` replays |
798
+ | `diffAddedFile(relPath, { context })` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --inter-hunk-context=0 --unified=<context, default 3> --no-index -- /dev/null <path>`, without `GIT_DIFF_OPTS` | none — exit 1 with output is success; exit 1 with no output, or exit 2, throws; the text is plain, as for `diffText`; `context` is checked but changes nothing |
768
799
  | `log(opts)` | `log` | none — raw stdout, unsplit |
769
800
  | `logLines(opts)` | `log`, split and filtered | none |
770
801
  | `lsTree(rev, { recursive, long, paths })` | `ls-tree -z` | none |
@@ -834,7 +865,7 @@ other non-zero exit throws.
834
865
  | Method | git | Returns |
835
866
  | --- | --- | --- |
836
867
  | `merge(ref, { noFf, noCommit, ffOnly, message })` | `merge --no-edit` | `MergeOutcome` — with `ffOnly`, a merge that cannot fast-forward throws |
837
- | `rebase(onto, { autostash, upstream })` | `rebase` (`--onto <onto> <upstream>` with `upstream`) | `RebaseOutcome` |
868
+ | `rebase(onto, { autostash, upstream, forkPoint })` | `rebase` (`--onto <onto> <upstream>` with `upstream`; `--fork-point` with `forkPoint`) | `RebaseOutcome` |
838
869
  | `rebaseContinue()` | `-c core.editor=true rebase --continue` | `RebaseOutcome` |
839
870
  | `mergeTree(ours, theirs, { mergeBase })` | `merge-tree --write-tree --name-only -z` | `MergeTreeOutcome` |
840
871
  | `lsFilesUnmerged()` | `ls-files -u -z` | `UnmergedEntry[]` — mode, sha, stage, path |
package/dist/async.d.ts CHANGED
@@ -18,7 +18,7 @@ import { type GitBackend, type GitCallOptions } from './backend.ts';
18
18
  import type { GitVersion } from './git-version.ts';
19
19
  import { type Soft, type TriedAsync } from './outcome.ts';
20
20
  import { type RemoteCoordinate } from './remote-url.ts';
21
- import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
21
+ import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffAddedFileOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
22
22
  /** A typed, awaitable git client bound to one working directory. */
23
23
  export declare class AsyncGit {
24
24
  readonly cwd: string;
@@ -219,7 +219,7 @@ export declare class AsyncGit {
219
219
  * One untracked file rendered as an all-added diff. A path git cannot read
220
220
  * rejects. See {@link Git.diffAddedFile}.
221
221
  */
222
- diffAddedFile(relPath: string, opts?: GitCallOptions): Promise<string>;
222
+ diffAddedFile(relPath: string, opts?: GitCallOptions & DiffAddedFileOptions): Promise<string>;
223
223
  /** `for-each-ref` rows, one line each, in the caller's format. */
224
224
  forEachRef(pattern: string | string[], opts?: GitCallOptions & ForEachRefOptions): Promise<string[]>;
225
225
  /** Local refs matching `pattern` as `{ sha, ref }` rows. */
package/dist/async.js CHANGED
@@ -348,14 +348,23 @@ export class AsyncGit {
348
348
  */
349
349
  diffText(rev, opts = {}) {
350
350
  const [call, req] = splitCallOptions(opts);
351
- return this.backend.execute(this.cwd, { kind: 'diffText', rev, staged: req.staged, binary: req.binary, paths: req.paths }, call);
351
+ return this.backend.execute(this.cwd, {
352
+ kind: 'diffText',
353
+ rev,
354
+ staged: req.staged,
355
+ binary: req.binary,
356
+ context: req.context,
357
+ findRenames: req.findRenames,
358
+ paths: req.paths,
359
+ }, call);
352
360
  }
353
361
  /**
354
362
  * One untracked file rendered as an all-added diff. A path git cannot read
355
363
  * rejects. See {@link Git.diffAddedFile}.
356
364
  */
357
365
  diffAddedFile(relPath, opts = {}) {
358
- return this.backend.execute(this.cwd, { kind: 'diffAddedFile', relPath }, opts);
366
+ const [call, req] = splitCallOptions(opts);
367
+ return this.backend.execute(this.cwd, { kind: 'diffAddedFile', relPath, context: req.context }, call);
359
368
  }
360
369
  /** `for-each-ref` rows, one line each, in the caller's format. */
361
370
  forEachRef(pattern, opts = {}) {
package/dist/backend.d.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  */
20
20
  import { type AsyncBytesCommandRunner, type AsyncCommandRunner, type CommandResult } from '@osdlc/command-seam';
21
21
  import { type GitVersion } from './git-version.ts';
22
- import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type CloneOptions, type CommitOptions, type ConfigGetOptions, type ConfigSetOptions, type ConflictSide, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type GcOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type NumstatEntry, type PushOptions, type PushReport, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type WorktreeAddOptions, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type Worktree, type WorktreeMoveOptions } from './verbs.ts';
22
+ import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type CloneOptions, type CommitOptions, type ConfigGetOptions, type ConfigSetOptions, type ConflictSide, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffAddedFileOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type GcOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type NumstatEntry, type PushOptions, type PushReport, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type WorktreeAddOptions, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type Worktree, type WorktreeMoveOptions } from './verbs.ts';
23
23
  /** Per-call concerns that are not part of the operation itself. */
24
24
  export interface GitCallOptions {
25
25
  /**
@@ -186,10 +186,10 @@ export type GitRequest = {
186
186
  } & GrepOptions) | ({
187
187
  kind: 'diffText';
188
188
  rev?: string | undefined;
189
- } & DiffTextOptions) | {
189
+ } & DiffTextOptions) | ({
190
190
  kind: 'diffAddedFile';
191
191
  relPath: string;
192
- } | ({
192
+ } & DiffAddedFileOptions) | ({
193
193
  kind: 'fetch';
194
194
  remote: string;
195
195
  refspec?: string | string[] | undefined;
package/dist/backend.js CHANGED
@@ -121,7 +121,7 @@ function toVerb(request) {
121
121
  case 'diffText':
122
122
  return v.diffText(request.rev, request);
123
123
  case 'diffAddedFile':
124
- return v.diffAddedFile(request.relPath);
124
+ return v.diffAddedFile(request.relPath, request);
125
125
  case 'fetch':
126
126
  return v.fetch(request.remote, request.refspec, request);
127
127
  case 'fetchMany':
package/dist/client.d.ts CHANGED
@@ -22,6 +22,6 @@ export { classifyGitFailure, describeGitFailure, UnsupportedRequest, type GitFai
22
22
  export { type Soft, type TriedAsync, type TriedSync } from './outcome.ts';
23
23
  export { GIT_FEATURES, GIT_FLOOR, gitSupports, type GitFeature, type GitFeatureSpec, type GitRelease, type UnsupportedGit, } from './features.ts';
24
24
  export { compareGitVersions, parseGitVersion, type GitVersion } from './git-version.ts';
25
- export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CheckoutOptions, type CleanOptions, type CloneOptions, type CommitFlags, type CommitOptions, type ConfigGetOptions, type ConfigScope, type ConfigSetOptions, type ConflictSide, type DiffCheckOptions, type DiffCheckResult, type DiffEntry, type DiffNameOnlyOptions, type DiffNameStatusOptions, type DiffStatOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type ForceLease, type GcOptions, type GrepOptions, type HashObjectOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type MktreeEntry, type NumstatEntry, type PushFlag, type PushOptions, type PushRefResult, type PushRejection, type PushRejectionInfo, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type IndexSubmodule, type TaggedFile, type TreeEntry, type UnmergedEntry, type UpdateRefOptions, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
25
+ export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CheckoutOptions, type CleanOptions, type CloneOptions, type CommitFlags, type CommitOptions, type ConfigGetOptions, type ConfigScope, type ConfigSetOptions, type ConflictSide, type DiffCheckOptions, type DiffCheckResult, type DiffEntry, type DiffNameOnlyOptions, type DiffNameStatusOptions, type DiffStatOptions, type DiffAddedFileOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type ForceLease, type GcOptions, type GrepOptions, type HashObjectOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type MktreeEntry, type NumstatEntry, type PushFlag, type PushOptions, type PushRefResult, type PushRejection, type PushRejectionInfo, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type IndexSubmodule, type TaggedFile, type TreeEntry, type UnmergedEntry, type UpdateRefOptions, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
26
26
  export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, spawnRunnerBytes, spawnRunnerBytesAsync, type AsyncBytesCommandRunner, type AsyncCommandRunner, type AsyncCommandRunOptions, type BytesCommandRunner, type CommandResult, type CommandRunner, type CommandRunOptions, } from '@osdlc/command-seam';
27
27
  export type { CatFileBatchOptions, CatFileEntry } from './cat-file.ts';
package/dist/sync.d.ts CHANGED
@@ -20,7 +20,7 @@ import { type CatFileBatchOptions, type CatFileEntry } from './cat-file.ts';
20
20
  import { type GitVersion } from './git-version.ts';
21
21
  import { type Soft, type TriedSync } from './outcome.ts';
22
22
  import { type RemoteCoordinate } from './remote-url.ts';
23
- import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
23
+ import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffAddedFileOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
24
24
  /**
25
25
  * Per-call concerns that are not part of the operation itself.
26
26
  *
@@ -343,7 +343,7 @@ export declare class Git {
343
343
  * One untracked file rendered as an all-added diff. A path git cannot read
344
344
  * throws. See `diffAddedFile` in `verbs.ts`.
345
345
  */
346
- diffAddedFile(relPath: string, opts?: GitSyncCallOptions): string;
346
+ diffAddedFile(relPath: string, opts?: GitSyncCallOptions & DiffAddedFileOptions): string;
347
347
  /** `for-each-ref` rows, one line each, in the caller's format. */
348
348
  forEachRef(pattern: string | string[], opts?: GitSyncCallOptions & ForEachRefOptions): string[];
349
349
  /**
package/dist/sync.js CHANGED
@@ -503,7 +503,7 @@ export class Git {
503
503
  * throws. See `diffAddedFile` in `verbs.ts`.
504
504
  */
505
505
  diffAddedFile(relPath, opts = {}) {
506
- return this.exec(v.diffAddedFile(relPath), opts);
506
+ return this.exec(v.diffAddedFile(relPath, opts), opts);
507
507
  }
508
508
  /** `for-each-ref` rows, one line each, in the caller's format. */
509
509
  forEachRef(pattern, opts = {}) {
package/dist/verbs.d.ts CHANGED
@@ -25,9 +25,11 @@ export interface GitVerb<T> {
25
25
  /**
26
26
  * Environment entries the verb needs, set over the client's and the call's
27
27
  * `env`. The integration verbs set `LC_ALL=C` here so their parsers read
28
- * English git output.
28
+ * English git output. An `undefined` value removes the variable from the
29
+ * child's environment (see `CommandRunOptions.env` in @osdlc/command-seam):
30
+ * `diffText` and `diffAddedFile` remove `GIT_DIFF_OPTS` this way.
29
31
  */
30
- env?: Readonly<Record<string, string>> | undefined;
32
+ env?: Readonly<Record<string, string | undefined>> | undefined;
31
33
  /**
32
34
  * Exit codes that mean "asked and answered: not there" for this verb — not
33
35
  * "git failed". `config --get` exits 1 for an unset key, `cat-file -e` exits
@@ -761,37 +763,81 @@ export interface DiffTextOptions {
761
763
  * The patch is ASCII (base85), so the decode to a string keeps it intact.
762
764
  */
763
765
  binary?: boolean | undefined;
766
+ /**
767
+ * `--unified=<n>`: lines of context around each change. Default 3, whatever
768
+ * `diff.context` or `GIT_DIFF_OPTS` says; 0 gives a patch of the changed
769
+ * lines alone (`--inter-hunk-context=0` keeps `diff.interHunkContext` from
770
+ * merging nearby hunks with the lines between them). A non-negative
771
+ * integer, else the verb throws a `TypeError`.
772
+ */
773
+ context?: number | undefined;
774
+ /**
775
+ * `-M`: detect renames, whatever `diff.renames` says, so a moved file reads
776
+ * as one `rename from`/`rename to` patch and not as a delete plus an add.
777
+ * It also overrides `diff.renames=copies`, under which a new file that
778
+ * copies a changed one reads as `copy from`/`copy to`: with `-M` it is a
779
+ * plain add. Off by default: without it `diff.renames` applies (git's own
780
+ * default is on). `diff.renameLimit` still applies: past it git stops
781
+ * looking for renames and only warns on stderr.
782
+ */
783
+ findRenames?: boolean | undefined;
764
784
  /** Pathspecs, passed after `--`. */
765
785
  paths?: string[] | undefined;
766
786
  }
787
+ /** Options for {@link diffAddedFile}. */
788
+ export interface DiffAddedFileOptions {
789
+ /**
790
+ * `--unified=<n>`, checked as {@link DiffTextOptions.context}. It does not
791
+ * change the text: a diff from `/dev/null` is one all-added hunk with no
792
+ * context lines, whatever the number. It is accepted so a caller can pass
793
+ * the same options to both verbs.
794
+ */
795
+ context?: number | undefined;
796
+ }
767
797
  /**
768
798
  * The unified diff text (`git diff --no-color --no-ext-diff --no-textconv
769
799
  * --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short
770
- * --unified=3 [--cached] [--binary] [rev] [--] [paths]`), for the same rev
800
+ * --inter-hunk-context=0 --unified=<context> [--cached] [--binary] [-M] [rev]
801
+ * [--] [paths]`, with `GIT_DIFF_OPTS` removed from git's environment), for the same rev
771
802
  * and staged shape {@link diffNameStatus} lists paths for. `--` is passed
772
803
  * once, when there is a rev or a path. Empty when nothing differs.
773
804
  * {@link diffNameOnly} selects the same paths except under `diff.relative`,
774
805
  * which it still follows.
775
806
  *
776
- * The text is a plain unified diff with `a/` and `b/` prefixes and three
777
- * lines of context. The flags that are always passed turn off colour codes
807
+ * The text is a plain unified diff with `a/` and `b/` prefixes. The flags that are always passed turn off colour codes
778
808
  * (`color.ui`, `color.diff`), an external diff tool (`diff.external`, a
779
809
  * `diff.<driver>.command`), textconv conversion, other prefixes
780
810
  * (`diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`,
781
811
  * `diff.dstPrefix`) and `diff.relative`, which with a cwd below the
782
812
  * repository root would drop changes outside it. They also keep a submodule
783
813
  * change as a `Subproject commit` patch, whatever `diff.submodule` says, and
784
- * the context at three lines, whatever `diff.context` says. Other settings
785
- * still apply: rename detection (`diff.renames`), `diff.ignoreSubmodules` and
786
- * `diff.algorithm`; so does the `GIT_DIFF_OPTS` environment variable, where
787
- * `-u0` overrides the three lines of context. The rev is followed by `--`, so git never reads it as a
814
+ * the context at `context` lines (default three), whatever `diff.context`,
815
+ * `diff.interHunkContext` or the `GIT_DIFF_OPTS` environment variable says.
816
+ *
817
+ * Other settings still change the text, so a caller that compares or counts
818
+ * lines across machines should know them: rename detection (`diff.renames`,
819
+ * unless `findRenames` pins it on, and `diff.renameLimit`), `diff.algorithm`
820
+ * (which lines read as changed, so the line counts too),
821
+ * `diff.indentHeuristic` (where a hunk starts), `diff.ignoreSubmodules` and
822
+ * `submodule.<name>.ignore` (whether a submodule change is shown at all),
823
+ * `core.quotePath` (whether a non-ASCII path is C-quoted), `diff.orderFile`
824
+ * (the order of the files), `diff.suppressBlankEmpty` (a blank context line
825
+ * loses its leading space), `core.abbrev` (the length of the `index` line's
826
+ * hashes), a `diff.<driver>.xfuncname` (the function name after `@@`), and a
827
+ * `-diff` or `binary` attribute (`Binary files … differ` in place of a
828
+ * patch, unless `binary` is set). Clean filters and end-of-line conversion
829
+ * (`core.autocrlf`, `text`, `eol` and `filter` attributes) change the
830
+ * working-tree content git compares.
831
+ *
832
+ * The rev is followed by `--`, so git never reads it as a
788
833
  * path: a rev that names a file but no revision throws, and a branch that
789
834
  * shares its name with a file works.
790
835
  *
791
836
  * The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
792
837
  * comes back with U+FFFD in them, and the patch no longer applies. For a
793
838
  * patch that must replay byte for byte, run the same argv through
794
- * `rawBytesChecked`.
839
+ * `rawBytesChecked`, with `env: { GIT_DIFF_OPTS: '' }` (git ignores an empty
840
+ * value) so the context stays as asked.
795
841
  *
796
842
  * `absent: []`. A rev that does not resolve exits 128, and outside a
797
843
  * repository `git diff` exits 129. Both throw, so "git failed" never reads as
@@ -801,17 +847,19 @@ export declare function diffText(rev?: string | undefined, opts?: DiffTextOption
801
847
  /**
802
848
  * One untracked file rendered as an all-added diff (`diff --no-color
803
849
  * --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative
804
- * --submodule=short --unified=3 --no-index -- /dev/null <path>`), so a new
850
+ * --submodule=short --inter-hunk-context=0 --unified=<context> --no-index --
851
+ * /dev/null <path>`, with `GIT_DIFF_OPTS` removed from git's environment), so a new
805
852
  * file reaches a consumer in the same shape as a modified one: the flags are
806
853
  * the ones {@link diffText} passes, and the text is as plain. An empty
807
- * existing file still gives a diff header.
854
+ * existing file still gives a diff header. `context` is checked but does not
855
+ * change the text (see {@link DiffAddedFileOptions.context}).
808
856
  *
809
857
  * `--no-index` exits 1 whenever the inputs differ, which for a real file is
810
858
  * always, so exit 1 is the success case. git also exits 1, with empty stdout,
811
859
  * for a path it cannot read; that throws the classified failure. Exit 2 (a usage or
812
860
  * read error) throws too.
813
861
  */
814
- export declare function diffAddedFile(relPath: string): GitVerb<string>;
862
+ export declare function diffAddedFile(relPath: string, opts?: DiffAddedFileOptions): GitVerb<string>;
815
863
  /**
816
864
  * The paths and statuses one commit changed (`git diff-tree --name-status -z`).
817
865
  *
@@ -1627,6 +1675,13 @@ export interface RebaseOptions {
1627
1675
  * base commits are left behind instead of replayed onto the new ones.
1628
1676
  */
1629
1677
  upstream?: string | undefined;
1678
+ /**
1679
+ * `--fork-point`: take the branch's old base from the reflog of `onto`, so
1680
+ * commits the base held before it was rewritten are left behind. Where the
1681
+ * reflog lacks the old base (a fresh clone), git falls back to the merge
1682
+ * base, which is a plain `rebase`. `upstream` wins when both are set.
1683
+ */
1684
+ forkPoint?: boolean | undefined;
1630
1685
  }
1631
1686
  /**
1632
1687
  * Replay the current branch onto `onto` (`git rebase`, or
package/dist/verbs.js CHANGED
@@ -210,7 +210,7 @@ function configKey(verb, key) {
210
210
  */
211
211
  function depthArg(verb, depth) {
212
212
  if (!Number.isSafeInteger(depth) || depth < 1) {
213
- throw new TypeError(`typed-git: ${verb}: depth must be a positive integer (got ${JSON.stringify(depth)})`);
213
+ throw new TypeError(`typed-git: ${verb}: depth must be a positive integer (got ${shown(depth)})`);
214
214
  }
215
215
  return `--depth=${depth}`;
216
216
  }
@@ -233,7 +233,9 @@ function pushRevAndPaths(argv, rev, paths) {
233
233
  * The `git diff` flags that pin patch text against the user's git settings:
234
234
  * no colour codes, no external diff tool, no textconv conversion, the `a/`
235
235
  * and `b/` prefixes, paths that are not cut to the cwd, a submodule change as
236
- * a `Subproject commit` patch, and three lines of context.
236
+ * a `Subproject commit` patch, and no context lines between hunks
237
+ * (`diff.interHunkContext`), so nearby hunks are not merged. The context is
238
+ * {@link unifiedArg}'s.
237
239
  */
238
240
  const PLAIN_PATCH = [
239
241
  '--no-color',
@@ -243,8 +245,39 @@ const PLAIN_PATCH = [
243
245
  '--dst-prefix=b/',
244
246
  '--no-relative',
245
247
  '--submodule=short',
246
- '--unified=3',
248
+ '--inter-hunk-context=0',
247
249
  ];
250
+ /**
251
+ * The child env of the patch verbs: `GIT_DIFF_OPTS` removed, because git
252
+ * reads a `-u<n>` or `--unified=<n>` there over the `--unified` flag. The
253
+ * `undefined` value removes it (see `CommandRunOptions.env` in
254
+ * @osdlc/command-seam).
255
+ */
256
+ const PLAIN_PATCH_ENV = Object.freeze({
257
+ GIT_DIFF_OPTS: undefined,
258
+ });
259
+ /** The lines of context {@link diffText} and {@link diffAddedFile} print by default. */
260
+ const DEFAULT_CONTEXT = 3;
261
+ /**
262
+ * `--unified=<context>`, or the default when `context` is undefined. Throws
263
+ * `TypeError` when `context` is not a non-negative safe integer; `verb` names
264
+ * the caller in the message.
265
+ */
266
+ function unifiedArg(verb, context) {
267
+ const n = context ?? DEFAULT_CONTEXT;
268
+ if (!Number.isSafeInteger(n) || n < 0) {
269
+ throw new TypeError(`typed-git: ${verb}: context must be a non-negative integer (got ${shown(n)})`);
270
+ }
271
+ return `--unified=${n}`;
272
+ }
273
+ /**
274
+ * A bad option value for an error message: a number as `String` prints it, so
275
+ * `NaN` and `Infinity` read as themselves (`JSON.stringify` prints `null`), and
276
+ * anything else as JSON, so a string keeps its quotes.
277
+ */
278
+ function shown(value) {
279
+ return typeof value === 'number' ? String(value) : JSON.stringify(value);
280
+ }
248
281
  /** The child env that makes git print English, whatever the caller's locale. */
249
282
  const C_LOCALE = Object.freeze({ LC_ALL: 'C' });
250
283
  // ── queries ─────────────────────────────────────────────────────────────────
@@ -1030,61 +1063,90 @@ export function lsTree(rev, opts = {}) {
1030
1063
  /**
1031
1064
  * The unified diff text (`git diff --no-color --no-ext-diff --no-textconv
1032
1065
  * --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short
1033
- * --unified=3 [--cached] [--binary] [rev] [--] [paths]`), for the same rev
1066
+ * --inter-hunk-context=0 --unified=<context> [--cached] [--binary] [-M] [rev]
1067
+ * [--] [paths]`, with `GIT_DIFF_OPTS` removed from git's environment), for the same rev
1034
1068
  * and staged shape {@link diffNameStatus} lists paths for. `--` is passed
1035
1069
  * once, when there is a rev or a path. Empty when nothing differs.
1036
1070
  * {@link diffNameOnly} selects the same paths except under `diff.relative`,
1037
1071
  * which it still follows.
1038
1072
  *
1039
- * The text is a plain unified diff with `a/` and `b/` prefixes and three
1040
- * lines of context. The flags that are always passed turn off colour codes
1073
+ * The text is a plain unified diff with `a/` and `b/` prefixes. The flags that are always passed turn off colour codes
1041
1074
  * (`color.ui`, `color.diff`), an external diff tool (`diff.external`, a
1042
1075
  * `diff.<driver>.command`), textconv conversion, other prefixes
1043
1076
  * (`diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`,
1044
1077
  * `diff.dstPrefix`) and `diff.relative`, which with a cwd below the
1045
1078
  * repository root would drop changes outside it. They also keep a submodule
1046
1079
  * change as a `Subproject commit` patch, whatever `diff.submodule` says, and
1047
- * the context at three lines, whatever `diff.context` says. Other settings
1048
- * still apply: rename detection (`diff.renames`), `diff.ignoreSubmodules` and
1049
- * `diff.algorithm`; so does the `GIT_DIFF_OPTS` environment variable, where
1050
- * `-u0` overrides the three lines of context. The rev is followed by `--`, so git never reads it as a
1080
+ * the context at `context` lines (default three), whatever `diff.context`,
1081
+ * `diff.interHunkContext` or the `GIT_DIFF_OPTS` environment variable says.
1082
+ *
1083
+ * Other settings still change the text, so a caller that compares or counts
1084
+ * lines across machines should know them: rename detection (`diff.renames`,
1085
+ * unless `findRenames` pins it on, and `diff.renameLimit`), `diff.algorithm`
1086
+ * (which lines read as changed, so the line counts too),
1087
+ * `diff.indentHeuristic` (where a hunk starts), `diff.ignoreSubmodules` and
1088
+ * `submodule.<name>.ignore` (whether a submodule change is shown at all),
1089
+ * `core.quotePath` (whether a non-ASCII path is C-quoted), `diff.orderFile`
1090
+ * (the order of the files), `diff.suppressBlankEmpty` (a blank context line
1091
+ * loses its leading space), `core.abbrev` (the length of the `index` line's
1092
+ * hashes), a `diff.<driver>.xfuncname` (the function name after `@@`), and a
1093
+ * `-diff` or `binary` attribute (`Binary files … differ` in place of a
1094
+ * patch, unless `binary` is set). Clean filters and end-of-line conversion
1095
+ * (`core.autocrlf`, `text`, `eol` and `filter` attributes) change the
1096
+ * working-tree content git compares.
1097
+ *
1098
+ * The rev is followed by `--`, so git never reads it as a
1051
1099
  * path: a rev that names a file but no revision throws, and a branch that
1052
1100
  * shares its name with a file works.
1053
1101
  *
1054
1102
  * The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
1055
1103
  * comes back with U+FFFD in them, and the patch no longer applies. For a
1056
1104
  * patch that must replay byte for byte, run the same argv through
1057
- * `rawBytesChecked`.
1105
+ * `rawBytesChecked`, with `env: { GIT_DIFF_OPTS: '' }` (git ignores an empty
1106
+ * value) so the context stays as asked.
1058
1107
  *
1059
1108
  * `absent: []`. A rev that does not resolve exits 128, and outside a
1060
1109
  * repository `git diff` exits 129. Both throw, so "git failed" never reads as
1061
1110
  * "no diff". `git.try.diffText` reports them as `{ ok: false }`.
1062
1111
  */
1063
1112
  export function diffText(rev, opts = {}) {
1064
- const argv = ['diff', ...PLAIN_PATCH];
1113
+ const argv = ['diff', ...PLAIN_PATCH, unifiedArg('diffText', opts.context)];
1065
1114
  if (opts.staged === true)
1066
1115
  argv.push('--cached');
1067
1116
  if (opts.binary === true)
1068
1117
  argv.push('--binary');
1118
+ if (opts.findRenames === true)
1119
+ argv.push('-M');
1069
1120
  pushRevAndPaths(argv, optionalPositional('diffText', 'rev', rev), opts.paths);
1070
- return { argv, absent: NONE, parse: (r) => r.stdout };
1121
+ return { argv, env: PLAIN_PATCH_ENV, absent: NONE, parse: (r) => r.stdout };
1071
1122
  }
1072
1123
  /**
1073
1124
  * One untracked file rendered as an all-added diff (`diff --no-color
1074
1125
  * --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative
1075
- * --submodule=short --unified=3 --no-index -- /dev/null <path>`), so a new
1126
+ * --submodule=short --inter-hunk-context=0 --unified=<context> --no-index --
1127
+ * /dev/null <path>`, with `GIT_DIFF_OPTS` removed from git's environment), so a new
1076
1128
  * file reaches a consumer in the same shape as a modified one: the flags are
1077
1129
  * the ones {@link diffText} passes, and the text is as plain. An empty
1078
- * existing file still gives a diff header.
1130
+ * existing file still gives a diff header. `context` is checked but does not
1131
+ * change the text (see {@link DiffAddedFileOptions.context}).
1079
1132
  *
1080
1133
  * `--no-index` exits 1 whenever the inputs differ, which for a real file is
1081
1134
  * always, so exit 1 is the success case. git also exits 1, with empty stdout,
1082
1135
  * for a path it cannot read; that throws the classified failure. Exit 2 (a usage or
1083
1136
  * read error) throws too.
1084
1137
  */
1085
- export function diffAddedFile(relPath) {
1138
+ export function diffAddedFile(relPath, opts = {}) {
1086
1139
  return {
1087
- argv: ['diff', ...PLAIN_PATCH, '--no-index', '--', '/dev/null', relPath],
1140
+ argv: [
1141
+ 'diff',
1142
+ ...PLAIN_PATCH,
1143
+ unifiedArg('diffAddedFile', opts.context),
1144
+ '--no-index',
1145
+ '--',
1146
+ '/dev/null',
1147
+ relPath,
1148
+ ],
1149
+ env: PLAIN_PATCH_ENV,
1088
1150
  absent: [1],
1089
1151
  parse(r, ranArgv) {
1090
1152
  if (r.exitCode !== 0 && r.stdout === '')
@@ -1582,7 +1644,7 @@ export function fetchMany(remotes, opts = {}) {
1582
1644
  argv.push('--no-tags');
1583
1645
  if (opts.jobs !== undefined) {
1584
1646
  if (!Number.isSafeInteger(opts.jobs) || opts.jobs < 1) {
1585
- throw new TypeError(`typed-git: fetchMany: jobs must be a positive integer (got ${JSON.stringify(opts.jobs)})`);
1647
+ throw new TypeError(`typed-git: fetchMany: jobs must be a positive integer (got ${shown(opts.jobs)})`);
1586
1648
  }
1587
1649
  argv.push(`--jobs=${opts.jobs}`);
1588
1650
  }
@@ -2259,8 +2321,11 @@ export function rebase(onto, opts = {}) {
2259
2321
  const argv = ['rebase'];
2260
2322
  if (opts.autostash)
2261
2323
  argv.push('--autostash');
2262
- if (opts.upstream === undefined)
2324
+ if (opts.upstream === undefined) {
2325
+ if (opts.forkPoint)
2326
+ argv.push('--fork-point');
2263
2327
  argv.push(positional('rebase', 'onto', onto));
2328
+ }
2264
2329
  else {
2265
2330
  argv.push('--onto', positional('rebase', 'onto', onto), positional('rebase', 'upstream', opts.upstream));
2266
2331
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdlc/typed-git",
3
- "version": "0.19.0",
3
+ "version": "0.22.0",
4
4
  "description": "A typed git client for TypeScript, sync and awaitable. Each verb declares what absence means for it; every other failure throws. git.try.* inspects, raw() bypasses — over an injectable backend that drives the git CLI or any other implementation.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "author": "sksizer",