@osdlc/typed-git 0.8.1 → 0.10.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,50 @@
1
1
  # @osdlc/typed-git
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - da5e6a3: New: `parseRemoteRepo(url)` reads a git remote into `{ host, owner, repo }` (type `RemoteRepo`), or null when it names no project. It reads a known host through `parseGitUrl` first (so shorthand reads as GitHub and a GitLab nested group stays whole in `owner`), then any other host through `parseRemoteUrl`, so a GitHub Enterprise or self-hosted Forgejo remote answers too. `host` is lower-cased and has no port. It is on the root entry, not `./client`.
8
+ The result gate, the `try` proxy, the start of `classifyGitFailure` and the leading-dash guard now use `@osdlc/command-seam`'s `runFailed`, `tryMethods`, `methodFacade`, `classifyFailed` and `notAnOption`. Nothing a caller sees changes: the same failures, the same `TypeError` and message for a positional that starts with `-`.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [da5e6a3]
13
+ - @osdlc/command-seam@0.14.0
14
+
15
+ ## 0.9.0
16
+
17
+ ### Minor Changes
18
+
19
+ - b835ae4: Behaviour change: `mainCheckout()` now answers null for a bare store with no main checkout, instead of the store's parent folder. When the common dir is not `<checkout>/.git` (a submodule, a `--separate-git-dir` clone), it reads `core.worktree`, this checkout when the cwd is the main worktree, or the first non-bare `worktree list` entry.
20
+ `branches()` lists `refs/heads/` names, so a branch that shares its name with a tag is no longer reported as `heads/<name>`. `statusEntries()` skips the source field of a rename or copy in the worktree column too, so the entry after it is no longer misread. `parseRepoRef` reads a GitLab page in a nested group (`…/group/sub/repo/-/…`) as the whole project path, and still reads a GitHub page whose path holds a `-` segment. `parseRemoteUrl` answers null for a `file://` URL and strips `.git` from `repo.git/`. `scanForCheckouts` on a folder that is itself a checkout answers that folder alone.
21
+ - fdef74f: New verbs and verb options, on both `Git` and `AsyncGit`, for operations that needed `raw` before:
22
+
23
+ - `worktreeAdd(path, { branch, resetBranch: true })` is `worktree add -B`: create the branch, or reset an existing one. This is the same shape as `checkout`'s `resetBranch`. `resetBranch` without `branch` throws a `TypeError`.
24
+ - `commit({ ..., paths })` appends `-- <paths…>`, with every message source, so only those paths are committed. An empty `paths` throws a `TypeError`, because git would commit everything staged.
25
+ - `push(remote, refspec, { delete: true })` is `push --delete`, and combines with `forceWithLease`.
26
+ - `hasStagedChanges()` is `diff --cached --quiet`: `true` for exit 1, `false` for exit 0, and a throw for anything else. On an unborn HEAD the index is compared against the empty tree. `git.soft.hasStagedChanges()` falls back to `false`.
27
+ - `showAtRevChecked(rev, path)` runs the same `show` as `showAtRev`, but a missing path throws the classified failure instead of returning `null`.
28
+ - `remoteSetHead(remote, { branch } | { auto: true } | { delete: true })` and `remoteSetBranches(remote, branches, { add })`. An empty `branches` throws a `TypeError`.
29
+ - `gc({ auto, aggressive, prune, quiet })`, where `prune` is a date string or `false` for `--no-prune`.
30
+
31
+ The new option types `WorktreeAddOptions`, `PushOptions`, `RemoteSetHeadOptions`, `RemoteSetBranchesOptions` and `GcOptions` are exported. `GitRequest` and `GitResults` gain the `hasStagedChanges`, `showAtRevChecked`, `remoteSetHead`, `remoteSetBranches` and `gc` kinds.
32
+
33
+ Fixed: `worktreeAdd` and `checkout` now refuse a `branch` that starts with `-`, as every other positional value already was. `worktree add` passes the name to a child `git branch`, so `worktreeAdd(path, { branch: '-M', resetBranch: true, startPoint: 'x' })` used to rename the current branch to `x` before failing.
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [b835ae4]
38
+ - @osdlc/command-seam@0.13.0
39
+
40
+ ## 0.8.2
41
+
42
+ ### Patch Changes
43
+
44
+ - f013f38: The default runners now find `git` and `gh` on absolute `PATH` entries only, and spawn the absolute path found. Before, a bare `git` or `gh` was spawned by name with the child's `cwd` set to the checkout, so a file of that name in the checkout could run in place of the real binary: on Windows, where a bare name is searched in `cwd` first, and on every platform through a relative or empty `PATH` entry. A binary that is not found on an absolute entry fails as a missing binary (`not-installed`). typed-gh's `defaultRunnerFactory` does the same lookup. An injected runner is unchanged.
45
+ - Updated dependencies [f013f38]
46
+ - @osdlc/command-seam@0.12.1
47
+
3
48
  ## 0.8.1
4
49
 
5
50
  ### Patch Changes
package/README.md CHANGED
@@ -205,6 +205,11 @@ there: `git.try.logSubject("HEAD")` outside a repository is `{ ok: true,
205
205
  value: null }`, not a failure. The contract reduces these cases. It does not
206
206
  remove them.
207
207
 
208
+ When a missing file is an error rather than an answer, use
209
+ `showAtRevChecked(rev, path)`. It runs the same `show` and declares no
210
+ absence, so a missing path throws the classified failure instead of reading as
211
+ `null`.
212
+
208
213
  Where the difference matters, probe with `hasHistory()` first:
209
214
 
210
215
  ```ts
@@ -505,7 +510,7 @@ trailing argument that is not a string.
505
510
 
506
511
  A ref, remote, URL, path, ref pattern or config key argument that starts with
507
512
  `-` could be read by git as an option, for example `--upload-pack=...` or
508
- `--output=<file>`. Forty-two verbs refuse it: they throw a `TypeError`
513
+ `--output=<file>`. Every verb that takes such an argument refuses it: they throw a `TypeError`
509
514
  before git runs. In `log` this covers `rev`, `range` and each `notRefs` entry.
510
515
  In `diffNameOnly` and `diffStat` it covers each `rangeArgs` token. The message is
511
516
  `typed-git: <verb>: <param> must not start with "-" (got "...")`. `try` and
@@ -531,6 +536,7 @@ exit throws the classified failure.
531
536
  | Method | git | Absence → value |
532
537
  | --- | --- | --- |
533
538
  | `showAtRev(rev, path)` | `show <rev>:<path>` | `128` → `null` |
539
+ | `showAtRevChecked(rev, path)` | `show <rev>:<path>` | none — a missing path throws; no `soft` form |
534
540
  | `revParse(...args)` | `rev-parse <args>` | `1` → `null` — needs `--verify --quiet` |
535
541
  | `resolveRef(ref)` | `rev-parse --verify --quiet <ref>` | `1` → `null` |
536
542
  | `hasHistory()` | `resolveRef("HEAD") !== null` | — |
@@ -538,13 +544,14 @@ exit throws the classified failure.
538
544
  | `topLevel()` | `rev-parse --show-toplevel` | `128` → `null` (not a repository) |
539
545
  | `gitCommonDir()` | `rev-parse --path-format=absolute --git-common-dir` | `128` → `null` |
540
546
  | `gitDir()` | `rev-parse --absolute-git-dir` | `128` → `null` — this worktree's own dir, `<common>/worktrees/<name>` in a linked worktree |
541
- | `mainCheckout()` | the parent of `gitCommonDir()` | `null` outside a repository |
547
+ | `mainCheckout()` | the parent of `gitCommonDir()` when that is `<checkout>/.git`, else `core.worktree` or the main worktree | `null` outside a repository, or for a bare store |
542
548
  | `symbolicRef(ref)` | `symbolic-ref <ref>` | `128` → `null` |
543
549
  | `currentBranch()` | `branch --show-current` | none — `null` when detached |
544
550
  | `statusPorcelain({ paths })` | `status --porcelain` | none |
545
551
  | `statusEntries()` | `status --porcelain -z --untracked-files=all` | none — `{ x, y, path }` rows; a rename is one row, with the source dropped |
546
552
  | `isDirty({ paths })` | `statusPorcelain().length > 0` | none |
547
- | `branches(pattern)` | `branch --list --format=%(refname:short)` | none |
553
+ | `hasStagedChanges()` | `diff --cached --quiet` | `1` → `true`, `0` → `false` — on an unborn HEAD the index is compared against the empty tree; outside a repository (`129`) it throws |
554
+ | `branches(pattern)` | `branch --list --format=%(refname:lstrip=2)` | none |
548
555
  | `branchExists(name)` | `branches(name).includes(name)` | none |
549
556
  | `worktrees()` | `worktree list --porcelain` | none — rows carry `locked` and `lockReason` |
550
557
  | `mergeBase(a, b)` | `merge-base <a> <b>` | `1` → `null` (unrelated histories) |
@@ -597,8 +604,8 @@ Integration, declares exit 1 absent and returns the rejected refs.
597
604
  | --- | --- |
598
605
  | `fetch(remote, refspec, { prune, quiet, noWriteFetchHead, depth, noTags })` | `fetch` |
599
606
  | `add(paths, { all, update, intentToAdd })` | `add` (paths go after `--`) |
600
- | `commit({ message, body } \| { messageFile } \| { messageStdin }, { allowEmpty, amend, noVerify, signoff })` | `commit` — one message source, enforced by the types; `messageStdin` is `-F -` with the string on stdin, no temp file |
601
- | `push(remote, refspec, { forceWithLease })` | `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. To learn why a push was rejected, use `pushPorcelain` |
607
+ | `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 |
608
+ | `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` |
602
609
  | `configSet(key, value, { scope })` | `config` |
603
610
  | `configRemoveSection(name)` | `config --remove-section` — `false` when there is no such section |
604
611
  | `init(path, { bare, initialBranch, quiet })` | `init` |
@@ -607,11 +614,15 @@ Integration, declares exit 1 absent and returns the rejected refs.
607
614
  | `clean({ directories })` | `clean -f`, or `-fd` — ignored files are kept |
608
615
  | `deleteBranch(name, { force })` | `branch -d` / `-D` |
609
616
  | `deleteRef(ref, { expected })` | `update-ref -d <ref> <expected>` — refuses when `ref` has moved |
610
- | `worktreeAdd(path, { branch, startPoint, detach })` | `worktree add` |
617
+ | `worktreeAdd(path, { branch, resetBranch, startPoint, detach })` | `worktree add` — `branch` is `-b`; `resetBranch` picks `-B` (create, or reset an existing branch), as for `checkout` |
611
618
  | `worktreeRemove(path, { force })` | `worktree remove` |
612
619
  | `worktreeMove(from, to, { force })` | `worktree move` |
620
+ | `worktreeUnlock(path)` | `worktree unlock` |
613
621
  | `worktreePrune()` | `worktree prune` |
614
622
  | `remoteAdd(name, url)` | `remote add` |
623
+ | `remoteSetHead(remote, { branch } \| { auto: true } \| { delete: true })` | `remote set-head <remote> <branch>\|--auto\|--delete` — exactly one, enforced by the types and at run time |
624
+ | `remoteSetBranches(remote, branches, { add })` | `remote set-branches [--add]` — an empty `branches` throws a `TypeError`, because git would clear every fetch refspec |
625
+ | `gc({ auto, aggressive, prune, quiet })` | `gc` — `prune` is a date such as `'now'` for `--prune=<date>`, or `false` for `--no-prune` |
615
626
  | `checkout(ref, { branch, resetBranch, force })` | `checkout` — `resetBranch` picks `-B` |
616
627
  | `checkoutSide(side, paths)` | `checkout --ours\|--theirs --` |
617
628
  | `mergeAbort()` / `rebaseAbort()` | `merge --abort` / `rebase --abort` |
@@ -698,12 +709,19 @@ const failing: CommandRunner = {
698
709
  new Git("/nowhere", { runner: failing }).currentBranch(); // throws FailureError (kind "not-a-repo")
699
710
  ```
700
711
 
712
+ The default runner finds `git` on absolute `PATH` entries only, so a file named
713
+ `git` in the checkout cannot run in its place. A real runner you build yourself
714
+ should do the same: `spawnRunner("git", { absolutePathOnly: true })`.
715
+
701
716
  `runner: undefined` is the same as omitting it, so a caller holding an optional
702
717
  runner passes it straight through, without a conditional spread. `cliBackend`
703
718
  accepts it too.
704
719
 
705
- command-seam's exports are re-exported here, so wiring a runner or catching a
706
- `CommandFailed` needs one import rather than two.
720
+ The runner and result types, `CommandFailed`, `spawnRunner`, `spawnRunnerAsync`,
721
+ `runChecked`, `runCheckedAsync` and `asAsync` are re-exported from command-seam,
722
+ so wiring a runner or catching a `CommandFailed` needs one import rather than
723
+ two. Import other runners, such as `spawnRunnerBytes` and `streamRunner`, from
724
+ `@osdlc/command-seam`.
707
725
 
708
726
  ## Also: git references
709
727
 
@@ -727,6 +745,21 @@ is what `remoteOwnerRepo` uses, and it stays on `@osdlc/typed-git/client`.
727
745
  Use it for a remote read from a checkout (any host); use `parseGitUrl` /
728
746
  `parseRepoRef` for a URL a person pasted.
729
747
 
748
+ `parseRemoteRepo` reads a remote into `{ host, owner, repo }`, for a known
749
+ host and any other alike. It tries `parseGitUrl` first, so shorthand reads as
750
+ GitHub and a GitLab nested group stays whole in `owner`, then falls back to
751
+ `parseRemoteUrl`, so a GitHub Enterprise or self-hosted Forgejo remote
752
+ answers too. `host` is lower-cased and carries no port. Decide which forge a
753
+ remote is on from `host`, not from the URL text.
754
+
755
+ ```ts
756
+ parseRemoteRepo("git@github.com:acme/widgets.git");
757
+ // { host: "github.com", owner: "acme", repo: "widgets" }
758
+ parseRemoteRepo("https://forge.example.com:3000/team/app.git");
759
+ // { host: "forge.example.com", owner: "team", repo: "app" }
760
+ parseRemoteRepo("/srv/git/repo.git"); // null — a local path names no project
761
+ ```
762
+
730
763
  `parseRepoRef` answers the question a clone command asks. Given anything a
731
764
  person might paste (a clone URL, the page of a pull request or a file, a bare
732
765
  `owner/repo`), which repository is it, and what does `git clone` take? It returns
@@ -746,7 +779,7 @@ parseRepoRef("./a/local/path"); // null — the input names no repository
746
779
  ## Subpath exports
747
780
 
748
781
  `@osdlc/typed-git/client` is everything above except the URL parsers
749
- (`parseGitUrl`, `gitSshUrl`, `parseRepoRef` and their types) and the checkout
782
+ (`parseGitUrl`, `gitSshUrl`, `parseRemoteRepo`, `parseRepoRef` and their types) and the checkout
750
783
  walks (`checkoutRoot`, `discoverCheckouts`, `scanForCheckouts`, their types,
751
784
  `DEFAULT_MAX_DEPTH` and `DEFAULT_WARN_AFTER`). It has no `hosted-git-info` on
752
785
  your module graph. That package stays in `dependencies` either way, so this
package/SECURITY.md CHANGED
@@ -24,8 +24,10 @@ We will credit you in the release notes if you want that.
24
24
 
25
25
  ## Scope
26
26
 
27
- - The client runs the `git` found on `PATH`. It builds argument arrays and
28
- starts no shell.
27
+ - The client runs the `git` found on an absolute `PATH` entry, by its
28
+ absolute path, so a file named `git` in the checkout cannot run in its
29
+ place. It builds argument arrays and starts no shell. A runner you inject
30
+ replaces this lookup.
29
31
  - Starting the process is the job of `@osdlc/command-seam`. Report problems
30
32
  in how a process is started there.
31
33
  - `@osdlc/typed-git/testing` makes and deletes temporary directories. It is
package/dist/async.d.ts CHANGED
@@ -16,7 +16,7 @@ import type { CommandResult } from '@osdlc/command-seam';
16
16
  import { type GitBackend, type GitCallOptions } from './backend.ts';
17
17
  import { type Soft, type TriedAsync } from './outcome.ts';
18
18
  import { type RemoteCoordinate } from './remote-url.ts';
19
- import { type AddOptions, type AheadBehind, 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 ForceLease, 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 WorktreeMoveOptions } from './verbs.ts';
19
+ import { type AddOptions, type AheadBehind, 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
20
  /** A typed, awaitable git client bound to one working directory. */
21
21
  export declare class AsyncGit {
22
22
  readonly cwd: string;
@@ -76,6 +76,8 @@ export declare class AsyncGit {
76
76
  }): Promise<CommandResult>;
77
77
  /** A file's content at a rev, null if absent. */
78
78
  showAtRev(rev: string, relPath: string, opts?: GitCallOptions): Promise<string | null>;
79
+ /** A file's content at a rev, rejecting when the path is missing. See {@link Git.showAtRevChecked}. */
80
+ showAtRevChecked(rev: string, relPath: string, opts?: GitCallOptions): Promise<string>;
79
81
  /**
80
82
  * See {@link Git.revParse}. Call options go last, as an object. For a ref,
81
83
  * prefer {@link AsyncGit.resolveRef}.
@@ -118,6 +120,8 @@ export declare class AsyncGit {
118
120
  statusPorcelain(opts?: GitCallOptions & StatusPorcelainOptions): Promise<string[]>;
119
121
  /** Every changed or untracked file, from `status --porcelain -z`. */
120
122
  statusEntries(opts?: GitCallOptions): Promise<StatusEntry[]>;
123
+ /** True iff anything is staged. See {@link Git.hasStagedChanges}. */
124
+ hasStagedChanges(opts?: GitCallOptions): Promise<boolean>;
121
125
  /** True iff the working tree has any staged/unstaged/untracked change. */
122
126
  isDirty(opts?: GitCallOptions & StatusPorcelainOptions): Promise<boolean>;
123
127
  /** Local branch shortnames matching `pattern` (all when omitted). */
@@ -252,12 +256,10 @@ export declare class AsyncGit {
252
256
  clone(url: string, dest?: string | undefined, opts?: GitCallOptions & CloneOptions): Promise<void>;
253
257
  /**
254
258
  * Push a refspec. A {@link ForceLease} pins `--force-with-lease`.
255
- * `{forceWithLease: true}` adds the bare flag, which is the unsafe form. See
256
- * {@link Git.push}.
259
+ * `{forceWithLease: true}` adds the bare flag, which is the unsafe form.
260
+ * `{delete: true}` deletes `refspec` on the remote. See {@link Git.push}.
257
261
  */
258
- push(remote: string, refspec: string, opts?: GitCallOptions & {
259
- forceWithLease?: boolean | ForceLease | undefined;
260
- }): Promise<void>;
262
+ push(remote: string, refspec: string, opts?: GitCallOptions & PushOptions): Promise<void>;
261
263
  /**
262
264
  * `git push --porcelain`, read into one result per ref. A rejected ref comes
263
265
  * back with a typed `rejection` rather than a rejection of the promise. See
@@ -281,22 +283,26 @@ export declare class AsyncGit {
281
283
  deleteRef(ref: string, opts: GitCallOptions & {
282
284
  expected: string;
283
285
  }): Promise<void>;
284
- /** `git worktree add [--detach] [-b branch] <path> [startPoint]`. */
285
- worktreeAdd(path: string, opts?: GitCallOptions & {
286
- branch?: string | undefined;
287
- startPoint?: string | undefined;
288
- detach?: boolean | undefined;
289
- }): Promise<void>;
286
+ /** `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`. See {@link Git.worktreeAdd}. */
287
+ worktreeAdd(path: string, opts?: GitCallOptions & WorktreeAddOptions): Promise<void>;
290
288
  /** `git worktree remove [--force] <path>`. */
291
289
  worktreeRemove(path: string, opts?: GitCallOptions & {
292
290
  force?: boolean | undefined;
293
291
  }): Promise<void>;
294
292
  /** `git worktree move [--force] <from> <to>`. */
295
293
  worktreeMove(from: string, to: string, opts?: GitCallOptions & WorktreeMoveOptions): Promise<void>;
294
+ /** `git worktree unlock <path>`. */
295
+ worktreeUnlock(path: string, opts?: GitCallOptions): Promise<void>;
296
296
  /** `git worktree prune`. */
297
297
  worktreePrune(opts?: GitCallOptions): Promise<void>;
298
298
  /** `git remote add <name> <url>`. */
299
299
  remoteAdd(name: string, url: string, opts?: GitCallOptions): Promise<void>;
300
+ /** `git remote set-head <remote> <branch> | --auto | --delete`. See {@link Git.remoteSetHead}. */
301
+ remoteSetHead(remote: string, opts: GitCallOptions & RemoteSetHeadOptions): Promise<void>;
302
+ /** `git remote set-branches [--add] <remote> <branch…>`; an empty list rejects. */
303
+ remoteSetBranches(remote: string, branches: string[], opts?: GitCallOptions & RemoteSetBranchesOptions): Promise<void>;
304
+ /** `git gc [--auto] [--aggressive] [--prune=<date> | --no-prune] [--quiet]`. */
305
+ gc(opts?: GitCallOptions & GcOptions): Promise<void>;
300
306
  /**
301
307
  * Merge `ref` into the current branch. A conflict is a value, not a
302
308
  * rejection: the outcome is `clean` or `conflict`. Git refusing to merge at
package/dist/async.js CHANGED
@@ -12,7 +12,7 @@
12
12
  * `new AsyncGit(cwd, { backend: cliBackend({ gitDir }) })`, where the sync
13
13
  * client takes `gitDir` on its own constructor.
14
14
  */
15
- import { dirname } from 'node:path';
15
+ import { basename, dirname, resolve } from 'node:path';
16
16
  import { cliBackend } from "./backend.js";
17
17
  import { softAsync, triedAsync } from "./outcome.js";
18
18
  import { parseRemoteUrl } from "./remote-url.js";
@@ -101,6 +101,10 @@ export class AsyncGit {
101
101
  showAtRev(rev, relPath, opts = {}) {
102
102
  return this.backend.execute(this.cwd, { kind: 'showAtRev', rev, relPath }, opts);
103
103
  }
104
+ /** A file's content at a rev, rejecting when the path is missing. See {@link Git.showAtRevChecked}. */
105
+ showAtRevChecked(rev, relPath, opts = {}) {
106
+ return this.backend.execute(this.cwd, { kind: 'showAtRevChecked', rev, relPath }, opts);
107
+ }
104
108
  /**
105
109
  * See {@link Git.revParse}. Call options go last, as an object. For a ref,
106
110
  * prefer {@link AsyncGit.resolveRef}.
@@ -152,7 +156,17 @@ export class AsyncGit {
152
156
  */
153
157
  async mainCheckout(opts = {}) {
154
158
  const common = await this.gitCommonDir(opts);
155
- return common === null ? null : dirname(common);
159
+ if (common === null)
160
+ return null;
161
+ if (basename(common) === '.git')
162
+ return dirname(common);
163
+ const configured = await this.configGet('core.worktree', opts);
164
+ if (configured !== null)
165
+ return resolve(common, configured);
166
+ if ((await this.gitDir(opts)) === common)
167
+ return this.topLevel(opts);
168
+ const main = (await this.worktrees(opts))[0];
169
+ return main === undefined || main.bare ? null : main.path;
156
170
  }
157
171
  /** Current branch shortname, or null when detached. Rejects outside a repo. */
158
172
  currentBranch(opts = {}) {
@@ -170,6 +184,10 @@ export class AsyncGit {
170
184
  statusEntries(opts = {}) {
171
185
  return this.backend.execute(this.cwd, { kind: 'statusEntries' }, opts);
172
186
  }
187
+ /** True iff anything is staged. See {@link Git.hasStagedChanges}. */
188
+ hasStagedChanges(opts = {}) {
189
+ return this.backend.execute(this.cwd, { kind: 'hasStagedChanges' }, opts);
190
+ }
173
191
  /** True iff the working tree has any staged/unstaged/untracked change. */
174
192
  async isDirty(opts = {}) {
175
193
  return (await this.statusPorcelain(opts)).length > 0;
@@ -420,11 +438,11 @@ export class AsyncGit {
420
438
  }
421
439
  /**
422
440
  * Push a refspec. A {@link ForceLease} pins `--force-with-lease`.
423
- * `{forceWithLease: true}` adds the bare flag, which is the unsafe form. See
424
- * {@link Git.push}.
441
+ * `{forceWithLease: true}` adds the bare flag, which is the unsafe form.
442
+ * `{delete: true}` deletes `refspec` on the remote. See {@link Git.push}.
425
443
  */
426
444
  push(remote, refspec, opts = {}) {
427
- return this.backend.execute(this.cwd, { kind: 'push', remote, refspec, forceWithLease: opts.forceWithLease }, opts);
445
+ return this.backend.execute(this.cwd, { kind: 'push', remote, refspec, forceWithLease: opts.forceWithLease, delete: opts.delete }, opts);
428
446
  }
429
447
  /**
430
448
  * `git push --porcelain`, read into one result per ref. A rejected ref comes
@@ -459,15 +477,10 @@ export class AsyncGit {
459
477
  deleteRef(ref, opts) {
460
478
  return this.backend.execute(this.cwd, { kind: 'deleteRef', ref, expected: opts.expected }, opts);
461
479
  }
462
- /** `git worktree add [--detach] [-b branch] <path> [startPoint]`. */
480
+ /** `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`. See {@link Git.worktreeAdd}. */
463
481
  worktreeAdd(path, opts = {}) {
464
- return this.backend.execute(this.cwd, {
465
- kind: 'worktreeAdd',
466
- path,
467
- branch: opts.branch,
468
- startPoint: opts.startPoint,
469
- detach: opts.detach,
470
- }, opts);
482
+ const [call, req] = splitCallOptions(opts);
483
+ return this.backend.execute(this.cwd, { kind: 'worktreeAdd', path, ...req }, call);
471
484
  }
472
485
  /** `git worktree remove [--force] <path>`. */
473
486
  worktreeRemove(path, opts = {}) {
@@ -478,6 +491,10 @@ export class AsyncGit {
478
491
  const [call, req] = splitCallOptions(opts);
479
492
  return this.backend.execute(this.cwd, { kind: 'worktreeMove', from, to, ...req }, call);
480
493
  }
494
+ /** `git worktree unlock <path>`. */
495
+ worktreeUnlock(path, opts = {}) {
496
+ return this.backend.execute(this.cwd, { kind: 'worktreeUnlock', path }, opts);
497
+ }
481
498
  /** `git worktree prune`. */
482
499
  worktreePrune(opts = {}) {
483
500
  return this.backend.execute(this.cwd, { kind: 'worktreePrune' }, opts);
@@ -486,6 +503,21 @@ export class AsyncGit {
486
503
  remoteAdd(name, url, opts = {}) {
487
504
  return this.backend.execute(this.cwd, { kind: 'remoteAdd', name, url }, opts);
488
505
  }
506
+ /** `git remote set-head <remote> <branch> | --auto | --delete`. See {@link Git.remoteSetHead}. */
507
+ remoteSetHead(remote, opts) {
508
+ const [call, req] = splitCallOptions(opts);
509
+ return this.backend.execute(this.cwd, { kind: 'remoteSetHead', remote, ...req }, call);
510
+ }
511
+ /** `git remote set-branches [--add] <remote> <branch…>`; an empty list rejects. */
512
+ remoteSetBranches(remote, branches, opts = {}) {
513
+ const [call, req] = splitCallOptions(opts);
514
+ return this.backend.execute(this.cwd, { kind: 'remoteSetBranches', remote, branches, ...req }, call);
515
+ }
516
+ /** `git gc [--auto] [--aggressive] [--prune=<date> | --no-prune] [--quiet]`. */
517
+ gc(opts = {}) {
518
+ const [call, req] = splitCallOptions(opts);
519
+ return this.backend.execute(this.cwd, { kind: 'gc', ...req }, call);
520
+ }
489
521
  // ── integration ───────────────────────────────────────────────────────────
490
522
  /**
491
523
  * Merge `ref` into the current branch. A conflict is a value, not a
package/dist/backend.d.ts CHANGED
@@ -18,7 +18,7 @@
18
18
  * `cliBackend` and `AsyncGit` are stable.
19
19
  */
20
20
  import { type AsyncCommandRunner, type CommandResult } from '@osdlc/command-seam';
21
- import { type AddOptions, type AheadBehind, 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 ForceLease, 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 PushPorcelainOptions, type PushReport, 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';
21
+ import { type AddOptions, type AheadBehind, 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
22
  /** Per-call concerns that are not part of the operation itself. */
23
23
  export interface GitCallOptions {
24
24
  /**
@@ -60,6 +60,10 @@ export type GitRequest = {
60
60
  kind: 'showAtRev';
61
61
  rev: string;
62
62
  relPath: string;
63
+ } | {
64
+ kind: 'showAtRevChecked';
65
+ rev: string;
66
+ relPath: string;
63
67
  } | {
64
68
  kind: 'revParse';
65
69
  args: string[];
@@ -138,7 +142,9 @@ export type GitRequest = {
138
142
  kind: 'diffStat';
139
143
  } & DiffStatOptions) | ({
140
144
  kind: 'diffCheck';
141
- } & DiffCheckOptions) | ({
145
+ } & DiffCheckOptions) | {
146
+ kind: 'hasStagedChanges';
147
+ } | ({
142
148
  kind: 'diffNameStatus';
143
149
  } & DiffNameStatusOptions) | ({
144
150
  kind: 'log';
@@ -183,12 +189,11 @@ export type GitRequest = {
183
189
  kind: 'clone';
184
190
  url: string;
185
191
  dest?: string | undefined;
186
- } & CloneOptions) | {
192
+ } & CloneOptions) | ({
187
193
  kind: 'push';
188
194
  remote: string;
189
195
  refspec: string;
190
- forceWithLease?: boolean | ForceLease | undefined;
191
- } | ({
196
+ } & PushOptions) | ({
192
197
  kind: 'pushPorcelain';
193
198
  remote: string;
194
199
  refspec: string | string[];
@@ -205,13 +210,10 @@ export type GitRequest = {
205
210
  kind: 'deleteRef';
206
211
  ref: string;
207
212
  expected: string;
208
- } | {
213
+ } | ({
209
214
  kind: 'worktreeAdd';
210
215
  path: string;
211
- branch?: string | undefined;
212
- startPoint?: string | undefined;
213
- detach?: boolean | undefined;
214
- } | {
216
+ } & WorktreeAddOptions) | {
215
217
  kind: 'worktreeRemove';
216
218
  path: string;
217
219
  force?: boolean | undefined;
@@ -220,6 +222,9 @@ export type GitRequest = {
220
222
  from: string;
221
223
  to: string;
222
224
  } & WorktreeMoveOptions) | {
225
+ kind: 'worktreeUnlock';
226
+ path: string;
227
+ } | {
223
228
  kind: 'worktreePrune';
224
229
  } | ({
225
230
  kind: 'merge';
@@ -261,7 +266,16 @@ export type GitRequest = {
261
266
  kind: 'remoteAdd';
262
267
  name: string;
263
268
  url: string;
264
- } | {
269
+ } | ({
270
+ kind: 'remoteSetHead';
271
+ remote: string;
272
+ } & RemoteSetHeadOptions) | ({
273
+ kind: 'remoteSetBranches';
274
+ remote: string;
275
+ branches: string[];
276
+ } & RemoteSetBranchesOptions) | ({
277
+ kind: 'gc';
278
+ } & GcOptions) | {
265
279
  kind: 'raw';
266
280
  argv: string[];
267
281
  input?: string | undefined;
@@ -274,6 +288,7 @@ export type GitRequest = {
274
288
  */
275
289
  export interface GitResults {
276
290
  showAtRev: string | null;
291
+ showAtRevChecked: string;
277
292
  revParse: string | null;
278
293
  resolveRef: string | null;
279
294
  headRef: string | null;
@@ -303,6 +318,7 @@ export interface GitResults {
303
318
  diffNameOnly: string[];
304
319
  diffStat: string;
305
320
  diffCheck: DiffCheckResult;
321
+ hasStagedChanges: boolean;
306
322
  diffNameStatus: DiffEntry[];
307
323
  log: string;
308
324
  lsTree: TreeEntry[];
@@ -327,6 +343,7 @@ export interface GitResults {
327
343
  worktreeAdd: void;
328
344
  worktreeRemove: void;
329
345
  worktreeMove: void;
346
+ worktreeUnlock: void;
330
347
  worktreePrune: void;
331
348
  merge: MergeOutcome;
332
349
  mergeAbort: void;
@@ -342,6 +359,9 @@ export interface GitResults {
342
359
  remoteGetUrls: string[];
343
360
  remoteHead: string | null;
344
361
  remoteAdd: void;
362
+ remoteSetHead: void;
363
+ remoteSetBranches: void;
364
+ gc: void;
345
365
  raw: CommandResult;
346
366
  }
347
367
  /** Every request kind, as a union of string literals. */
@@ -369,7 +389,9 @@ export declare class UnsupportedRequest extends Error {
369
389
  /**
370
390
  * The default backend: every request becomes a `git` subprocess, run through
371
391
  * an {@link AsyncCommandRunner} so the caller decides how spawning happens
372
- * (and tests inject a fake).
392
+ * (and tests inject a fake). The default runner spawns the `git` found on an
393
+ * absolute `PATH` entry, so a `git` file in the checkout cannot run in its
394
+ * place.
373
395
  */
374
396
  export declare function cliBackend(opts?: {
375
397
  runner?: AsyncCommandRunner | undefined;
package/dist/backend.js CHANGED
@@ -17,7 +17,7 @@
17
17
  * written as an exhaustive switch. Such a change can land in a minor release.
18
18
  * `cliBackend` and `AsyncGit` are stable.
19
19
  */
20
- import { resolveRunnerAsync, } from '@osdlc/command-seam';
20
+ import { spawnRunnerAsync, } from '@osdlc/command-seam';
21
21
  import * as v from "./verbs.js";
22
22
  import { gate, mergeEnv, repoPrefix, } from "./verbs.js";
23
23
  /** Thrown by a backend asked for an operation it cannot perform. */
@@ -34,6 +34,8 @@ function toVerb(request) {
34
34
  switch (request.kind) {
35
35
  case 'showAtRev':
36
36
  return v.showAtRev(request.rev, request.relPath);
37
+ case 'showAtRevChecked':
38
+ return v.showAtRevChecked(request.rev, request.relPath);
37
39
  case 'revParse':
38
40
  return v.revParse(...request.args);
39
41
  case 'resolveRef':
@@ -92,6 +94,8 @@ function toVerb(request) {
92
94
  return v.diffStat(request);
93
95
  case 'diffCheck':
94
96
  return v.diffCheck(request);
97
+ case 'hasStagedChanges':
98
+ return v.hasStagedChanges();
95
99
  case 'diffNameStatus':
96
100
  return v.diffNameStatus(request);
97
101
  case 'log':
@@ -123,9 +127,7 @@ function toVerb(request) {
123
127
  case 'clone':
124
128
  return v.clone(request.url, request.dest, request);
125
129
  case 'push':
126
- return v.push(request.remote, request.refspec, {
127
- forceWithLease: request.forceWithLease,
128
- });
130
+ return v.push(request.remote, request.refspec, request);
129
131
  case 'pushPorcelain':
130
132
  return v.pushPorcelain(request.remote, request.refspec, request);
131
133
  case 'resetHard':
@@ -142,6 +144,8 @@ function toVerb(request) {
142
144
  return v.worktreeRemove(request.path, { force: request.force });
143
145
  case 'worktreeMove':
144
146
  return v.worktreeMove(request.from, request.to, request);
147
+ case 'worktreeUnlock':
148
+ return v.worktreeUnlock(request.path);
145
149
  case 'worktreePrune':
146
150
  return v.worktreePrune();
147
151
  case 'merge':
@@ -172,6 +176,12 @@ function toVerb(request) {
172
176
  return v.remoteHead(request.remote);
173
177
  case 'remoteAdd':
174
178
  return v.remoteAdd(request.name, request.url);
179
+ case 'remoteSetHead':
180
+ return v.remoteSetHead(request.remote, request);
181
+ case 'remoteSetBranches':
182
+ return v.remoteSetBranches(request.remote, request.branches, request);
183
+ case 'gc':
184
+ return v.gc(request);
175
185
  case 'raw': {
176
186
  const verb = {
177
187
  argv: request.argv,
@@ -189,10 +199,12 @@ function toVerb(request) {
189
199
  /**
190
200
  * The default backend: every request becomes a `git` subprocess, run through
191
201
  * an {@link AsyncCommandRunner} so the caller decides how spawning happens
192
- * (and tests inject a fake).
202
+ * (and tests inject a fake). The default runner spawns the `git` found on an
203
+ * absolute `PATH` entry, so a `git` file in the checkout cannot run in its
204
+ * place.
193
205
  */
194
206
  export function cliBackend(opts = {}) {
195
- const runner = resolveRunnerAsync('git', opts.runner);
207
+ const runner = opts.runner ?? spawnRunnerAsync('git', { absolutePathOnly: true });
196
208
  const prefix = repoPrefix(opts.gitDir, opts.workTree);
197
209
  return {
198
210
  async execute(cwd, request, callOpts = {}) {
@@ -61,7 +61,8 @@ export interface CheckoutScan {
61
61
  * an owner directory per GitHub org, or a folder per client, and the
62
62
  * checkouts sit a level or two inside. Stopping at a checkout keeps this
63
63
  * fast: a repository's own `node_modules`, `vendor` and nested worktrees are
64
- * below it, so they are never entered.
64
+ * below it, so they are never entered. A search root that is a checkout
65
+ * answers itself alone.
65
66
  *
66
67
  * Two limits keep a bad search root from turning into a walk of the whole
67
68
  * disk: children whose names start with a dot are skipped, and nothing
@@ -54,7 +54,8 @@ export const DEFAULT_WARN_AFTER = 10_000;
54
54
  * an owner directory per GitHub org, or a folder per client, and the
55
55
  * checkouts sit a level or two inside. Stopping at a checkout keeps this
56
56
  * fast: a repository's own `node_modules`, `vendor` and nested worktrees are
57
- * below it, so they are never entered.
57
+ * below it, so they are never entered. A search root that is a checkout
58
+ * answers itself alone.
58
59
  *
59
60
  * Two limits keep a bad search root from turning into a walk of the whole
60
61
  * disk: children whose names start with a dot are skipped, and nothing
@@ -116,6 +117,11 @@ export function scanForCheckouts(dir, opts = {}) {
116
117
  visit(candidate, depth + 1);
117
118
  }
118
119
  };
120
+ // A search root that is itself a checkout is the answer, and the same rule
121
+ // holds: nothing inside it is entered.
122
+ if (existsSync(resolve(root, '.git'))) {
123
+ return { checkouts: [root], directoriesScanned: 0, depthLimited: 0 };
124
+ }
119
125
  visit(root, 1);
120
126
  return { checkouts: checkouts.sort(), directoriesScanned, depthLimited };
121
127
  }
package/dist/client.d.ts CHANGED
@@ -20,5 +20,5 @@ export { parseRemoteUrl, type RemoteCoordinate } from './remote-url.ts';
20
20
  export { cliBackend, partialBackend, UnsupportedRequest, type GitBackend, type GitCallOptions, type GitRequest, type GitRequestKind, type GitResults, } from './backend.ts';
21
21
  export { classifyGitFailure, describeGitFailure, type GitFailure, type GitFailureKind, } from './failure.ts';
22
22
  export { type Soft, type TriedAsync, type TriedSync } from './outcome.ts';
23
- export { forceWithLeaseArg, parseRefRows, REF_FORMAT, type AddOptions, type AheadBehind, 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 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 PushPorcelainOptions, type PushRefResult, type PushRejection, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type StatusEntry, type StatusPorcelainOptions, type TaggedFile, type TreeEntry, type UnmergedEntry, type Worktree, type WorktreeMoveOptions, } from './verbs.ts';
23
+ export { forceWithLeaseArg, parseRefRows, REF_FORMAT, type AddOptions, type AheadBehind, 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';
24
24
  export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, type AsyncCommandRunner, type AsyncCommandRunOptions, type CommandResult, type CommandRunner, type CommandRunOptions, } from '@osdlc/command-seam';