@osdlc/typed-git 0.21.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +42 -14
- package/dist/verbs.d.ts +54 -18
- package/dist/verbs.js +62 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @osdlc/typed-git
|
|
2
2
|
|
|
3
|
+
## 0.22.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3b7fc6b: `statusPorcelain()`, and so `isDirty()`, pass `--untracked-files=normal`, so a `status.showUntrackedFiles=no` in the user's config no longer hides untracked files. A check that found a worktree clean under that setting let `git worktree remove` delete files it never saw.
|
|
8
|
+
|
|
9
|
+
## 0.22.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 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`.
|
|
14
|
+
|
|
3
15
|
## 0.21.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -320,17 +320,45 @@ prints `-` there and a fabricated `0` would be worse than nothing.
|
|
|
320
320
|
`diffText` and `diffAddedFile` return a plain unified diff with `a/` and `b/`
|
|
321
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
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
`
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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.
|
|
334
362
|
|
|
335
363
|
`diffNameStatus` passes `--no-relative`, so its paths are relative to the
|
|
336
364
|
repository root and cover the whole repository when the cwd is below the
|
|
@@ -740,7 +768,7 @@ exit throws the classified failure.
|
|
|
740
768
|
| `mainCheckout()` | the parent of `gitCommonDir()` when that is `<checkout>/.git`, else `core.worktree` or the main worktree | `null` outside a repository, or for a bare store |
|
|
741
769
|
| `symbolicRef(ref)` | `symbolic-ref <ref>` | `128` → `null` |
|
|
742
770
|
| `currentBranch()` | `branch --show-current` | none — `null` when detached |
|
|
743
|
-
| `statusPorcelain({ paths })` | `status --porcelain` | none |
|
|
771
|
+
| `statusPorcelain({ paths })` | `status --porcelain --untracked-files=normal`, so `status.showUntrackedFiles=no` hides nothing | none |
|
|
744
772
|
| `statusEntries({ ignored })` | `status --porcelain -z --untracked-files=all [--ignored]` | none — `{ x, y, path }` rows; a rename is one row, with the source dropped; `ignored` adds each ignored file as a `!` row |
|
|
745
773
|
| `isDirty({ paths })` | `statusPorcelain().length > 0` | none |
|
|
746
774
|
| `hasStagedChanges()` | `diff --cached --quiet` | `1` → `true`, `0` → `false` — on an unborn HEAD the index is compared against the empty tree; outside a repository (`129`) it throws |
|
|
@@ -766,8 +794,8 @@ exit throws the classified failure.
|
|
|
766
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 |
|
|
767
795
|
| `diffStat({ rangeArgs, paths })` | `diff --stat` | none — raw stdout |
|
|
768
796
|
| `diffCheck({ paths })` | `diff --check` | `1`, `2` → `{ ok: false, output }` |
|
|
769
|
-
| `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 --unified=<context, default 3> [--cached] [--binary] [-M] [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 |
|
|
770
|
-
| `diffAddedFile(relPath, { context })` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=<context, default 3> --no-index -- /dev/null <path
|
|
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 |
|
|
771
799
|
| `log(opts)` | `log` | none — raw stdout, unsplit |
|
|
772
800
|
| `logLines(opts)` | `log`, split and filtered | none |
|
|
773
801
|
| `lsTree(rev, { recursive, long, paths })` | `ls-tree -z` | none |
|
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
|
|
@@ -292,11 +294,17 @@ export interface StatusPorcelainOptions {
|
|
|
292
294
|
paths?: string[] | undefined;
|
|
293
295
|
}
|
|
294
296
|
/**
|
|
295
|
-
* `git status --porcelain` lines; empty array on a
|
|
296
|
-
* outside a repository (exit 128).
|
|
297
|
+
* `git status --porcelain --untracked-files=normal` lines; empty array on a
|
|
298
|
+
* clean tree, and a throw outside a repository (exit 128).
|
|
297
299
|
*
|
|
298
300
|
* Verbatim: the first two columns are the status, so ` M f.ts` (unstaged
|
|
299
301
|
* modification) must not be trimmed down to `M f.ts` (staged one).
|
|
302
|
+
*
|
|
303
|
+
* `--untracked-files=normal` overrides a `status.showUntrackedFiles=no` in
|
|
304
|
+
* the user's config, which would hide untracked files from a dirty check
|
|
305
|
+
* while `git worktree remove` still deletes them. An untracked directory is
|
|
306
|
+
* one `?? dir/` line, as git shows it by default; {@link statusEntries}
|
|
307
|
+
* lists each file.
|
|
300
308
|
*/
|
|
301
309
|
export declare function statusPorcelain(opts?: StatusPorcelainOptions): GitVerb<string[]>;
|
|
302
310
|
/** One `git status --porcelain -z` record. */
|
|
@@ -763,15 +771,20 @@ export interface DiffTextOptions {
|
|
|
763
771
|
binary?: boolean | undefined;
|
|
764
772
|
/**
|
|
765
773
|
* `--unified=<n>`: lines of context around each change. Default 3, whatever
|
|
766
|
-
* `diff.context` says; 0 gives a patch of the changed
|
|
767
|
-
*
|
|
774
|
+
* `diff.context` or `GIT_DIFF_OPTS` says; 0 gives a patch of the changed
|
|
775
|
+
* lines alone (`--inter-hunk-context=0` keeps `diff.interHunkContext` from
|
|
776
|
+
* merging nearby hunks with the lines between them). A non-negative
|
|
777
|
+
* integer, else the verb throws a `TypeError`.
|
|
768
778
|
*/
|
|
769
779
|
context?: number | undefined;
|
|
770
780
|
/**
|
|
771
781
|
* `-M`: detect renames, whatever `diff.renames` says, so a moved file reads
|
|
772
782
|
* as one `rename from`/`rename to` patch and not as a delete plus an add.
|
|
773
|
-
*
|
|
774
|
-
*
|
|
783
|
+
* It also overrides `diff.renames=copies`, under which a new file that
|
|
784
|
+
* copies a changed one reads as `copy from`/`copy to`: with `-M` it is a
|
|
785
|
+
* plain add. Off by default: without it `diff.renames` applies (git's own
|
|
786
|
+
* default is on). `diff.renameLimit` still applies: past it git stops
|
|
787
|
+
* looking for renames and only warns on stderr.
|
|
775
788
|
*/
|
|
776
789
|
findRenames?: boolean | undefined;
|
|
777
790
|
/** Pathspecs, passed after `--`. */
|
|
@@ -779,13 +792,19 @@ export interface DiffTextOptions {
|
|
|
779
792
|
}
|
|
780
793
|
/** Options for {@link diffAddedFile}. */
|
|
781
794
|
export interface DiffAddedFileOptions {
|
|
782
|
-
/**
|
|
795
|
+
/**
|
|
796
|
+
* `--unified=<n>`, checked as {@link DiffTextOptions.context}. It does not
|
|
797
|
+
* change the text: a diff from `/dev/null` is one all-added hunk with no
|
|
798
|
+
* context lines, whatever the number. It is accepted so a caller can pass
|
|
799
|
+
* the same options to both verbs.
|
|
800
|
+
*/
|
|
783
801
|
context?: number | undefined;
|
|
784
802
|
}
|
|
785
803
|
/**
|
|
786
804
|
* The unified diff text (`git diff --no-color --no-ext-diff --no-textconv
|
|
787
805
|
* --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short
|
|
788
|
-
* --unified=<context> [--cached] [--binary] [-M] [rev]
|
|
806
|
+
* --inter-hunk-context=0 --unified=<context> [--cached] [--binary] [-M] [rev]
|
|
807
|
+
* [--] [paths]`, with `GIT_DIFF_OPTS` removed from git's environment), for the same rev
|
|
789
808
|
* and staged shape {@link diffNameStatus} lists paths for. `--` is passed
|
|
790
809
|
* once, when there is a rev or a path. Empty when nothing differs.
|
|
791
810
|
* {@link diffNameOnly} selects the same paths except under `diff.relative`,
|
|
@@ -798,18 +817,33 @@ export interface DiffAddedFileOptions {
|
|
|
798
817
|
* `diff.dstPrefix`) and `diff.relative`, which with a cwd below the
|
|
799
818
|
* repository root would drop changes outside it. They also keep a submodule
|
|
800
819
|
* change as a `Subproject commit` patch, whatever `diff.submodule` says, and
|
|
801
|
-
* the context at `context` lines (default three), whatever `diff.context
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
*
|
|
805
|
-
* lines
|
|
820
|
+
* the context at `context` lines (default three), whatever `diff.context`,
|
|
821
|
+
* `diff.interHunkContext` or the `GIT_DIFF_OPTS` environment variable says.
|
|
822
|
+
*
|
|
823
|
+
* Other settings still change the text, so a caller that compares or counts
|
|
824
|
+
* lines across machines should know them: rename detection (`diff.renames`,
|
|
825
|
+
* unless `findRenames` pins it on, and `diff.renameLimit`), `diff.algorithm`
|
|
826
|
+
* (which lines read as changed, so the line counts too),
|
|
827
|
+
* `diff.indentHeuristic` (where a hunk starts), `diff.ignoreSubmodules` and
|
|
828
|
+
* `submodule.<name>.ignore` (whether a submodule change is shown at all),
|
|
829
|
+
* `core.quotePath` (whether a non-ASCII path is C-quoted), `diff.orderFile`
|
|
830
|
+
* (the order of the files), `diff.suppressBlankEmpty` (a blank context line
|
|
831
|
+
* loses its leading space), `core.abbrev` (the length of the `index` line's
|
|
832
|
+
* hashes), a `diff.<driver>.xfuncname` (the function name after `@@`), and a
|
|
833
|
+
* `-diff` or `binary` attribute (`Binary files … differ` in place of a
|
|
834
|
+
* patch, unless `binary` is set). Clean filters and end-of-line conversion
|
|
835
|
+
* (`core.autocrlf`, `text`, `eol` and `filter` attributes) change the
|
|
836
|
+
* working-tree content git compares.
|
|
837
|
+
*
|
|
838
|
+
* The rev is followed by `--`, so git never reads it as a
|
|
806
839
|
* path: a rev that names a file but no revision throws, and a branch that
|
|
807
840
|
* shares its name with a file works.
|
|
808
841
|
*
|
|
809
842
|
* The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
|
|
810
843
|
* comes back with U+FFFD in them, and the patch no longer applies. For a
|
|
811
844
|
* patch that must replay byte for byte, run the same argv through
|
|
812
|
-
* `rawBytesChecked
|
|
845
|
+
* `rawBytesChecked`, with `env: { GIT_DIFF_OPTS: '' }` (git ignores an empty
|
|
846
|
+
* value) so the context stays as asked.
|
|
813
847
|
*
|
|
814
848
|
* `absent: []`. A rev that does not resolve exits 128, and outside a
|
|
815
849
|
* repository `git diff` exits 129. Both throw, so "git failed" never reads as
|
|
@@ -819,10 +853,12 @@ export declare function diffText(rev?: string | undefined, opts?: DiffTextOption
|
|
|
819
853
|
/**
|
|
820
854
|
* One untracked file rendered as an all-added diff (`diff --no-color
|
|
821
855
|
* --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative
|
|
822
|
-
* --submodule=short --unified=<context> --no-index --
|
|
856
|
+
* --submodule=short --inter-hunk-context=0 --unified=<context> --no-index --
|
|
857
|
+
* /dev/null <path>`, with `GIT_DIFF_OPTS` removed from git's environment), so a new
|
|
823
858
|
* file reaches a consumer in the same shape as a modified one: the flags are
|
|
824
859
|
* the ones {@link diffText} passes, and the text is as plain. An empty
|
|
825
|
-
* existing file still gives a diff header.
|
|
860
|
+
* existing file still gives a diff header. `context` is checked but does not
|
|
861
|
+
* change the text (see {@link DiffAddedFileOptions.context}).
|
|
826
862
|
*
|
|
827
863
|
* `--no-index` exits 1 whenever the inputs differ, which for a real file is
|
|
828
864
|
* always, so exit 1 is the success case. git also exits 1, with empty stdout,
|
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 ${
|
|
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
|
|
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,7 +245,17 @@ const PLAIN_PATCH = [
|
|
|
243
245
|
'--dst-prefix=b/',
|
|
244
246
|
'--no-relative',
|
|
245
247
|
'--submodule=short',
|
|
248
|
+
'--inter-hunk-context=0',
|
|
246
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
|
+
});
|
|
247
259
|
/** The lines of context {@link diffText} and {@link diffAddedFile} print by default. */
|
|
248
260
|
const DEFAULT_CONTEXT = 3;
|
|
249
261
|
/**
|
|
@@ -254,10 +266,18 @@ const DEFAULT_CONTEXT = 3;
|
|
|
254
266
|
function unifiedArg(verb, context) {
|
|
255
267
|
const n = context ?? DEFAULT_CONTEXT;
|
|
256
268
|
if (!Number.isSafeInteger(n) || n < 0) {
|
|
257
|
-
throw new TypeError(`typed-git: ${verb}: context must be a non-negative integer (got ${
|
|
269
|
+
throw new TypeError(`typed-git: ${verb}: context must be a non-negative integer (got ${shown(n)})`);
|
|
258
270
|
}
|
|
259
271
|
return `--unified=${n}`;
|
|
260
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
|
+
}
|
|
261
281
|
/** The child env that makes git print English, whatever the caller's locale. */
|
|
262
282
|
const C_LOCALE = Object.freeze({ LC_ALL: 'C' });
|
|
263
283
|
// ── queries ─────────────────────────────────────────────────────────────────
|
|
@@ -416,14 +436,20 @@ export function currentBranch() {
|
|
|
416
436
|
return { argv: ['branch', '--show-current'], absent: NONE, parse: trimmedOrNull };
|
|
417
437
|
}
|
|
418
438
|
/**
|
|
419
|
-
* `git status --porcelain` lines; empty array on a
|
|
420
|
-
* outside a repository (exit 128).
|
|
439
|
+
* `git status --porcelain --untracked-files=normal` lines; empty array on a
|
|
440
|
+
* clean tree, and a throw outside a repository (exit 128).
|
|
421
441
|
*
|
|
422
442
|
* Verbatim: the first two columns are the status, so ` M f.ts` (unstaged
|
|
423
443
|
* modification) must not be trimmed down to `M f.ts` (staged one).
|
|
444
|
+
*
|
|
445
|
+
* `--untracked-files=normal` overrides a `status.showUntrackedFiles=no` in
|
|
446
|
+
* the user's config, which would hide untracked files from a dirty check
|
|
447
|
+
* while `git worktree remove` still deletes them. An untracked directory is
|
|
448
|
+
* one `?? dir/` line, as git shows it by default; {@link statusEntries}
|
|
449
|
+
* lists each file.
|
|
424
450
|
*/
|
|
425
451
|
export function statusPorcelain(opts = {}) {
|
|
426
|
-
const argv = ['status', '--porcelain'];
|
|
452
|
+
const argv = ['status', '--porcelain', '--untracked-files=normal'];
|
|
427
453
|
if (opts.paths !== undefined && opts.paths.length > 0)
|
|
428
454
|
argv.push('--', ...opts.paths);
|
|
429
455
|
return {
|
|
@@ -1043,7 +1069,8 @@ export function lsTree(rev, opts = {}) {
|
|
|
1043
1069
|
/**
|
|
1044
1070
|
* The unified diff text (`git diff --no-color --no-ext-diff --no-textconv
|
|
1045
1071
|
* --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short
|
|
1046
|
-
* --unified=<context> [--cached] [--binary] [-M] [rev]
|
|
1072
|
+
* --inter-hunk-context=0 --unified=<context> [--cached] [--binary] [-M] [rev]
|
|
1073
|
+
* [--] [paths]`, with `GIT_DIFF_OPTS` removed from git's environment), for the same rev
|
|
1047
1074
|
* and staged shape {@link diffNameStatus} lists paths for. `--` is passed
|
|
1048
1075
|
* once, when there is a rev or a path. Empty when nothing differs.
|
|
1049
1076
|
* {@link diffNameOnly} selects the same paths except under `diff.relative`,
|
|
@@ -1056,18 +1083,33 @@ export function lsTree(rev, opts = {}) {
|
|
|
1056
1083
|
* `diff.dstPrefix`) and `diff.relative`, which with a cwd below the
|
|
1057
1084
|
* repository root would drop changes outside it. They also keep a submodule
|
|
1058
1085
|
* change as a `Subproject commit` patch, whatever `diff.submodule` says, and
|
|
1059
|
-
* the context at `context` lines (default three), whatever `diff.context
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
* lines
|
|
1086
|
+
* the context at `context` lines (default three), whatever `diff.context`,
|
|
1087
|
+
* `diff.interHunkContext` or the `GIT_DIFF_OPTS` environment variable says.
|
|
1088
|
+
*
|
|
1089
|
+
* Other settings still change the text, so a caller that compares or counts
|
|
1090
|
+
* lines across machines should know them: rename detection (`diff.renames`,
|
|
1091
|
+
* unless `findRenames` pins it on, and `diff.renameLimit`), `diff.algorithm`
|
|
1092
|
+
* (which lines read as changed, so the line counts too),
|
|
1093
|
+
* `diff.indentHeuristic` (where a hunk starts), `diff.ignoreSubmodules` and
|
|
1094
|
+
* `submodule.<name>.ignore` (whether a submodule change is shown at all),
|
|
1095
|
+
* `core.quotePath` (whether a non-ASCII path is C-quoted), `diff.orderFile`
|
|
1096
|
+
* (the order of the files), `diff.suppressBlankEmpty` (a blank context line
|
|
1097
|
+
* loses its leading space), `core.abbrev` (the length of the `index` line's
|
|
1098
|
+
* hashes), a `diff.<driver>.xfuncname` (the function name after `@@`), and a
|
|
1099
|
+
* `-diff` or `binary` attribute (`Binary files … differ` in place of a
|
|
1100
|
+
* patch, unless `binary` is set). Clean filters and end-of-line conversion
|
|
1101
|
+
* (`core.autocrlf`, `text`, `eol` and `filter` attributes) change the
|
|
1102
|
+
* working-tree content git compares.
|
|
1103
|
+
*
|
|
1104
|
+
* The rev is followed by `--`, so git never reads it as a
|
|
1064
1105
|
* path: a rev that names a file but no revision throws, and a branch that
|
|
1065
1106
|
* shares its name with a file works.
|
|
1066
1107
|
*
|
|
1067
1108
|
* The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
|
|
1068
1109
|
* comes back with U+FFFD in them, and the patch no longer applies. For a
|
|
1069
1110
|
* patch that must replay byte for byte, run the same argv through
|
|
1070
|
-
* `rawBytesChecked
|
|
1111
|
+
* `rawBytesChecked`, with `env: { GIT_DIFF_OPTS: '' }` (git ignores an empty
|
|
1112
|
+
* value) so the context stays as asked.
|
|
1071
1113
|
*
|
|
1072
1114
|
* `absent: []`. A rev that does not resolve exits 128, and outside a
|
|
1073
1115
|
* repository `git diff` exits 129. Both throw, so "git failed" never reads as
|
|
@@ -1082,15 +1124,17 @@ export function diffText(rev, opts = {}) {
|
|
|
1082
1124
|
if (opts.findRenames === true)
|
|
1083
1125
|
argv.push('-M');
|
|
1084
1126
|
pushRevAndPaths(argv, optionalPositional('diffText', 'rev', rev), opts.paths);
|
|
1085
|
-
return { argv, absent: NONE, parse: (r) => r.stdout };
|
|
1127
|
+
return { argv, env: PLAIN_PATCH_ENV, absent: NONE, parse: (r) => r.stdout };
|
|
1086
1128
|
}
|
|
1087
1129
|
/**
|
|
1088
1130
|
* One untracked file rendered as an all-added diff (`diff --no-color
|
|
1089
1131
|
* --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative
|
|
1090
|
-
* --submodule=short --unified=<context> --no-index --
|
|
1132
|
+
* --submodule=short --inter-hunk-context=0 --unified=<context> --no-index --
|
|
1133
|
+
* /dev/null <path>`, with `GIT_DIFF_OPTS` removed from git's environment), so a new
|
|
1091
1134
|
* file reaches a consumer in the same shape as a modified one: the flags are
|
|
1092
1135
|
* the ones {@link diffText} passes, and the text is as plain. An empty
|
|
1093
|
-
* existing file still gives a diff header.
|
|
1136
|
+
* existing file still gives a diff header. `context` is checked but does not
|
|
1137
|
+
* change the text (see {@link DiffAddedFileOptions.context}).
|
|
1094
1138
|
*
|
|
1095
1139
|
* `--no-index` exits 1 whenever the inputs differ, which for a real file is
|
|
1096
1140
|
* always, so exit 1 is the success case. git also exits 1, with empty stdout,
|
|
@@ -1108,6 +1152,7 @@ export function diffAddedFile(relPath, opts = {}) {
|
|
|
1108
1152
|
'/dev/null',
|
|
1109
1153
|
relPath,
|
|
1110
1154
|
],
|
|
1155
|
+
env: PLAIN_PATCH_ENV,
|
|
1111
1156
|
absent: [1],
|
|
1112
1157
|
parse(r, ranArgv) {
|
|
1113
1158
|
if (r.exitCode !== 0 && r.stdout === '')
|
|
@@ -1605,7 +1650,7 @@ export function fetchMany(remotes, opts = {}) {
|
|
|
1605
1650
|
argv.push('--no-tags');
|
|
1606
1651
|
if (opts.jobs !== undefined) {
|
|
1607
1652
|
if (!Number.isSafeInteger(opts.jobs) || opts.jobs < 1) {
|
|
1608
|
-
throw new TypeError(`typed-git: fetchMany: jobs must be a positive integer (got ${
|
|
1653
|
+
throw new TypeError(`typed-git: fetchMany: jobs must be a positive integer (got ${shown(opts.jobs)})`);
|
|
1609
1654
|
}
|
|
1610
1655
|
argv.push(`--jobs=${opts.jobs}`);
|
|
1611
1656
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.1",
|
|
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",
|