@osdlc/typed-git 0.14.0 → 0.15.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 +11 -0
- package/README.md +43 -5
- package/dist/async.d.ts +10 -1
- package/dist/async.js +17 -0
- package/dist/backend.d.ts +14 -1
- package/dist/backend.js +6 -0
- package/dist/client.d.ts +1 -1
- package/dist/sync.d.ts +13 -1
- package/dist/sync.js +18 -0
- package/dist/verbs.d.ts +92 -0
- package/dist/verbs.js +202 -10
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @osdlc/typed-git
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 912296d: Add `hashObject`, `mktree` and `updateRef` to `Git`, `AsyncGit` and the backend seam, so a commit can be written and a ref pointed at it without the index or a checkout.
|
|
8
|
+
|
|
9
|
+
- `hashObject(content, { write })` runs `git hash-object [-w] --stdin` and returns the blob sha. `content` goes on stdin as UTF-8, with no `.gitattributes` filters. Binary content is not supported.
|
|
10
|
+
- `mktree(entries)` runs `git mktree -z` and returns the tree sha. Each entry is `{ mode, type?, sha, path }`, and a non-recursive `lsTree` row fits. A mode git does not write, a type that does not match the mode, a sha that is not full, a name that is empty, `.`, `..`, has `/` or NUL, or appears twice, a name git reads as `.git` (any letter case, also after a backslash, and the NTFS and HFS+ spellings such as `git~1`, `.git.` and `.git` with a zero-width character inside), and a `.gitmodules` (or `gitmod~1`) that is not a file throw a `TypeError` before git runs. git does not check a submodule (`160000`) entry's sha.
|
|
11
|
+
- `updateRef(ref, sha, { oldSha, reason })` runs `git update-ref [-m <reason>] <ref> <sha> <oldSha>`: it moves `ref` only while it holds `oldSha`, or with `oldSha: null` only while it does not exist. `oldSha` is required and must be a full sha. `ref` must be `HEAD` or start with `refs/`. A lost race throws.
|
|
12
|
+
- A new example, `examples/orphan-commit.ts`, keeps data on an orphan branch with all four plumbing verbs.
|
|
13
|
+
|
|
3
14
|
## 0.14.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -443,6 +443,39 @@ need to call `lsFilesUnmerged()` after it. And it takes
|
|
|
443
443
|
both sides as arguments rather than merging into the current branch, so
|
|
444
444
|
nothing depends on where `HEAD` happens to be.
|
|
445
445
|
|
|
446
|
+
## Writing a commit without a checkout
|
|
447
|
+
|
|
448
|
+
`hashObject`, `mktree`, `commitTree` and `updateRef` write a commit straight
|
|
449
|
+
into the object store and point a ref at it. The index, the working tree and
|
|
450
|
+
`HEAD` stay as they are, so a tool can keep data on a side branch while
|
|
451
|
+
someone works in the checkout:
|
|
452
|
+
|
|
453
|
+
```ts
|
|
454
|
+
const parent = git.resolveRef("refs/heads/data"); // null: no branch yet
|
|
455
|
+
const blob = git.hashObject(json, { write: true });
|
|
456
|
+
const tree = git.mktree([{ mode: "100644", sha: blob, path: "state.json" }]);
|
|
457
|
+
const commit = git.commitTree(tree, { parents: parent ? [parent] : [], message: "Save" });
|
|
458
|
+
git.updateRef("refs/heads/data", commit, { oldSha: parent });
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
`oldSha` is required. git moves the ref only while it still holds `oldSha`,
|
|
462
|
+
or, for `null`, only while it does not exist, so two writers cannot both
|
|
463
|
+
win. The one that loses gets a thrown failure (exit 128, `is at … but
|
|
464
|
+
expected …` or `reference already exists` in `detail`) and can re-read the
|
|
465
|
+
ref and try again. `mktree` takes one directory level: a subdirectory is an
|
|
466
|
+
entry with mode `040000` and the sha of a tree written before it.
|
|
467
|
+
|
|
468
|
+
Before git runs, `mktree` throws a `TypeError` for a name that git's fsck
|
|
469
|
+
reports, so a tool that builds names from data keys cannot write a tree a
|
|
470
|
+
host's push check rejects. That covers `.git` and the spellings NTFS and
|
|
471
|
+
HFS+ read as `.git`, such as `git~1`, `.git.` and `.git` with a zero-width
|
|
472
|
+
character inside, and a `.gitmodules` (or `gitmod~1`) that is not a file.
|
|
473
|
+
Each sha must name an object already in the store, except a submodule
|
|
474
|
+
(`160000`) commit: it lives in another repository, and git does not check
|
|
475
|
+
it. The
|
|
476
|
+
[orphan-commit example](https://github.com/osdlc/osdlc/tree/main/packages/ts/typed-git/examples/orphan-commit.ts)
|
|
477
|
+
runs the whole sequence.
|
|
478
|
+
|
|
446
479
|
## Pushing: a rejected ref is a value
|
|
447
480
|
|
|
448
481
|
`push` runs `git push --porcelain` and returns one result per ref, so a
|
|
@@ -710,6 +743,8 @@ exit throws the classified failure.
|
|
|
710
743
|
| `aheadBehind(base, tip)` | `rev-list --left-right --count <base>...<tip>` | none |
|
|
711
744
|
| `cherry(upstream, head)` | `cherry <upstream> [<head>]` | none — `{ sha, equivalent }` per commit; empty output is `[]`, an unreadable line throws |
|
|
712
745
|
| `commitTree(tree, { parents, message })` | `commit-tree <tree> [-p <parent>]... -m <message>` | none — writes an object and no ref; needs a git identity |
|
|
746
|
+
| `hashObject(content, { write })` | `hash-object [-w] --stdin` | none — the blob sha; `write` stores the blob; `content` goes on stdin as UTF-8, unfiltered |
|
|
747
|
+
| `mktree(entries)` | `mktree -z` | none — writes a tree object and no ref; each entry is `{ mode, type?, sha, path }`, one name per entry; a duplicate name, a mode git does not write, a name git reads as `.git` (including `git~1`, `.git.` and the HFS+ spellings), or a `.gitmodules` that is not a file, each of which `git fsck --strict` reports, throws a `TypeError` |
|
|
713
748
|
| `remotes()` | `remote` | none — names, not remotes |
|
|
714
749
|
| `remote()` | `remote` | none — deprecated alias of `remotes()` |
|
|
715
750
|
| `remoteGetUrl(name, { push })` | `remote get-url [--push] <name>` | `2` → `null` (unknown remote) — the first URL |
|
|
@@ -742,6 +777,7 @@ Integration, declares exit 1 absent and returns the rejected refs.
|
|
|
742
777
|
| `clean({ directories })` | `clean -f`, or `-fd` — ignored files are kept |
|
|
743
778
|
| `deleteBranch(name, { force })` | `branch -d` / `-D` |
|
|
744
779
|
| `deleteRef(ref, { expected })` | `update-ref -d <ref> <expected>` — refuses when `ref` has moved |
|
|
780
|
+
| `updateRef(ref, sha, { oldSha, reason })` | `update-ref [-m <reason>] <ref> <sha> <oldSha>` — refuses when `ref` is not at `oldSha`; `oldSha: null` refuses when `ref` exists. `ref` is `HEAD` or a full `refs/…` name, and `oldSha` a full sha; anything else throws a `TypeError` |
|
|
745
781
|
| `worktreeAdd(path, { branch, resetBranch, startPoint, detach })` | `worktree add` — `branch` is `-b`; `resetBranch` picks `-B` (create, or reset an existing branch), as for `checkout` |
|
|
746
782
|
| `worktreeRemove(path, { force })` | `worktree remove` |
|
|
747
783
|
| `worktreeMove(from, to, { force })` | `worktree move` |
|
|
@@ -779,9 +815,10 @@ other non-zero exit throws.
|
|
|
779
815
|
| `try.*` | The whole surface again, returning `Result<T, GitFailure>` (from `@osdlc/result`) instead of throwing. |
|
|
780
816
|
| `soft.*` | Every verb with an absence value, returning it instead of throwing. |
|
|
781
817
|
|
|
782
|
-
Use `raw` for a one-off command, such as `
|
|
783
|
-
from `diff --unified`. A git
|
|
784
|
-
parser worth sharing or an
|
|
818
|
+
Use `raw` for a one-off command, such as `tag -a`, `update-ref --stdin` for
|
|
819
|
+
several refs in one transaction, or a patch from `diff --unified`. A git
|
|
820
|
+
command gets its own verb only when it has a parser worth sharing or an
|
|
821
|
+
absence worth declaring.
|
|
785
822
|
|
|
786
823
|
## Driving the CLI, or something else
|
|
787
824
|
|
|
@@ -1021,8 +1058,9 @@ de-duplicate.
|
|
|
1021
1058
|
cap or a timeout is a failure, never an answer.
|
|
1022
1059
|
- stdout is text. There is no verb or call option that returns raw bytes,
|
|
1023
1060
|
such as a binary blob. Use command-seam's `spawnRunnerBytes` for that.
|
|
1024
|
-
`raw` and `
|
|
1025
|
-
|
|
1061
|
+
`raw`, `rawChecked` and `hashObject` take their input as a string, so
|
|
1062
|
+
binary stdin, such as a binary file for `hash-object --stdin`, needs that
|
|
1063
|
+
runner too.
|
|
1026
1064
|
- Output is captured, never streamed. For live progress from `clone` or
|
|
1027
1065
|
`fetch`, run git through command-seam's `streamRunner`.
|
|
1028
1066
|
- `Git` cannot cancel a call. `AsyncGit` takes a `signal`.
|
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 IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
20
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
21
21
|
/** A typed, awaitable git client bound to one working directory. */
|
|
22
22
|
export declare class AsyncGit {
|
|
23
23
|
readonly cwd: string;
|
|
@@ -233,6 +233,10 @@ export declare class AsyncGit {
|
|
|
233
233
|
cherry(upstream: string, head?: string, opts?: GitCallOptions): Promise<CherryEntry[]>;
|
|
234
234
|
/** Write a commit for `tree` and return its sha; no ref moves. Needs a git identity. */
|
|
235
235
|
commitTree(tree: string, commitOpts: CommitTreeOptions, opts?: GitCallOptions): Promise<string>;
|
|
236
|
+
/** The blob sha of `content`; `{ write: true }` also writes the blob. See {@link Git.hashObject}. */
|
|
237
|
+
hashObject(content: string, opts?: GitCallOptions & HashObjectOptions): Promise<string>;
|
|
238
|
+
/** Write a tree of `entries` and return its sha; no ref moves. See {@link Git.mktree}. */
|
|
239
|
+
mktree(entries: readonly MktreeEntry[], opts?: GitCallOptions): Promise<string>;
|
|
236
240
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
237
241
|
remotes(opts?: GitCallOptions): Promise<string[]>;
|
|
238
242
|
/**
|
|
@@ -295,6 +299,11 @@ export declare class AsyncGit {
|
|
|
295
299
|
deleteRef(ref: string, opts: GitCallOptions & {
|
|
296
300
|
expected: string;
|
|
297
301
|
}): Promise<void>;
|
|
302
|
+
/**
|
|
303
|
+
* Point `ref` at `sha` only while it holds `oldSha` (`null`: only while it
|
|
304
|
+
* does not exist). See {@link Git.updateRef}.
|
|
305
|
+
*/
|
|
306
|
+
updateRef(ref: string, sha: string, opts: GitCallOptions & UpdateRefOptions): Promise<void>;
|
|
298
307
|
/** `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`. See {@link Git.worktreeAdd}. */
|
|
299
308
|
worktreeAdd(path: string, opts?: GitCallOptions & WorktreeAddOptions): Promise<void>;
|
|
300
309
|
/** `git worktree remove [--force] <path>`. */
|
package/dist/async.js
CHANGED
|
@@ -388,6 +388,15 @@ export class AsyncGit {
|
|
|
388
388
|
commitTree(tree, commitOpts, opts = {}) {
|
|
389
389
|
return this.backend.execute(this.cwd, { kind: 'commitTree', tree, ...commitOpts }, opts);
|
|
390
390
|
}
|
|
391
|
+
/** The blob sha of `content`; `{ write: true }` also writes the blob. See {@link Git.hashObject}. */
|
|
392
|
+
hashObject(content, opts = {}) {
|
|
393
|
+
const [call, req] = splitCallOptions(opts);
|
|
394
|
+
return this.backend.execute(this.cwd, { kind: 'hashObject', content, ...req }, call);
|
|
395
|
+
}
|
|
396
|
+
/** Write a tree of `entries` and return its sha; no ref moves. See {@link Git.mktree}. */
|
|
397
|
+
mktree(entries, opts = {}) {
|
|
398
|
+
return this.backend.execute(this.cwd, { kind: 'mktree', entries }, opts);
|
|
399
|
+
}
|
|
391
400
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
392
401
|
remotes(opts = {}) {
|
|
393
402
|
return this.backend.execute(this.cwd, { kind: 'remote' }, opts);
|
|
@@ -494,6 +503,14 @@ export class AsyncGit {
|
|
|
494
503
|
deleteRef(ref, opts) {
|
|
495
504
|
return this.backend.execute(this.cwd, { kind: 'deleteRef', ref, expected: opts.expected }, opts);
|
|
496
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Point `ref` at `sha` only while it holds `oldSha` (`null`: only while it
|
|
508
|
+
* does not exist). See {@link Git.updateRef}.
|
|
509
|
+
*/
|
|
510
|
+
updateRef(ref, sha, opts) {
|
|
511
|
+
const [call, req] = splitCallOptions(opts);
|
|
512
|
+
return this.backend.execute(this.cwd, { kind: 'updateRef', ref, sha, ...req }, call);
|
|
513
|
+
}
|
|
497
514
|
/** `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`. See {@link Git.worktreeAdd}. */
|
|
498
515
|
worktreeAdd(path, opts = {}) {
|
|
499
516
|
const [call, req] = splitCallOptions(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 PushReport, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type WorktreeAddOptions, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type Worktree, type WorktreeMoveOptions } from './verbs.ts';
|
|
22
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type CloneOptions, type CommitOptions, type ConfigGetOptions, type ConfigSetOptions, type ConflictSide, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GcOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type NumstatEntry, type PushOptions, type PushReport, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type WorktreeAddOptions, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type Worktree, type WorktreeMoveOptions } from './verbs.ts';
|
|
23
23
|
/** Per-call concerns that are not part of the operation itself. */
|
|
24
24
|
export interface GitCallOptions {
|
|
25
25
|
/**
|
|
@@ -140,6 +140,12 @@ export type GitRequest = {
|
|
|
140
140
|
kind: 'commitTree';
|
|
141
141
|
tree: string;
|
|
142
142
|
} & CommitTreeOptions) | ({
|
|
143
|
+
kind: 'hashObject';
|
|
144
|
+
content: string;
|
|
145
|
+
} & HashObjectOptions) | {
|
|
146
|
+
kind: 'mktree';
|
|
147
|
+
entries: readonly MktreeEntry[];
|
|
148
|
+
} | ({
|
|
143
149
|
kind: 'lsFiles';
|
|
144
150
|
} & LsFilesOptions) | {
|
|
145
151
|
kind: 'lsFilesTagged';
|
|
@@ -219,6 +225,10 @@ export type GitRequest = {
|
|
|
219
225
|
ref: string;
|
|
220
226
|
expected: string;
|
|
221
227
|
} | ({
|
|
228
|
+
kind: 'updateRef';
|
|
229
|
+
ref: string;
|
|
230
|
+
sha: string;
|
|
231
|
+
} & UpdateRefOptions) | ({
|
|
222
232
|
kind: 'worktreeAdd';
|
|
223
233
|
path: string;
|
|
224
234
|
} & WorktreeAddOptions) | {
|
|
@@ -323,6 +333,8 @@ export interface GitResults {
|
|
|
323
333
|
aheadBehind: AheadBehind;
|
|
324
334
|
cherry: CherryEntry[];
|
|
325
335
|
commitTree: string;
|
|
336
|
+
hashObject: string;
|
|
337
|
+
mktree: string;
|
|
326
338
|
lsFiles: string[];
|
|
327
339
|
lsFilesTagged: TaggedFile[];
|
|
328
340
|
submodules: IndexSubmodule[];
|
|
@@ -351,6 +363,7 @@ export interface GitResults {
|
|
|
351
363
|
clean: void;
|
|
352
364
|
deleteBranch: void;
|
|
353
365
|
deleteRef: void;
|
|
366
|
+
updateRef: void;
|
|
354
367
|
worktreeAdd: void;
|
|
355
368
|
worktreeRemove: void;
|
|
356
369
|
worktreeMove: void;
|
package/dist/backend.js
CHANGED
|
@@ -86,6 +86,10 @@ function toVerb(request) {
|
|
|
86
86
|
return v.cherry(request.upstream, request.head);
|
|
87
87
|
case 'commitTree':
|
|
88
88
|
return v.commitTree(request.tree, request);
|
|
89
|
+
case 'hashObject':
|
|
90
|
+
return v.hashObject(request.content, request);
|
|
91
|
+
case 'mktree':
|
|
92
|
+
return v.mktree(request.entries);
|
|
89
93
|
case 'checkIgnore':
|
|
90
94
|
return v.checkIgnore(request.relPaths);
|
|
91
95
|
case 'checkIgnoreVerbose':
|
|
@@ -146,6 +150,8 @@ function toVerb(request) {
|
|
|
146
150
|
return v.deleteBranch(request.name, { force: request.force });
|
|
147
151
|
case 'deleteRef':
|
|
148
152
|
return v.deleteRef(request.ref, { expected: request.expected });
|
|
153
|
+
case 'updateRef':
|
|
154
|
+
return v.updateRef(request.ref, request.sha, request);
|
|
149
155
|
case 'worktreeAdd':
|
|
150
156
|
return v.worktreeAdd(request.path, request);
|
|
151
157
|
case 'worktreeRemove':
|
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, PUSH_REJECTIONS, REF_FORMAT, type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CheckoutOptions, type CleanOptions, type CloneOptions, type CommitFlags, type CommitOptions, type ConfigGetOptions, type ConfigScope, type ConfigSetOptions, type ConflictSide, type DiffCheckOptions, type DiffCheckResult, type DiffEntry, type DiffNameOnlyOptions, type DiffNameStatusOptions, type DiffStatOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type ForceLease, type GcOptions, type GrepOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type NumstatEntry, type PushFlag, type PushOptions, type PushRefResult, type PushRejection, type PushRejectionInfo, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type StatusEntry, type StatusPorcelainOptions, type IndexSubmodule, type TaggedFile, type TreeEntry, type UnmergedEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
|
|
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 HashObjectOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type MktreeEntry, type NumstatEntry, type PushFlag, type PushOptions, type PushRefResult, type PushRejection, type PushRejectionInfo, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type StatusEntry, type StatusPorcelainOptions, type IndexSubmodule, type TaggedFile, type TreeEntry, type UnmergedEntry, type UpdateRefOptions, 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/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 IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
22
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
23
23
|
/**
|
|
24
24
|
* Per-call concerns that are not part of the operation itself.
|
|
25
25
|
*
|
|
@@ -350,6 +350,13 @@ export declare class Git {
|
|
|
350
350
|
cherry(upstream: string, head?: string, opts?: GitSyncCallOptions): CherryEntry[];
|
|
351
351
|
/** Write a commit for `tree` and return its sha; no ref moves. Needs a git identity. */
|
|
352
352
|
commitTree(tree: string, commitOpts: CommitTreeOptions, opts?: GitSyncCallOptions): string;
|
|
353
|
+
/**
|
|
354
|
+
* The blob sha of `content`; `{ write: true }` also writes the blob. See
|
|
355
|
+
* `hashObject` in `verbs.ts`.
|
|
356
|
+
*/
|
|
357
|
+
hashObject(content: string, opts?: GitSyncCallOptions & HashObjectOptions): string;
|
|
358
|
+
/** Write a tree of `entries` and return its sha; no ref moves. See `mktree` in `verbs.ts`. */
|
|
359
|
+
mktree(entries: readonly MktreeEntry[], opts?: GitSyncCallOptions): string;
|
|
353
360
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
354
361
|
remotes(opts?: GitSyncCallOptions): string[];
|
|
355
362
|
/**
|
|
@@ -428,6 +435,11 @@ export declare class Git {
|
|
|
428
435
|
deleteRef(ref: string, opts: GitSyncCallOptions & {
|
|
429
436
|
expected: string;
|
|
430
437
|
}): void;
|
|
438
|
+
/**
|
|
439
|
+
* Point `ref` at `sha` only while it holds `oldSha` (`null`: only while it
|
|
440
|
+
* does not exist). See `updateRef` in `verbs.ts`.
|
|
441
|
+
*/
|
|
442
|
+
updateRef(ref: string, sha: string, opts: GitSyncCallOptions & UpdateRefOptions): void;
|
|
431
443
|
/**
|
|
432
444
|
* `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`.
|
|
433
445
|
* `resetBranch` picks `-B`: create `branch`, or reset it if it exists.
|
package/dist/sync.js
CHANGED
|
@@ -513,6 +513,17 @@ export class Git {
|
|
|
513
513
|
commitTree(tree, commitOpts, opts = {}) {
|
|
514
514
|
return this.exec(v.commitTree(tree, commitOpts), opts);
|
|
515
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* The blob sha of `content`; `{ write: true }` also writes the blob. See
|
|
518
|
+
* `hashObject` in `verbs.ts`.
|
|
519
|
+
*/
|
|
520
|
+
hashObject(content, opts = {}) {
|
|
521
|
+
return this.exec(v.hashObject(content, opts), opts);
|
|
522
|
+
}
|
|
523
|
+
/** Write a tree of `entries` and return its sha; no ref moves. See `mktree` in `verbs.ts`. */
|
|
524
|
+
mktree(entries, opts = {}) {
|
|
525
|
+
return this.exec(v.mktree(entries), opts);
|
|
526
|
+
}
|
|
516
527
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
517
528
|
remotes(opts = {}) {
|
|
518
529
|
return this.exec(v.remote(), opts);
|
|
@@ -625,6 +636,13 @@ export class Git {
|
|
|
625
636
|
deleteRef(ref, opts) {
|
|
626
637
|
this.exec(v.deleteRef(ref, opts), opts);
|
|
627
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* Point `ref` at `sha` only while it holds `oldSha` (`null`: only while it
|
|
641
|
+
* does not exist). See `updateRef` in `verbs.ts`.
|
|
642
|
+
*/
|
|
643
|
+
updateRef(ref, sha, opts) {
|
|
644
|
+
this.exec(v.updateRef(ref, sha, opts), opts);
|
|
645
|
+
}
|
|
628
646
|
/**
|
|
629
647
|
* `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`.
|
|
630
648
|
* `resetBranch` picks `-B`: create `branch`, or reset it if it exists.
|
package/dist/verbs.d.ts
CHANGED
|
@@ -850,6 +850,68 @@ export interface CommitTreeOptions {
|
|
|
850
850
|
* this throws. `absent: []`, and a reply that is not a sha throws.
|
|
851
851
|
*/
|
|
852
852
|
export declare function commitTree(tree: string, opts: CommitTreeOptions): GitVerb<string>;
|
|
853
|
+
/** Options for {@link hashObject}. */
|
|
854
|
+
export interface HashObjectOptions {
|
|
855
|
+
/**
|
|
856
|
+
* `-w`: also write the blob into the object store; without it only the sha is computed.
|
|
857
|
+
*/
|
|
858
|
+
write?: boolean | undefined;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* The blob sha of `content`, and with `{ write: true }` the blob itself
|
|
862
|
+
* written to the object store (`git hash-object [-w] --stdin`).
|
|
863
|
+
*
|
|
864
|
+
* `content` goes to git on stdin as UTF-8, so the blob holds exactly those
|
|
865
|
+
* bytes: input from stdin skips the clean filters and line-ending
|
|
866
|
+
* conversion that `.gitattributes` would apply to a file. A string cannot
|
|
867
|
+
* carry arbitrary bytes, so binary content is not supported.
|
|
868
|
+
*
|
|
869
|
+
* `absent: []`, and a reply that is not a sha throws.
|
|
870
|
+
*/
|
|
871
|
+
export declare function hashObject(content: string, opts?: HashObjectOptions): GitVerb<string>;
|
|
872
|
+
/**
|
|
873
|
+
* One entry of a tree written by {@link mktree}: a name in that tree, not a
|
|
874
|
+
* path through it. A row of {@link lsTree} without `recursive` has this shape,
|
|
875
|
+
* so `mktree(lsTree(rev))` writes the same tree back.
|
|
876
|
+
*/
|
|
877
|
+
export interface MktreeEntry {
|
|
878
|
+
/**
|
|
879
|
+
* `100644` (file), `100755` (executable), `120000` (symlink), `040000`
|
|
880
|
+
* (tree) or `160000` (submodule commit). Any other mode throws.
|
|
881
|
+
*/
|
|
882
|
+
mode: string;
|
|
883
|
+
/**
|
|
884
|
+
* The object type. Each mode has one, so it may be left out; when given,
|
|
885
|
+
* it must be the mode's type.
|
|
886
|
+
*/
|
|
887
|
+
type?: 'blob' | 'tree' | 'commit' | undefined;
|
|
888
|
+
/** The full sha of an object already in the store. */
|
|
889
|
+
sha: string;
|
|
890
|
+
/**
|
|
891
|
+
* The entry's name: no `/`, no NUL, not empty, `.`, `..`, or a name git
|
|
892
|
+
* reads as `.git` (see {@link mktree}).
|
|
893
|
+
*/
|
|
894
|
+
path: string;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Write a tree object holding `entries` and return its sha (`git mktree -z`).
|
|
898
|
+
* No entries writes the empty tree.
|
|
899
|
+
*
|
|
900
|
+
* The entries go to git on stdin, NUL-terminated, so a name may hold spaces,
|
|
901
|
+
* tabs or newlines; git sorts them into tree order itself.
|
|
902
|
+
*
|
|
903
|
+
* Throws a `TypeError` before git runs for a duplicate, empty, `.`, `..`,
|
|
904
|
+
* `/`- or NUL-bearing name, a name git reads as `.git`, a `.gitmodules` that
|
|
905
|
+
* is not a file, an unknown mode, a sha that is not a full sha, and a type
|
|
906
|
+
* that does not match the mode. `git mktree` writes most of these, but
|
|
907
|
+
* `git fsck --strict` reports them. D-03 lists the NTFS and HFS+ spellings.
|
|
908
|
+
*
|
|
909
|
+
* Every sha must name an object already in the store, of the entry's type,
|
|
910
|
+
* except a submodule (`160000`) commit, which git does not check; otherwise
|
|
911
|
+
* git exits 128 and this throws. `absent: []`, and a reply that is not a
|
|
912
|
+
* sha throws.
|
|
913
|
+
*/
|
|
914
|
+
export declare function mktree(entries: readonly MktreeEntry[]): GitVerb<string>;
|
|
853
915
|
/**
|
|
854
916
|
* How far `tip` has diverged from `base`
|
|
855
917
|
* (`git rev-list --left-right --count base...tip`).
|
|
@@ -1257,6 +1319,36 @@ export declare function deleteBranch(name: string, opts?: {
|
|
|
1257
1319
|
export declare function deleteRef(ref: string, opts: {
|
|
1258
1320
|
expected: string;
|
|
1259
1321
|
}): GitVerb<void>;
|
|
1322
|
+
/** Options for {@link updateRef}. */
|
|
1323
|
+
export interface UpdateRefOptions {
|
|
1324
|
+
/**
|
|
1325
|
+
* The sha `ref` must hold now, or `null` when `ref` must not exist yet.
|
|
1326
|
+
* Required: git checks it and moves the ref in one step, so a commit
|
|
1327
|
+
* another writer put on the ref after the caller looked is never lost.
|
|
1328
|
+
* It must be a full sha: a ref name here would resolve at the moment of
|
|
1329
|
+
* the check and always match.
|
|
1330
|
+
*/
|
|
1331
|
+
oldSha: string | null;
|
|
1332
|
+
/** `-m <reason>` — the message the reflog records for this update. */
|
|
1333
|
+
reason?: string | undefined;
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* `git update-ref [-m <reason>] <ref> <sha> <oldSha>`: point `ref` at `sha`,
|
|
1337
|
+
* only while `ref` still holds `oldSha` (`null`: only while it does not
|
|
1338
|
+
* exist). It writes no object and leaves the index and working tree alone.
|
|
1339
|
+
*
|
|
1340
|
+
* `ref` must be `HEAD` or a full name under `refs/`. git does not expand a
|
|
1341
|
+
* short name here: `update-ref main` would write a new top-level ref named
|
|
1342
|
+
* `main` beside `refs/heads/main`, so a name that is neither throws a
|
|
1343
|
+
* `TypeError` before git runs. `HEAD` on a branch moves that branch.
|
|
1344
|
+
*
|
|
1345
|
+
* When `ref` is not where `oldSha` says, git exits 128 and this throws,
|
|
1346
|
+
* like any other failure: `reference already exists`, `is at <sha> but
|
|
1347
|
+
* expected <oldSha>`, or `unable to resolve reference`. Re-read the ref with
|
|
1348
|
+
* `resolveRef` to decide whether to retry. git also refuses a `sha` that
|
|
1349
|
+
* names no object, a non-commit on a branch, and a malformed ref name.
|
|
1350
|
+
*/
|
|
1351
|
+
export declare function updateRef(ref: string, sha: string, opts: UpdateRefOptions): GitVerb<void>;
|
|
1260
1352
|
/** Options for {@link worktreeAdd}. */
|
|
1261
1353
|
export interface WorktreeAddOptions {
|
|
1262
1354
|
/** `-b <branch>` — create this branch at `startPoint`; git refuses if it exists. */
|
package/dist/verbs.js
CHANGED
|
@@ -1167,16 +1167,166 @@ export function commitTree(tree, opts) {
|
|
|
1167
1167
|
argv.push('-p', positional('commitTree', 'parent', parent));
|
|
1168
1168
|
}
|
|
1169
1169
|
argv.push('-m', opts.message);
|
|
1170
|
-
return {
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1170
|
+
return { argv, absent: NONE, parse: shaReply };
|
|
1171
|
+
}
|
|
1172
|
+
/** A full object id in either hash format: 40 hex digits (SHA-1) or 64 (SHA-256). */
|
|
1173
|
+
const FULL_SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
1174
|
+
/** The one sha a plumbing verb prints. Anything else throws rather than reading as an id. */
|
|
1175
|
+
function shaReply(r, ranArgv) {
|
|
1176
|
+
const sha = r.stdout.trim();
|
|
1177
|
+
if (!FULL_SHA.test(sha))
|
|
1178
|
+
throw new CommandFailed(ranArgv, r);
|
|
1179
|
+
return sha;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* The blob sha of `content`, and with `{ write: true }` the blob itself
|
|
1183
|
+
* written to the object store (`git hash-object [-w] --stdin`).
|
|
1184
|
+
*
|
|
1185
|
+
* `content` goes to git on stdin as UTF-8, so the blob holds exactly those
|
|
1186
|
+
* bytes: input from stdin skips the clean filters and line-ending
|
|
1187
|
+
* conversion that `.gitattributes` would apply to a file. A string cannot
|
|
1188
|
+
* carry arbitrary bytes, so binary content is not supported.
|
|
1189
|
+
*
|
|
1190
|
+
* `absent: []`, and a reply that is not a sha throws.
|
|
1191
|
+
*/
|
|
1192
|
+
export function hashObject(content, opts = {}) {
|
|
1193
|
+
const argv = ['hash-object'];
|
|
1194
|
+
if (opts.write)
|
|
1195
|
+
argv.push('-w');
|
|
1196
|
+
argv.push('--stdin');
|
|
1197
|
+
return { argv, input: content, absent: NONE, parse: shaReply };
|
|
1198
|
+
}
|
|
1199
|
+
/** The object type each tree mode git writes stands for. */
|
|
1200
|
+
const TREE_MODE_TYPES = {
|
|
1201
|
+
'100644': 'blob',
|
|
1202
|
+
'100755': 'blob',
|
|
1203
|
+
'120000': 'blob',
|
|
1204
|
+
'040000': 'tree',
|
|
1205
|
+
'160000': 'commit',
|
|
1206
|
+
};
|
|
1207
|
+
/** Code points HFS+ ignores in a name (git's `next_hfs_char`). */
|
|
1208
|
+
const HFS_IGNORED = /[\u200C-\u200F\u202A-\u202E\u206A-\u206F\uFEFF]/gu;
|
|
1209
|
+
/** Lower-case the ASCII letters only, as git does against its ASCII needles. */
|
|
1210
|
+
const asciiLower = (s) => s.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
1211
|
+
/**
|
|
1212
|
+
* HFS+ reads `name` as `.<needle>` (git's `is_hfs_dot_generic`): equal to it
|
|
1213
|
+
* in ASCII letter case once the ignorable code points are dropped.
|
|
1214
|
+
*/
|
|
1215
|
+
function hfsReadsAs(name, needle) {
|
|
1216
|
+
return asciiLower(name.replace(HFS_IGNORED, '')) === `.${needle}`;
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* NTFS drops trailing dots and spaces, and a `:` starts an alternate data
|
|
1220
|
+
* stream. True when `rest` holds only dots and spaces before its end or a `:`.
|
|
1221
|
+
*/
|
|
1222
|
+
function ntfsTailIsEmpty(rest) {
|
|
1223
|
+
return /^[. ]*(?:$|:)/.test(rest);
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* A name git's fsck reports as `hasDotgit` (git's `is_hfs_dotgit` and
|
|
1227
|
+
* `is_ntfs_dotgit`, which checks each part between backslashes), and checkout refuses on every platform.
|
|
1228
|
+
*/
|
|
1229
|
+
function readsAsDotGit(name) {
|
|
1230
|
+
if (hfsReadsAs(name, 'git'))
|
|
1231
|
+
return true;
|
|
1232
|
+
for (const part of name.split('\\')) {
|
|
1233
|
+
const lower = asciiLower(part);
|
|
1234
|
+
if (lower.startsWith('.git') && ntfsTailIsEmpty(part.slice(4)))
|
|
1235
|
+
return true;
|
|
1236
|
+
if (lower.startsWith('git~1') && ntfsTailIsEmpty(part.slice(5)))
|
|
1237
|
+
return true;
|
|
1238
|
+
if (part.includes(':'))
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* A name git's fsck treats as `.gitmodules` (git's `is_hfs_dotgitmodules`
|
|
1245
|
+
* and `is_ntfs_dotgitmodules`): the HFS+ and NTFS spellings, the short names
|
|
1246
|
+
* `gitmod~1` to `~4`, and the 8.3 fallback short name, whose prefix
|
|
1247
|
+
* `gi7eba` git took from a hash of the long name.
|
|
1248
|
+
*/
|
|
1249
|
+
function readsAsDotGitmodules(name) {
|
|
1250
|
+
if (hfsReadsAs(name, 'gitmodules'))
|
|
1251
|
+
return true;
|
|
1252
|
+
const lower = asciiLower(name);
|
|
1253
|
+
if (lower.startsWith('.gitmodules'))
|
|
1254
|
+
return ntfsTailIsEmpty(name.slice(11));
|
|
1255
|
+
if (/^gitmod~[1-4]/.test(lower))
|
|
1256
|
+
return ntfsTailIsEmpty(name.slice(8));
|
|
1257
|
+
// The fallback: a leading part of `gi7eba` (at most six characters), `~`,
|
|
1258
|
+
// a digit 1-9, then digits up to eight characters. This follows git's loop
|
|
1259
|
+
// step for step, so a `~` at index 7 reads one character past eight.
|
|
1260
|
+
const prefix = 'gi7eba';
|
|
1261
|
+
let sawTilde = false;
|
|
1262
|
+
let i = 0;
|
|
1263
|
+
for (; i < 8; i++) {
|
|
1264
|
+
const c = lower[i];
|
|
1265
|
+
if (c === undefined)
|
|
1266
|
+
return false;
|
|
1267
|
+
if (sawTilde) {
|
|
1268
|
+
if (c < '0' || c > '9')
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1271
|
+
else if (c === '~') {
|
|
1272
|
+
i++;
|
|
1273
|
+
const d = lower[i];
|
|
1274
|
+
if (d === undefined || d < '1' || d > '9')
|
|
1275
|
+
return false;
|
|
1276
|
+
sawTilde = true;
|
|
1277
|
+
}
|
|
1278
|
+
else if (i >= 6 || c !== prefix[i]) {
|
|
1279
|
+
return false;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
return ntfsTailIsEmpty(name.slice(i));
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Write a tree object holding `entries` and return its sha (`git mktree -z`).
|
|
1286
|
+
* No entries writes the empty tree.
|
|
1287
|
+
*
|
|
1288
|
+
* The entries go to git on stdin, NUL-terminated, so a name may hold spaces,
|
|
1289
|
+
* tabs or newlines; git sorts them into tree order itself.
|
|
1290
|
+
*
|
|
1291
|
+
* Throws a `TypeError` before git runs for a duplicate, empty, `.`, `..`,
|
|
1292
|
+
* `/`- or NUL-bearing name, a name git reads as `.git`, a `.gitmodules` that
|
|
1293
|
+
* is not a file, an unknown mode, a sha that is not a full sha, and a type
|
|
1294
|
+
* that does not match the mode. `git mktree` writes most of these, but
|
|
1295
|
+
* `git fsck --strict` reports them. D-03 lists the NTFS and HFS+ spellings.
|
|
1296
|
+
*
|
|
1297
|
+
* Every sha must name an object already in the store, of the entry's type,
|
|
1298
|
+
* except a submodule (`160000`) commit, which git does not check; otherwise
|
|
1299
|
+
* git exits 128 and this throws. `absent: []`, and a reply that is not a
|
|
1300
|
+
* sha throws.
|
|
1301
|
+
*/
|
|
1302
|
+
export function mktree(entries) {
|
|
1303
|
+
const names = new Set();
|
|
1304
|
+
const records = [];
|
|
1305
|
+
for (const { mode, type: given, sha, path } of entries) {
|
|
1306
|
+
const bad = (why) => new TypeError(`typed-git: mktree: entry ${JSON.stringify(path)} ${why}`);
|
|
1307
|
+
const type = TREE_MODE_TYPES[mode];
|
|
1308
|
+
if (type === undefined)
|
|
1309
|
+
throw bad(`has mode ${JSON.stringify(mode)}, which git does not write`);
|
|
1310
|
+
if (given !== undefined && given !== type) {
|
|
1311
|
+
throw bad(`has type ${JSON.stringify(given)}, but mode ${mode} is a ${type}`);
|
|
1312
|
+
}
|
|
1313
|
+
if (!FULL_SHA.test(sha))
|
|
1314
|
+
throw bad(`needs a full sha (got ${JSON.stringify(sha)})`);
|
|
1315
|
+
if (path === '' || path === '.' || path === '..' || readsAsDotGit(path)) {
|
|
1316
|
+
throw bad('is not a name git allows in a tree');
|
|
1317
|
+
}
|
|
1318
|
+
if (path.includes('/') || path.includes('\x00')) {
|
|
1319
|
+
throw bad('must be one name, without "/" or NUL');
|
|
1320
|
+
}
|
|
1321
|
+
if (mode !== '100644' && mode !== '100755' && readsAsDotGitmodules(path)) {
|
|
1322
|
+
throw bad(`is read by git as .gitmodules, which must be a file (got mode ${mode})`);
|
|
1323
|
+
}
|
|
1324
|
+
if (names.has(path))
|
|
1325
|
+
throw bad('appears twice');
|
|
1326
|
+
names.add(path);
|
|
1327
|
+
records.push(`${mode} ${type} ${sha}\t${path}\x00`);
|
|
1328
|
+
}
|
|
1329
|
+
return { argv: ['mktree', '-z'], input: records.join(''), absent: NONE, parse: shaReply };
|
|
1180
1330
|
}
|
|
1181
1331
|
/**
|
|
1182
1332
|
* How far `tip` has diverged from `base`
|
|
@@ -1696,6 +1846,48 @@ export function deleteRef(ref, opts) {
|
|
|
1696
1846
|
parse: nothing,
|
|
1697
1847
|
};
|
|
1698
1848
|
}
|
|
1849
|
+
/**
|
|
1850
|
+
* `git update-ref [-m <reason>] <ref> <sha> <oldSha>`: point `ref` at `sha`,
|
|
1851
|
+
* only while `ref` still holds `oldSha` (`null`: only while it does not
|
|
1852
|
+
* exist). It writes no object and leaves the index and working tree alone.
|
|
1853
|
+
*
|
|
1854
|
+
* `ref` must be `HEAD` or a full name under `refs/`. git does not expand a
|
|
1855
|
+
* short name here: `update-ref main` would write a new top-level ref named
|
|
1856
|
+
* `main` beside `refs/heads/main`, so a name that is neither throws a
|
|
1857
|
+
* `TypeError` before git runs. `HEAD` on a branch moves that branch.
|
|
1858
|
+
*
|
|
1859
|
+
* When `ref` is not where `oldSha` says, git exits 128 and this throws,
|
|
1860
|
+
* like any other failure: `reference already exists`, `is at <sha> but
|
|
1861
|
+
* expected <oldSha>`, or `unable to resolve reference`. Re-read the ref with
|
|
1862
|
+
* `resolveRef` to decide whether to retry. git also refuses a `sha` that
|
|
1863
|
+
* names no object, a non-commit on a branch, and a malformed ref name.
|
|
1864
|
+
*/
|
|
1865
|
+
export function updateRef(ref, sha, opts) {
|
|
1866
|
+
const name = positional('updateRef', 'ref', ref);
|
|
1867
|
+
if (name !== 'HEAD' && !name.startsWith('refs/')) {
|
|
1868
|
+
throw new TypeError(`typed-git: updateRef: ref must be HEAD or start with "refs/" (got ${JSON.stringify(ref)})`);
|
|
1869
|
+
}
|
|
1870
|
+
const argv = ['update-ref'];
|
|
1871
|
+
if (opts.reason !== undefined)
|
|
1872
|
+
argv.push('-m', opts.reason);
|
|
1873
|
+
argv.push(name, positional('updateRef', 'sha', sha));
|
|
1874
|
+
if (opts.oldSha === null) {
|
|
1875
|
+
// An empty old value is git's "must not exist", in either hash format.
|
|
1876
|
+
argv.push('');
|
|
1877
|
+
}
|
|
1878
|
+
else if (opts.oldSha === undefined) {
|
|
1879
|
+
// Only reachable without types: report the missing option, not an invalid sha.
|
|
1880
|
+
throw new TypeError('typed-git: updateRef: oldSha is required: the sha the ref holds now, or null for "must not exist"');
|
|
1881
|
+
}
|
|
1882
|
+
else {
|
|
1883
|
+
const old = positional('updateRef', 'oldSha', opts.oldSha);
|
|
1884
|
+
if (!FULL_SHA.test(old)) {
|
|
1885
|
+
throw new TypeError(`typed-git: updateRef: oldSha must be a full sha, or null for "must not exist" (got ${JSON.stringify(old)})`);
|
|
1886
|
+
}
|
|
1887
|
+
argv.push(old);
|
|
1888
|
+
}
|
|
1889
|
+
return { argv, absent: NONE, parse: nothing };
|
|
1890
|
+
}
|
|
1699
1891
|
/** `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`. */
|
|
1700
1892
|
export function worktreeAdd(path, opts = {}) {
|
|
1701
1893
|
if (opts.resetBranch && opts.branch === undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"typescript": "~6.0.3",
|
|
64
64
|
"typescript59": "npm:typescript@5.9.3",
|
|
65
65
|
"vitest": "^5.0.5",
|
|
66
|
-
"@osdlc/
|
|
67
|
-
"@osdlc/
|
|
66
|
+
"@osdlc/tsconfig": "^0.4.1",
|
|
67
|
+
"@osdlc/prettier-config": "^0.3.1"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"build": "tsc -p tsconfig.build.json",
|