@osdlc/typed-git 0.16.0 → 0.17.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,21 @@
1
1
  # @osdlc/typed-git
2
2
 
3
+ ## 0.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6236a97: `diffText`, `diffAddedFile` and `diffNameStatus` pass fixed flags that pin their output against the git settings named below, and `diffText` and `diffNameStatus` never read a rev as a path.
8
+
9
+ - `diffText` and `diffAddedFile` always pass `--no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=3`. Their text is a plain unified diff with `a/` and `b/` prefixes and three lines of context under `color.ui`, `color.diff`, `diff.external`, a `diff.<driver>.command` or textconv driver, `diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`, `diff.dstPrefix`, `diff.relative`, `diff.submodule` and `diff.context`, so none of those settings stops `git apply` taking it. Other settings still apply: rename detection (`diff.renames`), `diff.ignoreSubmodules` and `diff.algorithm`, and the `GIT_DIFF_OPTS` environment variable, where `-u0` overrides the three lines of context. These are the two verbs whose output changes under a colour setting.
10
+ - `diffNameStatus` always passes `--no-color --no-relative`. `--no-color` is a guard: git never coloured that output.
11
+ - **Breaking:** under `diff.relative=true` with a cwd below the repository root, `diffNameStatus` and `diffText` now give paths relative to the root and list changes outside the cwd, where they gave paths relative to the cwd and left those changes out.
12
+ - **Breaking:** `diffText` and `diffNameStatus` pass `--` after the rev or range, with or without paths. A rev that names a file but no revision now throws, where it returned that file's diff. A branch that shares its name with a file or folder now works, where git refused it as ambiguous.
13
+ - `diffStat`, `diffCheck`, `log` and `logLines` with no `format`, and `grep` without `noColor` still follow the user's colour setting. `diffNameOnly`, `diffStat` and `diffCheck` still follow `diff.relative`. The README's new "Diff output and the user's git configuration" section lists them.
14
+ - **Breaking for fake runners:** the argv of three verbs changed, so a `CommandRunner` keyed on the old argv no longer matches and gives its default reply. To migrate, key the fake on the new argv. `--` is passed once, when there is a rev, a range or a path.
15
+ - `diffText`: `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=3 [--cached] [--binary] [rev] [--] [paths]`. It was `diff [--cached] [--binary] [rev] [-- paths]`. The eight flags follow `diff`, and `--` follows a rev even with no paths.
16
+ - `diffAddedFile`: `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>`. It was `diff --no-index -- /dev/null <path>`.
17
+ - `diffNameStatus`: `diff --no-color --no-relative --name-status -z [--cached] [--no-renames] [range] [--] [paths]`. It was `diff --name-status -z [--cached] [--no-renames] [range] [-- paths]`. The two flags follow `diff`, and `--` follows a range even with no paths.
18
+
3
19
  ## 0.16.0
4
20
 
5
21
  ### Minor Changes
package/README.md CHANGED
@@ -125,8 +125,10 @@ release, with a CHANGELOG entry that starts with `Breaking:`.
125
125
  This package exists for plain TypeScript callers that want a synchronous form,
126
126
  typed results and a declared absence value per verb.
127
127
 
128
- The Rust crate `typed-git` is this package's twin. The two keep the same major
129
- and minor version. Their APIs differ. The crate is not on crates.io yet.
128
+ The Rust crate [`typed-git`](https://crates.io/crates/typed-git) is this
129
+ package's twin. Its version number is behind this package's: a later release
130
+ of the crate closes the gap and takes this package's number. Their APIs
131
+ differ.
130
132
 
131
133
  ## Quick look
132
134
 
@@ -313,6 +315,35 @@ record is two. A split written by hand often gets this wrong.
313
315
  under `{ long: true }`; a tree or submodule reports `null`, because `--long`
314
316
  prints `-` there and a fabricated `0` would be worse than nothing.
315
317
 
318
+ ## Diff output and the user's git configuration
319
+
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`,
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.
331
+
332
+ `diffNameStatus` passes `--no-relative`, so its paths are relative to the
333
+ repository root and cover the whole repository when the cwd is below the
334
+ root. It passes `--no-color` as a guard: git does not colour that output.
335
+
336
+ `diffNameOnly`, `diffStat` and `diffCheck` still follow `diff.relative`. From
337
+ a folder below the root their paths are relative to that folder and changes
338
+ outside it are left out, so their paths can differ from `diffNameStatus`'s.
339
+
340
+ These verbs follow the user's colour setting. Under `color.ui=always` their
341
+ output holds escape codes: `diffStat`, `diffCheck`, `log` and `logLines` with
342
+ no `format`, and `grep` without `noColor`. Verbs that read a fixed machine
343
+ format, such as `diffNameOnly`, `diffTree`, `statusPorcelain`,
344
+ `statusEntries`, `branches` and `worktrees`, get no escape codes: git does not
345
+ colour that output.
346
+
316
347
  ## Exit codes that are answers
317
348
 
318
349
  Two verbs carry their answer in the exit code rather than in stdout. Both are
@@ -728,11 +759,11 @@ exit throws the classified failure.
728
759
  | `forEachRef(pattern, { format, sort, count })` | `for-each-ref` | none — lines verbatim |
729
760
  | `refs(pattern)` | `forEachRef` + `parseRefRows` | none |
730
761
  | `diffNameOnly({ cached, diffFilter, rangeArgs, paths })` | `diff --name-only -z` | none |
731
- | `diffNameStatus({ cached, range, noRenames, paths })` | `diff --name-status -z` | none |
762
+ | `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 |
732
763
  | `diffStat({ rangeArgs, paths })` | `diff --stat` | none — raw stdout |
733
764
  | `diffCheck({ paths })` | `diff --check` | `1`, `2` → `{ ok: false, output }` |
734
- | `diffText(rev?, { staged, binary, paths })` | `diff [--cached] [--binary] [rev]` | none — empty string only when nothing differs; a bad rev or a non-repository throws; `binary` writes a binary file's change as a patch `git apply` replays |
735
- | `diffAddedFile(relPath)` | `diff --no-index -- /dev/null <path>` | none — exit 1 with output is success; exit 1 with no output, or exit 2, throws |
765
+ | `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 |
766
+ | `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` |
736
767
  | `log(opts)` | `log` | none — raw stdout, unsplit |
737
768
  | `logLines(opts)` | `log`, split and filtered | none |
738
769
  | `lsTree(rev, { recursive, long, paths })` | `ls-tree -z` | none |
package/dist/verbs.d.ts CHANGED
@@ -628,7 +628,15 @@ export interface DiffNameStatusOptions {
628
628
  paths?: string[] | undefined;
629
629
  }
630
630
  /**
631
- * Changed paths with their status (`git diff --name-status -z`).
631
+ * Changed paths with their status
632
+ * (`git diff --no-color --no-relative --name-status -z`).
633
+ *
634
+ * `--no-relative` is always passed, so with a cwd below the repository root
635
+ * the paths are still relative to the root and changes outside the cwd are
636
+ * still listed, whatever `diff.relative` says. `--no-color` is passed as a
637
+ * guard: git does not colour this output. The range is followed by `--`, so
638
+ * git never reads it as a path: a range that names a file but no revision
639
+ * throws, and a branch that shares its name with a file works.
632
640
  *
633
641
  * `absent: []` — no changes is exit 0 with empty stdout, including before the
634
642
  * first commit, where `--cached` diffs against the empty tree. Outside a
@@ -755,9 +763,28 @@ export interface DiffTextOptions {
755
763
  paths?: string[] | undefined;
756
764
  }
757
765
  /**
758
- * The unified diff text (`git diff [--cached] [--binary] [rev] [-- paths]`),
759
- * for the same rev and staged shape {@link diffNameOnly} selects paths for.
760
- * Empty when nothing differs.
766
+ * The unified diff text (`git diff --no-color --no-ext-diff --no-textconv
767
+ * --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short
768
+ * --unified=3 [--cached] [--binary] [rev] [--] [paths]`), for the same rev
769
+ * and staged shape {@link diffNameStatus} lists paths for. `--` is passed
770
+ * once, when there is a rev or a path. Empty when nothing differs.
771
+ * {@link diffNameOnly} selects the same paths except under `diff.relative`,
772
+ * which it still follows.
773
+ *
774
+ * The text is a plain unified diff with `a/` and `b/` prefixes and three
775
+ * lines of context. The flags that are always passed turn off colour codes
776
+ * (`color.ui`, `color.diff`), an external diff tool (`diff.external`, a
777
+ * `diff.<driver>.command`), textconv conversion, other prefixes
778
+ * (`diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`,
779
+ * `diff.dstPrefix`) and `diff.relative`, which with a cwd below the
780
+ * repository root would drop changes outside it. They also keep a submodule
781
+ * change as a `Subproject commit` patch, whatever `diff.submodule` says, and
782
+ * the context at three lines, whatever `diff.context` says. Other settings
783
+ * still apply: rename detection (`diff.renames`), `diff.ignoreSubmodules` and
784
+ * `diff.algorithm`; so does the `GIT_DIFF_OPTS` environment variable, where
785
+ * `-u0` overrides the three lines of context. The rev is followed by `--`, so git never reads it as a
786
+ * path: a rev that names a file but no revision throws, and a branch that
787
+ * shares its name with a file works.
761
788
  *
762
789
  * The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
763
790
  * comes back with U+FFFD in them, and the patch no longer applies. For a
@@ -770,10 +797,12 @@ export interface DiffTextOptions {
770
797
  */
771
798
  export declare function diffText(rev?: string | undefined, opts?: DiffTextOptions): GitVerb<string>;
772
799
  /**
773
- * One untracked file rendered as an all-added diff
774
- * (`diff --no-index -- /dev/null <path>`), so a new file reaches a consumer in
775
- * the same shape as a modified one. An empty existing file still gives a diff
776
- * header.
800
+ * One untracked file rendered as an all-added diff (`diff --no-color
801
+ * --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative
802
+ * --submodule=short --unified=3 --no-index -- /dev/null <path>`), so a new
803
+ * file reaches a consumer in the same shape as a modified one: the flags are
804
+ * the ones {@link diffText} passes, and the text is as plain. An empty
805
+ * existing file still gives a diff header.
777
806
  *
778
807
  * `--no-index` exits 1 whenever the inputs differ, which for a real file is
779
808
  * always, so exit 1 is the success case. git also exits 1, with empty stdout,
package/dist/verbs.js CHANGED
@@ -218,6 +218,33 @@ function depthArg(verb, depth) {
218
218
  function optionalPositional(verb, param, value) {
219
219
  return value === undefined ? undefined : positional(verb, param, value);
220
220
  }
221
+ /**
222
+ * Appends `[rev] [--] [paths]` to a `git diff` argv. `--` follows a rev even
223
+ * with no paths, so git never reads the rev as a path.
224
+ */
225
+ function pushRevAndPaths(argv, rev, paths) {
226
+ if (rev !== undefined)
227
+ argv.push(rev);
228
+ if (rev !== undefined || (paths !== undefined && paths.length > 0))
229
+ argv.push('--');
230
+ argv.push(...(paths ?? []));
231
+ }
232
+ /**
233
+ * The `git diff` flags that pin patch text against the user's git settings:
234
+ * no colour codes, no external diff tool, no textconv conversion, the `a/`
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.
237
+ */
238
+ const PLAIN_PATCH = [
239
+ '--no-color',
240
+ '--no-ext-diff',
241
+ '--no-textconv',
242
+ '--src-prefix=a/',
243
+ '--dst-prefix=b/',
244
+ '--no-relative',
245
+ '--submodule=short',
246
+ '--unified=3',
247
+ ];
221
248
  /** The child env that makes git print English, whatever the caller's locale. */
222
249
  const C_LOCALE = Object.freeze({ LC_ALL: 'C' });
223
250
  // ── queries ─────────────────────────────────────────────────────────────────
@@ -875,7 +902,15 @@ export function hasStagedChanges() {
875
902
  };
876
903
  }
877
904
  /**
878
- * Changed paths with their status (`git diff --name-status -z`).
905
+ * Changed paths with their status
906
+ * (`git diff --no-color --no-relative --name-status -z`).
907
+ *
908
+ * `--no-relative` is always passed, so with a cwd below the repository root
909
+ * the paths are still relative to the root and changes outside the cwd are
910
+ * still listed, whatever `diff.relative` says. `--no-color` is passed as a
911
+ * guard: git does not colour this output. The range is followed by `--`, so
912
+ * git never reads it as a path: a range that names a file but no revision
913
+ * throws, and a branch that shares its name with a file works.
879
914
  *
880
915
  * `absent: []` — no changes is exit 0 with empty stdout, including before the
881
916
  * first commit, where `--cached` diffs against the empty tree. Outside a
@@ -884,15 +919,13 @@ export function hasStagedChanges() {
884
919
  * See {@link DiffEntry} for what a rename record costs a naive parser.
885
920
  */
886
921
  export function diffNameStatus(opts = {}) {
887
- const argv = ['diff', '--name-status', '-z'];
922
+ const argv = ['diff', '--no-color', '--no-relative', '--name-status', '-z'];
888
923
  if (opts.cached)
889
924
  argv.push('--cached');
890
925
  if (opts.noRenames)
891
926
  argv.push('--no-renames');
892
- if (opts.range !== undefined)
893
- argv.push(positional('diffNameStatus', 'range', opts.range));
894
- if (opts.paths !== undefined && opts.paths.length > 0)
895
- argv.push('--', ...opts.paths);
927
+ const range = optionalPositional('diffNameStatus', 'range', opts.range);
928
+ pushRevAndPaths(argv, range, opts.paths);
896
929
  return { argv, absent: NONE, parse: nameStatusEntries };
897
930
  }
898
931
  /**
@@ -993,9 +1026,28 @@ export function lsTree(rev, opts = {}) {
993
1026
  };
994
1027
  }
995
1028
  /**
996
- * The unified diff text (`git diff [--cached] [--binary] [rev] [-- paths]`),
997
- * for the same rev and staged shape {@link diffNameOnly} selects paths for.
998
- * Empty when nothing differs.
1029
+ * The unified diff text (`git diff --no-color --no-ext-diff --no-textconv
1030
+ * --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short
1031
+ * --unified=3 [--cached] [--binary] [rev] [--] [paths]`), for the same rev
1032
+ * and staged shape {@link diffNameStatus} lists paths for. `--` is passed
1033
+ * once, when there is a rev or a path. Empty when nothing differs.
1034
+ * {@link diffNameOnly} selects the same paths except under `diff.relative`,
1035
+ * which it still follows.
1036
+ *
1037
+ * The text is a plain unified diff with `a/` and `b/` prefixes and three
1038
+ * lines of context. The flags that are always passed turn off colour codes
1039
+ * (`color.ui`, `color.diff`), an external diff tool (`diff.external`, a
1040
+ * `diff.<driver>.command`), textconv conversion, other prefixes
1041
+ * (`diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`,
1042
+ * `diff.dstPrefix`) and `diff.relative`, which with a cwd below the
1043
+ * repository root would drop changes outside it. They also keep a submodule
1044
+ * change as a `Subproject commit` patch, whatever `diff.submodule` says, and
1045
+ * the context at three lines, whatever `diff.context` says. Other settings
1046
+ * still apply: rename detection (`diff.renames`), `diff.ignoreSubmodules` and
1047
+ * `diff.algorithm`; so does the `GIT_DIFF_OPTS` environment variable, where
1048
+ * `-u0` overrides the three lines of context. The rev is followed by `--`, so git never reads it as a
1049
+ * path: a rev that names a file but no revision throws, and a branch that
1050
+ * shares its name with a file works.
999
1051
  *
1000
1052
  * The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
1001
1053
  * comes back with U+FFFD in them, and the patch no longer applies. For a
@@ -1007,23 +1059,21 @@ export function lsTree(rev, opts = {}) {
1007
1059
  * "no diff". `git.try.diffText` reports them as `{ ok: false }`.
1008
1060
  */
1009
1061
  export function diffText(rev, opts = {}) {
1010
- const argv = ['diff'];
1062
+ const argv = ['diff', ...PLAIN_PATCH];
1011
1063
  if (opts.staged === true)
1012
1064
  argv.push('--cached');
1013
1065
  if (opts.binary === true)
1014
1066
  argv.push('--binary');
1015
- const from = optionalPositional('diffText', 'rev', rev);
1016
- if (from !== undefined)
1017
- argv.push(from);
1018
- if (opts.paths !== undefined && opts.paths.length > 0)
1019
- argv.push('--', ...opts.paths);
1067
+ pushRevAndPaths(argv, optionalPositional('diffText', 'rev', rev), opts.paths);
1020
1068
  return { argv, absent: NONE, parse: (r) => r.stdout };
1021
1069
  }
1022
1070
  /**
1023
- * One untracked file rendered as an all-added diff
1024
- * (`diff --no-index -- /dev/null <path>`), so a new file reaches a consumer in
1025
- * the same shape as a modified one. An empty existing file still gives a diff
1026
- * header.
1071
+ * One untracked file rendered as an all-added diff (`diff --no-color
1072
+ * --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative
1073
+ * --submodule=short --unified=3 --no-index -- /dev/null <path>`), so a new
1074
+ * file reaches a consumer in the same shape as a modified one: the flags are
1075
+ * the ones {@link diffText} passes, and the text is as plain. An empty
1076
+ * existing file still gives a diff header.
1027
1077
  *
1028
1078
  * `--no-index` exits 1 whenever the inputs differ, which for a real file is
1029
1079
  * always, so exit 1 is the success case. git also exits 1, with empty stdout,
@@ -1032,7 +1082,7 @@ export function diffText(rev, opts = {}) {
1032
1082
  */
1033
1083
  export function diffAddedFile(relPath) {
1034
1084
  return {
1035
- argv: ['diff', '--no-index', '--', '/dev/null', relPath],
1085
+ argv: ['diff', ...PLAIN_PATCH, '--no-index', '--', '/dev/null', relPath],
1036
1086
  absent: [1],
1037
1087
  parse(r, ranArgv) {
1038
1088
  if (r.exitCode !== 0 && r.stdout === '')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdlc/typed-git",
3
- "version": "0.16.0",
3
+ "version": "0.17.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",