@osdlc/typed-git 0.11.1 → 0.13.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 +18 -0
- package/README.md +83 -16
- package/dist/async.d.ts +7 -11
- package/dist/async.js +8 -12
- package/dist/backend.d.ts +7 -9
- package/dist/backend.js +2 -2
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/soft.d.ts +1 -0
- package/dist/soft.js +1 -0
- package/dist/sync.d.ts +11 -15
- package/dist/sync.js +12 -16
- package/dist/verbs.d.ts +73 -38
- package/dist/verbs.js +118 -30
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @osdlc/typed-git
|
|
2
2
|
|
|
3
|
+
## 0.13.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 25ccd9e: `submodules()` is a new read verb: the submodules the index records, as `{ path, commit }` rows (`git ls-files --stage -z`, the mode `160000` gitlink entries). It reads the index, not `.gitmodules`, and says nothing of whether a submodule is checked out; its directory holds a `.git` when it is. A path in conflict appears once. `git.soft.submodules()` answers `[]` on failure.
|
|
8
|
+
|
|
9
|
+
## 0.12.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- e0aaba5: **Breaking:** `push` and `pushPorcelain` are now one verb. `push(remote, refspec | refspecs, { atomic, delete, forceWithLease })` runs `git push --porcelain` and returns the `PushReport` that `pushPorcelain` returned, with one result per ref. A rejected ref no longer throws: check each ref's `flag`, or `report.refs.some((r) => r.flag === '!')`. A failure that reaches no ref still throws, as before. `pushPorcelain` and `PushPorcelainOptions` are removed; rename the call to `push`.
|
|
14
|
+
|
|
15
|
+
New `PUSH_REJECTIONS`: for every `PushRejection`, a one-line `message`, an `explanation`, a `hint` and a `docs` link into git's manual. The README's new "Rejection reference" section has the same text.
|
|
16
|
+
|
|
17
|
+
New rejection `atomic-failed` for the other refs of a failed `--atomic` push (`atomic push failed`, `atomic transaction failed`), which were `other`.
|
|
18
|
+
|
|
19
|
+
The push tests now also replay output recorded from git 2.47.3 and 2.56.0, before and after git 2.51 reworded the remote's reasons. `tests/fixtures/push/record-push.mjs` records a new version.
|
|
20
|
+
|
|
3
21
|
## 0.11.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -38,8 +38,10 @@ The tests run on Vitest under Node. Bun is not a tested runtime for consumers.
|
|
|
38
38
|
The supported floor is git 2.34, the git of Ubuntu 22.04 LTS. CI tests the
|
|
39
39
|
git that the GitHub-hosted runners ship. On 2026-10-20 that was git 2.55.0 on
|
|
40
40
|
`ubuntu-latest` (Ubuntu 24.04) and git 2.56.0 on `macos-latest` (macOS 26), as
|
|
41
|
-
the checkout step logs it.
|
|
42
|
-
git 2.
|
|
41
|
+
the checkout step logs it. An `old git` job also runs this package's tests,
|
|
42
|
+
and pr-update's and trust-repo's, on git 2.34 on Ubuntu 22.04, so the floor
|
|
43
|
+
and the fallbacks below run against a real git. The behaviour tables below
|
|
44
|
+
were measured against git 2.50.1.
|
|
43
45
|
|
|
44
46
|
Every flag typed-git passes unconditionally is in git 2.34. A few features are
|
|
45
47
|
newer, and one table (`GIT_FEATURES`, in `src/features.ts`) lists them:
|
|
@@ -408,7 +410,7 @@ For the paths alone, `diffNameOnly({ diffFilter: "U" })` is cheaper.
|
|
|
408
410
|
|
|
409
411
|
`merge`, `rebase` and `rebaseContinue` run with `LC_ALL=C`, over the client,
|
|
410
412
|
backend and call `env`, so `fastForward`, `alreadyUpToDate` and `conflicts` do
|
|
411
|
-
not change with the caller's locale. `
|
|
413
|
+
not change with the caller's locale. `push` does the same for its
|
|
412
414
|
reasons. Other verbs keep the caller's locale.
|
|
413
415
|
|
|
414
416
|
One trap in `checkoutSide`: on a path that is not conflicted, git exits 0 and
|
|
@@ -443,12 +445,11 @@ nothing depends on where `HEAD` happens to be.
|
|
|
443
445
|
|
|
444
446
|
## Pushing: a rejected ref is a value
|
|
445
447
|
|
|
446
|
-
`push`
|
|
447
|
-
|
|
448
|
-
race is an answer you can branch on, not stderr you grep:
|
|
448
|
+
`push` runs `git push --porcelain` and returns one result per ref, so a
|
|
449
|
+
lease that lost a race is an answer you can branch on, not stderr you grep:
|
|
449
450
|
|
|
450
451
|
```ts
|
|
451
|
-
const report = git.
|
|
452
|
+
const report = git.push("origin", `${next}:refs/heads/lease`, {
|
|
452
453
|
forceWithLease: { ref: "refs/heads/lease", expect: seen },
|
|
453
454
|
});
|
|
454
455
|
const ref = report.refs[0];
|
|
@@ -459,14 +460,18 @@ if (ref.flag === "!") {
|
|
|
459
460
|
case "lock-failed": // another writer moved or deleted it at the remote
|
|
460
461
|
case "already-exists": // a create lost to another writer
|
|
461
462
|
return retry();
|
|
462
|
-
default:
|
|
463
|
-
|
|
463
|
+
default: {
|
|
464
|
+
const info = PUSH_REJECTIONS[ref.rejection];
|
|
465
|
+
throw new Error(`${ref.dst}: ${info.message} ${info.hint} See ${info.docs}`);
|
|
466
|
+
}
|
|
464
467
|
}
|
|
465
468
|
}
|
|
466
469
|
```
|
|
467
470
|
|
|
468
|
-
|
|
469
|
-
`
|
|
471
|
+
A rejected ref does not throw, so a caller that ignores the report misses it:
|
|
472
|
+
check `flag`, or `report.refs.some((r) => r.flag === "!")`. It takes a refspec
|
|
473
|
+
or a list, and `{ atomic, delete, forceWithLease }`, where `forceWithLease`
|
|
474
|
+
also takes one lease per ref. `flag` is git's status
|
|
470
475
|
character: `' '` fast-forward, `'+'` forced, `'-'` deleted, `'*'` new, `'!'`
|
|
471
476
|
rejected, `'='` up to date. A failure that reaches no ref still throws the
|
|
472
477
|
classified failure: an unknown remote, auth, network, TLS, a refspec that
|
|
@@ -487,7 +492,7 @@ wording has changed across versions:
|
|
|
487
492
|
| `<ref>` beside an existing `<ref>/child` | `(refname conflict)` | `(failed to update ref)` + `'<ref>/child' exists; cannot create '<ref>'` | `ref-conflict` |
|
|
488
493
|
| a remote hook refused it | `(pre-receive hook declined)`, `(hook declined)` | same | `hook-declined` |
|
|
489
494
|
| a `.lock` file in the way, an unwritable refs directory | `(reference already exists)`, `(failed to update refs)` + `Unable to create '….lock'` | `(failed to update ref)` + the same | `other` |
|
|
490
|
-
| the other refs of a failed `--atomic` push | `[rejected] (atomic push failed)`, `[remote rejected] (atomic transaction failed)` | same | `
|
|
495
|
+
| the other refs of a failed `--atomic` push | `[rejected] (atomic push failed)`, `[remote rejected] (atomic transaction failed)` | same | `atomic-failed` |
|
|
491
496
|
|
|
492
497
|
The "+ …" text is the remote's `cannot lock ref '<ref>': …` line. git prints
|
|
493
498
|
it on stderr, not on the ref line, and `detail` carries it for the ref it
|
|
@@ -501,6 +506,68 @@ remote prints the detail, and that reads as `other`.
|
|
|
501
506
|
This table is the one list of wordings. `tests/push.test.ts` covers each
|
|
502
507
|
row, against real git or as a canned row in `CANNED`.
|
|
503
508
|
|
|
509
|
+
`tests/push-fixtures.test.ts` replays output recorded from real git, one file
|
|
510
|
+
per version under `tests/fixtures/push/`: today git 2.47.3, from before the
|
|
511
|
+
2.51 rewording, and git 2.56.0. Every file must read the same way. To add a
|
|
512
|
+
version, run `node tests/fixtures/push/record-push.mjs` with that git on
|
|
513
|
+
`PATH`; a new wording fails the test until `pushRejection` in `src/verbs.ts`
|
|
514
|
+
maps it, and this table gains the row.
|
|
515
|
+
|
|
516
|
+
### Rejection reference
|
|
517
|
+
|
|
518
|
+
`PUSH_REJECTIONS[rejection]` holds, for every value, a one-line `message`, an
|
|
519
|
+
`explanation`, a `hint` and a `docs` link into git's own manual. Each one in
|
|
520
|
+
brief, with the same link:
|
|
521
|
+
|
|
522
|
+
**`stale`**: the remote ref is not where the lease expected it. With
|
|
523
|
+
`--force-with-lease`, git compares the remote ref with the expected value
|
|
524
|
+
before sending anything; they differed, so someone pushed since you looked.
|
|
525
|
+
A create-only lease (`expect: null`) fails this way when the ref exists.
|
|
526
|
+
Fetch, look at what changed, and push again with the new expected value.
|
|
527
|
+
[git-push: --force-with-lease](https://git-scm.com/docs/git-push#Documentation/git-push.txt---force-with-lease)
|
|
528
|
+
|
|
529
|
+
**`non-fast-forward`**: the push would discard commits on the remote, and was
|
|
530
|
+
not forced. `fetch first` means this git does not have the remote commits at
|
|
531
|
+
all; `needs force` that one side is not a commit. Fetch and integrate, or
|
|
532
|
+
force with a pinned lease.
|
|
533
|
+
[git-push: note about fast-forwards](https://git-scm.com/docs/git-push#_note_about_fast_forwards)
|
|
534
|
+
|
|
535
|
+
**`tag-exists`**: the tag is already on the remote, and git does not move a
|
|
536
|
+
tag unless forced. A retry fails the same way. Push a new tag name, or force
|
|
537
|
+
the push if replacing the tag is intended.
|
|
538
|
+
[git-push: push rules](https://git-scm.com/docs/git-push#_push_rules)
|
|
539
|
+
|
|
540
|
+
**`already-exists`**: another push created the ref first: the remote found it
|
|
541
|
+
already there when it locked it. Fetch, look at what the other push created,
|
|
542
|
+
and decide whether to push again.
|
|
543
|
+
[git-push: --force-with-lease](https://git-scm.com/docs/git-push#Documentation/git-push.txt---force-with-lease)
|
|
544
|
+
|
|
545
|
+
**`ref-conflict`**: ref names are paths, so `refs/heads/x` and
|
|
546
|
+
`refs/heads/x/child` cannot both exist. Nothing raced. Pick a name that is
|
|
547
|
+
not a prefix or an extension of an existing ref, or delete the other ref.
|
|
548
|
+
git's manual has no page on this clash, so the link is to the output format.
|
|
549
|
+
[git-push: output](https://git-scm.com/docs/git-push#_output)
|
|
550
|
+
|
|
551
|
+
**`lock-failed`**: the lease check passed, but when the remote locked the ref
|
|
552
|
+
it no longer held the expected value, or no longer existed: another push won
|
|
553
|
+
a race at the remote. Treat it like a stale lease.
|
|
554
|
+
[git-push: --force-with-lease](https://git-scm.com/docs/git-push#Documentation/git-push.txt---force-with-lease)
|
|
555
|
+
|
|
556
|
+
**`hook-declined`**: a `pre-receive` hook refused the whole push, or an
|
|
557
|
+
`update` hook this ref. GitHub reports branch protection as `protected branch
|
|
558
|
+
hook declined`. The hook's own message is in the `remote:` lines on stderr.
|
|
559
|
+
[githooks: pre-receive](https://git-scm.com/docs/githooks#pre-receive)
|
|
560
|
+
|
|
561
|
+
**`atomic-failed`**: with `--atomic` the remote updates every ref or none.
|
|
562
|
+
This ref was fine on its own; another ref in the report carries the cause.
|
|
563
|
+
[git-push: --atomic](https://git-scm.com/docs/git-push#Documentation/git-push.txt---atomic)
|
|
564
|
+
|
|
565
|
+
**`other`**: a reason this library does not classify, kept verbatim in
|
|
566
|
+
`rawReason` and `detail`: a stale lock file or an unwritable refs directory
|
|
567
|
+
on the remote, or settings such as `receive.denyCurrentBranch` and
|
|
568
|
+
`receive.denyDeletes`.
|
|
569
|
+
[git-push: output](https://git-scm.com/docs/git-push#_output)
|
|
570
|
+
|
|
504
571
|
## `log` hands back bytes
|
|
505
572
|
|
|
506
573
|
```ts
|
|
@@ -624,6 +691,7 @@ exit throws the classified failure.
|
|
|
624
691
|
| `checkIgnoreVerbose(paths)` | `check-ignore -v --stdin -z` | `1` → empty list; rows are `{ path, source, line, pattern }`, a `!` pattern is a negation |
|
|
625
692
|
| `lsFiles({ cached, others, excludeStandard, directory, paths })` | `ls-files -z` | none |
|
|
626
693
|
| `lsFilesTagged()` | `ls-files -v -z` | none — `{ tag, path }` rows; `S` is skip-worktree, lowercase is assume-unchanged |
|
|
694
|
+
| `submodules()` | `ls-files --stage -z` | none — `{ path, commit }` per gitlink in the index; whether one is checked out is on disk (its `.git`) |
|
|
627
695
|
| `forEachRef(pattern, { format, sort, count })` | `for-each-ref` | none — lines verbatim |
|
|
628
696
|
| `refs(pattern)` | `forEachRef` + `parseRefRows` | none |
|
|
629
697
|
| `diffNameOnly({ cached, diffFilter, rangeArgs, paths })` | `diff --name-only -z` | none |
|
|
@@ -658,7 +726,7 @@ empty repository from a dangling HEAD or a missing object store. Use
|
|
|
658
726
|
Every mutation except `configRemoveSection` declares no absence: a non-zero
|
|
659
727
|
exit throws the classified failure, because the only sane handling of "the write did
|
|
660
728
|
not happen" is to surface it. `configRemoveSection` declares 128 absent and
|
|
661
|
-
returns `false` when there is no such section. `
|
|
729
|
+
returns `false` when there is no such section. `push`, listed under
|
|
662
730
|
Integration, declares exit 1 absent and returns the rejected refs.
|
|
663
731
|
|
|
664
732
|
| Method | git |
|
|
@@ -666,7 +734,6 @@ Integration, declares exit 1 absent and returns the rejected refs.
|
|
|
666
734
|
| `fetch(remote, refspec, { prune, quiet, noWriteFetchHead, depth, noTags })` | `fetch` |
|
|
667
735
|
| `add(paths, { all, update, intentToAdd })` | `add` (paths go after `--`) |
|
|
668
736
|
| `commit({ message, body } \| { messageFile } \| { messageStdin }, plus { allowEmpty, amend, noVerify, signoff, paths } in the same object)` | `commit` — one argument, e.g. `commit({ message, allowEmpty: true })`; one message source, enforced by the types; `messageStdin` is `-F -` with the string on stdin, no temp file. `paths` appends `-- <paths…>`: only those paths are committed, from the working tree, and anything else staged stays staged. An empty `paths` throws a `TypeError`, because git would commit everything staged |
|
|
669
|
-
| `push(remote, refspec, { forceWithLease, delete })` | `push` — `forceWithLease` takes `true` or a pinned `{ ref, expect }` (`expect: null` = ref must be absent); `forceWithLeaseArg(lease)` is the pure formatter. `true` is the bare form: it overwrites whatever is on the remote, so prefer the pinned form. `delete` is `--delete`, and a pinned lease deletes only while the remote ref holds `expect`. To learn why a push was rejected, use `pushPorcelain` |
|
|
670
737
|
| `configSet(key, value, { scope })` | `config` |
|
|
671
738
|
| `configRemoveSection(name)` | `config --remove-section` — `false` when there is no such section |
|
|
672
739
|
| `init(path, { bare, initialBranch, quiet })` | `init` |
|
|
@@ -700,7 +767,7 @@ other non-zero exit throws.
|
|
|
700
767
|
| `rebaseContinue()` | `-c core.editor=true rebase --continue` | `RebaseOutcome` |
|
|
701
768
|
| `mergeTree(ours, theirs, { mergeBase })` | `merge-tree --write-tree --name-only -z` | `MergeTreeOutcome` |
|
|
702
769
|
| `lsFilesUnmerged()` | `ls-files -u -z` | `UnmergedEntry[]` — mode, sha, stage, path |
|
|
703
|
-
| `
|
|
770
|
+
| `push(remote, refspec \| refspecs, { atomic, delete, forceWithLease })` | `push --porcelain` | `PushReport` — `{ refs, stderr }`, one `PushRefResult` per ref; a `'!'` ref also has `rejection` and `detail`, explained in `PUSH_REJECTIONS`; exit 1 without a rejected ref throws. `forceWithLease` takes `true`, a pinned `{ ref, expect }` (`expect: null` = ref must be absent) or one per ref; `forceWithLeaseArg(lease)` is the pure formatter. `true` is the bare form: it overwrites whatever is on the remote, so prefer the pinned form. `delete` is `--delete`, and a pinned lease deletes only while the remote ref holds `expect` |
|
|
704
771
|
|
|
705
772
|
### Escape hatches and re-rooting
|
|
706
773
|
|
|
@@ -965,7 +1032,7 @@ de-duplicate.
|
|
|
965
1032
|
`CommandFailed`, with the raw `result`.
|
|
966
1033
|
- `UnsupportedRequest` is not a git failure, so `try` and `soft` let it
|
|
967
1034
|
through.
|
|
968
|
-
- `merge`, `rebase`, `rebaseContinue` and `
|
|
1035
|
+
- `merge`, `rebase`, `rebaseContinue` and `push` run with `LC_ALL=C`. Any other verb
|
|
969
1036
|
that reads git's messages assumes English output, so a localized git can
|
|
970
1037
|
change what it returns.
|
|
971
1038
|
- Test fixtures need a manual `cleanup()`.
|
package/dist/async.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { type GitBackend, type GitCallOptions } from './backend.ts';
|
|
|
17
17
|
import type { GitVersion } from './git-version.ts';
|
|
18
18
|
import { type Soft, type TriedAsync } from './outcome.ts';
|
|
19
19
|
import { type RemoteCoordinate } from './remote-url.ts';
|
|
20
|
-
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type
|
|
20
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, 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 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 StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
21
21
|
/** A typed, awaitable git client bound to one working directory. */
|
|
22
22
|
export declare class AsyncGit {
|
|
23
23
|
readonly cwd: string;
|
|
@@ -173,6 +173,8 @@ export declare class AsyncGit {
|
|
|
173
173
|
lsFiles(opts?: GitCallOptions & LsFilesOptions): Promise<string[]>;
|
|
174
174
|
/** Tracked files with their `ls-files -v` tag. See {@link Git.lsFilesTagged}. */
|
|
175
175
|
lsFilesTagged(opts?: GitCallOptions): Promise<TaggedFile[]>;
|
|
176
|
+
/** The submodules the index records. See {@link Git.submodules}. */
|
|
177
|
+
submodules(opts?: GitCallOptions): Promise<IndexSubmodule[]>;
|
|
176
178
|
/**
|
|
177
179
|
* The unified diff; `""` when nothing differs. A bad rev, or a cwd outside a
|
|
178
180
|
* repository, rejects. See {@link Git.diffText}.
|
|
@@ -271,17 +273,11 @@ export declare class AsyncGit {
|
|
|
271
273
|
/** `git clone [--depth n] [--branch ref] <url> [dest]`, from this client's `cwd`. */
|
|
272
274
|
clone(url: string, dest?: string | undefined, opts?: GitCallOptions & CloneOptions): Promise<void>;
|
|
273
275
|
/**
|
|
274
|
-
* Push
|
|
275
|
-
*
|
|
276
|
-
*
|
|
276
|
+
* Push one refspec or several, read into one result per ref. A rejected
|
|
277
|
+
* ref comes back with a typed `rejection` rather than a rejection of the
|
|
278
|
+
* promise. See {@link Git.push}.
|
|
277
279
|
*/
|
|
278
|
-
push(remote: string, refspec: string, opts?: GitCallOptions & PushOptions): Promise<
|
|
279
|
-
/**
|
|
280
|
-
* `git push --porcelain`, read into one result per ref. A rejected ref comes
|
|
281
|
-
* back with a typed `rejection` rather than a rejection of the promise. See
|
|
282
|
-
* {@link Git.pushPorcelain}.
|
|
283
|
-
*/
|
|
284
|
-
pushPorcelain(remote: string, refspec: string | string[], opts?: GitCallOptions & PushPorcelainOptions): Promise<PushReport>;
|
|
280
|
+
push(remote: string, refspec: string | readonly string[], opts?: GitCallOptions & PushOptions): Promise<PushReport>;
|
|
285
281
|
/** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
|
|
286
282
|
clean(opts?: GitCallOptions & CleanOptions): Promise<void>;
|
|
287
283
|
/** `git reset --hard <rev>`. */
|
package/dist/async.js
CHANGED
|
@@ -279,6 +279,10 @@ export class AsyncGit {
|
|
|
279
279
|
lsFilesTagged(opts = {}) {
|
|
280
280
|
return this.backend.execute(this.cwd, { kind: 'lsFilesTagged' }, opts);
|
|
281
281
|
}
|
|
282
|
+
/** The submodules the index records. See {@link Git.submodules}. */
|
|
283
|
+
submodules(opts = {}) {
|
|
284
|
+
return this.backend.execute(this.cwd, { kind: 'submodules' }, opts);
|
|
285
|
+
}
|
|
282
286
|
/**
|
|
283
287
|
* The unified diff; `""` when nothing differs. A bad rev, or a cwd outside a
|
|
284
288
|
* repository, rejects. See {@link Git.diffText}.
|
|
@@ -458,21 +462,13 @@ export class AsyncGit {
|
|
|
458
462
|
return this.backend.execute(this.cwd, { kind: 'clone', url, dest, ...req }, call);
|
|
459
463
|
}
|
|
460
464
|
/**
|
|
461
|
-
* Push
|
|
462
|
-
*
|
|
463
|
-
*
|
|
465
|
+
* Push one refspec or several, read into one result per ref. A rejected
|
|
466
|
+
* ref comes back with a typed `rejection` rather than a rejection of the
|
|
467
|
+
* promise. See {@link Git.push}.
|
|
464
468
|
*/
|
|
465
469
|
push(remote, refspec, opts = {}) {
|
|
466
|
-
return this.backend.execute(this.cwd, { kind: 'push', remote, refspec, forceWithLease: opts.forceWithLease, delete: opts.delete }, opts);
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* `git push --porcelain`, read into one result per ref. A rejected ref comes
|
|
470
|
-
* back with a typed `rejection` rather than a rejection of the promise. See
|
|
471
|
-
* {@link Git.pushPorcelain}.
|
|
472
|
-
*/
|
|
473
|
-
pushPorcelain(remote, refspec, opts = {}) {
|
|
474
470
|
const [call, req] = splitCallOptions(opts);
|
|
475
|
-
return this.backend.execute(this.cwd, { kind: '
|
|
471
|
+
return this.backend.execute(this.cwd, { kind: 'push', remote, refspec, ...req }, call);
|
|
476
472
|
}
|
|
477
473
|
/** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
|
|
478
474
|
clean(opts = {}) {
|
package/dist/backend.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { 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 CheckoutOptions, type CloneOptions, type CommitOptions, type ConfigGetOptions, type ConfigSetOptions, type ConflictSide, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, 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
|
|
22
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, 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 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 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
|
/**
|
|
@@ -143,6 +143,8 @@ export type GitRequest = {
|
|
|
143
143
|
kind: 'lsFiles';
|
|
144
144
|
} & LsFilesOptions) | {
|
|
145
145
|
kind: 'lsFilesTagged';
|
|
146
|
+
} | {
|
|
147
|
+
kind: 'submodules';
|
|
146
148
|
} | ({
|
|
147
149
|
kind: 'forEachRef';
|
|
148
150
|
pattern: string | string[];
|
|
@@ -202,12 +204,8 @@ export type GitRequest = {
|
|
|
202
204
|
} & CloneOptions) | ({
|
|
203
205
|
kind: 'push';
|
|
204
206
|
remote: string;
|
|
205
|
-
refspec: string;
|
|
206
|
-
} & PushOptions) |
|
|
207
|
-
kind: 'pushPorcelain';
|
|
208
|
-
remote: string;
|
|
209
|
-
refspec: string | string[];
|
|
210
|
-
} & PushPorcelainOptions) | {
|
|
207
|
+
refspec: string | readonly string[];
|
|
208
|
+
} & PushOptions) | {
|
|
211
209
|
kind: 'resetHard';
|
|
212
210
|
rev: string;
|
|
213
211
|
} | ({
|
|
@@ -327,6 +325,7 @@ export interface GitResults {
|
|
|
327
325
|
commitTree: string;
|
|
328
326
|
lsFiles: string[];
|
|
329
327
|
lsFilesTagged: TaggedFile[];
|
|
328
|
+
submodules: IndexSubmodule[];
|
|
330
329
|
forEachRef: string[];
|
|
331
330
|
diffNameOnly: string[];
|
|
332
331
|
diffStat: string;
|
|
@@ -347,8 +346,7 @@ export interface GitResults {
|
|
|
347
346
|
configRemoveSection: boolean;
|
|
348
347
|
init: void;
|
|
349
348
|
clone: void;
|
|
350
|
-
push:
|
|
351
|
-
pushPorcelain: PushReport;
|
|
349
|
+
push: PushReport;
|
|
352
350
|
resetHard: void;
|
|
353
351
|
clean: void;
|
|
354
352
|
deleteBranch: void;
|
package/dist/backend.js
CHANGED
|
@@ -94,6 +94,8 @@ function toVerb(request) {
|
|
|
94
94
|
return v.lsFiles(request);
|
|
95
95
|
case 'lsFilesTagged':
|
|
96
96
|
return v.lsFilesTagged();
|
|
97
|
+
case 'submodules':
|
|
98
|
+
return v.submodules();
|
|
97
99
|
case 'forEachRef':
|
|
98
100
|
return v.forEachRef(request.pattern, request);
|
|
99
101
|
case 'diffNameOnly':
|
|
@@ -136,8 +138,6 @@ function toVerb(request) {
|
|
|
136
138
|
return v.clone(request.url, request.dest, request);
|
|
137
139
|
case 'push':
|
|
138
140
|
return v.push(request.remote, request.refspec, request);
|
|
139
|
-
case 'pushPorcelain':
|
|
140
|
-
return v.pushPorcelain(request.remote, request.refspec, request);
|
|
141
141
|
case 'resetHard':
|
|
142
142
|
return v.resetHard(request.rev);
|
|
143
143
|
case 'clean':
|
package/dist/client.d.ts
CHANGED
|
@@ -22,5 +22,5 @@ export { classifyGitFailure, describeGitFailure, type GitFailure, type GitFailur
|
|
|
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, 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 FetchOptions, type ForEachRefOptions, type ForceLease, type GcOptions, type GrepOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type NumstatEntry, type PushFlag, type PushOptions, type
|
|
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 FetchOptions, type ForEachRefOptions, type ForceLease, type GcOptions, type GrepOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, 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 StatusEntry, type StatusPorcelainOptions, type IndexSubmodule, type TaggedFile, type TreeEntry, type UnmergedEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
|
|
26
26
|
export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, type AsyncCommandRunner, type AsyncCommandRunOptions, type CommandResult, type CommandRunner, type CommandRunOptions, } from '@osdlc/command-seam';
|
package/dist/client.js
CHANGED
|
@@ -22,7 +22,7 @@ export { classifyGitFailure, describeGitFailure, } from "./failure.js";
|
|
|
22
22
|
export {} from "./outcome.js";
|
|
23
23
|
export { GIT_FEATURES, GIT_FLOOR, gitSupports, } from "./features.js";
|
|
24
24
|
export { compareGitVersions, parseGitVersion } from "./git-version.js";
|
|
25
|
-
export { forceWithLeaseArg, parseRefRows, REF_FORMAT, } from "./verbs.js";
|
|
25
|
+
export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, } from "./verbs.js";
|
|
26
26
|
// The command-seam exports are re-exported so a caller wiring a runner or catching
|
|
27
27
|
// a failure needs one import, not two. `@osdlc/command-seam` is the package
|
|
28
28
|
// that owns these; it is usable on its own, without a git client.
|
package/dist/soft.d.ts
CHANGED
package/dist/soft.js
CHANGED
package/dist/sync.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { type CommandResult, type CommandRunner } from '@osdlc/command-seam';
|
|
|
19
19
|
import { type GitVersion } from './git-version.ts';
|
|
20
20
|
import { type Soft, type TriedSync } from './outcome.ts';
|
|
21
21
|
import { type RemoteCoordinate } from './remote-url.ts';
|
|
22
|
-
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type
|
|
22
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, 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 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 StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
23
23
|
/**
|
|
24
24
|
* Per-call concerns that are not part of the operation itself.
|
|
25
25
|
*
|
|
@@ -278,6 +278,8 @@ export declare class Git {
|
|
|
278
278
|
lsFiles(opts?: GitSyncCallOptions & LsFilesOptions): string[];
|
|
279
279
|
/** Tracked files with their `ls-files -v` tag — see `lsFilesTagged` in `verbs.ts`. */
|
|
280
280
|
lsFilesTagged(opts?: GitSyncCallOptions): TaggedFile[];
|
|
281
|
+
/** The submodules the index records, as `{ path, commit }` — see `submodules` in `verbs.ts`. */
|
|
282
|
+
submodules(opts?: GitSyncCallOptions): IndexSubmodule[];
|
|
281
283
|
/**
|
|
282
284
|
* The unified diff; `""` when nothing differs. A bad rev, or a cwd outside a
|
|
283
285
|
* repository, throws. See `diffText` in `verbs.ts`.
|
|
@@ -400,21 +402,15 @@ export declare class Git {
|
|
|
400
402
|
*/
|
|
401
403
|
clone(url: string, dest?: string | undefined, opts?: GitSyncCallOptions & CloneOptions): void;
|
|
402
404
|
/**
|
|
403
|
-
* Push
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* `
|
|
405
|
+
* Push one refspec or several, read into one result per ref. A rejected
|
|
406
|
+
* ref comes back with a typed `rejection` rather than a throw, so check
|
|
407
|
+
* `flag`; a failure that reaches no ref (an unknown remote, auth, network)
|
|
408
|
+
* still throws. A {@link ForceLease} pins `--force-with-lease`, which means
|
|
409
|
+
* "push only if the remote ref is still where I saw it";
|
|
410
|
+
* `{forceWithLease: true}` is the unsafe bare flag. `{delete: true}`
|
|
411
|
+
* deletes each refspec on the remote. See `push` in `verbs.ts`.
|
|
409
412
|
*/
|
|
410
|
-
push(remote: string, refspec: string, opts?: GitSyncCallOptions & PushOptions):
|
|
411
|
-
/**
|
|
412
|
-
* `git push --porcelain`, read into one result per ref. A rejected ref comes
|
|
413
|
-
* back with a typed `rejection` rather than a throw; a failure that reaches
|
|
414
|
-
* no ref (an unknown remote, auth, network) still throws. See
|
|
415
|
-
* `pushPorcelain` in `verbs.ts`.
|
|
416
|
-
*/
|
|
417
|
-
pushPorcelain(remote: string, refspec: string | string[], opts?: GitSyncCallOptions & PushPorcelainOptions): PushReport;
|
|
413
|
+
push(remote: string, refspec: string | readonly string[], opts?: GitSyncCallOptions & PushOptions): PushReport;
|
|
418
414
|
/** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
|
|
419
415
|
clean(opts?: GitSyncCallOptions & CleanOptions): void;
|
|
420
416
|
/** `git reset --hard <rev>`. */
|
package/dist/sync.js
CHANGED
|
@@ -403,6 +403,10 @@ export class Git {
|
|
|
403
403
|
lsFilesTagged(opts = {}) {
|
|
404
404
|
return this.exec(v.lsFilesTagged(), opts);
|
|
405
405
|
}
|
|
406
|
+
/** The submodules the index records, as `{ path, commit }` — see `submodules` in `verbs.ts`. */
|
|
407
|
+
submodules(opts = {}) {
|
|
408
|
+
return this.exec(v.submodules(), opts);
|
|
409
|
+
}
|
|
406
410
|
/**
|
|
407
411
|
* The unified diff; `""` when nothing differs. A bad rev, or a cwd outside a
|
|
408
412
|
* repository, throws. See `diffText` in `verbs.ts`.
|
|
@@ -587,24 +591,16 @@ export class Git {
|
|
|
587
591
|
this.exec(v.clone(url, dest, opts), opts);
|
|
588
592
|
}
|
|
589
593
|
/**
|
|
590
|
-
* Push
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
* `
|
|
594
|
+
* Push one refspec or several, read into one result per ref. A rejected
|
|
595
|
+
* ref comes back with a typed `rejection` rather than a throw, so check
|
|
596
|
+
* `flag`; a failure that reaches no ref (an unknown remote, auth, network)
|
|
597
|
+
* still throws. A {@link ForceLease} pins `--force-with-lease`, which means
|
|
598
|
+
* "push only if the remote ref is still where I saw it";
|
|
599
|
+
* `{forceWithLease: true}` is the unsafe bare flag. `{delete: true}`
|
|
600
|
+
* deletes each refspec on the remote. See `push` in `verbs.ts`.
|
|
596
601
|
*/
|
|
597
602
|
push(remote, refspec, opts = {}) {
|
|
598
|
-
this.exec(v.push(remote, refspec, opts), opts);
|
|
599
|
-
}
|
|
600
|
-
/**
|
|
601
|
-
* `git push --porcelain`, read into one result per ref. A rejected ref comes
|
|
602
|
-
* back with a typed `rejection` rather than a throw; a failure that reaches
|
|
603
|
-
* no ref (an unknown remote, auth, network) still throws. See
|
|
604
|
-
* `pushPorcelain` in `verbs.ts`.
|
|
605
|
-
*/
|
|
606
|
-
pushPorcelain(remote, refspec, opts = {}) {
|
|
607
|
-
return this.exec(v.pushPorcelain(remote, refspec, opts), opts);
|
|
603
|
+
return this.exec(v.push(remote, refspec, opts), opts);
|
|
608
604
|
}
|
|
609
605
|
/** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
|
|
610
606
|
clean(opts = {}) {
|
package/dist/verbs.d.ts
CHANGED
|
@@ -468,6 +468,28 @@ export interface TaggedFile {
|
|
|
468
468
|
* as {@link lsFiles} does.
|
|
469
469
|
*/
|
|
470
470
|
export declare function lsFilesTagged(): GitVerb<TaggedFile[]>;
|
|
471
|
+
/** One submodule the index records: a gitlink entry (`ls-files --stage`, mode `160000`). */
|
|
472
|
+
export interface IndexSubmodule {
|
|
473
|
+
/** The submodule's path from the repository root, `/`-separated. */
|
|
474
|
+
path: string;
|
|
475
|
+
/** The commit the index records for it, which need not be the one checked out. */
|
|
476
|
+
commit: string;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* The submodules this repository's index records (`git ls-files --stage -z`,
|
|
480
|
+
* the mode `160000` gitlink entries), in index order.
|
|
481
|
+
*
|
|
482
|
+
* It reads the index, not `.gitmodules`, so it lists what a checkout holds:
|
|
483
|
+
* a submodule added but not committed is here, one only named in
|
|
484
|
+
* `.gitmodules` is not. It says nothing of whether a submodule is checked
|
|
485
|
+
* out: its directory holds a `.git` when it is. Nested submodules belong to
|
|
486
|
+
* the submodule's own index; ask a client at that path. A path in conflict
|
|
487
|
+
* appears once, with the commit of its lowest stage.
|
|
488
|
+
*
|
|
489
|
+
* `absent: []` — a repository with no submodules is exit 0 and no gitlinks,
|
|
490
|
+
* so `[]` means "none". Outside a repository git exits 128 and this throws.
|
|
491
|
+
*/
|
|
492
|
+
export declare function submodules(): GitVerb<IndexSubmodule[]>;
|
|
471
493
|
/** Options for {@link forEachRef}. */
|
|
472
494
|
export interface ForEachRefOptions {
|
|
473
495
|
/** `--format=` value; defaults to `%(objectname)%09%(refname)`. */
|
|
@@ -1083,33 +1105,21 @@ export interface ForceLease {
|
|
|
1083
1105
|
export declare function forceWithLeaseArg(lease: ForceLease): string;
|
|
1084
1106
|
/** Options for {@link push}. */
|
|
1085
1107
|
export interface PushOptions {
|
|
1086
|
-
/** `--force-with-lease`: `true` for the bare flag, a {@link ForceLease} to pin it. */
|
|
1087
|
-
forceWithLease?: boolean | ForceLease | undefined;
|
|
1088
1108
|
/**
|
|
1089
|
-
* `--
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1109
|
+
* `--force-with-lease`: a {@link ForceLease} to pin it, one lease per ref
|
|
1110
|
+
* for a multi-ref push, or `true` for the bare flag. `true` is the unsafe
|
|
1111
|
+
* form. It trusts whatever the local remote-tracking ref says, and a
|
|
1112
|
+
* background fetch can bring that up to date. The lease then blocks
|
|
1113
|
+
* nothing, and a concurrent push is overwritten. Pin the lease whenever the
|
|
1114
|
+
* expected remote sha is known. An empty list throws a `TypeError`.
|
|
1092
1115
|
*/
|
|
1093
|
-
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* Push a refspec, or delete it on the remote with `{ delete: true }`.
|
|
1097
|
-
*
|
|
1098
|
-
* `forceWithLease` takes a {@link ForceLease} for the pinned form, or `true`
|
|
1099
|
-
* for the bare `--force-with-lease`. `true` is the unsafe form. It trusts
|
|
1100
|
-
* whatever the local remote-tracking ref says, and a background fetch can
|
|
1101
|
-
* bring that up to date. The lease then blocks nothing, and a concurrent push
|
|
1102
|
-
* is overwritten. Pin the lease whenever the expected remote sha is known.
|
|
1103
|
-
*/
|
|
1104
|
-
export declare function push(remote: string, refspec: string, opts?: PushOptions): GitVerb<void>;
|
|
1105
|
-
/** Options for {@link pushPorcelain}. */
|
|
1106
|
-
export interface PushPorcelainOptions {
|
|
1116
|
+
forceWithLease?: boolean | ForceLease | readonly ForceLease[] | undefined;
|
|
1107
1117
|
/**
|
|
1108
|
-
* `--
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1118
|
+
* `--delete` — delete each `refspec` on the remote rather than pushing to
|
|
1119
|
+
* it. Combines with `forceWithLease`, so a pinned lease deletes the remote
|
|
1120
|
+
* ref only while it still holds the expected sha.
|
|
1111
1121
|
*/
|
|
1112
|
-
|
|
1122
|
+
delete?: boolean | undefined;
|
|
1113
1123
|
/** `--atomic` — the remote updates every ref or none. */
|
|
1114
1124
|
atomic?: boolean | undefined;
|
|
1115
1125
|
}
|
|
@@ -1134,13 +1144,37 @@ export type PushFlag = ' ' | '+' | '-' | '*' | '!' | '=';
|
|
|
1134
1144
|
* - `lock-failed`: another writer moved or deleted the ref at the remote
|
|
1135
1145
|
* after the lease check passed.
|
|
1136
1146
|
* - `hook-declined`: a remote hook refused the ref.
|
|
1147
|
+
* - `atomic-failed`: another ref of an `--atomic` push failed, so this one
|
|
1148
|
+
* was not updated. The other ref carries the cause.
|
|
1137
1149
|
* - `other`: anything else, kept in `rawReason` and `detail`. This includes
|
|
1138
|
-
* a lock file in the way, an unwritable refs directory,
|
|
1139
|
-
*
|
|
1140
|
-
* `remote
|
|
1141
|
-
*
|
|
1150
|
+
* a lock file in the way, an unwritable refs directory, and git's `new
|
|
1151
|
+
* shallow roots not allowed`, `remote does not support deleting refs` and
|
|
1152
|
+
* `remote failed to report status`.
|
|
1153
|
+
*
|
|
1154
|
+
* {@link PUSH_REJECTIONS} explains each one and links git's documentation.
|
|
1155
|
+
*/
|
|
1156
|
+
export type PushRejection = 'stale' | 'non-fast-forward' | 'tag-exists' | 'already-exists' | 'ref-conflict' | 'lock-failed' | 'hook-declined' | 'atomic-failed' | 'other';
|
|
1157
|
+
/** One entry of {@link PUSH_REJECTIONS}. */
|
|
1158
|
+
export interface PushRejectionInfo {
|
|
1159
|
+
/** One line: what happened. */
|
|
1160
|
+
readonly message: string;
|
|
1161
|
+
/** Why git refuses it, and how git words it by version. */
|
|
1162
|
+
readonly explanation: string;
|
|
1163
|
+
/** What to do next. */
|
|
1164
|
+
readonly hint: string;
|
|
1165
|
+
/** The section of git's documentation that covers it. */
|
|
1166
|
+
readonly docs: string;
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* A reference entry for every {@link PushRejection}: a one-line `message`, a
|
|
1170
|
+
* longer `explanation`, a `hint` and a link to git's documentation.
|
|
1171
|
+
*
|
|
1172
|
+
* ```ts
|
|
1173
|
+
* const info = PUSH_REJECTIONS[ref.rejection]
|
|
1174
|
+
* console.error(`${ref.dst}: ${info.message} ${info.hint} (${info.docs})`)
|
|
1175
|
+
* ```
|
|
1142
1176
|
*/
|
|
1143
|
-
export
|
|
1177
|
+
export declare const PUSH_REJECTIONS: Readonly<Record<PushRejection, PushRejectionInfo>>;
|
|
1144
1178
|
/** The fields every ref line of `git push --porcelain` has. */
|
|
1145
1179
|
interface PushRefFields {
|
|
1146
1180
|
/** The local side as git printed it: a ref, `HEAD`, a sha, or `''` for a delete. */
|
|
@@ -1173,7 +1207,7 @@ export type PushRefResult = (PushRefFields & {
|
|
|
1173
1207
|
rejection?: never;
|
|
1174
1208
|
detail?: never;
|
|
1175
1209
|
});
|
|
1176
|
-
/** What {@link
|
|
1210
|
+
/** What {@link push} returns. */
|
|
1177
1211
|
export interface PushReport {
|
|
1178
1212
|
/** One entry per ref line. A remote with several push URLs repeats its refs. */
|
|
1179
1213
|
refs: PushRefResult[];
|
|
@@ -1181,21 +1215,22 @@ export interface PushReport {
|
|
|
1181
1215
|
stderr: string;
|
|
1182
1216
|
}
|
|
1183
1217
|
/**
|
|
1184
|
-
* `git push --porcelain [--atomic] [--force-with-lease…] <remote>
|
|
1185
|
-
* read into one result per ref.
|
|
1218
|
+
* `git push --porcelain [--delete] [--atomic] [--force-with-lease…] <remote>
|
|
1219
|
+
* <refspec…>`, read into one result per ref. `{ delete: true }` deletes each
|
|
1220
|
+
* refspec on the remote instead.
|
|
1186
1221
|
*
|
|
1187
|
-
* A rejected ref is a value, not a throw
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1191
|
-
*
|
|
1192
|
-
* classified failure.
|
|
1222
|
+
* A rejected ref is a value, not a throw: check each ref's `flag`, or
|
|
1223
|
+
* whether any is `'!'`. git exits 1 when any ref is rejected, so exit 1 is
|
|
1224
|
+
* declared absent, and the parse throws unless a ref line says `!`. A local
|
|
1225
|
+
* pre-push hook decline and a refspec that matches nothing exit 1 with no
|
|
1226
|
+
* ref lines, so they throw. So does every transport failure (exit 128: an
|
|
1227
|
+
* unknown remote, auth, network, TLS), as the classified failure.
|
|
1193
1228
|
*
|
|
1194
1229
|
* Runs with `LC_ALL=C`, so the caller's locale does not change the reason
|
|
1195
1230
|
* text. An empty refspec list throws a `TypeError`: git would push its
|
|
1196
1231
|
* default set.
|
|
1197
1232
|
*/
|
|
1198
|
-
export declare function
|
|
1233
|
+
export declare function push(remote: string, refspec: string | readonly string[], opts?: PushOptions): GitVerb<PushReport>;
|
|
1199
1234
|
/** `git reset --hard <rev>`. */
|
|
1200
1235
|
export declare function resetHard(rev: string): GitVerb<void>;
|
|
1201
1236
|
/** Options for {@link clean}. */
|
package/dist/verbs.js
CHANGED
|
@@ -704,6 +704,40 @@ export function lsFilesTagged() {
|
|
|
704
704
|
},
|
|
705
705
|
};
|
|
706
706
|
}
|
|
707
|
+
/** `<mode> <sha> <stage>\t<path>` */
|
|
708
|
+
const STAGE_ROW = /^(\d+) ([0-9a-f]+) ([0123])\t(.*)$/s;
|
|
709
|
+
/**
|
|
710
|
+
* The submodules this repository's index records (`git ls-files --stage -z`,
|
|
711
|
+
* the mode `160000` gitlink entries), in index order.
|
|
712
|
+
*
|
|
713
|
+
* It reads the index, not `.gitmodules`, so it lists what a checkout holds:
|
|
714
|
+
* a submodule added but not committed is here, one only named in
|
|
715
|
+
* `.gitmodules` is not. It says nothing of whether a submodule is checked
|
|
716
|
+
* out: its directory holds a `.git` when it is. Nested submodules belong to
|
|
717
|
+
* the submodule's own index; ask a client at that path. A path in conflict
|
|
718
|
+
* appears once, with the commit of its lowest stage.
|
|
719
|
+
*
|
|
720
|
+
* `absent: []` — a repository with no submodules is exit 0 and no gitlinks,
|
|
721
|
+
* so `[]` means "none". Outside a repository git exits 128 and this throws.
|
|
722
|
+
*/
|
|
723
|
+
export function submodules() {
|
|
724
|
+
return {
|
|
725
|
+
argv: ['ls-files', '--stage', '-z'],
|
|
726
|
+
absent: NONE,
|
|
727
|
+
parse(r) {
|
|
728
|
+
const rows = [];
|
|
729
|
+
const seen = new Set();
|
|
730
|
+
for (const chunk of r.stdout.split('\x00')) {
|
|
731
|
+
const m = STAGE_ROW.exec(chunk);
|
|
732
|
+
if (m === null || m[1] !== '160000' || seen.has(m[4]))
|
|
733
|
+
continue;
|
|
734
|
+
seen.add(m[4]);
|
|
735
|
+
rows.push({ path: m[4], commit: m[2] });
|
|
736
|
+
}
|
|
737
|
+
return rows;
|
|
738
|
+
},
|
|
739
|
+
};
|
|
740
|
+
}
|
|
707
741
|
/** The `forEachRef` format {@link refs} parses: sha, TAB, full refname. */
|
|
708
742
|
export const REF_FORMAT = '%(objectname)%09%(refname)';
|
|
709
743
|
/**
|
|
@@ -1403,23 +1437,6 @@ export function forceWithLeaseArg(lease) {
|
|
|
1403
1437
|
}
|
|
1404
1438
|
return `--force-with-lease=${lease.ref}:${lease.expect ?? ''}`;
|
|
1405
1439
|
}
|
|
1406
|
-
/**
|
|
1407
|
-
* Push a refspec, or delete it on the remote with `{ delete: true }`.
|
|
1408
|
-
*
|
|
1409
|
-
* `forceWithLease` takes a {@link ForceLease} for the pinned form, or `true`
|
|
1410
|
-
* for the bare `--force-with-lease`. `true` is the unsafe form. It trusts
|
|
1411
|
-
* whatever the local remote-tracking ref says, and a background fetch can
|
|
1412
|
-
* bring that up to date. The lease then blocks nothing, and a concurrent push
|
|
1413
|
-
* is overwritten. Pin the lease whenever the expected remote sha is known.
|
|
1414
|
-
*/
|
|
1415
|
-
export function push(remote, refspec, opts = {}) {
|
|
1416
|
-
const argv = ['push'];
|
|
1417
|
-
if (opts.delete)
|
|
1418
|
-
argv.push('--delete');
|
|
1419
|
-
argv.push(...forceWithLeaseArgs('push', opts.forceWithLease));
|
|
1420
|
-
argv.push(positional('push', 'remote', remote), positional('push', 'refspec', refspec));
|
|
1421
|
-
return { argv, absent: NONE, parse: nothing };
|
|
1422
|
-
}
|
|
1423
1440
|
/**
|
|
1424
1441
|
* The `--force-with-lease` arguments for a `forceWithLease` option: none, the
|
|
1425
1442
|
* bare flag, or one per pinned lease. An empty lease list throws a
|
|
@@ -1439,6 +1456,72 @@ function forceWithLeaseArgs(verb, lease) {
|
|
|
1439
1456
|
return [forceWithLeaseArg(lease)];
|
|
1440
1457
|
throw new Error(`force-with-lease: unsupported value ${JSON.stringify(lease)}`);
|
|
1441
1458
|
}
|
|
1459
|
+
const GIT_PUSH_DOCS = 'https://git-scm.com/docs/git-push';
|
|
1460
|
+
/**
|
|
1461
|
+
* A reference entry for every {@link PushRejection}: a one-line `message`, a
|
|
1462
|
+
* longer `explanation`, a `hint` and a link to git's documentation.
|
|
1463
|
+
*
|
|
1464
|
+
* ```ts
|
|
1465
|
+
* const info = PUSH_REJECTIONS[ref.rejection]
|
|
1466
|
+
* console.error(`${ref.dst}: ${info.message} ${info.hint} (${info.docs})`)
|
|
1467
|
+
* ```
|
|
1468
|
+
*/
|
|
1469
|
+
export const PUSH_REJECTIONS = Object.freeze({
|
|
1470
|
+
stale: {
|
|
1471
|
+
message: 'The remote ref is not where the lease expected it.',
|
|
1472
|
+
explanation: 'With `--force-with-lease`, git compares the remote ref with the expected value before it sends anything. They differed, so someone else pushed to the ref since you last looked, and git refused rather than overwrite their work. A create-only lease fails this way when the ref exists. `remote ref updated since checkout` is the same check under `--force-if-includes`.',
|
|
1473
|
+
hint: 'Fetch, look at what changed, and push again with the new expected value.',
|
|
1474
|
+
docs: `${GIT_PUSH_DOCS}#Documentation/git-push.txt---force-with-lease`,
|
|
1475
|
+
},
|
|
1476
|
+
'non-fast-forward': {
|
|
1477
|
+
message: 'The push would discard commits on the remote.',
|
|
1478
|
+
explanation: 'The remote ref has commits that the pushed commit does not contain, and the push was not forced. `fetch first` says the same when this git does not have the remote commits at all; `needs force` when the remote ref or the pushed object is not a commit.',
|
|
1479
|
+
hint: 'Fetch and integrate the remote commits, or force the push with a pinned lease.',
|
|
1480
|
+
docs: `${GIT_PUSH_DOCS}#_note_about_fast_forwards`,
|
|
1481
|
+
},
|
|
1482
|
+
'tag-exists': {
|
|
1483
|
+
message: 'The tag already exists on the remote.',
|
|
1484
|
+
explanation: 'git does not move an existing tag unless the push is forced, so a retry fails the same way.',
|
|
1485
|
+
hint: 'Push a new tag name, or force the push if replacing the tag is intended.',
|
|
1486
|
+
docs: `${GIT_PUSH_DOCS}#_push_rules`,
|
|
1487
|
+
},
|
|
1488
|
+
'already-exists': {
|
|
1489
|
+
message: 'Another push created the ref first.',
|
|
1490
|
+
explanation: 'The push would have created the ref, but when the remote locked it, it already existed: another writer won a race on the remote. git before 2.51 reports this as `failed to update ref`, with `reference already exists` in a `remote: error:` line.',
|
|
1491
|
+
hint: 'Fetch, look at the ref the other push created, and decide whether to push again.',
|
|
1492
|
+
docs: `${GIT_PUSH_DOCS}#Documentation/git-push.txt---force-with-lease`,
|
|
1493
|
+
},
|
|
1494
|
+
'ref-conflict': {
|
|
1495
|
+
message: 'The ref name collides with another ref on the remote.',
|
|
1496
|
+
explanation: 'Ref names are paths, so `refs/heads/x` and `refs/heads/x/child` cannot both exist: one would have to be a file and a directory at once. The remote already has one of them. git before 2.51 reports this as `failed to update ref`, with the cause in a `remote: error:` line.',
|
|
1497
|
+
hint: 'Pick a name that is not a prefix or an extension of an existing ref, or delete the other ref first.',
|
|
1498
|
+
docs: `${GIT_PUSH_DOCS}#_output`,
|
|
1499
|
+
},
|
|
1500
|
+
'lock-failed': {
|
|
1501
|
+
message: 'The remote ref moved while the push was updating it.',
|
|
1502
|
+
explanation: 'The lease check passed, but when the remote locked the ref to update it, the ref no longer held the expected value, or no longer existed. Another push won a race on the remote. git before 2.51 reports this as `failed to update ref`, with `is at … but expected …` in a `remote: error:` line.',
|
|
1503
|
+
hint: 'Treat it like a stale lease: fetch, look at what changed, and push again.',
|
|
1504
|
+
docs: `${GIT_PUSH_DOCS}#Documentation/git-push.txt---force-with-lease`,
|
|
1505
|
+
},
|
|
1506
|
+
'hook-declined': {
|
|
1507
|
+
message: 'A hook on the remote refused the push.',
|
|
1508
|
+
explanation: "The remote's `pre-receive` hook refuses the whole push; its `update` hook refuses one ref. GitHub reports branch protection as `protected branch hook declined`. The hook's own message is in the `remote:` lines on stderr.",
|
|
1509
|
+
hint: "Read the hook's message on stderr, which says what the remote requires.",
|
|
1510
|
+
docs: 'https://git-scm.com/docs/githooks#pre-receive',
|
|
1511
|
+
},
|
|
1512
|
+
'atomic-failed': {
|
|
1513
|
+
message: 'Another ref in this atomic push failed, so this one was not updated.',
|
|
1514
|
+
explanation: 'With `--atomic` the remote updates every ref or none. This ref was fine on its own; another ref in the same push carries the real reason. The client says `atomic push failed` when it refused locally, the remote `atomic transaction failed`.',
|
|
1515
|
+
hint: 'Look at the other refs in the report for the cause.',
|
|
1516
|
+
docs: `${GIT_PUSH_DOCS}#Documentation/git-push.txt---atomic`,
|
|
1517
|
+
},
|
|
1518
|
+
other: {
|
|
1519
|
+
message: 'git refused the ref for a reason this library does not classify.',
|
|
1520
|
+
explanation: "The reason text is kept verbatim. Common ones are a stale lock file or an unwritable refs directory on the remote, and the remote's safety settings, such as `receive.denyCurrentBranch` or `receive.denyDeletes`.",
|
|
1521
|
+
hint: 'Read `rawReason` and `detail` on the ref, and the remote lines on stderr.',
|
|
1522
|
+
docs: `${GIT_PUSH_DOCS}#_output`,
|
|
1523
|
+
},
|
|
1524
|
+
});
|
|
1442
1525
|
/** `<flag>\t<src>:<dst>\t<summary>[ (<reason>)]` */
|
|
1443
1526
|
const PUSH_REF_LINE = /^([ +\-*!=])\t([^\t]*)\t(.*)$/;
|
|
1444
1527
|
/**
|
|
@@ -1471,6 +1554,8 @@ function pushRejection(reason, detail) {
|
|
|
1471
1554
|
return 'tag-exists';
|
|
1472
1555
|
if (r.includes('hook declined'))
|
|
1473
1556
|
return 'hook-declined';
|
|
1557
|
+
if (r === 'atomic push failed' || r === 'atomic transaction failed')
|
|
1558
|
+
return 'atomic-failed';
|
|
1474
1559
|
if (r === 'refname conflict')
|
|
1475
1560
|
return 'ref-conflict';
|
|
1476
1561
|
if (r === 'incorrect old value provided' || r === 'reference does not exist') {
|
|
@@ -1528,31 +1613,34 @@ function parsePushReport(stdout, stderr) {
|
|
|
1528
1613
|
return { refs, stderr };
|
|
1529
1614
|
}
|
|
1530
1615
|
/**
|
|
1531
|
-
* `git push --porcelain [--atomic] [--force-with-lease…] <remote>
|
|
1532
|
-
* read into one result per ref.
|
|
1616
|
+
* `git push --porcelain [--delete] [--atomic] [--force-with-lease…] <remote>
|
|
1617
|
+
* <refspec…>`, read into one result per ref. `{ delete: true }` deletes each
|
|
1618
|
+
* refspec on the remote instead.
|
|
1533
1619
|
*
|
|
1534
|
-
* A rejected ref is a value, not a throw
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1537
|
-
*
|
|
1538
|
-
*
|
|
1539
|
-
* classified failure.
|
|
1620
|
+
* A rejected ref is a value, not a throw: check each ref's `flag`, or
|
|
1621
|
+
* whether any is `'!'`. git exits 1 when any ref is rejected, so exit 1 is
|
|
1622
|
+
* declared absent, and the parse throws unless a ref line says `!`. A local
|
|
1623
|
+
* pre-push hook decline and a refspec that matches nothing exit 1 with no
|
|
1624
|
+
* ref lines, so they throw. So does every transport failure (exit 128: an
|
|
1625
|
+
* unknown remote, auth, network, TLS), as the classified failure.
|
|
1540
1626
|
*
|
|
1541
1627
|
* Runs with `LC_ALL=C`, so the caller's locale does not change the reason
|
|
1542
1628
|
* text. An empty refspec list throws a `TypeError`: git would push its
|
|
1543
1629
|
* default set.
|
|
1544
1630
|
*/
|
|
1545
|
-
export function
|
|
1631
|
+
export function push(remote, refspec, opts = {}) {
|
|
1546
1632
|
const specs = typeof refspec === 'string' ? [refspec] : refspec;
|
|
1547
1633
|
if (specs.length === 0)
|
|
1548
|
-
throw new TypeError('typed-git:
|
|
1634
|
+
throw new TypeError('typed-git: push: refspec list is empty');
|
|
1549
1635
|
const argv = ['push', '--porcelain'];
|
|
1636
|
+
if (opts.delete)
|
|
1637
|
+
argv.push('--delete');
|
|
1550
1638
|
if (opts.atomic)
|
|
1551
1639
|
argv.push('--atomic');
|
|
1552
|
-
argv.push(...forceWithLeaseArgs('
|
|
1553
|
-
argv.push(positional('
|
|
1640
|
+
argv.push(...forceWithLeaseArgs('push', opts.forceWithLease));
|
|
1641
|
+
argv.push(positional('push', 'remote', remote));
|
|
1554
1642
|
for (const spec of specs)
|
|
1555
|
-
argv.push(positional('
|
|
1643
|
+
argv.push(positional('push', 'refspec', spec));
|
|
1556
1644
|
return {
|
|
1557
1645
|
argv,
|
|
1558
1646
|
env: C_LOCALE,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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",
|