@osdlc/typed-git 0.8.2 → 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 +37 -0
- package/README.md +37 -9
- package/dist/async.d.ts +16 -12
- package/dist/async.js +41 -13
- package/dist/backend.d.ts +27 -11
- package/dist/backend.js +11 -3
- package/dist/checkout-root.d.ts +2 -1
- package/dist/checkout-root.js +7 -1
- package/dist/client.d.ts +1 -1
- package/dist/failure.js +6 -17
- package/dist/git-url.d.ts +24 -0
- package/dist/git-url.js +43 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/outcome.d.ts +7 -2
- package/dist/outcome.js +9 -45
- package/dist/remote-url.d.ts +2 -2
- package/dist/remote-url.js +7 -3
- package/dist/soft.d.ts +1 -0
- package/dist/soft.js +1 -0
- package/dist/sync.d.ts +35 -14
- package/dist/sync.js +54 -7
- package/dist/verbs.d.ts +134 -8
- package/dist/verbs.js +138 -20
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
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
|
+
|
|
3
40
|
## 0.8.2
|
|
4
41
|
|
|
5
42
|
### 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>`.
|
|
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
|
-
| `
|
|
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,12 +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` |
|
|
613
620
|
| `worktreeUnlock(path)` | `worktree unlock` |
|
|
614
621
|
| `worktreePrune()` | `worktree prune` |
|
|
615
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` |
|
|
616
626
|
| `checkout(ref, { branch, resetBranch, force })` | `checkout` — `resetBranch` picks `-B` |
|
|
617
627
|
| `checkoutSide(side, paths)` | `checkout --ours\|--theirs --` |
|
|
618
628
|
| `mergeAbort()` / `rebaseAbort()` | `merge --abort` / `rebase --abort` |
|
|
@@ -707,8 +717,11 @@ should do the same: `spawnRunner("git", { absolutePathOnly: true })`.
|
|
|
707
717
|
runner passes it straight through, without a conditional spread. `cliBackend`
|
|
708
718
|
accepts it too.
|
|
709
719
|
|
|
710
|
-
|
|
711
|
-
`
|
|
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`.
|
|
712
725
|
|
|
713
726
|
## Also: git references
|
|
714
727
|
|
|
@@ -732,6 +745,21 @@ is what `remoteOwnerRepo` uses, and it stays on `@osdlc/typed-git/client`.
|
|
|
732
745
|
Use it for a remote read from a checkout (any host); use `parseGitUrl` /
|
|
733
746
|
`parseRepoRef` for a URL a person pasted.
|
|
734
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
|
+
|
|
735
763
|
`parseRepoRef` answers the question a clone command asks. Given anything a
|
|
736
764
|
person might paste (a clone URL, the page of a pull request or a file, a bare
|
|
737
765
|
`owner/repo`), which repository is it, and what does `git clone` take? It returns
|
|
@@ -751,7 +779,7 @@ parseRepoRef("./a/local/path"); // null — the input names no repository
|
|
|
751
779
|
## Subpath exports
|
|
752
780
|
|
|
753
781
|
`@osdlc/typed-git/client` is everything above except the URL parsers
|
|
754
|
-
(`parseGitUrl`, `gitSshUrl`, `parseRepoRef` and their types) and the checkout
|
|
782
|
+
(`parseGitUrl`, `gitSshUrl`, `parseRemoteRepo`, `parseRepoRef` and their types) and the checkout
|
|
755
783
|
walks (`checkoutRoot`, `discoverCheckouts`, `scanForCheckouts`, their types,
|
|
756
784
|
`DEFAULT_MAX_DEPTH` and `DEFAULT_WARN_AFTER`). It has no `hosted-git-info` on
|
|
757
785
|
your module graph. That package stays in `dependencies` either way, so this
|
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
|
|
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.
|
|
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,12 +283,8 @@ 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;
|
|
@@ -299,6 +297,12 @@ export declare class AsyncGit {
|
|
|
299
297
|
worktreePrune(opts?: GitCallOptions): Promise<void>;
|
|
300
298
|
/** `git remote add <name> <url>`. */
|
|
301
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>;
|
|
302
306
|
/**
|
|
303
307
|
* Merge `ref` into the current branch. A conflict is a value, not a
|
|
304
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
|
-
|
|
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.
|
|
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
|
-
|
|
465
|
-
|
|
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 = {}) {
|
|
@@ -490,6 +503,21 @@ export class AsyncGit {
|
|
|
490
503
|
remoteAdd(name, url, opts = {}) {
|
|
491
504
|
return this.backend.execute(this.cwd, { kind: 'remoteAdd', name, url }, opts);
|
|
492
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
|
+
}
|
|
493
521
|
// ── integration ───────────────────────────────────────────────────────────
|
|
494
522
|
/**
|
|
495
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
|
|
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
|
-
|
|
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
|
-
|
|
212
|
-
startPoint?: string | undefined;
|
|
213
|
-
detach?: boolean | undefined;
|
|
214
|
-
} | {
|
|
216
|
+
} & WorktreeAddOptions) | {
|
|
215
217
|
kind: 'worktreeRemove';
|
|
216
218
|
path: string;
|
|
217
219
|
force?: boolean | undefined;
|
|
@@ -264,7 +266,16 @@ export type GitRequest = {
|
|
|
264
266
|
kind: 'remoteAdd';
|
|
265
267
|
name: string;
|
|
266
268
|
url: string;
|
|
267
|
-
} | {
|
|
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) | {
|
|
268
279
|
kind: 'raw';
|
|
269
280
|
argv: string[];
|
|
270
281
|
input?: string | undefined;
|
|
@@ -277,6 +288,7 @@ export type GitRequest = {
|
|
|
277
288
|
*/
|
|
278
289
|
export interface GitResults {
|
|
279
290
|
showAtRev: string | null;
|
|
291
|
+
showAtRevChecked: string;
|
|
280
292
|
revParse: string | null;
|
|
281
293
|
resolveRef: string | null;
|
|
282
294
|
headRef: string | null;
|
|
@@ -306,6 +318,7 @@ export interface GitResults {
|
|
|
306
318
|
diffNameOnly: string[];
|
|
307
319
|
diffStat: string;
|
|
308
320
|
diffCheck: DiffCheckResult;
|
|
321
|
+
hasStagedChanges: boolean;
|
|
309
322
|
diffNameStatus: DiffEntry[];
|
|
310
323
|
log: string;
|
|
311
324
|
lsTree: TreeEntry[];
|
|
@@ -346,6 +359,9 @@ export interface GitResults {
|
|
|
346
359
|
remoteGetUrls: string[];
|
|
347
360
|
remoteHead: string | null;
|
|
348
361
|
remoteAdd: void;
|
|
362
|
+
remoteSetHead: void;
|
|
363
|
+
remoteSetBranches: void;
|
|
364
|
+
gc: void;
|
|
349
365
|
raw: CommandResult;
|
|
350
366
|
}
|
|
351
367
|
/** Every request kind, as a union of string literals. */
|
package/dist/backend.js
CHANGED
|
@@ -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':
|
|
@@ -174,6 +176,12 @@ function toVerb(request) {
|
|
|
174
176
|
return v.remoteHead(request.remote);
|
|
175
177
|
case 'remoteAdd':
|
|
176
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);
|
|
177
185
|
case 'raw': {
|
|
178
186
|
const verb = {
|
|
179
187
|
argv: request.argv,
|
package/dist/checkout-root.d.ts
CHANGED
|
@@ -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
|
package/dist/checkout-root.js
CHANGED
|
@@ -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';
|
package/dist/failure.js
CHANGED
|
@@ -8,20 +8,15 @@
|
|
|
8
8
|
* kind, so an unrecognised failure is still an `exit` with git's first stderr
|
|
9
9
|
* line as its message, never a wrong git kind.
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import { classifyFailed, isCommandFailed, } from '@osdlc/command-seam';
|
|
12
12
|
import { describe, FailureError, isFailure } from '@osdlc/result';
|
|
13
13
|
const INSTALL_HINT = 'Install git from https://git-scm.com.';
|
|
14
14
|
/** The git failure for a failed `git` run. */
|
|
15
15
|
export function classifyGitFailure(failed) {
|
|
16
16
|
// The client's runner may not name its binary; this is git either way, so
|
|
17
17
|
// the messages say `git` rather than "The command".
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
: failed.failure;
|
|
21
|
-
const base = { ...f, cause: failed };
|
|
22
|
-
if (f.kind === 'not-installed')
|
|
23
|
-
return { ...base, hint: INSTALL_HINT };
|
|
24
|
-
if (f.kind !== 'exit')
|
|
18
|
+
const base = classifyFailed(failed, { binary: 'git', installHint: INSTALL_HINT });
|
|
19
|
+
if (base.kind !== 'exit')
|
|
25
20
|
return base;
|
|
26
21
|
// git's own words: stderr, then the stdout some commands explain with.
|
|
27
22
|
const text = `${failed.result.stderr}\n${failed.result.stdout}`;
|
|
@@ -45,18 +40,12 @@ export function classifyGitFailure(failed) {
|
|
|
45
40
|
hint: 'List the remotes with `git remote -v`.',
|
|
46
41
|
};
|
|
47
42
|
}
|
|
48
|
-
if (/Authentication failed|Permission denied \(publickey\)|could not read (Username|Password)/i.test(text)) {
|
|
49
|
-
return {
|
|
50
|
-
...base,
|
|
51
|
-
kind: 'not-authenticated',
|
|
52
|
-
message: 'The remote refused the credentials.',
|
|
53
|
-
hint: 'Check that you are signed in to the host, or that your SSH key is added.',
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
43
|
// "unable to access" with a status means the host answered. A refusal or a
|
|
57
44
|
// wrong URL will not clear up by retrying, so it must not read as unreachable.
|
|
58
45
|
const status = /unable to access[^\n]*returned error: (\d{3})/.exec(text)?.[1];
|
|
59
|
-
if (
|
|
46
|
+
if (/Authentication failed|Permission denied \(publickey\)|could not read (Username|Password)/i.test(text) ||
|
|
47
|
+
status === '401' ||
|
|
48
|
+
status === '403') {
|
|
60
49
|
return {
|
|
61
50
|
...base,
|
|
62
51
|
kind: 'not-authenticated',
|
package/dist/git-url.d.ts
CHANGED
|
@@ -18,6 +18,30 @@ export interface GitHostInfo {
|
|
|
18
18
|
export declare function parseGitUrl(ref: string): GitHostInfo | null;
|
|
19
19
|
/** `ref` as a scp-style SSH clone URL (`git@github.com:owner/repo.git`), or null. */
|
|
20
20
|
export declare function gitSshUrl(ref: string): string | null;
|
|
21
|
+
/** The repository a git remote names, and the host it is on. */
|
|
22
|
+
export interface RemoteRepo {
|
|
23
|
+
/** The host, lower-cased and without a port: `github.com`, `git.example.com`. */
|
|
24
|
+
host: string;
|
|
25
|
+
owner: string;
|
|
26
|
+
repo: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* `{host, owner, repo}` from a git remote reference, or null when it names no
|
|
30
|
+
* project (a local path, a single path segment).
|
|
31
|
+
*
|
|
32
|
+
* It reads a known host (GitHub, GitLab, Bitbucket, Sourcehut) with
|
|
33
|
+
* {@link parseGitUrl} first, so `owner/repo` and `github:owner/repo`
|
|
34
|
+
* shorthand read as GitHub and a GitLab nested group stays whole in `owner`
|
|
35
|
+
* (`group/sub`). Any other clone URL, such as a GitHub Enterprise or a
|
|
36
|
+
* self-hosted Forgejo remote, is read host-agnostically by `parseRemoteUrl`:
|
|
37
|
+
* `host/owner/repo`, scp-style or `scheme://`, where `owner` is the second to
|
|
38
|
+
* last path segment.
|
|
39
|
+
*
|
|
40
|
+
* Use it to read a remote into the repository it names. To decide which forge
|
|
41
|
+
* a host is, compare `host`, never the URL text: `notgithub.com` is not
|
|
42
|
+
* GitHub, and neither is a path that mentions `github.com`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseRemoteRepo(url: string): RemoteRepo | null;
|
|
21
45
|
export type CloneProtocol = 'https' | 'ssh';
|
|
22
46
|
/**
|
|
23
47
|
* A hosted repository named by any reference a person might paste: one
|