gitx.do 0.0.2 → 0.0.3
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/dist/cli/commands/blame.d.ts +259 -0
- package/dist/cli/commands/blame.d.ts.map +1 -0
- package/dist/cli/commands/blame.js +609 -0
- package/dist/cli/commands/blame.js.map +1 -0
- package/dist/cli/commands/branch.d.ts +249 -0
- package/dist/cli/commands/branch.d.ts.map +1 -0
- package/dist/cli/commands/branch.js +693 -0
- package/dist/cli/commands/branch.js.map +1 -0
- package/dist/cli/commands/commit.d.ts +182 -0
- package/dist/cli/commands/commit.d.ts.map +1 -0
- package/dist/cli/commands/commit.js +437 -0
- package/dist/cli/commands/commit.js.map +1 -0
- package/dist/cli/commands/diff.d.ts +464 -0
- package/dist/cli/commands/diff.d.ts.map +1 -0
- package/dist/cli/commands/diff.js +958 -0
- package/dist/cli/commands/diff.js.map +1 -0
- package/dist/cli/commands/log.d.ts +239 -0
- package/dist/cli/commands/log.d.ts.map +1 -0
- package/dist/cli/commands/log.js +535 -0
- package/dist/cli/commands/log.js.map +1 -0
- package/dist/cli/commands/review.d.ts +457 -0
- package/dist/cli/commands/review.d.ts.map +1 -0
- package/dist/cli/commands/review.js +533 -0
- package/dist/cli/commands/review.js.map +1 -0
- package/dist/cli/commands/status.d.ts +269 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +493 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/web.d.ts +199 -0
- package/dist/cli/commands/web.d.ts.map +1 -0
- package/dist/cli/commands/web.js +696 -0
- package/dist/cli/commands/web.js.map +1 -0
- package/dist/cli/fs-adapter.d.ts +656 -0
- package/dist/cli/fs-adapter.d.ts.map +1 -0
- package/dist/cli/fs-adapter.js +1179 -0
- package/dist/cli/fs-adapter.js.map +1 -0
- package/dist/cli/index.d.ts +387 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +523 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/ui/components/DiffView.d.ts +7 -0
- package/dist/cli/ui/components/DiffView.d.ts.map +1 -0
- package/dist/cli/ui/components/DiffView.js +11 -0
- package/dist/cli/ui/components/DiffView.js.map +1 -0
- package/dist/cli/ui/components/ErrorDisplay.d.ts +6 -0
- package/dist/cli/ui/components/ErrorDisplay.d.ts.map +1 -0
- package/dist/cli/ui/components/ErrorDisplay.js +11 -0
- package/dist/cli/ui/components/ErrorDisplay.js.map +1 -0
- package/dist/cli/ui/components/FuzzySearch.d.ts +9 -0
- package/dist/cli/ui/components/FuzzySearch.d.ts.map +1 -0
- package/dist/cli/ui/components/FuzzySearch.js +12 -0
- package/dist/cli/ui/components/FuzzySearch.js.map +1 -0
- package/dist/cli/ui/components/LoadingSpinner.d.ts +6 -0
- package/dist/cli/ui/components/LoadingSpinner.d.ts.map +1 -0
- package/dist/cli/ui/components/LoadingSpinner.js +10 -0
- package/dist/cli/ui/components/LoadingSpinner.js.map +1 -0
- package/dist/cli/ui/components/NavigationList.d.ts +9 -0
- package/dist/cli/ui/components/NavigationList.d.ts.map +1 -0
- package/dist/cli/ui/components/NavigationList.js +11 -0
- package/dist/cli/ui/components/NavigationList.js.map +1 -0
- package/dist/cli/ui/components/ScrollableContent.d.ts +8 -0
- package/dist/cli/ui/components/ScrollableContent.d.ts.map +1 -0
- package/dist/cli/ui/components/ScrollableContent.js +11 -0
- package/dist/cli/ui/components/ScrollableContent.js.map +1 -0
- package/dist/cli/ui/components/index.d.ts +7 -0
- package/dist/cli/ui/components/index.d.ts.map +1 -0
- package/dist/cli/ui/components/index.js +9 -0
- package/dist/cli/ui/components/index.js.map +1 -0
- package/dist/cli/ui/terminal-ui.d.ts +52 -0
- package/dist/cli/ui/terminal-ui.d.ts.map +1 -0
- package/dist/cli/ui/terminal-ui.js +121 -0
- package/dist/cli/ui/terminal-ui.js.map +1 -0
- package/dist/durable-object/object-store.d.ts +401 -23
- package/dist/durable-object/object-store.d.ts.map +1 -1
- package/dist/durable-object/object-store.js +414 -25
- package/dist/durable-object/object-store.js.map +1 -1
- package/dist/durable-object/schema.d.ts +188 -0
- package/dist/durable-object/schema.d.ts.map +1 -1
- package/dist/durable-object/schema.js +160 -0
- package/dist/durable-object/schema.js.map +1 -1
- package/dist/durable-object/wal.d.ts +336 -31
- package/dist/durable-object/wal.d.ts.map +1 -1
- package/dist/durable-object/wal.js +272 -27
- package/dist/durable-object/wal.js.map +1 -1
- package/dist/index.d.ts +379 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +379 -7
- package/dist/index.js.map +1 -1
- package/dist/mcp/adapter.d.ts +579 -38
- package/dist/mcp/adapter.d.ts.map +1 -1
- package/dist/mcp/adapter.js +426 -33
- package/dist/mcp/adapter.js.map +1 -1
- package/dist/mcp/sandbox.d.ts +532 -29
- package/dist/mcp/sandbox.d.ts.map +1 -1
- package/dist/mcp/sandbox.js +389 -22
- package/dist/mcp/sandbox.js.map +1 -1
- package/dist/mcp/sdk-adapter.d.ts +478 -56
- package/dist/mcp/sdk-adapter.d.ts.map +1 -1
- package/dist/mcp/sdk-adapter.js +346 -44
- package/dist/mcp/sdk-adapter.js.map +1 -1
- package/dist/mcp/tools.d.ts +445 -30
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +363 -33
- package/dist/mcp/tools.js.map +1 -1
- package/dist/ops/blame.d.ts +424 -21
- package/dist/ops/blame.d.ts.map +1 -1
- package/dist/ops/blame.js +303 -20
- package/dist/ops/blame.js.map +1 -1
- package/dist/ops/branch.d.ts +583 -32
- package/dist/ops/branch.d.ts.map +1 -1
- package/dist/ops/branch.js +365 -23
- package/dist/ops/branch.js.map +1 -1
- package/dist/ops/commit-traversal.d.ts +164 -24
- package/dist/ops/commit-traversal.d.ts.map +1 -1
- package/dist/ops/commit-traversal.js +68 -2
- package/dist/ops/commit-traversal.js.map +1 -1
- package/dist/ops/commit.d.ts +387 -53
- package/dist/ops/commit.d.ts.map +1 -1
- package/dist/ops/commit.js +249 -29
- package/dist/ops/commit.js.map +1 -1
- package/dist/ops/merge-base.d.ts +195 -21
- package/dist/ops/merge-base.d.ts.map +1 -1
- package/dist/ops/merge-base.js +122 -12
- package/dist/ops/merge-base.js.map +1 -1
- package/dist/ops/merge.d.ts +600 -130
- package/dist/ops/merge.d.ts.map +1 -1
- package/dist/ops/merge.js +408 -60
- package/dist/ops/merge.js.map +1 -1
- package/dist/ops/tag.d.ts +67 -2
- package/dist/ops/tag.d.ts.map +1 -1
- package/dist/ops/tag.js +42 -1
- package/dist/ops/tag.js.map +1 -1
- package/dist/ops/tree-builder.d.ts +102 -6
- package/dist/ops/tree-builder.d.ts.map +1 -1
- package/dist/ops/tree-builder.js +30 -5
- package/dist/ops/tree-builder.js.map +1 -1
- package/dist/ops/tree-diff.d.ts +50 -2
- package/dist/ops/tree-diff.d.ts.map +1 -1
- package/dist/ops/tree-diff.js +50 -2
- package/dist/ops/tree-diff.js.map +1 -1
- package/dist/pack/delta.d.ts +211 -39
- package/dist/pack/delta.d.ts.map +1 -1
- package/dist/pack/delta.js +232 -46
- package/dist/pack/delta.js.map +1 -1
- package/dist/pack/format.d.ts +390 -28
- package/dist/pack/format.d.ts.map +1 -1
- package/dist/pack/format.js +344 -33
- package/dist/pack/format.js.map +1 -1
- package/dist/pack/full-generation.d.ts +313 -28
- package/dist/pack/full-generation.d.ts.map +1 -1
- package/dist/pack/full-generation.js +238 -19
- package/dist/pack/full-generation.js.map +1 -1
- package/dist/pack/generation.d.ts +346 -23
- package/dist/pack/generation.d.ts.map +1 -1
- package/dist/pack/generation.js +269 -21
- package/dist/pack/generation.js.map +1 -1
- package/dist/pack/index.d.ts +407 -86
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +351 -70
- package/dist/pack/index.js.map +1 -1
- package/dist/refs/branch.d.ts +517 -71
- package/dist/refs/branch.d.ts.map +1 -1
- package/dist/refs/branch.js +410 -26
- package/dist/refs/branch.js.map +1 -1
- package/dist/refs/storage.d.ts +610 -57
- package/dist/refs/storage.d.ts.map +1 -1
- package/dist/refs/storage.js +481 -29
- package/dist/refs/storage.js.map +1 -1
- package/dist/refs/tag.d.ts +677 -67
- package/dist/refs/tag.d.ts.map +1 -1
- package/dist/refs/tag.js +497 -30
- package/dist/refs/tag.js.map +1 -1
- package/dist/storage/lru-cache.d.ts +556 -53
- package/dist/storage/lru-cache.d.ts.map +1 -1
- package/dist/storage/lru-cache.js +439 -36
- package/dist/storage/lru-cache.js.map +1 -1
- package/dist/storage/object-index.d.ts +483 -38
- package/dist/storage/object-index.d.ts.map +1 -1
- package/dist/storage/object-index.js +388 -22
- package/dist/storage/object-index.js.map +1 -1
- package/dist/storage/r2-pack.d.ts +957 -94
- package/dist/storage/r2-pack.d.ts.map +1 -1
- package/dist/storage/r2-pack.js +756 -48
- package/dist/storage/r2-pack.js.map +1 -1
- package/dist/tiered/cdc-pipeline.d.ts +1610 -38
- package/dist/tiered/cdc-pipeline.d.ts.map +1 -1
- package/dist/tiered/cdc-pipeline.js +1131 -22
- package/dist/tiered/cdc-pipeline.js.map +1 -1
- package/dist/tiered/migration.d.ts +903 -41
- package/dist/tiered/migration.d.ts.map +1 -1
- package/dist/tiered/migration.js +646 -24
- package/dist/tiered/migration.js.map +1 -1
- package/dist/tiered/parquet-writer.d.ts +944 -47
- package/dist/tiered/parquet-writer.d.ts.map +1 -1
- package/dist/tiered/parquet-writer.js +667 -39
- package/dist/tiered/parquet-writer.js.map +1 -1
- package/dist/tiered/read-path.d.ts +728 -34
- package/dist/tiered/read-path.d.ts.map +1 -1
- package/dist/tiered/read-path.js +310 -27
- package/dist/tiered/read-path.js.map +1 -1
- package/dist/types/objects.d.ts +457 -0
- package/dist/types/objects.d.ts.map +1 -1
- package/dist/types/objects.js +305 -4
- package/dist/types/objects.js.map +1 -1
- package/dist/types/storage.d.ts +407 -35
- package/dist/types/storage.d.ts.map +1 -1
- package/dist/types/storage.js +27 -3
- package/dist/types/storage.js.map +1 -1
- package/dist/utils/hash.d.ts +133 -12
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +133 -12
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/sha1.d.ts +102 -9
- package/dist/utils/sha1.d.ts.map +1 -1
- package/dist/utils/sha1.js +114 -11
- package/dist/utils/sha1.js.map +1 -1
- package/dist/wire/capabilities.d.ts +896 -88
- package/dist/wire/capabilities.d.ts.map +1 -1
- package/dist/wire/capabilities.js +566 -62
- package/dist/wire/capabilities.js.map +1 -1
- package/dist/wire/pkt-line.d.ts +293 -15
- package/dist/wire/pkt-line.d.ts.map +1 -1
- package/dist/wire/pkt-line.js +251 -15
- package/dist/wire/pkt-line.js.map +1 -1
- package/dist/wire/receive-pack.d.ts +814 -64
- package/dist/wire/receive-pack.d.ts.map +1 -1
- package/dist/wire/receive-pack.js +542 -41
- package/dist/wire/receive-pack.js.map +1 -1
- package/dist/wire/smart-http.d.ts +575 -97
- package/dist/wire/smart-http.d.ts.map +1 -1
- package/dist/wire/smart-http.js +337 -46
- package/dist/wire/smart-http.js.map +1 -1
- package/dist/wire/upload-pack.d.ts +492 -98
- package/dist/wire/upload-pack.d.ts.map +1 -1
- package/dist/wire/upload-pack.js +347 -59
- package/dist/wire/upload-pack.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,257 +1,832 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Git receive-pack
|
|
2
|
+
* @fileoverview Git receive-pack Protocol Implementation
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 3. Validates and applies the updates
|
|
4
|
+
* This module implements the server-side of Git's receive-pack service, which
|
|
5
|
+
* handles `git-push` operations. It receives ref updates and packfile data
|
|
6
|
+
* from clients and applies them to the repository.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
* 1. Server advertises refs with capabilities
|
|
11
|
-
* 2. Client sends ref update commands (old-sha new-sha refname)
|
|
12
|
-
* 3. Client sends packfile with new objects
|
|
13
|
-
* 4. Server validates packfile and updates refs
|
|
14
|
-
* 5. Server sends status report (if report-status enabled)
|
|
8
|
+
* @module wire/receive-pack
|
|
15
9
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
10
|
+
* ## Protocol Flow
|
|
11
|
+
*
|
|
12
|
+
* 1. **Ref Advertisement**: Server advertises current refs and capabilities
|
|
13
|
+
* 2. **Command Reception**: Client sends ref update commands (old-sha new-sha refname)
|
|
14
|
+
* 3. **Packfile Reception**: Client sends packfile with new objects (if needed)
|
|
15
|
+
* 4. **Validation**: Server validates packfile and ref updates
|
|
16
|
+
* 5. **Application**: Server applies updates and sends status report
|
|
17
|
+
*
|
|
18
|
+
* ## Security Considerations
|
|
19
|
+
*
|
|
20
|
+
* - Validates all SHA-1 hashes before processing
|
|
21
|
+
* - Checks fast-forward constraints for updates
|
|
22
|
+
* - Supports atomic pushes for consistency
|
|
23
|
+
* - Validates ref names according to Git rules
|
|
24
|
+
* - Supports pre-receive, update, and post-receive hooks
|
|
25
|
+
*
|
|
26
|
+
* @see {@link https://git-scm.com/docs/pack-protocol} Git Pack Protocol
|
|
27
|
+
* @see {@link https://git-scm.com/docs/git-receive-pack} git-receive-pack Documentation
|
|
28
|
+
*
|
|
29
|
+
* @example Basic push handling
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import {
|
|
32
|
+
* createReceiveSession,
|
|
33
|
+
* advertiseReceiveRefs,
|
|
34
|
+
* handleReceivePack
|
|
35
|
+
* } from './wire/receive-pack'
|
|
36
|
+
*
|
|
37
|
+
* // Create session and advertise refs
|
|
38
|
+
* const session = createReceiveSession('my-repo')
|
|
39
|
+
* const advertisement = await advertiseReceiveRefs(store, { atomic: true })
|
|
40
|
+
*
|
|
41
|
+
* // Handle push request
|
|
42
|
+
* const response = await handleReceivePack(session, requestBody, store)
|
|
43
|
+
* ```
|
|
18
44
|
*/
|
|
19
45
|
import type { ObjectType } from '../types/objects';
|
|
20
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Zero SHA - used for ref creation and deletion.
|
|
48
|
+
*
|
|
49
|
+
* @description
|
|
50
|
+
* This 40-character string of zeros is used as a placeholder:
|
|
51
|
+
* - In `oldSha`: indicates a ref is being created (doesn't exist yet)
|
|
52
|
+
* - In `newSha`: indicates a ref is being deleted
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Check if this is a create operation
|
|
57
|
+
* const isCreate = cmd.oldSha === ZERO_SHA
|
|
58
|
+
*
|
|
59
|
+
* // Check if this is a delete operation
|
|
60
|
+
* const isDelete = cmd.newSha === ZERO_SHA
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
21
63
|
export declare const ZERO_SHA: string;
|
|
22
64
|
/**
|
|
23
|
-
* A reference (branch, tag, etc.) with its SHA and optional peeled value
|
|
65
|
+
* A reference (branch, tag, etc.) with its SHA and optional peeled value.
|
|
66
|
+
*
|
|
67
|
+
* @description
|
|
68
|
+
* Represents a Git reference that can be advertised to clients.
|
|
69
|
+
* For annotated tags, the `peeled` field contains the SHA of the
|
|
70
|
+
* underlying commit/object.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const branch: Ref = {
|
|
75
|
+
* name: 'refs/heads/main',
|
|
76
|
+
* sha: 'abc123def456...'
|
|
77
|
+
* }
|
|
78
|
+
*
|
|
79
|
+
* const tag: Ref = {
|
|
80
|
+
* name: 'refs/tags/v1.0.0',
|
|
81
|
+
* sha: 'tag-object-sha...',
|
|
82
|
+
* peeled: 'target-commit-sha...'
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
24
85
|
*/
|
|
25
86
|
export interface Ref {
|
|
87
|
+
/** Full ref name (e.g., 'refs/heads/main') */
|
|
26
88
|
name: string;
|
|
89
|
+
/** SHA-1 hash of the object this ref points to */
|
|
27
90
|
sha: string;
|
|
91
|
+
/** For annotated tags, the SHA of the target object */
|
|
28
92
|
peeled?: string;
|
|
29
93
|
}
|
|
30
94
|
/**
|
|
31
|
-
* Capabilities supported by receive-pack
|
|
95
|
+
* Capabilities supported by receive-pack.
|
|
96
|
+
*
|
|
97
|
+
* @description
|
|
98
|
+
* These capabilities are advertised during ref advertisement and
|
|
99
|
+
* negotiated with the client. They control what features are
|
|
100
|
+
* available during the push operation.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const caps: ReceivePackCapabilities = {
|
|
105
|
+
* reportStatus: true,
|
|
106
|
+
* deleteRefs: true,
|
|
107
|
+
* atomic: true,
|
|
108
|
+
* agent: 'my-server/1.0'
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
32
111
|
*/
|
|
33
112
|
export interface ReceivePackCapabilities {
|
|
34
|
-
/** Client wants status report */
|
|
113
|
+
/** Client wants status report after push */
|
|
35
114
|
reportStatus?: boolean;
|
|
36
|
-
/** Client wants v2 status report */
|
|
115
|
+
/** Client wants v2 status report (extended format) */
|
|
37
116
|
reportStatusV2?: boolean;
|
|
38
|
-
/** Allow ref deletion */
|
|
117
|
+
/** Allow ref deletion via push */
|
|
39
118
|
deleteRefs?: boolean;
|
|
40
119
|
/** Suppress progress messages */
|
|
41
120
|
quiet?: boolean;
|
|
42
|
-
/** Atomic push
|
|
121
|
+
/** Atomic push - all refs update or none */
|
|
43
122
|
atomic?: boolean;
|
|
44
|
-
/** Support push options */
|
|
123
|
+
/** Support push options (custom metadata) */
|
|
45
124
|
pushOptions?: boolean;
|
|
46
|
-
/** Side-band multiplexing */
|
|
125
|
+
/** Side-band multiplexing for output */
|
|
47
126
|
sideBand64k?: boolean;
|
|
48
|
-
/** Push certificate nonce */
|
|
127
|
+
/** Push certificate nonce for signed pushes */
|
|
49
128
|
pushCert?: string;
|
|
50
|
-
/**
|
|
129
|
+
/** Server agent identification string */
|
|
51
130
|
agent?: string;
|
|
52
131
|
}
|
|
53
132
|
/**
|
|
54
|
-
* Ref update command from client
|
|
133
|
+
* Ref update command from client.
|
|
134
|
+
*
|
|
135
|
+
* @description
|
|
136
|
+
* Each command describes a single ref update operation:
|
|
137
|
+
* - **create**: oldSha is ZERO_SHA, newSha is the new value
|
|
138
|
+
* - **update**: oldSha is current value, newSha is new value
|
|
139
|
+
* - **delete**: oldSha is current value, newSha is ZERO_SHA
|
|
140
|
+
*
|
|
141
|
+
* The type is derived from the SHA values.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Create a new branch
|
|
146
|
+
* const createCmd: RefUpdateCommand = {
|
|
147
|
+
* oldSha: ZERO_SHA,
|
|
148
|
+
* newSha: 'abc123...',
|
|
149
|
+
* refName: 'refs/heads/feature',
|
|
150
|
+
* type: 'create'
|
|
151
|
+
* }
|
|
152
|
+
*
|
|
153
|
+
* // Update existing branch
|
|
154
|
+
* const updateCmd: RefUpdateCommand = {
|
|
155
|
+
* oldSha: 'abc123...',
|
|
156
|
+
* newSha: 'def456...',
|
|
157
|
+
* refName: 'refs/heads/main',
|
|
158
|
+
* type: 'update'
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
55
161
|
*/
|
|
56
162
|
export interface RefUpdateCommand {
|
|
163
|
+
/** Old SHA (ZERO_SHA for create operations) */
|
|
57
164
|
oldSha: string;
|
|
165
|
+
/** New SHA (ZERO_SHA for delete operations) */
|
|
58
166
|
newSha: string;
|
|
167
|
+
/** Full ref name (e.g., 'refs/heads/main') */
|
|
59
168
|
refName: string;
|
|
169
|
+
/** Command type: create, update, or delete */
|
|
60
170
|
type: 'create' | 'update' | 'delete';
|
|
171
|
+
/** Capabilities from first command line (if any) */
|
|
61
172
|
capabilities?: string[];
|
|
62
173
|
}
|
|
63
174
|
/**
|
|
64
|
-
* Result of a ref update operation
|
|
175
|
+
* Result of a ref update operation.
|
|
176
|
+
*
|
|
177
|
+
* @description
|
|
178
|
+
* Contains the outcome of a single ref update, including
|
|
179
|
+
* success/failure status and any error message.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const result: RefUpdateResult = {
|
|
184
|
+
* refName: 'refs/heads/main',
|
|
185
|
+
* success: true,
|
|
186
|
+
* oldTarget: 'abc123...',
|
|
187
|
+
* newTarget: 'def456...'
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
65
190
|
*/
|
|
66
191
|
export interface RefUpdateResult {
|
|
192
|
+
/** The ref that was updated */
|
|
67
193
|
refName: string;
|
|
194
|
+
/** Whether the update succeeded */
|
|
68
195
|
success: boolean;
|
|
196
|
+
/** Error message if update failed */
|
|
69
197
|
error?: string;
|
|
198
|
+
/** Previous ref value (for logging/hooks) */
|
|
70
199
|
oldTarget?: string;
|
|
200
|
+
/** New ref value (for logging/hooks) */
|
|
71
201
|
newTarget?: string;
|
|
202
|
+
/** Whether this was a force update (non-fast-forward) */
|
|
72
203
|
forced?: boolean;
|
|
73
204
|
}
|
|
74
205
|
/**
|
|
75
|
-
* Packfile validation result
|
|
206
|
+
* Packfile validation result.
|
|
207
|
+
*
|
|
208
|
+
* @description
|
|
209
|
+
* Contains the result of validating a packfile's structure,
|
|
210
|
+
* checksum, and object count.
|
|
76
211
|
*/
|
|
77
212
|
export interface PackfileValidation {
|
|
213
|
+
/** Whether the packfile is valid */
|
|
78
214
|
valid: boolean;
|
|
215
|
+
/** Number of objects in the packfile */
|
|
79
216
|
objectCount?: number;
|
|
217
|
+
/** Error message if validation failed */
|
|
80
218
|
error?: string;
|
|
81
219
|
}
|
|
82
220
|
/**
|
|
83
|
-
* Hook execution point
|
|
221
|
+
* Hook execution point.
|
|
222
|
+
*
|
|
223
|
+
* @description
|
|
224
|
+
* The different points where hooks can be executed during receive-pack:
|
|
225
|
+
* - `pre-receive`: Before any refs are updated (can reject entire push)
|
|
226
|
+
* - `update`: Before each individual ref update (can reject per-ref)
|
|
227
|
+
* - `post-receive`: After all refs are updated (for notifications)
|
|
228
|
+
* - `post-update`: After refs are updated (simpler than post-receive)
|
|
84
229
|
*/
|
|
85
230
|
export type HookExecutionPoint = 'pre-receive' | 'update' | 'post-receive' | 'post-update';
|
|
86
231
|
/**
|
|
87
|
-
* Hook execution result
|
|
232
|
+
* Hook execution result.
|
|
233
|
+
*
|
|
234
|
+
* @description
|
|
235
|
+
* Contains the result of executing a server-side hook. For pre-receive
|
|
236
|
+
* and update hooks, failure will reject the push.
|
|
88
237
|
*/
|
|
89
238
|
export interface HookResult {
|
|
239
|
+
/** Whether the hook succeeded */
|
|
90
240
|
success: boolean;
|
|
241
|
+
/** Message from the hook (displayed to client) */
|
|
91
242
|
message?: string;
|
|
243
|
+
/** Whether the push operation succeeded (post-receive) */
|
|
92
244
|
pushSuccess?: boolean;
|
|
245
|
+
/** Whether the hook execution succeeded (post-receive) */
|
|
93
246
|
hookSuccess?: boolean;
|
|
247
|
+
/** Per-ref results from update hook */
|
|
94
248
|
results?: RefUpdateResult[];
|
|
95
249
|
}
|
|
96
250
|
/**
|
|
97
|
-
* Session state for receive-pack operation
|
|
251
|
+
* Session state for receive-pack operation.
|
|
252
|
+
*
|
|
253
|
+
* @description
|
|
254
|
+
* Maintains state across the receive-pack protocol phases.
|
|
255
|
+
* This includes capabilities and commands received from the client.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const session = createReceiveSession('my-repo')
|
|
260
|
+
* // session.capabilities and session.commands are populated
|
|
261
|
+
* // as the request is processed
|
|
262
|
+
* ```
|
|
98
263
|
*/
|
|
99
264
|
export interface ReceivePackSession {
|
|
265
|
+
/** Repository identifier for logging/tracking */
|
|
100
266
|
repoId: string;
|
|
267
|
+
/** Negotiated capabilities */
|
|
101
268
|
capabilities: ReceivePackCapabilities;
|
|
269
|
+
/** Ref update commands from client */
|
|
102
270
|
commands: RefUpdateCommand[];
|
|
103
271
|
}
|
|
104
272
|
/**
|
|
105
|
-
* Object store interface
|
|
273
|
+
* Object store interface for receive-pack operations.
|
|
274
|
+
*
|
|
275
|
+
* @description
|
|
276
|
+
* Defines the methods required from an object store to support
|
|
277
|
+
* receive-pack operations. Implementations typically wrap a Git
|
|
278
|
+
* object database or similar storage.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* class MyObjectStore implements ObjectStore {
|
|
283
|
+
* async getObject(sha: string) {
|
|
284
|
+
* return this.database.get(sha)
|
|
285
|
+
* }
|
|
286
|
+
* async hasObject(sha: string) {
|
|
287
|
+
* return this.database.has(sha)
|
|
288
|
+
* }
|
|
289
|
+
* async setRef(name: string, sha: string) {
|
|
290
|
+
* await this.database.updateRef(name, sha)
|
|
291
|
+
* }
|
|
292
|
+
* // ... other methods
|
|
293
|
+
* }
|
|
294
|
+
* ```
|
|
106
295
|
*/
|
|
107
296
|
export interface ObjectStore {
|
|
297
|
+
/**
|
|
298
|
+
* Get an object by its SHA.
|
|
299
|
+
* @param sha - The SHA-1 hash of the object
|
|
300
|
+
* @returns The object type and data, or null if not found
|
|
301
|
+
*/
|
|
108
302
|
getObject(sha: string): Promise<{
|
|
109
303
|
type: ObjectType;
|
|
110
304
|
data: Uint8Array;
|
|
111
305
|
} | null>;
|
|
306
|
+
/**
|
|
307
|
+
* Check if an object exists in the store.
|
|
308
|
+
* @param sha - The SHA-1 hash to check
|
|
309
|
+
* @returns true if the object exists
|
|
310
|
+
*/
|
|
112
311
|
hasObject(sha: string): Promise<boolean>;
|
|
312
|
+
/**
|
|
313
|
+
* Get the parent commit SHAs for a commit.
|
|
314
|
+
* @param sha - The commit SHA
|
|
315
|
+
* @returns Array of parent commit SHAs
|
|
316
|
+
*/
|
|
113
317
|
getCommitParents(sha: string): Promise<string[]>;
|
|
318
|
+
/**
|
|
319
|
+
* Get all refs in the repository.
|
|
320
|
+
* @returns Array of Ref objects
|
|
321
|
+
*/
|
|
114
322
|
getRefs(): Promise<Ref[]>;
|
|
323
|
+
/**
|
|
324
|
+
* Get a specific ref by name.
|
|
325
|
+
* @param name - Full ref name (e.g., 'refs/heads/main')
|
|
326
|
+
* @returns The ref, or null if not found
|
|
327
|
+
*/
|
|
115
328
|
getRef(name: string): Promise<Ref | null>;
|
|
329
|
+
/**
|
|
330
|
+
* Set/update a ref to point to a SHA.
|
|
331
|
+
* @param name - Full ref name
|
|
332
|
+
* @param sha - SHA-1 hash to point to
|
|
333
|
+
*/
|
|
116
334
|
setRef(name: string, sha: string): Promise<void>;
|
|
335
|
+
/**
|
|
336
|
+
* Delete a ref.
|
|
337
|
+
* @param name - Full ref name to delete
|
|
338
|
+
*/
|
|
117
339
|
deleteRef(name: string): Promise<void>;
|
|
340
|
+
/**
|
|
341
|
+
* Store an object in the database.
|
|
342
|
+
* @param sha - The SHA-1 hash of the object
|
|
343
|
+
* @param type - Object type (commit, tree, blob, tag)
|
|
344
|
+
* @param data - Object data
|
|
345
|
+
*/
|
|
118
346
|
storeObject(sha: string, type: string, data: Uint8Array): Promise<void>;
|
|
347
|
+
/**
|
|
348
|
+
* Check if one commit is an ancestor of another.
|
|
349
|
+
* @param ancestor - Potential ancestor commit SHA
|
|
350
|
+
* @param descendant - Potential descendant commit SHA
|
|
351
|
+
* @returns true if ancestor is reachable from descendant
|
|
352
|
+
*/
|
|
119
353
|
isAncestor(ancestor: string, descendant: string): Promise<boolean>;
|
|
120
354
|
}
|
|
121
355
|
/**
|
|
122
|
-
* Parsed receive-pack request
|
|
356
|
+
* Parsed receive-pack request.
|
|
357
|
+
*
|
|
358
|
+
* @description
|
|
359
|
+
* Contains all data parsed from a receive-pack request, including
|
|
360
|
+
* ref update commands, capabilities, packfile data, and push options.
|
|
123
361
|
*/
|
|
124
362
|
export interface ReceivePackRequest {
|
|
363
|
+
/** Ref update commands */
|
|
125
364
|
commands: RefUpdateCommand[];
|
|
365
|
+
/** Capabilities from first command */
|
|
126
366
|
capabilities: string[];
|
|
367
|
+
/** Packfile binary data */
|
|
127
368
|
packfile: Uint8Array;
|
|
369
|
+
/** Push options (if push-options capability enabled) */
|
|
128
370
|
pushOptions: string[];
|
|
129
371
|
}
|
|
130
372
|
/**
|
|
131
|
-
* Report status input
|
|
373
|
+
* Report status input.
|
|
374
|
+
*
|
|
375
|
+
* @description
|
|
376
|
+
* Data needed to generate a status report response to the client.
|
|
132
377
|
*/
|
|
133
378
|
export interface ReportStatusInput {
|
|
379
|
+
/** Status of packfile unpacking ('ok' or error message) */
|
|
134
380
|
unpackStatus: string;
|
|
381
|
+
/** Results for each ref update */
|
|
135
382
|
refResults: RefUpdateResult[];
|
|
383
|
+
/** Additional options (for report-status-v2) */
|
|
136
384
|
options?: Record<string, string>;
|
|
137
385
|
}
|
|
138
386
|
/**
|
|
139
|
-
* Unpack result
|
|
387
|
+
* Unpack result.
|
|
388
|
+
*
|
|
389
|
+
* @description
|
|
390
|
+
* Result of unpacking objects from a packfile into the object store.
|
|
140
391
|
*/
|
|
141
392
|
export interface UnpackResult {
|
|
393
|
+
/** Whether unpacking succeeded */
|
|
142
394
|
success: boolean;
|
|
395
|
+
/** Number of objects unpacked */
|
|
143
396
|
objectsUnpacked: number;
|
|
397
|
+
/** SHAs of unpacked objects */
|
|
144
398
|
unpackedShas: string[];
|
|
399
|
+
/** Error message if unpacking failed */
|
|
145
400
|
error?: string;
|
|
146
401
|
}
|
|
147
402
|
/**
|
|
148
|
-
* Process commands result
|
|
403
|
+
* Process commands result.
|
|
404
|
+
*
|
|
405
|
+
* @description
|
|
406
|
+
* Result of processing ref update commands.
|
|
149
407
|
*/
|
|
150
408
|
export interface ProcessCommandsResult {
|
|
409
|
+
/** Results for each ref update */
|
|
151
410
|
results: RefUpdateResult[];
|
|
152
411
|
}
|
|
153
412
|
/**
|
|
154
|
-
* Atomic ref update result
|
|
413
|
+
* Atomic ref update result.
|
|
414
|
+
*
|
|
415
|
+
* @description
|
|
416
|
+
* Result of an atomic push operation where all refs update
|
|
417
|
+
* together or none do.
|
|
155
418
|
*/
|
|
156
419
|
export interface AtomicRefUpdateResult {
|
|
420
|
+
/** Whether all updates succeeded */
|
|
157
421
|
success: boolean;
|
|
422
|
+
/** Results for each ref */
|
|
158
423
|
results: RefUpdateResult[];
|
|
159
424
|
}
|
|
160
425
|
/**
|
|
161
|
-
* Permission check result
|
|
426
|
+
* Permission check result.
|
|
427
|
+
*
|
|
428
|
+
* @description
|
|
429
|
+
* Result of checking whether an operation is permitted.
|
|
162
430
|
*/
|
|
163
431
|
export interface PermissionCheckResult {
|
|
432
|
+
/** Whether the operation is allowed */
|
|
164
433
|
allowed: boolean;
|
|
434
|
+
/** Reason for rejection (if not allowed) */
|
|
165
435
|
reason?: string;
|
|
166
436
|
}
|
|
167
437
|
/**
|
|
168
|
-
* Permission check options
|
|
438
|
+
* Permission check options.
|
|
439
|
+
*
|
|
440
|
+
* @description
|
|
441
|
+
* Options for configuring permission checks.
|
|
169
442
|
*/
|
|
170
443
|
export interface PermissionCheckOptions {
|
|
444
|
+
/** Refs that cannot be modified */
|
|
171
445
|
protectedRefs?: string[];
|
|
446
|
+
/** Glob patterns of allowed refs */
|
|
172
447
|
allowedRefPatterns?: string[];
|
|
173
448
|
}
|
|
174
449
|
/**
|
|
175
|
-
* Process commands options
|
|
450
|
+
* Process commands options.
|
|
451
|
+
*
|
|
452
|
+
* @description
|
|
453
|
+
* Options for processing ref update commands.
|
|
176
454
|
*/
|
|
177
455
|
export interface ProcessCommandsOptions {
|
|
456
|
+
/** Allow non-fast-forward updates */
|
|
178
457
|
forcePush?: boolean;
|
|
179
458
|
}
|
|
180
459
|
/**
|
|
181
|
-
* Packfile validation options
|
|
460
|
+
* Packfile validation options.
|
|
461
|
+
*
|
|
462
|
+
* @description
|
|
463
|
+
* Options for validating packfile structure and content.
|
|
182
464
|
*/
|
|
183
465
|
export interface PackfileValidationOptions {
|
|
466
|
+
/** Verify SHA-1 checksum */
|
|
184
467
|
verifyChecksum?: boolean;
|
|
468
|
+
/** Allow empty packfile */
|
|
185
469
|
allowEmpty?: boolean;
|
|
186
470
|
}
|
|
187
471
|
/**
|
|
188
|
-
* Unpack options
|
|
472
|
+
* Unpack options.
|
|
473
|
+
*
|
|
474
|
+
* @description
|
|
475
|
+
* Options for unpacking objects from a packfile.
|
|
189
476
|
*/
|
|
190
477
|
export interface UnpackOptions {
|
|
478
|
+
/** Resolve delta objects */
|
|
191
479
|
resolveDelta?: boolean;
|
|
480
|
+
/** Progress callback */
|
|
192
481
|
onProgress?: (message: string) => void;
|
|
193
482
|
}
|
|
194
483
|
/**
|
|
195
|
-
* Hook options
|
|
484
|
+
* Hook options.
|
|
485
|
+
*
|
|
486
|
+
* @description
|
|
487
|
+
* Options for hook execution.
|
|
196
488
|
*/
|
|
197
489
|
export interface HookOptions {
|
|
490
|
+
/** Timeout in milliseconds */
|
|
198
491
|
timeout?: number;
|
|
492
|
+
/** Push options to pass to hooks */
|
|
199
493
|
pushOptions?: string[];
|
|
200
494
|
}
|
|
201
495
|
/**
|
|
202
|
-
* Build capability string for receive-pack
|
|
496
|
+
* Build capability string for receive-pack advertisement.
|
|
497
|
+
*
|
|
498
|
+
* @description
|
|
499
|
+
* Converts a capabilities object into a space-separated string suitable
|
|
500
|
+
* for inclusion in the ref advertisement. Boolean capabilities become
|
|
501
|
+
* simple names, while capabilities with values become "name=value".
|
|
502
|
+
*
|
|
503
|
+
* @param capabilities - Capabilities to advertise
|
|
504
|
+
* @returns Space-separated capability string
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* const caps: ReceivePackCapabilities = {
|
|
509
|
+
* reportStatus: true,
|
|
510
|
+
* deleteRefs: true,
|
|
511
|
+
* atomic: true,
|
|
512
|
+
* agent: 'my-server/1.0'
|
|
513
|
+
* }
|
|
514
|
+
* const str = buildReceiveCapabilityString(caps)
|
|
515
|
+
* // 'report-status delete-refs atomic agent=my-server/1.0'
|
|
516
|
+
* ```
|
|
203
517
|
*/
|
|
204
518
|
export declare function buildReceiveCapabilityString(capabilities: ReceivePackCapabilities): string;
|
|
205
519
|
/**
|
|
206
|
-
* Parse capabilities from string
|
|
520
|
+
* Parse capabilities from string.
|
|
521
|
+
*
|
|
522
|
+
* @description
|
|
523
|
+
* Parses a space-separated capability string into a structured
|
|
524
|
+
* capabilities object.
|
|
525
|
+
*
|
|
526
|
+
* @param capsString - Space-separated capabilities
|
|
527
|
+
* @returns Parsed capabilities object
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* const caps = parseReceiveCapabilities(
|
|
532
|
+
* 'report-status delete-refs atomic agent=git/2.30.0'
|
|
533
|
+
* )
|
|
534
|
+
* // caps.reportStatus === true
|
|
535
|
+
* // caps.deleteRefs === true
|
|
536
|
+
* // caps.atomic === true
|
|
537
|
+
* // caps.agent === 'git/2.30.0'
|
|
538
|
+
* ```
|
|
207
539
|
*/
|
|
208
540
|
export declare function parseReceiveCapabilities(capsString: string): ReceivePackCapabilities;
|
|
209
541
|
/**
|
|
210
|
-
* Create a new receive-pack session
|
|
542
|
+
* Create a new receive-pack session.
|
|
543
|
+
*
|
|
544
|
+
* @description
|
|
545
|
+
* Initializes a new session for a receive-pack operation. The session
|
|
546
|
+
* tracks state across the protocol phases.
|
|
547
|
+
*
|
|
548
|
+
* @param repoId - Repository identifier for logging/tracking
|
|
549
|
+
* @returns New session object
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```typescript
|
|
553
|
+
* const session = createReceiveSession('my-repo')
|
|
554
|
+
* // session.capabilities === {}
|
|
555
|
+
* // session.commands === []
|
|
556
|
+
* ```
|
|
211
557
|
*/
|
|
212
558
|
export declare function createReceiveSession(repoId: string): ReceivePackSession;
|
|
213
559
|
/**
|
|
214
|
-
* Advertise refs to client
|
|
560
|
+
* Advertise refs to client.
|
|
561
|
+
*
|
|
562
|
+
* @description
|
|
563
|
+
* Generates the ref advertisement response for the initial phase of
|
|
564
|
+
* receive-pack. This includes:
|
|
565
|
+
* - HEAD reference with capabilities (or zero SHA for empty repos)
|
|
566
|
+
* - All refs sorted alphabetically
|
|
567
|
+
* - Peeled refs for annotated tags
|
|
568
|
+
*
|
|
569
|
+
* @param store - Object store to get refs from
|
|
570
|
+
* @param capabilities - Optional server capabilities to advertise
|
|
571
|
+
* @returns Pkt-line formatted ref advertisement
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```typescript
|
|
575
|
+
* const advertisement = await advertiseReceiveRefs(store, {
|
|
576
|
+
* reportStatus: true,
|
|
577
|
+
* deleteRefs: true,
|
|
578
|
+
* atomic: true
|
|
579
|
+
* })
|
|
580
|
+
* // Send as response to GET /info/refs?service=git-receive-pack
|
|
581
|
+
* ```
|
|
215
582
|
*/
|
|
216
583
|
export declare function advertiseReceiveRefs(store: ObjectStore, capabilities?: ReceivePackCapabilities): Promise<string>;
|
|
217
584
|
/**
|
|
218
|
-
* Parse a single command line
|
|
585
|
+
* Parse a single command line.
|
|
586
|
+
*
|
|
587
|
+
* @description
|
|
588
|
+
* Parses a ref update command line in the format:
|
|
589
|
+
* `<old-sha> <new-sha> <refname>[NUL<capabilities>]`
|
|
590
|
+
*
|
|
591
|
+
* The first command line may include capabilities after a NUL byte.
|
|
592
|
+
*
|
|
593
|
+
* @param line - Command line to parse
|
|
594
|
+
* @returns Parsed command object
|
|
595
|
+
*
|
|
596
|
+
* @throws {Error} If the line format is invalid or SHAs are malformed
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```typescript
|
|
600
|
+
* // Simple command
|
|
601
|
+
* const cmd = parseCommandLine(
|
|
602
|
+
* 'abc123... def456... refs/heads/main'
|
|
603
|
+
* )
|
|
604
|
+
*
|
|
605
|
+
* // Command with capabilities (first line)
|
|
606
|
+
* const cmdWithCaps = parseCommandLine(
|
|
607
|
+
* 'abc123... def456... refs/heads/main\0report-status atomic'
|
|
608
|
+
* )
|
|
609
|
+
* ```
|
|
219
610
|
*/
|
|
220
611
|
export declare function parseCommandLine(line: string): RefUpdateCommand;
|
|
221
612
|
/**
|
|
222
|
-
* Parse complete receive-pack request
|
|
613
|
+
* Parse complete receive-pack request.
|
|
614
|
+
*
|
|
615
|
+
* @description
|
|
616
|
+
* Parses the full receive-pack request body, extracting:
|
|
617
|
+
* - Ref update commands
|
|
618
|
+
* - Capabilities (from first command)
|
|
619
|
+
* - Push options (if enabled)
|
|
620
|
+
* - Packfile data
|
|
621
|
+
*
|
|
622
|
+
* @param data - Raw request body as Uint8Array
|
|
623
|
+
* @returns Parsed request object
|
|
624
|
+
*
|
|
625
|
+
* @throws {Error} If the request format is invalid
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```typescript
|
|
629
|
+
* const request = parseReceivePackRequest(requestBody)
|
|
630
|
+
* // request.commands - array of RefUpdateCommand
|
|
631
|
+
* // request.capabilities - capabilities from first command
|
|
632
|
+
* // request.packfile - packfile binary data
|
|
633
|
+
* // request.pushOptions - push options (if enabled)
|
|
634
|
+
* ```
|
|
223
635
|
*/
|
|
224
636
|
export declare function parseReceivePackRequest(data: Uint8Array): ReceivePackRequest;
|
|
225
637
|
/**
|
|
226
|
-
* Validate packfile structure
|
|
638
|
+
* Validate packfile structure.
|
|
639
|
+
*
|
|
640
|
+
* @description
|
|
641
|
+
* Validates a packfile's structure, including:
|
|
642
|
+
* - PACK signature (4 bytes)
|
|
643
|
+
* - Version number (must be 2 or 3)
|
|
644
|
+
* - Object count
|
|
645
|
+
* - Checksum (if verifyChecksum option is true)
|
|
646
|
+
*
|
|
647
|
+
* @param packfile - Packfile binary data
|
|
648
|
+
* @param options - Validation options
|
|
649
|
+
* @returns Validation result
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```typescript
|
|
653
|
+
* const result = await validatePackfile(packData, { verifyChecksum: true })
|
|
654
|
+
* if (!result.valid) {
|
|
655
|
+
* console.error('Invalid packfile:', result.error)
|
|
656
|
+
* } else {
|
|
657
|
+
* console.log('Objects in pack:', result.objectCount)
|
|
658
|
+
* }
|
|
659
|
+
* ```
|
|
227
660
|
*/
|
|
228
661
|
export declare function validatePackfile(packfile: Uint8Array, options?: PackfileValidationOptions): Promise<PackfileValidation>;
|
|
229
662
|
/**
|
|
230
|
-
* Unpack objects from packfile
|
|
663
|
+
* Unpack objects from packfile.
|
|
664
|
+
*
|
|
665
|
+
* @description
|
|
666
|
+
* Extracts and stores objects from a packfile into the object store.
|
|
667
|
+
* Handles both regular objects and delta-compressed objects.
|
|
668
|
+
*
|
|
669
|
+
* @param packfile - Packfile binary data
|
|
670
|
+
* @param _store - Object store to store unpacked objects
|
|
671
|
+
* @param options - Unpack options
|
|
672
|
+
* @returns Unpack result
|
|
673
|
+
*
|
|
674
|
+
* @example
|
|
675
|
+
* ```typescript
|
|
676
|
+
* const result = await unpackObjects(packfile, store, {
|
|
677
|
+
* resolveDelta: true,
|
|
678
|
+
* onProgress: (msg) => console.log(msg)
|
|
679
|
+
* })
|
|
680
|
+
* if (result.success) {
|
|
681
|
+
* console.log('Unpacked', result.objectsUnpacked, 'objects')
|
|
682
|
+
* }
|
|
683
|
+
* ```
|
|
231
684
|
*/
|
|
232
685
|
export declare function unpackObjects(packfile: Uint8Array, _store: ObjectStore, options?: UnpackOptions): Promise<UnpackResult>;
|
|
233
686
|
/**
|
|
234
|
-
* Validate ref name according to git rules
|
|
687
|
+
* Validate ref name according to git rules.
|
|
688
|
+
*
|
|
689
|
+
* @description
|
|
690
|
+
* Validates a ref name against Git's naming rules:
|
|
691
|
+
* - Must not be empty
|
|
692
|
+
* - Must not start or end with `/`
|
|
693
|
+
* - Must not contain `//` or `..`
|
|
694
|
+
* - Must not contain control characters
|
|
695
|
+
* - Must not contain spaces, `~`, `^`, `:`, or `@{`
|
|
696
|
+
* - Must not end with `.lock`
|
|
697
|
+
* - Components must not start with `.`
|
|
698
|
+
*
|
|
699
|
+
* @param refName - Ref name to validate
|
|
700
|
+
* @returns true if the ref name is valid
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* validateRefName('refs/heads/main') // true
|
|
705
|
+
* validateRefName('refs/heads/feature') // true
|
|
706
|
+
* validateRefName('refs/heads/.hidden') // false (starts with .)
|
|
707
|
+
* validateRefName('refs/heads/a..b') // false (contains ..)
|
|
708
|
+
* validateRefName('refs/heads/a b') // false (contains space)
|
|
709
|
+
* ```
|
|
235
710
|
*/
|
|
236
711
|
export declare function validateRefName(refName: string): boolean;
|
|
237
712
|
/**
|
|
238
|
-
* Validate fast-forward update
|
|
713
|
+
* Validate fast-forward update.
|
|
714
|
+
*
|
|
715
|
+
* @description
|
|
716
|
+
* Checks if updating a ref from oldSha to newSha is a fast-forward.
|
|
717
|
+
* A fast-forward means oldSha is an ancestor of newSha.
|
|
718
|
+
*
|
|
719
|
+
* Creation and deletion are always allowed (not fast-forward questions).
|
|
720
|
+
*
|
|
721
|
+
* @param oldSha - Current ref value (or ZERO_SHA for create)
|
|
722
|
+
* @param newSha - New ref value (or ZERO_SHA for delete)
|
|
723
|
+
* @param store - Object store to check ancestry
|
|
724
|
+
* @returns true if the update is allowed
|
|
725
|
+
*
|
|
726
|
+
* @example
|
|
727
|
+
* ```typescript
|
|
728
|
+
* // Fast-forward update
|
|
729
|
+
* const ok = await validateFastForward(parent, child, store) // true
|
|
730
|
+
*
|
|
731
|
+
* // Non-fast-forward update
|
|
732
|
+
* const notOk = await validateFastForward(child, parent, store) // false
|
|
733
|
+
*
|
|
734
|
+
* // Creation always allowed
|
|
735
|
+
* const create = await validateFastForward(ZERO_SHA, sha, store) // true
|
|
736
|
+
* ```
|
|
239
737
|
*/
|
|
240
738
|
export declare function validateFastForward(oldSha: string, newSha: string, store: ObjectStore): Promise<boolean>;
|
|
241
739
|
/**
|
|
242
|
-
* Check ref permissions
|
|
740
|
+
* Check ref permissions.
|
|
741
|
+
*
|
|
742
|
+
* @description
|
|
743
|
+
* Checks whether a ref operation is allowed based on:
|
|
744
|
+
* - Protected refs (cannot be modified)
|
|
745
|
+
* - Allowed ref patterns (must match at least one)
|
|
746
|
+
* - Force push restrictions on protected branches
|
|
747
|
+
*
|
|
748
|
+
* @param refName - Ref being modified
|
|
749
|
+
* @param operation - Type of operation
|
|
750
|
+
* @param options - Permission check options
|
|
751
|
+
* @returns Permission check result
|
|
752
|
+
*
|
|
753
|
+
* @example
|
|
754
|
+
* ```typescript
|
|
755
|
+
* const result = await checkRefPermissions(
|
|
756
|
+
* 'refs/heads/main',
|
|
757
|
+
* 'force-update',
|
|
758
|
+
* { protectedRefs: ['refs/heads/main'] }
|
|
759
|
+
* )
|
|
760
|
+
* // result.allowed === false
|
|
761
|
+
* // result.reason === 'force push not allowed on protected branch'
|
|
762
|
+
* ```
|
|
243
763
|
*/
|
|
244
764
|
export declare function checkRefPermissions(refName: string, operation: 'create' | 'update' | 'delete' | 'force-update', options: PermissionCheckOptions): Promise<PermissionCheckResult>;
|
|
245
765
|
/**
|
|
246
|
-
* Process ref update commands
|
|
766
|
+
* Process ref update commands.
|
|
767
|
+
*
|
|
768
|
+
* @description
|
|
769
|
+
* Validates and processes ref update commands without actually
|
|
770
|
+
* applying them. Checks:
|
|
771
|
+
* - Ref name validity
|
|
772
|
+
* - Current ref state matches expected old SHA
|
|
773
|
+
* - Fast-forward constraints (unless force push)
|
|
774
|
+
* - Delete-refs capability for deletions
|
|
775
|
+
*
|
|
776
|
+
* @param session - Current session state
|
|
777
|
+
* @param commands - Commands to process
|
|
778
|
+
* @param store - Object store
|
|
779
|
+
* @param options - Processing options
|
|
780
|
+
* @returns Processing result with per-ref status
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```typescript
|
|
784
|
+
* const result = await processCommands(session, commands, store)
|
|
785
|
+
* for (const refResult of result.results) {
|
|
786
|
+
* if (!refResult.success) {
|
|
787
|
+
* console.error(`Failed to update ${refResult.refName}: ${refResult.error}`)
|
|
788
|
+
* }
|
|
789
|
+
* }
|
|
790
|
+
* ```
|
|
247
791
|
*/
|
|
248
792
|
export declare function processCommands(session: ReceivePackSession, commands: RefUpdateCommand[], store: ObjectStore, options?: ProcessCommandsOptions): Promise<ProcessCommandsResult>;
|
|
249
793
|
/**
|
|
250
|
-
* Update refs in the store
|
|
794
|
+
* Update refs in the store.
|
|
795
|
+
*
|
|
796
|
+
* @description
|
|
797
|
+
* Actually applies ref updates to the object store. Should only be
|
|
798
|
+
* called after validation via processCommands.
|
|
799
|
+
*
|
|
800
|
+
* @param commands - Commands to apply
|
|
801
|
+
* @param store - Object store
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* ```typescript
|
|
805
|
+
* // After validation
|
|
806
|
+
* await updateRefs(commands, store)
|
|
807
|
+
* ```
|
|
251
808
|
*/
|
|
252
809
|
export declare function updateRefs(commands: RefUpdateCommand[], store: ObjectStore): Promise<void>;
|
|
253
810
|
/**
|
|
254
|
-
* Atomic ref update - all or nothing
|
|
811
|
+
* Atomic ref update - all or nothing.
|
|
812
|
+
*
|
|
813
|
+
* @description
|
|
814
|
+
* Applies all ref updates atomically. If any update fails, all
|
|
815
|
+
* changes are rolled back to the original state.
|
|
816
|
+
*
|
|
817
|
+
* @param commands - Commands to apply
|
|
818
|
+
* @param store - Object store
|
|
819
|
+
* @returns Atomic update result
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* ```typescript
|
|
823
|
+
* const result = await atomicRefUpdate(commands, store)
|
|
824
|
+
* if (result.success) {
|
|
825
|
+
* console.log('All refs updated successfully')
|
|
826
|
+
* } else {
|
|
827
|
+
* console.error('Atomic push failed, all changes rolled back')
|
|
828
|
+
* }
|
|
829
|
+
* ```
|
|
255
830
|
*/
|
|
256
831
|
export declare function atomicRefUpdate(commands: RefUpdateCommand[], store: ObjectStore): Promise<AtomicRefUpdateResult>;
|
|
257
832
|
type PreReceiveHookFn = (commands: RefUpdateCommand[], env: Record<string, string>) => Promise<HookResult>;
|
|
@@ -259,43 +834,218 @@ type UpdateHookFn = (refName: string, oldSha: string, newSha: string, env: Recor
|
|
|
259
834
|
type PostReceiveHookFn = (commands: RefUpdateCommand[], results: RefUpdateResult[], env: Record<string, string>) => Promise<HookResult>;
|
|
260
835
|
type PostUpdateHookFn = (refNames: string[]) => Promise<HookResult>;
|
|
261
836
|
/**
|
|
262
|
-
* Execute pre-receive hook
|
|
837
|
+
* Execute pre-receive hook.
|
|
838
|
+
*
|
|
839
|
+
* @description
|
|
840
|
+
* Runs the pre-receive hook before any refs are updated.
|
|
841
|
+
* The hook receives all commands and can reject the entire push.
|
|
842
|
+
*
|
|
843
|
+
* @param commands - Commands to be executed
|
|
844
|
+
* @param _store - Object store
|
|
845
|
+
* @param hookFn - Hook function to execute
|
|
846
|
+
* @param env - Environment variables for the hook
|
|
847
|
+
* @param options - Hook options
|
|
848
|
+
* @returns Hook result
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* ```typescript
|
|
852
|
+
* const result = await executePreReceiveHook(
|
|
853
|
+
* commands,
|
|
854
|
+
* store,
|
|
855
|
+
* async (cmds, env) => {
|
|
856
|
+
* // Validate commands
|
|
857
|
+
* return { success: true }
|
|
858
|
+
* },
|
|
859
|
+
* { GIT_DIR: '/path/to/repo' },
|
|
860
|
+
* { timeout: 30000 }
|
|
861
|
+
* )
|
|
862
|
+
* ```
|
|
263
863
|
*/
|
|
264
864
|
export declare function executePreReceiveHook(commands: RefUpdateCommand[], _store: ObjectStore, hookFn: PreReceiveHookFn, env?: Record<string, string>, options?: HookOptions): Promise<HookResult>;
|
|
265
865
|
/**
|
|
266
|
-
* Execute update hook for each ref
|
|
866
|
+
* Execute update hook for each ref.
|
|
867
|
+
*
|
|
868
|
+
* @description
|
|
869
|
+
* Runs the update hook for each ref being updated.
|
|
870
|
+
* Unlike pre-receive, this hook can reject individual refs.
|
|
871
|
+
*
|
|
872
|
+
* @param commands - Commands being executed
|
|
873
|
+
* @param _store - Object store
|
|
874
|
+
* @param hookFn - Hook function to execute per-ref
|
|
875
|
+
* @param env - Environment variables for the hook
|
|
876
|
+
* @returns Results for each ref
|
|
877
|
+
*
|
|
878
|
+
* @example
|
|
879
|
+
* ```typescript
|
|
880
|
+
* const { results } = await executeUpdateHook(
|
|
881
|
+
* commands,
|
|
882
|
+
* store,
|
|
883
|
+
* async (refName, oldSha, newSha, env) => {
|
|
884
|
+
* // Check if update is allowed for this ref
|
|
885
|
+
* return { success: true }
|
|
886
|
+
* },
|
|
887
|
+
* { GIT_DIR: '/path/to/repo' }
|
|
888
|
+
* )
|
|
889
|
+
* ```
|
|
267
890
|
*/
|
|
268
891
|
export declare function executeUpdateHook(commands: RefUpdateCommand[], _store: ObjectStore, hookFn: UpdateHookFn, env?: Record<string, string>): Promise<{
|
|
269
892
|
results: RefUpdateResult[];
|
|
270
893
|
}>;
|
|
271
894
|
/**
|
|
272
|
-
* Execute post-receive hook
|
|
895
|
+
* Execute post-receive hook.
|
|
896
|
+
*
|
|
897
|
+
* @description
|
|
898
|
+
* Runs the post-receive hook after all refs are updated.
|
|
899
|
+
* This hook cannot affect the push result but is useful for
|
|
900
|
+
* notifications, CI triggers, etc.
|
|
901
|
+
*
|
|
902
|
+
* @param commands - Commands that were executed
|
|
903
|
+
* @param results - Results of ref updates
|
|
904
|
+
* @param _store - Object store
|
|
905
|
+
* @param hookFn - Hook function to execute
|
|
906
|
+
* @param options - Hook options
|
|
907
|
+
* @returns Hook execution result
|
|
908
|
+
*
|
|
909
|
+
* @example
|
|
910
|
+
* ```typescript
|
|
911
|
+
* const { hookSuccess } = await executePostReceiveHook(
|
|
912
|
+
* commands,
|
|
913
|
+
* results,
|
|
914
|
+
* store,
|
|
915
|
+
* async (cmds, results, env) => {
|
|
916
|
+
* // Trigger CI, send notifications, etc.
|
|
917
|
+
* return { success: true }
|
|
918
|
+
* },
|
|
919
|
+
* { pushOptions: ['ci.skip'] }
|
|
920
|
+
* )
|
|
921
|
+
* ```
|
|
273
922
|
*/
|
|
274
923
|
export declare function executePostReceiveHook(commands: RefUpdateCommand[], results: RefUpdateResult[], _store: ObjectStore, hookFn: PostReceiveHookFn, options?: HookOptions): Promise<{
|
|
275
924
|
pushSuccess: boolean;
|
|
276
925
|
hookSuccess: boolean;
|
|
277
926
|
}>;
|
|
278
927
|
/**
|
|
279
|
-
* Execute post-update hook
|
|
928
|
+
* Execute post-update hook.
|
|
929
|
+
*
|
|
930
|
+
* @description
|
|
931
|
+
* Runs the post-update hook with the names of successfully updated refs.
|
|
932
|
+
* Simpler than post-receive, takes only ref names as arguments.
|
|
933
|
+
*
|
|
934
|
+
* @param _commands - Commands that were executed
|
|
935
|
+
* @param results - Results of ref updates
|
|
936
|
+
* @param hookFn - Hook function to execute
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* ```typescript
|
|
940
|
+
* await executePostUpdateHook(
|
|
941
|
+
* commands,
|
|
942
|
+
* results,
|
|
943
|
+
* async (refNames) => {
|
|
944
|
+
* console.log('Updated refs:', refNames)
|
|
945
|
+
* return { success: true }
|
|
946
|
+
* }
|
|
947
|
+
* )
|
|
948
|
+
* ```
|
|
280
949
|
*/
|
|
281
950
|
export declare function executePostUpdateHook(_commands: RefUpdateCommand[], results: RefUpdateResult[], hookFn: PostUpdateHookFn): Promise<void>;
|
|
282
951
|
/**
|
|
283
|
-
* Format report-status response
|
|
952
|
+
* Format report-status response.
|
|
953
|
+
*
|
|
954
|
+
* @description
|
|
955
|
+
* Creates a pkt-line formatted status report response to send
|
|
956
|
+
* to the client after processing the push. The format is:
|
|
957
|
+
* 1. Unpack status: "unpack ok" or "unpack <error>"
|
|
958
|
+
* 2. Ref status lines: "ok <refname>" or "ng <refname> <error>"
|
|
959
|
+
* 3. Flush packet
|
|
960
|
+
*
|
|
961
|
+
* @param input - Status report data
|
|
962
|
+
* @returns Pkt-line formatted status report
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* ```typescript
|
|
966
|
+
* const report = formatReportStatus({
|
|
967
|
+
* unpackStatus: 'ok',
|
|
968
|
+
* refResults: [
|
|
969
|
+
* { refName: 'refs/heads/main', success: true },
|
|
970
|
+
* { refName: 'refs/heads/feature', success: false, error: 'non-fast-forward' }
|
|
971
|
+
* ]
|
|
972
|
+
* })
|
|
973
|
+
* // "0010unpack ok\n0019ok refs/heads/main\n002cng refs/heads/feature non-fast-forward\n0000"
|
|
974
|
+
* ```
|
|
284
975
|
*/
|
|
285
976
|
export declare function formatReportStatus(input: ReportStatusInput): string;
|
|
286
977
|
/**
|
|
287
|
-
* Format report-status-v2 response
|
|
978
|
+
* Format report-status-v2 response.
|
|
979
|
+
*
|
|
980
|
+
* @description
|
|
981
|
+
* Creates an extended status report for report-status-v2 capability.
|
|
982
|
+
* Adds option lines before the unpack status and supports forced
|
|
983
|
+
* update indication.
|
|
984
|
+
*
|
|
985
|
+
* @param input - Status report data
|
|
986
|
+
* @returns Pkt-line formatted v2 status report
|
|
987
|
+
*
|
|
988
|
+
* @example
|
|
989
|
+
* ```typescript
|
|
990
|
+
* const report = formatReportStatusV2({
|
|
991
|
+
* unpackStatus: 'ok',
|
|
992
|
+
* refResults: [
|
|
993
|
+
* { refName: 'refs/heads/main', success: true, forced: true }
|
|
994
|
+
* ],
|
|
995
|
+
* options: { 'object-format': 'sha1' }
|
|
996
|
+
* })
|
|
997
|
+
* ```
|
|
288
998
|
*/
|
|
289
999
|
export declare function formatReportStatusV2(input: ReportStatusInput): string;
|
|
290
1000
|
/**
|
|
291
|
-
* Format rejection message
|
|
1001
|
+
* Format rejection message.
|
|
1002
|
+
*
|
|
1003
|
+
* @description
|
|
1004
|
+
* Creates a rejection message in the appropriate format based
|
|
1005
|
+
* on the client's capabilities (side-band or report-status).
|
|
1006
|
+
*
|
|
1007
|
+
* @param refName - Ref that was rejected
|
|
1008
|
+
* @param reason - Reason for rejection
|
|
1009
|
+
* @param options - Formatting options
|
|
1010
|
+
* @returns Formatted rejection message
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```typescript
|
|
1014
|
+
* // Side-band format
|
|
1015
|
+
* const msg = rejectPush('refs/heads/main', 'protected branch', { sideBand: true })
|
|
1016
|
+
* // Returns Uint8Array with side-band channel 3 message
|
|
1017
|
+
*
|
|
1018
|
+
* // Report-status format
|
|
1019
|
+
* const msg = rejectPush('refs/heads/main', 'protected branch', { reportStatus: true })
|
|
1020
|
+
* // Returns "ng refs/heads/main protected branch"
|
|
1021
|
+
* ```
|
|
292
1022
|
*/
|
|
293
1023
|
export declare function rejectPush(refName: string, reason: string, options: {
|
|
294
1024
|
reportStatus?: boolean;
|
|
295
1025
|
sideBand?: boolean;
|
|
296
1026
|
}): string | Uint8Array;
|
|
297
1027
|
/**
|
|
298
|
-
* Handle complete receive-pack request
|
|
1028
|
+
* Handle complete receive-pack request.
|
|
1029
|
+
*
|
|
1030
|
+
* @description
|
|
1031
|
+
* This is the main entry point that handles the full receive-pack
|
|
1032
|
+
* protocol flow:
|
|
1033
|
+
* 1. Parse request (commands, capabilities, packfile)
|
|
1034
|
+
* 2. Validate and unpack packfile (if present)
|
|
1035
|
+
* 3. Process each ref update command
|
|
1036
|
+
* 4. Return status report (if requested)
|
|
1037
|
+
*
|
|
1038
|
+
* @param session - Receive pack session
|
|
1039
|
+
* @param request - Raw request data
|
|
1040
|
+
* @param store - Object store
|
|
1041
|
+
* @returns Response data (status report or empty)
|
|
1042
|
+
*
|
|
1043
|
+
* @example
|
|
1044
|
+
* ```typescript
|
|
1045
|
+
* const session = createReceiveSession('my-repo')
|
|
1046
|
+
* const response = await handleReceivePack(session, requestBody, store)
|
|
1047
|
+
* // response contains status report if report-status was enabled
|
|
1048
|
+
* ```
|
|
299
1049
|
*/
|
|
300
1050
|
export declare function handleReceivePack(session: ReceivePackSession, request: Uint8Array, store: ObjectStore): Promise<Uint8Array>;
|
|
301
1051
|
export {};
|