@osdlc/typed-git 0.11.1 → 0.12.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,17 @@
1
1
  # @osdlc/typed-git
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 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`.
8
+
9
+ 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.
10
+
11
+ New rejection `atomic-failed` for the other refs of a failed `--atomic` push (`atomic push failed`, `atomic transaction failed`), which were `other`.
12
+
13
+ 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.
14
+
3
15
  ## 0.11.1
4
16
 
5
17
  ### 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. The behaviour tables below were measured against
42
- git 2.50.1.
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. `pushPorcelain` does the same for its
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` throws when git exits non-zero. `pushPorcelain` runs
447
- `git push --porcelain` and returns one result per ref, so a lease that lost a
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.pushPorcelain("origin", `${next}:refs/heads/lease`, {
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: // tag-exists, ref-conflict, hook-declined, non-fast-forward, other
463
- throw new Error(`${ref.dst}: ${ref.rawReason} ${ref.detail ?? ""}`);
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
- It takes a refspec or a list, and `{ atomic, forceWithLease }`, where
469
- `forceWithLease` also takes one lease per ref. `flag` is git's status
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 | `other` |
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
@@ -658,7 +725,7 @@ empty repository from a dangling HEAD or a missing object store. Use
658
725
  Every mutation except `configRemoveSection` declares no absence: a non-zero
659
726
  exit throws the classified failure, because the only sane handling of "the write did
660
727
  not happen" is to surface it. `configRemoveSection` declares 128 absent and
661
- returns `false` when there is no such section. `pushPorcelain`, listed under
728
+ returns `false` when there is no such section. `push`, listed under
662
729
  Integration, declares exit 1 absent and returns the rejected refs.
663
730
 
664
731
  | Method | git |
@@ -666,7 +733,6 @@ Integration, declares exit 1 absent and returns the rejected refs.
666
733
  | `fetch(remote, refspec, { prune, quiet, noWriteFetchHead, depth, noTags })` | `fetch` |
667
734
  | `add(paths, { all, update, intentToAdd })` | `add` (paths go after `--`) |
668
735
  | `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
736
  | `configSet(key, value, { scope })` | `config` |
671
737
  | `configRemoveSection(name)` | `config --remove-section` — `false` when there is no such section |
672
738
  | `init(path, { bare, initialBranch, quiet })` | `init` |
@@ -700,7 +766,7 @@ other non-zero exit throws.
700
766
  | `rebaseContinue()` | `-c core.editor=true rebase --continue` | `RebaseOutcome` |
701
767
  | `mergeTree(ours, theirs, { mergeBase })` | `merge-tree --write-tree --name-only -z` | `MergeTreeOutcome` |
702
768
  | `lsFilesUnmerged()` | `ls-files -u -z` | `UnmergedEntry[]` — mode, sha, stage, path |
703
- | `pushPorcelain(remote, refspec \| refspecs, { atomic, forceWithLease })` | `push --porcelain` | `PushReport` — `{ refs, stderr }`, one `PushRefResult` per ref; a `'!'` ref also has `rejection` and `detail`; exit 1 without a rejected ref throws |
769
+ | `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
770
 
705
771
  ### Escape hatches and re-rooting
706
772
 
@@ -965,7 +1031,7 @@ de-duplicate.
965
1031
  `CommandFailed`, with the raw `result`.
966
1032
  - `UnsupportedRequest` is not a git failure, so `try` and `soft` let it
967
1033
  through.
968
- - `merge`, `rebase`, `rebaseContinue` and `pushPorcelain` run with `LC_ALL=C`. Any other verb
1034
+ - `merge`, `rebase`, `rebaseContinue` and `push` run with `LC_ALL=C`. Any other verb
969
1035
  that reads git's messages assumes English output, so a localized git can
970
1036
  change what it returns.
971
1037
  - 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 PushPorcelainOptions, 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';
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 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;
@@ -271,17 +271,11 @@ export declare class AsyncGit {
271
271
  /** `git clone [--depth n] [--branch ref] <url> [dest]`, from this client's `cwd`. */
272
272
  clone(url: string, dest?: string | undefined, opts?: GitCallOptions & CloneOptions): Promise<void>;
273
273
  /**
274
- * Push a refspec. A {@link ForceLease} pins `--force-with-lease`.
275
- * `{forceWithLease: true}` adds the bare flag, which is the unsafe form.
276
- * `{delete: true}` deletes `refspec` on the remote. See {@link Git.push}.
274
+ * Push one refspec or several, read into one result per ref. A rejected
275
+ * ref comes back with a typed `rejection` rather than a rejection of the
276
+ * promise. See {@link Git.push}.
277
277
  */
278
- push(remote: string, refspec: string, opts?: GitCallOptions & PushOptions): Promise<void>;
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>;
278
+ push(remote: string, refspec: string | readonly string[], opts?: GitCallOptions & PushOptions): Promise<PushReport>;
285
279
  /** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
286
280
  clean(opts?: GitCallOptions & CleanOptions): Promise<void>;
287
281
  /** `git reset --hard <rev>`. */
package/dist/async.js CHANGED
@@ -458,21 +458,13 @@ export class AsyncGit {
458
458
  return this.backend.execute(this.cwd, { kind: 'clone', url, dest, ...req }, call);
459
459
  }
460
460
  /**
461
- * Push a refspec. A {@link ForceLease} pins `--force-with-lease`.
462
- * `{forceWithLease: true}` adds the bare flag, which is the unsafe form.
463
- * `{delete: true}` deletes `refspec` on the remote. See {@link Git.push}.
461
+ * Push one refspec or several, read into one result per ref. A rejected
462
+ * ref comes back with a typed `rejection` rather than a rejection of the
463
+ * promise. See {@link Git.push}.
464
464
  */
465
465
  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
466
  const [call, req] = splitCallOptions(opts);
475
- return this.backend.execute(this.cwd, { kind: 'pushPorcelain', remote, refspec, ...req }, call);
467
+ return this.backend.execute(this.cwd, { kind: 'push', remote, refspec, ...req }, call);
476
468
  }
477
469
  /** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
478
470
  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 PushPorcelainOptions, 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 TaggedFile, type UnmergedEntry, type Worktree, type WorktreeMoveOptions } from './verbs.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 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 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
  /**
@@ -202,12 +202,8 @@ export type GitRequest = {
202
202
  } & CloneOptions) | ({
203
203
  kind: 'push';
204
204
  remote: string;
205
- refspec: string;
206
- } & PushOptions) | ({
207
- kind: 'pushPorcelain';
208
- remote: string;
209
- refspec: string | string[];
210
- } & PushPorcelainOptions) | {
205
+ refspec: string | readonly string[];
206
+ } & PushOptions) | {
211
207
  kind: 'resetHard';
212
208
  rev: string;
213
209
  } | ({
@@ -347,8 +343,7 @@ export interface GitResults {
347
343
  configRemoveSection: boolean;
348
344
  init: void;
349
345
  clone: void;
350
- push: void;
351
- pushPorcelain: PushReport;
346
+ push: PushReport;
352
347
  resetHard: void;
353
348
  clean: void;
354
349
  deleteBranch: void;
package/dist/backend.js CHANGED
@@ -136,8 +136,6 @@ function toVerb(request) {
136
136
  return v.clone(request.url, request.dest, request);
137
137
  case 'push':
138
138
  return v.push(request.remote, request.refspec, request);
139
- case 'pushPorcelain':
140
- return v.pushPorcelain(request.remote, request.refspec, request);
141
139
  case 'resetHard':
142
140
  return v.resetHard(request.rev);
143
141
  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 PushPorcelainOptions, type PushRefResult, type PushRejection, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type StatusEntry, type StatusPorcelainOptions, type TaggedFile, type TreeEntry, type UnmergedEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
25
+ export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CheckoutOptions, type CleanOptions, type CloneOptions, type CommitFlags, type CommitOptions, type ConfigGetOptions, type ConfigScope, type ConfigSetOptions, type ConflictSide, type DiffCheckOptions, type DiffCheckResult, type DiffEntry, type DiffNameOnlyOptions, type DiffNameStatusOptions, type DiffStatOptions, type 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 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/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 PushPorcelainOptions, 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';
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 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
  *
@@ -400,21 +400,15 @@ export declare class Git {
400
400
  */
401
401
  clone(url: string, dest?: string | undefined, opts?: GitSyncCallOptions & CloneOptions): void;
402
402
  /**
403
- * Push a refspec. A {@link ForceLease} pins `--force-with-lease`, which means
404
- * "push only if the remote ref is still where I saw it". `{forceWithLease: true}` adds the
405
- * bare flag, which is the unsafe form: it compares against the
406
- * remote-tracking ref, which a fetch in this same process may have just
407
- * updated. `{delete: true}` deletes `refspec` on the remote. See `push` in
408
- * `verbs.ts`.
403
+ * Push one refspec or several, read into one result per ref. A rejected
404
+ * ref comes back with a typed `rejection` rather than a throw, so check
405
+ * `flag`; a failure that reaches no ref (an unknown remote, auth, network)
406
+ * still throws. A {@link ForceLease} pins `--force-with-lease`, which means
407
+ * "push only if the remote ref is still where I saw it";
408
+ * `{forceWithLease: true}` is the unsafe bare flag. `{delete: true}`
409
+ * deletes each refspec on the remote. See `push` in `verbs.ts`.
409
410
  */
410
- push(remote: string, refspec: string, opts?: GitSyncCallOptions & PushOptions): void;
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;
411
+ push(remote: string, refspec: string | readonly string[], opts?: GitSyncCallOptions & PushOptions): PushReport;
418
412
  /** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
419
413
  clean(opts?: GitSyncCallOptions & CleanOptions): void;
420
414
  /** `git reset --hard <rev>`. */
package/dist/sync.js CHANGED
@@ -587,24 +587,16 @@ export class Git {
587
587
  this.exec(v.clone(url, dest, opts), opts);
588
588
  }
589
589
  /**
590
- * Push a refspec. A {@link ForceLease} pins `--force-with-lease`, which means
591
- * "push only if the remote ref is still where I saw it". `{forceWithLease: true}` adds the
592
- * bare flag, which is the unsafe form: it compares against the
593
- * remote-tracking ref, which a fetch in this same process may have just
594
- * updated. `{delete: true}` deletes `refspec` on the remote. See `push` in
595
- * `verbs.ts`.
590
+ * Push one refspec or several, read into one result per ref. A rejected
591
+ * ref comes back with a typed `rejection` rather than a throw, so check
592
+ * `flag`; a failure that reaches no ref (an unknown remote, auth, network)
593
+ * still throws. A {@link ForceLease} pins `--force-with-lease`, which means
594
+ * "push only if the remote ref is still where I saw it";
595
+ * `{forceWithLease: true}` is the unsafe bare flag. `{delete: true}`
596
+ * deletes each refspec on the remote. See `push` in `verbs.ts`.
596
597
  */
597
598
  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);
599
+ return this.exec(v.push(remote, refspec, opts), opts);
608
600
  }
609
601
  /** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
610
602
  clean(opts = {}) {
package/dist/verbs.d.ts CHANGED
@@ -1083,33 +1083,21 @@ export interface ForceLease {
1083
1083
  export declare function forceWithLeaseArg(lease: ForceLease): string;
1084
1084
  /** Options for {@link push}. */
1085
1085
  export interface PushOptions {
1086
- /** `--force-with-lease`: `true` for the bare flag, a {@link ForceLease} to pin it. */
1087
- forceWithLease?: boolean | ForceLease | undefined;
1088
1086
  /**
1089
- * `--delete` — delete `refspec` on the remote rather than pushing to it.
1090
- * Combines with `forceWithLease`, so a pinned lease deletes the remote ref
1091
- * only while it still holds the expected sha.
1087
+ * `--force-with-lease`: a {@link ForceLease} to pin it, one lease per ref
1088
+ * for a multi-ref push, or `true` for the bare flag. `true` is the unsafe
1089
+ * form. It trusts whatever the local remote-tracking ref says, and a
1090
+ * background fetch can bring that up to date. The lease then blocks
1091
+ * nothing, and a concurrent push is overwritten. Pin the lease whenever the
1092
+ * expected remote sha is known. An empty list throws a `TypeError`.
1092
1093
  */
1093
- delete?: boolean | undefined;
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 {
1094
+ forceWithLease?: boolean | ForceLease | readonly ForceLease[] | undefined;
1107
1095
  /**
1108
- * `--force-with-lease`: `true` for the bare form, a {@link ForceLease}, or
1109
- * one lease per ref for a multi-ref push. See {@link push} for why `true` is
1110
- * the unsafe form. An empty list throws a `TypeError`.
1096
+ * `--delete` — delete each `refspec` on the remote rather than pushing to
1097
+ * it. Combines with `forceWithLease`, so a pinned lease deletes the remote
1098
+ * ref only while it still holds the expected sha.
1111
1099
  */
1112
- forceWithLease?: boolean | ForceLease | ForceLease[] | undefined;
1100
+ delete?: boolean | undefined;
1113
1101
  /** `--atomic` — the remote updates every ref or none. */
1114
1102
  atomic?: boolean | undefined;
1115
1103
  }
@@ -1134,13 +1122,37 @@ export type PushFlag = ' ' | '+' | '-' | '*' | '!' | '=';
1134
1122
  * - `lock-failed`: another writer moved or deleted the ref at the remote
1135
1123
  * after the lease check passed.
1136
1124
  * - `hook-declined`: a remote hook refused the ref.
1125
+ * - `atomic-failed`: another ref of an `--atomic` push failed, so this one
1126
+ * was not updated. The other ref carries the cause.
1137
1127
  * - `other`: anything else, kept in `rawReason` and `detail`. This includes
1138
- * a lock file in the way, an unwritable refs directory, the collateral refs
1139
- * of a failed `--atomic` push, and git's `new shallow roots not allowed`,
1140
- * `remote does not support deleting refs` and `remote failed to report
1141
- * status`.
1128
+ * a lock file in the way, an unwritable refs directory, and git's `new
1129
+ * shallow roots not allowed`, `remote does not support deleting refs` and
1130
+ * `remote failed to report status`.
1131
+ *
1132
+ * {@link PUSH_REJECTIONS} explains each one and links git's documentation.
1133
+ */
1134
+ export type PushRejection = 'stale' | 'non-fast-forward' | 'tag-exists' | 'already-exists' | 'ref-conflict' | 'lock-failed' | 'hook-declined' | 'atomic-failed' | 'other';
1135
+ /** One entry of {@link PUSH_REJECTIONS}. */
1136
+ export interface PushRejectionInfo {
1137
+ /** One line: what happened. */
1138
+ readonly message: string;
1139
+ /** Why git refuses it, and how git words it by version. */
1140
+ readonly explanation: string;
1141
+ /** What to do next. */
1142
+ readonly hint: string;
1143
+ /** The section of git's documentation that covers it. */
1144
+ readonly docs: string;
1145
+ }
1146
+ /**
1147
+ * A reference entry for every {@link PushRejection}: a one-line `message`, a
1148
+ * longer `explanation`, a `hint` and a link to git's documentation.
1149
+ *
1150
+ * ```ts
1151
+ * const info = PUSH_REJECTIONS[ref.rejection]
1152
+ * console.error(`${ref.dst}: ${info.message} ${info.hint} (${info.docs})`)
1153
+ * ```
1142
1154
  */
1143
- export type PushRejection = 'stale' | 'non-fast-forward' | 'tag-exists' | 'already-exists' | 'ref-conflict' | 'lock-failed' | 'hook-declined' | 'other';
1155
+ export declare const PUSH_REJECTIONS: Readonly<Record<PushRejection, PushRejectionInfo>>;
1144
1156
  /** The fields every ref line of `git push --porcelain` has. */
1145
1157
  interface PushRefFields {
1146
1158
  /** The local side as git printed it: a ref, `HEAD`, a sha, or `''` for a delete. */
@@ -1173,7 +1185,7 @@ export type PushRefResult = (PushRefFields & {
1173
1185
  rejection?: never;
1174
1186
  detail?: never;
1175
1187
  });
1176
- /** What {@link pushPorcelain} returns. */
1188
+ /** What {@link push} returns. */
1177
1189
  export interface PushReport {
1178
1190
  /** One entry per ref line. A remote with several push URLs repeats its refs. */
1179
1191
  refs: PushRefResult[];
@@ -1181,21 +1193,22 @@ export interface PushReport {
1181
1193
  stderr: string;
1182
1194
  }
1183
1195
  /**
1184
- * `git push --porcelain [--atomic] [--force-with-lease…] <remote> <refspec…>`,
1185
- * read into one result per ref.
1196
+ * `git push --porcelain [--delete] [--atomic] [--force-with-lease…] <remote>
1197
+ * <refspec…>`, read into one result per ref. `{ delete: true }` deletes each
1198
+ * refspec on the remote instead.
1186
1199
  *
1187
- * A rejected ref is a value, not a throw. git exits 1 when any ref is
1188
- * rejected, so exit 1 is declared absent, and the parse throws unless a ref
1189
- * line says `!`. A local pre-push hook decline and a refspec that matches
1190
- * nothing exit 1 with no ref lines, so they throw. So does every transport
1191
- * failure (exit 128: an unknown remote, auth, network, TLS), as the
1192
- * classified failure.
1200
+ * A rejected ref is a value, not a throw: check each ref's `flag`, or
1201
+ * whether any is `'!'`. git exits 1 when any ref is rejected, so exit 1 is
1202
+ * declared absent, and the parse throws unless a ref line says `!`. A local
1203
+ * pre-push hook decline and a refspec that matches nothing exit 1 with no
1204
+ * ref lines, so they throw. So does every transport failure (exit 128: an
1205
+ * unknown remote, auth, network, TLS), as the classified failure.
1193
1206
  *
1194
1207
  * Runs with `LC_ALL=C`, so the caller's locale does not change the reason
1195
1208
  * text. An empty refspec list throws a `TypeError`: git would push its
1196
1209
  * default set.
1197
1210
  */
1198
- export declare function pushPorcelain(remote: string, refspec: string | string[], opts?: PushPorcelainOptions): GitVerb<PushReport>;
1211
+ export declare function push(remote: string, refspec: string | readonly string[], opts?: PushOptions): GitVerb<PushReport>;
1199
1212
  /** `git reset --hard <rev>`. */
1200
1213
  export declare function resetHard(rev: string): GitVerb<void>;
1201
1214
  /** Options for {@link clean}. */
package/dist/verbs.js CHANGED
@@ -1403,23 +1403,6 @@ export function forceWithLeaseArg(lease) {
1403
1403
  }
1404
1404
  return `--force-with-lease=${lease.ref}:${lease.expect ?? ''}`;
1405
1405
  }
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
1406
  /**
1424
1407
  * The `--force-with-lease` arguments for a `forceWithLease` option: none, the
1425
1408
  * bare flag, or one per pinned lease. An empty lease list throws a
@@ -1439,6 +1422,72 @@ function forceWithLeaseArgs(verb, lease) {
1439
1422
  return [forceWithLeaseArg(lease)];
1440
1423
  throw new Error(`force-with-lease: unsupported value ${JSON.stringify(lease)}`);
1441
1424
  }
1425
+ const GIT_PUSH_DOCS = 'https://git-scm.com/docs/git-push';
1426
+ /**
1427
+ * A reference entry for every {@link PushRejection}: a one-line `message`, a
1428
+ * longer `explanation`, a `hint` and a link to git's documentation.
1429
+ *
1430
+ * ```ts
1431
+ * const info = PUSH_REJECTIONS[ref.rejection]
1432
+ * console.error(`${ref.dst}: ${info.message} ${info.hint} (${info.docs})`)
1433
+ * ```
1434
+ */
1435
+ export const PUSH_REJECTIONS = Object.freeze({
1436
+ stale: {
1437
+ message: 'The remote ref is not where the lease expected it.',
1438
+ 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`.',
1439
+ hint: 'Fetch, look at what changed, and push again with the new expected value.',
1440
+ docs: `${GIT_PUSH_DOCS}#Documentation/git-push.txt---force-with-lease`,
1441
+ },
1442
+ 'non-fast-forward': {
1443
+ message: 'The push would discard commits on the remote.',
1444
+ 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.',
1445
+ hint: 'Fetch and integrate the remote commits, or force the push with a pinned lease.',
1446
+ docs: `${GIT_PUSH_DOCS}#_note_about_fast_forwards`,
1447
+ },
1448
+ 'tag-exists': {
1449
+ message: 'The tag already exists on the remote.',
1450
+ explanation: 'git does not move an existing tag unless the push is forced, so a retry fails the same way.',
1451
+ hint: 'Push a new tag name, or force the push if replacing the tag is intended.',
1452
+ docs: `${GIT_PUSH_DOCS}#_push_rules`,
1453
+ },
1454
+ 'already-exists': {
1455
+ message: 'Another push created the ref first.',
1456
+ 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.',
1457
+ hint: 'Fetch, look at the ref the other push created, and decide whether to push again.',
1458
+ docs: `${GIT_PUSH_DOCS}#Documentation/git-push.txt---force-with-lease`,
1459
+ },
1460
+ 'ref-conflict': {
1461
+ message: 'The ref name collides with another ref on the remote.',
1462
+ 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.',
1463
+ hint: 'Pick a name that is not a prefix or an extension of an existing ref, or delete the other ref first.',
1464
+ docs: `${GIT_PUSH_DOCS}#_output`,
1465
+ },
1466
+ 'lock-failed': {
1467
+ message: 'The remote ref moved while the push was updating it.',
1468
+ 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.',
1469
+ hint: 'Treat it like a stale lease: fetch, look at what changed, and push again.',
1470
+ docs: `${GIT_PUSH_DOCS}#Documentation/git-push.txt---force-with-lease`,
1471
+ },
1472
+ 'hook-declined': {
1473
+ message: 'A hook on the remote refused the push.',
1474
+ 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.",
1475
+ hint: "Read the hook's message on stderr, which says what the remote requires.",
1476
+ docs: 'https://git-scm.com/docs/githooks#pre-receive',
1477
+ },
1478
+ 'atomic-failed': {
1479
+ message: 'Another ref in this atomic push failed, so this one was not updated.',
1480
+ 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`.',
1481
+ hint: 'Look at the other refs in the report for the cause.',
1482
+ docs: `${GIT_PUSH_DOCS}#Documentation/git-push.txt---atomic`,
1483
+ },
1484
+ other: {
1485
+ message: 'git refused the ref for a reason this library does not classify.',
1486
+ 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`.",
1487
+ hint: 'Read `rawReason` and `detail` on the ref, and the remote lines on stderr.',
1488
+ docs: `${GIT_PUSH_DOCS}#_output`,
1489
+ },
1490
+ });
1442
1491
  /** `<flag>\t<src>:<dst>\t<summary>[ (<reason>)]` */
1443
1492
  const PUSH_REF_LINE = /^([ +\-*!=])\t([^\t]*)\t(.*)$/;
1444
1493
  /**
@@ -1471,6 +1520,8 @@ function pushRejection(reason, detail) {
1471
1520
  return 'tag-exists';
1472
1521
  if (r.includes('hook declined'))
1473
1522
  return 'hook-declined';
1523
+ if (r === 'atomic push failed' || r === 'atomic transaction failed')
1524
+ return 'atomic-failed';
1474
1525
  if (r === 'refname conflict')
1475
1526
  return 'ref-conflict';
1476
1527
  if (r === 'incorrect old value provided' || r === 'reference does not exist') {
@@ -1528,31 +1579,34 @@ function parsePushReport(stdout, stderr) {
1528
1579
  return { refs, stderr };
1529
1580
  }
1530
1581
  /**
1531
- * `git push --porcelain [--atomic] [--force-with-lease…] <remote> <refspec…>`,
1532
- * read into one result per ref.
1582
+ * `git push --porcelain [--delete] [--atomic] [--force-with-lease…] <remote>
1583
+ * <refspec…>`, read into one result per ref. `{ delete: true }` deletes each
1584
+ * refspec on the remote instead.
1533
1585
  *
1534
- * A rejected ref is a value, not a throw. git exits 1 when any ref is
1535
- * rejected, so exit 1 is declared absent, and the parse throws unless a ref
1536
- * line says `!`. A local pre-push hook decline and a refspec that matches
1537
- * nothing exit 1 with no ref lines, so they throw. So does every transport
1538
- * failure (exit 128: an unknown remote, auth, network, TLS), as the
1539
- * classified failure.
1586
+ * A rejected ref is a value, not a throw: check each ref's `flag`, or
1587
+ * whether any is `'!'`. git exits 1 when any ref is rejected, so exit 1 is
1588
+ * declared absent, and the parse throws unless a ref line says `!`. A local
1589
+ * pre-push hook decline and a refspec that matches nothing exit 1 with no
1590
+ * ref lines, so they throw. So does every transport failure (exit 128: an
1591
+ * unknown remote, auth, network, TLS), as the classified failure.
1540
1592
  *
1541
1593
  * Runs with `LC_ALL=C`, so the caller's locale does not change the reason
1542
1594
  * text. An empty refspec list throws a `TypeError`: git would push its
1543
1595
  * default set.
1544
1596
  */
1545
- export function pushPorcelain(remote, refspec, opts = {}) {
1597
+ export function push(remote, refspec, opts = {}) {
1546
1598
  const specs = typeof refspec === 'string' ? [refspec] : refspec;
1547
1599
  if (specs.length === 0)
1548
- throw new TypeError('typed-git: pushPorcelain: refspec list is empty');
1600
+ throw new TypeError('typed-git: push: refspec list is empty');
1549
1601
  const argv = ['push', '--porcelain'];
1602
+ if (opts.delete)
1603
+ argv.push('--delete');
1550
1604
  if (opts.atomic)
1551
1605
  argv.push('--atomic');
1552
- argv.push(...forceWithLeaseArgs('pushPorcelain', opts.forceWithLease));
1553
- argv.push(positional('pushPorcelain', 'remote', remote));
1606
+ argv.push(...forceWithLeaseArgs('push', opts.forceWithLease));
1607
+ argv.push(positional('push', 'remote', remote));
1554
1608
  for (const spec of specs)
1555
- argv.push(positional('pushPorcelain', 'refspec', spec));
1609
+ argv.push(positional('push', 'refspec', spec));
1556
1610
  return {
1557
1611
  argv,
1558
1612
  env: C_LOCALE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdlc/typed-git",
3
- "version": "0.11.1",
3
+ "version": "0.12.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",