gitx.do 0.0.1 → 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 +10 -2
|
@@ -1,249 +1,610 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Git Smart HTTP Protocol Implementation
|
|
2
|
+
* @fileoverview Git Smart HTTP Protocol Implementation
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* - Push discovery (GET /info/refs?service=git-receive-pack)
|
|
7
|
-
* - Fetch data transfer (POST /git-upload-pack)
|
|
8
|
-
* - Push data transfer (POST /git-receive-pack)
|
|
4
|
+
* This module implements the Git Smart HTTP protocol for server-side handling of
|
|
5
|
+
* Git fetch and push operations over HTTP. It provides handlers for:
|
|
9
6
|
*
|
|
10
|
-
*
|
|
7
|
+
* - **Ref Discovery** (`GET /info/refs?service=git-upload-pack|git-receive-pack`)
|
|
8
|
+
* Advertises available refs and server capabilities to clients.
|
|
9
|
+
*
|
|
10
|
+
* - **Fetch Data Transfer** (`POST /git-upload-pack`)
|
|
11
|
+
* Handles client fetch requests by processing wants/haves and returning packfiles.
|
|
12
|
+
*
|
|
13
|
+
* - **Push Data Transfer** (`POST /git-receive-pack`)
|
|
14
|
+
* Handles client push requests by processing ref updates and incoming packfiles.
|
|
15
|
+
*
|
|
16
|
+
* @module wire/smart-http
|
|
17
|
+
* @see {@link https://git-scm.com/docs/http-protocol} Git HTTP Protocol Documentation
|
|
18
|
+
* @see {@link https://git-scm.com/docs/protocol-common} Git Protocol Common
|
|
19
|
+
*
|
|
20
|
+
* @example Basic server integration
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { handleInfoRefs, handleUploadPack, handleReceivePack } from './wire/smart-http'
|
|
23
|
+
*
|
|
24
|
+
* // Handle GET /repo.git/info/refs?service=git-upload-pack
|
|
25
|
+
* app.get('/:repo/info/refs', async (req, res) => {
|
|
26
|
+
* const request: SmartHTTPRequest = {
|
|
27
|
+
* method: 'GET',
|
|
28
|
+
* path: '/info/refs',
|
|
29
|
+
* query: { service: req.query.service },
|
|
30
|
+
* headers: req.headers,
|
|
31
|
+
* repository: req.params.repo
|
|
32
|
+
* }
|
|
33
|
+
* const response = await handleInfoRefs(request, repositoryProvider, capabilities)
|
|
34
|
+
* res.status(response.status).set(response.headers).send(response.body)
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
11
37
|
*/
|
|
12
38
|
/**
|
|
13
|
-
* Supported Git Smart HTTP services
|
|
39
|
+
* Supported Git Smart HTTP services.
|
|
40
|
+
*
|
|
41
|
+
* @description
|
|
42
|
+
* Git Smart HTTP supports two services:
|
|
43
|
+
* - `git-upload-pack`: Used by git-fetch to download objects
|
|
44
|
+
* - `git-receive-pack`: Used by git-push to upload objects
|
|
14
45
|
*/
|
|
15
46
|
export type GitService = 'git-upload-pack' | 'git-receive-pack';
|
|
16
47
|
/**
|
|
17
|
-
* HTTP methods supported by the Smart HTTP protocol
|
|
48
|
+
* HTTP methods supported by the Smart HTTP protocol.
|
|
49
|
+
*
|
|
50
|
+
* @description
|
|
51
|
+
* - `GET`: Used for ref discovery (/info/refs)
|
|
52
|
+
* - `POST`: Used for data transfer (upload-pack and receive-pack)
|
|
18
53
|
*/
|
|
19
54
|
export type HTTPMethod = 'GET' | 'POST';
|
|
20
55
|
/**
|
|
21
|
-
* Represents a Git reference (branch, tag, etc.)
|
|
56
|
+
* Represents a Git reference (branch, tag, etc.).
|
|
57
|
+
*
|
|
58
|
+
* @description
|
|
59
|
+
* A Git reference is a named pointer to a specific commit or object.
|
|
60
|
+
* Common ref types include:
|
|
61
|
+
* - Branches: `refs/heads/main`, `refs/heads/feature`
|
|
62
|
+
* - Tags: `refs/tags/v1.0.0`
|
|
63
|
+
* - Remote tracking: `refs/remotes/origin/main`
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const mainBranch: GitRef = {
|
|
68
|
+
* sha: 'abc123def456...',
|
|
69
|
+
* name: 'refs/heads/main'
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* const annotatedTag: GitRef = {
|
|
73
|
+
* sha: 'tag-object-sha...',
|
|
74
|
+
* name: 'refs/tags/v1.0.0',
|
|
75
|
+
* peeled: 'target-commit-sha...'
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
22
78
|
*/
|
|
23
79
|
export interface GitRef {
|
|
24
|
-
/** SHA-1 hash of the object this ref points to */
|
|
80
|
+
/** SHA-1 hash of the object this ref points to (40 hex characters) */
|
|
25
81
|
sha: string;
|
|
26
|
-
/** Full ref name (e.g., 'refs/heads/main') */
|
|
82
|
+
/** Full ref name (e.g., 'refs/heads/main', 'refs/tags/v1.0.0') */
|
|
27
83
|
name: string;
|
|
28
|
-
/** Optional peeled SHA for annotated tags */
|
|
84
|
+
/** Optional peeled SHA for annotated tags - the SHA of the target object */
|
|
29
85
|
peeled?: string;
|
|
30
86
|
}
|
|
31
87
|
/**
|
|
32
|
-
* Server capabilities advertised during ref discovery
|
|
88
|
+
* Server capabilities advertised during ref discovery.
|
|
89
|
+
*
|
|
90
|
+
* @description
|
|
91
|
+
* Capabilities determine what features the server supports. Clients select
|
|
92
|
+
* which capabilities to use during the initial handshake. Common capability
|
|
93
|
+
* categories include:
|
|
94
|
+
*
|
|
95
|
+
* - **Negotiation**: `multi_ack`, `multi_ack_detailed` - for efficient fetch negotiation
|
|
96
|
+
* - **Transfer**: `thin-pack`, `ofs-delta` - for efficient packfile transfer
|
|
97
|
+
* - **Communication**: `side-band`, `side-band-64k` - for multiplexed output
|
|
98
|
+
* - **Features**: `shallow`, `filter`, `atomic` - for advanced operations
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const capabilities: ServerCapabilities = {
|
|
103
|
+
* multiAckDetailed: true,
|
|
104
|
+
* sideBand64k: true,
|
|
105
|
+
* thinPack: true,
|
|
106
|
+
* ofsDelta: true,
|
|
107
|
+
* shallow: true,
|
|
108
|
+
* reportStatus: true,
|
|
109
|
+
* deleteRefs: true,
|
|
110
|
+
* agent: 'my-git-server/1.0'
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @see {@link https://git-scm.com/docs/protocol-capabilities} Git Protocol Capabilities
|
|
33
115
|
*/
|
|
34
116
|
export interface ServerCapabilities {
|
|
35
|
-
/** Server supports multi_ack */
|
|
117
|
+
/** Server supports multi_ack for negotiation optimization */
|
|
36
118
|
multiAck?: boolean;
|
|
37
|
-
/** Server supports multi_ack_detailed */
|
|
119
|
+
/** Server supports multi_ack_detailed for finer-grained negotiation */
|
|
38
120
|
multiAckDetailed?: boolean;
|
|
39
|
-
/** Server supports thin-pack */
|
|
121
|
+
/** Server supports thin-pack (deltas against objects not in pack) */
|
|
40
122
|
thinPack?: boolean;
|
|
41
|
-
/** Server supports side-band communication */
|
|
123
|
+
/** Server supports side-band communication (multiplexed output) */
|
|
42
124
|
sideBand?: boolean;
|
|
43
|
-
/** Server supports side-band-64k communication */
|
|
125
|
+
/** Server supports side-band-64k communication (larger packets) */
|
|
44
126
|
sideBand64k?: boolean;
|
|
45
|
-
/** Server supports ofs-delta */
|
|
127
|
+
/** Server supports ofs-delta (offset-based delta encoding) */
|
|
46
128
|
ofsDelta?: boolean;
|
|
47
|
-
/** Server supports shallow clones */
|
|
129
|
+
/** Server supports shallow clones (limited history) */
|
|
48
130
|
shallow?: boolean;
|
|
49
|
-
/** Server supports deepen-since */
|
|
131
|
+
/** Server supports deepen-since (shallow by date) */
|
|
50
132
|
deepenSince?: boolean;
|
|
51
|
-
/** Server supports deepen-not */
|
|
133
|
+
/** Server supports deepen-not (exclude refs from shallow) */
|
|
52
134
|
deepenNot?: boolean;
|
|
53
|
-
/** Server supports deepen-relative */
|
|
135
|
+
/** Server supports deepen-relative (deepen from current shallow) */
|
|
54
136
|
deepenRelative?: boolean;
|
|
55
|
-
/** Server supports no-progress */
|
|
137
|
+
/** Server supports no-progress (suppress progress output) */
|
|
56
138
|
noProgress?: boolean;
|
|
57
|
-
/** Server supports include-tag */
|
|
139
|
+
/** Server supports include-tag (auto-send annotated tags) */
|
|
58
140
|
includeTag?: boolean;
|
|
59
|
-
/** Server supports report-status */
|
|
141
|
+
/** Server supports report-status (push status report) */
|
|
60
142
|
reportStatus?: boolean;
|
|
61
|
-
/** Server supports report-status-v2 */
|
|
143
|
+
/** Server supports report-status-v2 (enhanced push status) */
|
|
62
144
|
reportStatusV2?: boolean;
|
|
63
|
-
/** Server supports delete-refs */
|
|
145
|
+
/** Server supports delete-refs (ref deletion via push) */
|
|
64
146
|
deleteRefs?: boolean;
|
|
65
|
-
/** Server supports quiet mode */
|
|
147
|
+
/** Server supports quiet mode (suppress output) */
|
|
66
148
|
quiet?: boolean;
|
|
67
|
-
/** Server supports atomic pushes */
|
|
149
|
+
/** Server supports atomic pushes (all-or-nothing ref updates) */
|
|
68
150
|
atomic?: boolean;
|
|
69
|
-
/** Server supports push-options */
|
|
151
|
+
/** Server supports push-options (custom push metadata) */
|
|
70
152
|
pushOptions?: boolean;
|
|
71
|
-
/** Server allows
|
|
153
|
+
/** Server allows fetching tip SHA-1 not in refs */
|
|
72
154
|
allowTipSha1InWant?: boolean;
|
|
73
|
-
/** Server allows reachable SHA-1
|
|
155
|
+
/** Server allows fetching reachable SHA-1 not in refs */
|
|
74
156
|
allowReachableSha1InWant?: boolean;
|
|
75
|
-
/** Server's agent string */
|
|
157
|
+
/** Server's agent identification string */
|
|
76
158
|
agent?: string;
|
|
77
|
-
/** Server supports object-format (sha1/sha256) */
|
|
159
|
+
/** Server supports object-format (sha1/sha256 hash algorithm) */
|
|
78
160
|
objectFormat?: string;
|
|
79
|
-
/** Server supports filter capability */
|
|
161
|
+
/** Server supports filter capability (partial clone) */
|
|
80
162
|
filter?: boolean;
|
|
81
163
|
}
|
|
82
164
|
/**
|
|
83
|
-
* Incoming Smart HTTP request
|
|
165
|
+
* Incoming Smart HTTP request structure.
|
|
166
|
+
*
|
|
167
|
+
* @description
|
|
168
|
+
* Encapsulates all information from an incoming HTTP request that is
|
|
169
|
+
* relevant for Git Smart HTTP processing. This abstraction allows the
|
|
170
|
+
* protocol handlers to be framework-agnostic.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // Converting from Express request
|
|
175
|
+
* const smartRequest: SmartHTTPRequest = {
|
|
176
|
+
* method: req.method as HTTPMethod,
|
|
177
|
+
* path: req.path,
|
|
178
|
+
* query: req.query as Record<string, string>,
|
|
179
|
+
* headers: req.headers as Record<string, string>,
|
|
180
|
+
* body: req.body, // Buffer/Uint8Array
|
|
181
|
+
* repository: req.params.repo
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
84
184
|
*/
|
|
85
185
|
export interface SmartHTTPRequest {
|
|
86
186
|
/** HTTP method (GET or POST) */
|
|
87
187
|
method: HTTPMethod;
|
|
88
188
|
/** Request path (e.g., '/info/refs' or '/git-upload-pack') */
|
|
89
189
|
path: string;
|
|
90
|
-
/** Query parameters */
|
|
190
|
+
/** Query parameters as key-value pairs */
|
|
91
191
|
query: Record<string, string>;
|
|
92
|
-
/** HTTP headers */
|
|
192
|
+
/** HTTP headers as key-value pairs (lowercase keys recommended) */
|
|
93
193
|
headers: Record<string, string>;
|
|
94
194
|
/** Request body as Uint8Array (for POST requests) */
|
|
95
195
|
body?: Uint8Array;
|
|
96
|
-
/** Repository identifier/name */
|
|
196
|
+
/** Repository identifier/name extracted from the URL */
|
|
97
197
|
repository: string;
|
|
98
198
|
}
|
|
99
199
|
/**
|
|
100
|
-
* Outgoing Smart HTTP response
|
|
200
|
+
* Outgoing Smart HTTP response structure.
|
|
201
|
+
*
|
|
202
|
+
* @description
|
|
203
|
+
* Contains all information needed to send an HTTP response back to the
|
|
204
|
+
* Git client. The body is always a Uint8Array to handle both text and
|
|
205
|
+
* binary packfile data.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* // Converting to Express response
|
|
210
|
+
* const response = await handleInfoRefs(request, repo, caps)
|
|
211
|
+
* res.status(response.status)
|
|
212
|
+
* .set(response.headers)
|
|
213
|
+
* .send(Buffer.from(response.body))
|
|
214
|
+
* ```
|
|
101
215
|
*/
|
|
102
216
|
export interface SmartHTTPResponse {
|
|
103
|
-
/** HTTP status code */
|
|
217
|
+
/** HTTP status code (e.g., 200, 400, 403, 404) */
|
|
104
218
|
status: number;
|
|
105
|
-
/** HTTP status text */
|
|
219
|
+
/** HTTP status text (e.g., 'OK', 'Bad Request', 'Not Found') */
|
|
106
220
|
statusText: string;
|
|
107
|
-
/** Response headers */
|
|
221
|
+
/** Response headers to send */
|
|
108
222
|
headers: Record<string, string>;
|
|
109
223
|
/** Response body as Uint8Array */
|
|
110
224
|
body: Uint8Array;
|
|
111
225
|
}
|
|
112
226
|
/**
|
|
113
|
-
* Error response with specific HTTP status codes
|
|
227
|
+
* Error response with specific HTTP status codes.
|
|
228
|
+
*
|
|
229
|
+
* @description
|
|
230
|
+
* Extends the standard Error class with an HTTP status code for
|
|
231
|
+
* proper error handling in HTTP responses.
|
|
114
232
|
*/
|
|
115
233
|
export interface SmartHTTPError extends Error {
|
|
116
|
-
/** HTTP status code for the error */
|
|
234
|
+
/** HTTP status code for the error (e.g., 400, 403, 404, 500) */
|
|
117
235
|
statusCode: number;
|
|
118
236
|
}
|
|
119
237
|
/**
|
|
120
|
-
* Repository interface for Smart HTTP operations
|
|
121
|
-
*
|
|
238
|
+
* Repository interface for Smart HTTP operations.
|
|
239
|
+
*
|
|
240
|
+
* @description
|
|
241
|
+
* This interface defines the contract that a repository implementation must
|
|
242
|
+
* fulfill to support Smart HTTP operations. Implementations typically wrap
|
|
243
|
+
* a Git repository or object store.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* class MyRepositoryProvider implements RepositoryProvider {
|
|
248
|
+
* async getRefs(): Promise<GitRef[]> {
|
|
249
|
+
* return this.store.listRefs()
|
|
250
|
+
* }
|
|
251
|
+
*
|
|
252
|
+
* async exists(): Promise<boolean> {
|
|
253
|
+
* return this.store.repositoryExists()
|
|
254
|
+
* }
|
|
255
|
+
*
|
|
256
|
+
* async hasPermission(service: GitService): Promise<boolean> {
|
|
257
|
+
* if (service === 'git-receive-pack') {
|
|
258
|
+
* return this.user.canPush()
|
|
259
|
+
* }
|
|
260
|
+
* return this.user.canRead()
|
|
261
|
+
* }
|
|
262
|
+
*
|
|
263
|
+
* async uploadPack(wants, haves, caps): Promise<Uint8Array> {
|
|
264
|
+
* return this.packGenerator.generatePack(wants, haves)
|
|
265
|
+
* }
|
|
266
|
+
*
|
|
267
|
+
* async receivePack(packData, commands): Promise<ReceivePackResult> {
|
|
268
|
+
* return this.refUpdater.processUpdates(packData, commands)
|
|
269
|
+
* }
|
|
270
|
+
* }
|
|
271
|
+
* ```
|
|
122
272
|
*/
|
|
123
273
|
export interface RepositoryProvider {
|
|
124
|
-
/**
|
|
274
|
+
/**
|
|
275
|
+
* Get all refs in the repository.
|
|
276
|
+
* @returns Promise resolving to array of GitRef objects
|
|
277
|
+
*/
|
|
125
278
|
getRefs(): Promise<GitRef[]>;
|
|
126
|
-
/**
|
|
279
|
+
/**
|
|
280
|
+
* Check if the repository exists.
|
|
281
|
+
* @returns Promise resolving to true if repository exists
|
|
282
|
+
*/
|
|
127
283
|
exists(): Promise<boolean>;
|
|
128
|
-
/**
|
|
284
|
+
/**
|
|
285
|
+
* Check if the client has permission for the specified service.
|
|
286
|
+
* @param service - The Git service being requested
|
|
287
|
+
* @returns Promise resolving to true if permission is granted
|
|
288
|
+
*/
|
|
129
289
|
hasPermission(service: GitService): Promise<boolean>;
|
|
130
|
-
/**
|
|
290
|
+
/**
|
|
291
|
+
* Handle upload-pack (fetch) - generates and returns packfile data.
|
|
292
|
+
* @param wants - SHA-1 hashes of objects the client wants
|
|
293
|
+
* @param haves - SHA-1 hashes of objects the client already has
|
|
294
|
+
* @param capabilities - Client-requested capabilities
|
|
295
|
+
* @returns Promise resolving to packfile data as Uint8Array
|
|
296
|
+
*/
|
|
131
297
|
uploadPack(wants: string[], haves: string[], capabilities: string[]): Promise<Uint8Array>;
|
|
132
|
-
/**
|
|
298
|
+
/**
|
|
299
|
+
* Handle receive-pack (push) - processes incoming packfile and ref updates.
|
|
300
|
+
* @param packData - Incoming packfile data
|
|
301
|
+
* @param commands - Ref update commands from the client
|
|
302
|
+
* @returns Promise resolving to the result of the push operation
|
|
303
|
+
*/
|
|
133
304
|
receivePack(packData: Uint8Array, commands: RefUpdateCommand[]): Promise<ReceivePackResult>;
|
|
134
305
|
}
|
|
135
306
|
/**
|
|
136
|
-
* Command to update a reference during push
|
|
307
|
+
* Command to update a reference during push.
|
|
308
|
+
*
|
|
309
|
+
* @description
|
|
310
|
+
* Each command describes a single ref update operation:
|
|
311
|
+
* - **Create**: oldSha is ZERO_SHA, newSha is the new commit
|
|
312
|
+
* - **Update**: oldSha is current ref value, newSha is new value
|
|
313
|
+
* - **Delete**: oldSha is current ref value, newSha is ZERO_SHA
|
|
314
|
+
*
|
|
315
|
+
* The oldSha is used for optimistic locking - the server verifies the ref
|
|
316
|
+
* hasn't changed before applying the update.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* // Create a new branch
|
|
321
|
+
* const createBranch: RefUpdateCommand = {
|
|
322
|
+
* oldSha: ZERO_SHA,
|
|
323
|
+
* newSha: 'abc123...',
|
|
324
|
+
* refName: 'refs/heads/feature'
|
|
325
|
+
* }
|
|
326
|
+
*
|
|
327
|
+
* // Update existing branch
|
|
328
|
+
* const updateBranch: RefUpdateCommand = {
|
|
329
|
+
* oldSha: 'abc123...',
|
|
330
|
+
* newSha: 'def456...',
|
|
331
|
+
* refName: 'refs/heads/main'
|
|
332
|
+
* }
|
|
333
|
+
*
|
|
334
|
+
* // Delete a branch
|
|
335
|
+
* const deleteBranch: RefUpdateCommand = {
|
|
336
|
+
* oldSha: 'abc123...',
|
|
337
|
+
* newSha: ZERO_SHA,
|
|
338
|
+
* refName: 'refs/heads/old-feature'
|
|
339
|
+
* }
|
|
340
|
+
* ```
|
|
137
341
|
*/
|
|
138
342
|
export interface RefUpdateCommand {
|
|
139
|
-
/** Old SHA (
|
|
343
|
+
/** Old SHA (ZERO_SHA for create operations) */
|
|
140
344
|
oldSha: string;
|
|
141
|
-
/** New SHA (
|
|
345
|
+
/** New SHA (ZERO_SHA for delete operations) */
|
|
142
346
|
newSha: string;
|
|
143
|
-
/** Full ref name */
|
|
347
|
+
/** Full ref name (e.g., 'refs/heads/main') */
|
|
144
348
|
refName: string;
|
|
145
349
|
}
|
|
146
350
|
/**
|
|
147
|
-
* Result of receive-pack operation
|
|
351
|
+
* Result of receive-pack operation.
|
|
352
|
+
*
|
|
353
|
+
* @description
|
|
354
|
+
* Contains the overall success status and individual results for each
|
|
355
|
+
* ref update that was requested. Used to generate the status report
|
|
356
|
+
* sent back to the client.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const result: ReceivePackResult = {
|
|
361
|
+
* success: true,
|
|
362
|
+
* refResults: [
|
|
363
|
+
* { refName: 'refs/heads/main', success: true },
|
|
364
|
+
* { refName: 'refs/heads/feature', success: false, error: 'non-fast-forward' }
|
|
365
|
+
* ]
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
148
368
|
*/
|
|
149
369
|
export interface ReceivePackResult {
|
|
150
|
-
/** Whether the overall operation succeeded */
|
|
370
|
+
/** Whether the overall operation succeeded (all refs updated successfully) */
|
|
151
371
|
success: boolean;
|
|
152
372
|
/** Individual ref update results */
|
|
153
373
|
refResults: Array<{
|
|
374
|
+
/** The ref that was being updated */
|
|
154
375
|
refName: string;
|
|
376
|
+
/** Whether this specific ref update succeeded */
|
|
155
377
|
success: boolean;
|
|
378
|
+
/** Error message if the update failed */
|
|
156
379
|
error?: string;
|
|
157
380
|
}>;
|
|
158
381
|
}
|
|
159
382
|
/**
|
|
160
|
-
* Content-Type for git-upload-pack advertisement
|
|
383
|
+
* Content-Type for git-upload-pack advertisement response.
|
|
384
|
+
* @see {@link https://git-scm.com/docs/http-protocol#_smart_server_response}
|
|
161
385
|
*/
|
|
162
386
|
export declare const CONTENT_TYPE_UPLOAD_PACK_ADVERTISEMENT = "application/x-git-upload-pack-advertisement";
|
|
163
387
|
/**
|
|
164
|
-
* Content-Type for git-receive-pack advertisement
|
|
388
|
+
* Content-Type for git-receive-pack advertisement response.
|
|
389
|
+
* @see {@link https://git-scm.com/docs/http-protocol#_smart_server_response}
|
|
165
390
|
*/
|
|
166
391
|
export declare const CONTENT_TYPE_RECEIVE_PACK_ADVERTISEMENT = "application/x-git-receive-pack-advertisement";
|
|
167
392
|
/**
|
|
168
|
-
* Content-Type for git-upload-pack request
|
|
393
|
+
* Content-Type for git-upload-pack request body.
|
|
169
394
|
*/
|
|
170
395
|
export declare const CONTENT_TYPE_UPLOAD_PACK_REQUEST = "application/x-git-upload-pack-request";
|
|
171
396
|
/**
|
|
172
|
-
* Content-Type for git-upload-pack
|
|
397
|
+
* Content-Type for git-upload-pack response body.
|
|
173
398
|
*/
|
|
174
399
|
export declare const CONTENT_TYPE_UPLOAD_PACK_RESULT = "application/x-git-upload-pack-result";
|
|
175
400
|
/**
|
|
176
|
-
* Content-Type for git-receive-pack request
|
|
401
|
+
* Content-Type for git-receive-pack request body.
|
|
177
402
|
*/
|
|
178
403
|
export declare const CONTENT_TYPE_RECEIVE_PACK_REQUEST = "application/x-git-receive-pack-request";
|
|
179
404
|
/**
|
|
180
|
-
* Content-Type for git-receive-pack
|
|
405
|
+
* Content-Type for git-receive-pack response body.
|
|
181
406
|
*/
|
|
182
407
|
export declare const CONTENT_TYPE_RECEIVE_PACK_RESULT = "application/x-git-receive-pack-result";
|
|
183
408
|
/**
|
|
184
|
-
* Zero SHA constant used for ref creation/deletion
|
|
409
|
+
* Zero SHA constant used for ref creation/deletion.
|
|
410
|
+
*
|
|
411
|
+
* @description
|
|
412
|
+
* This 40-character string of zeros is used as a placeholder SHA:
|
|
413
|
+
* - In oldSha: indicates a ref is being created (doesn't exist yet)
|
|
414
|
+
* - In newSha: indicates a ref is being deleted
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* // Check if this is a create operation
|
|
419
|
+
* const isCreate = command.oldSha === ZERO_SHA
|
|
420
|
+
*
|
|
421
|
+
* // Check if this is a delete operation
|
|
422
|
+
* const isDelete = command.newSha === ZERO_SHA
|
|
423
|
+
* ```
|
|
185
424
|
*/
|
|
186
425
|
export declare const ZERO_SHA = "0000000000000000000000000000000000000000";
|
|
187
426
|
/**
|
|
188
427
|
* Handle GET /info/refs requests for ref discovery.
|
|
189
428
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
429
|
+
* @description
|
|
430
|
+
* This is the first endpoint called by git clients when initiating a fetch
|
|
431
|
+
* or push operation. It returns:
|
|
432
|
+
* 1. The service being requested
|
|
433
|
+
* 2. A list of all refs with their current SHA values
|
|
434
|
+
* 3. Server capabilities on the first ref line
|
|
435
|
+
*
|
|
436
|
+
* The response format is pkt-line encoded for compatibility with Git's
|
|
437
|
+
* smart HTTP protocol.
|
|
192
438
|
*
|
|
193
439
|
* @param request - The incoming HTTP request
|
|
194
440
|
* @param repository - Repository provider for fetching refs
|
|
195
|
-
* @param capabilities -
|
|
196
|
-
* @returns HTTP response with ref advertisement
|
|
197
|
-
*
|
|
441
|
+
* @param capabilities - Optional server capabilities to advertise
|
|
442
|
+
* @returns Promise resolving to HTTP response with ref advertisement
|
|
443
|
+
*
|
|
444
|
+
* @throws {SmartHTTPError} 400 if service parameter is missing or invalid
|
|
445
|
+
* @throws {SmartHTTPError} 403 if permission is denied
|
|
446
|
+
* @throws {SmartHTTPError} 404 if repository does not exist
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* // Handle ref discovery request
|
|
451
|
+
* const request: SmartHTTPRequest = {
|
|
452
|
+
* method: 'GET',
|
|
453
|
+
* path: '/info/refs',
|
|
454
|
+
* query: { service: 'git-upload-pack' },
|
|
455
|
+
* headers: {},
|
|
456
|
+
* repository: 'my-repo'
|
|
457
|
+
* }
|
|
458
|
+
*
|
|
459
|
+
* const capabilities: ServerCapabilities = {
|
|
460
|
+
* sideBand64k: true,
|
|
461
|
+
* thinPack: true
|
|
462
|
+
* }
|
|
463
|
+
*
|
|
464
|
+
* const response = await handleInfoRefs(request, repoProvider, capabilities)
|
|
465
|
+
* // response.status === 200
|
|
466
|
+
* // response.headers['Content-Type'] === 'application/x-git-upload-pack-advertisement'
|
|
467
|
+
* ```
|
|
198
468
|
*/
|
|
199
469
|
export declare function handleInfoRefs(request: SmartHTTPRequest, repository: RepositoryProvider, capabilities?: ServerCapabilities): Promise<SmartHTTPResponse>;
|
|
200
470
|
/**
|
|
201
471
|
* Handle POST /git-upload-pack requests for fetch data transfer.
|
|
202
472
|
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
473
|
+
* @description
|
|
474
|
+
* This endpoint processes fetch requests from git clients. It:
|
|
475
|
+
* 1. Parses the client's wants (objects they need) and haves (objects they have)
|
|
476
|
+
* 2. Negotiates which objects need to be sent
|
|
477
|
+
* 3. Generates and returns a packfile containing the required objects
|
|
478
|
+
*
|
|
479
|
+
* The response includes ACK/NAK lines followed by the packfile data,
|
|
480
|
+
* optionally wrapped in side-band format for progress reporting.
|
|
205
481
|
*
|
|
206
482
|
* @param request - The incoming HTTP request with wants/haves
|
|
207
483
|
* @param repository - Repository provider for creating packfile
|
|
208
|
-
* @returns HTTP response with packfile data
|
|
209
|
-
*
|
|
484
|
+
* @returns Promise resolving to HTTP response with packfile data
|
|
485
|
+
*
|
|
486
|
+
* @throws {SmartHTTPError} 400 if request body is missing or malformed
|
|
487
|
+
* @throws {SmartHTTPError} 403 if permission is denied
|
|
488
|
+
* @throws {SmartHTTPError} 415 if content type is invalid
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```typescript
|
|
492
|
+
* // Handle fetch request
|
|
493
|
+
* const request: SmartHTTPRequest = {
|
|
494
|
+
* method: 'POST',
|
|
495
|
+
* path: '/git-upload-pack',
|
|
496
|
+
* query: {},
|
|
497
|
+
* headers: { 'Content-Type': 'application/x-git-upload-pack-request' },
|
|
498
|
+
* body: requestBody, // pkt-line encoded wants/haves
|
|
499
|
+
* repository: 'my-repo'
|
|
500
|
+
* }
|
|
501
|
+
*
|
|
502
|
+
* const response = await handleUploadPack(request, repoProvider)
|
|
503
|
+
* // response.body contains NAK + packfile data
|
|
504
|
+
* ```
|
|
210
505
|
*/
|
|
211
506
|
export declare function handleUploadPack(request: SmartHTTPRequest, repository: RepositoryProvider): Promise<SmartHTTPResponse>;
|
|
212
507
|
/**
|
|
213
508
|
* Handle POST /git-receive-pack requests for push data transfer.
|
|
214
509
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
510
|
+
* @description
|
|
511
|
+
* This endpoint processes push requests from git clients. It:
|
|
512
|
+
* 1. Parses ref update commands (create, update, delete)
|
|
513
|
+
* 2. Extracts and validates the incoming packfile
|
|
514
|
+
* 3. Applies ref updates (if packfile is valid)
|
|
515
|
+
* 4. Returns a status report (if report-status capability was requested)
|
|
516
|
+
*
|
|
517
|
+
* The response includes unpack status and individual ref update results.
|
|
217
518
|
*
|
|
218
519
|
* @param request - The incoming HTTP request with commands and packfile
|
|
219
520
|
* @param repository - Repository provider for processing push
|
|
220
|
-
* @returns HTTP response with status report
|
|
221
|
-
*
|
|
521
|
+
* @returns Promise resolving to HTTP response with status report
|
|
522
|
+
*
|
|
523
|
+
* @throws {SmartHTTPError} 400 if request body is missing or malformed
|
|
524
|
+
* @throws {SmartHTTPError} 403 if permission is denied
|
|
525
|
+
* @throws {SmartHTTPError} 415 if content type is invalid
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```typescript
|
|
529
|
+
* // Handle push request
|
|
530
|
+
* const request: SmartHTTPRequest = {
|
|
531
|
+
* method: 'POST',
|
|
532
|
+
* path: '/git-receive-pack',
|
|
533
|
+
* query: {},
|
|
534
|
+
* headers: { 'Content-Type': 'application/x-git-receive-pack-request' },
|
|
535
|
+
* body: requestBody, // commands + packfile
|
|
536
|
+
* repository: 'my-repo'
|
|
537
|
+
* }
|
|
538
|
+
*
|
|
539
|
+
* const response = await handleReceivePack(request, repoProvider)
|
|
540
|
+
* // response.body contains "unpack ok" + ref status lines
|
|
541
|
+
* ```
|
|
222
542
|
*/
|
|
223
543
|
export declare function handleReceivePack(request: SmartHTTPRequest, repository: RepositoryProvider): Promise<SmartHTTPResponse>;
|
|
224
544
|
/**
|
|
225
545
|
* Format ref advertisement for info/refs response.
|
|
226
546
|
*
|
|
227
|
-
*
|
|
228
|
-
* -
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
547
|
+
* @description
|
|
548
|
+
* Creates a pkt-line formatted ref advertisement that includes:
|
|
549
|
+
* 1. Service announcement line (e.g., "# service=git-upload-pack")
|
|
550
|
+
* 2. Flush packet
|
|
551
|
+
* 3. First ref with capabilities (or zero SHA for empty repos)
|
|
552
|
+
* 4. Remaining refs
|
|
553
|
+
* 5. Peeled refs for annotated tags
|
|
554
|
+
* 6. Final flush packet
|
|
232
555
|
*
|
|
233
556
|
* @param service - The git service (git-upload-pack or git-receive-pack)
|
|
234
557
|
* @param refs - Array of refs to advertise
|
|
235
|
-
* @param capabilities -
|
|
558
|
+
* @param capabilities - Optional server capabilities to include
|
|
236
559
|
* @returns Formatted ref advertisement as Uint8Array
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```typescript
|
|
563
|
+
* const refs: GitRef[] = [
|
|
564
|
+
* { sha: 'abc123...', name: 'refs/heads/main' },
|
|
565
|
+
* { sha: 'def456...', name: 'refs/heads/feature' }
|
|
566
|
+
* ]
|
|
567
|
+
*
|
|
568
|
+
* const advertisement = formatRefAdvertisement(
|
|
569
|
+
* 'git-upload-pack',
|
|
570
|
+
* refs,
|
|
571
|
+
* { sideBand64k: true, thinPack: true }
|
|
572
|
+
* )
|
|
573
|
+
* ```
|
|
237
574
|
*/
|
|
238
575
|
export declare function formatRefAdvertisement(service: GitService, refs: GitRef[], capabilities?: ServerCapabilities): Uint8Array;
|
|
239
576
|
/**
|
|
240
577
|
* Parse upload-pack request body.
|
|
241
578
|
*
|
|
579
|
+
* @description
|
|
242
580
|
* Extracts wants, haves, and capabilities from the pkt-line formatted
|
|
243
|
-
* request body sent by git fetch.
|
|
581
|
+
* request body sent by git fetch. The format is:
|
|
582
|
+
* 1. Want lines: "want <sha> [capabilities]" (caps only on first)
|
|
583
|
+
* 2. Shallow/filter commands (optional)
|
|
584
|
+
* 3. Flush packet
|
|
585
|
+
* 4. Have lines: "have <sha>"
|
|
586
|
+
* 5. "done" line (or flush for multi_ack)
|
|
244
587
|
*
|
|
245
588
|
* @param body - Request body as Uint8Array
|
|
246
|
-
* @returns Parsed wants, haves, and
|
|
589
|
+
* @returns Parsed wants, haves, capabilities, and done flag
|
|
590
|
+
*
|
|
591
|
+
* @throws {Error} If the request is malformed (invalid pkt-line format)
|
|
592
|
+
*
|
|
593
|
+
* @example
|
|
594
|
+
* ```typescript
|
|
595
|
+
* const body = encoder.encode(
|
|
596
|
+
* '0032want abc123... side-band-64k\n' +
|
|
597
|
+
* '0000' +
|
|
598
|
+
* '0032have def456...\n' +
|
|
599
|
+
* '0009done\n'
|
|
600
|
+
* )
|
|
601
|
+
*
|
|
602
|
+
* const { wants, haves, capabilities, done } = parseUploadPackRequest(body)
|
|
603
|
+
* // wants = ['abc123...']
|
|
604
|
+
* // haves = ['def456...']
|
|
605
|
+
* // capabilities = ['side-band-64k']
|
|
606
|
+
* // done = true
|
|
607
|
+
* ```
|
|
247
608
|
*/
|
|
248
609
|
export declare function parseUploadPackRequest(body: Uint8Array): {
|
|
249
610
|
wants: string[];
|
|
@@ -254,11 +615,32 @@ export declare function parseUploadPackRequest(body: Uint8Array): {
|
|
|
254
615
|
/**
|
|
255
616
|
* Parse receive-pack request body.
|
|
256
617
|
*
|
|
618
|
+
* @description
|
|
257
619
|
* Extracts ref update commands, capabilities, and packfile data from
|
|
258
|
-
* the request body sent by git push.
|
|
620
|
+
* the request body sent by git push. The format is:
|
|
621
|
+
* 1. Command lines: "<old-sha> <new-sha> <refname>" (caps on first via NUL)
|
|
622
|
+
* 2. Flush packet
|
|
623
|
+
* 3. Push options (optional, if push-options capability)
|
|
624
|
+
* 4. Flush packet (if push options present)
|
|
625
|
+
* 5. PACK data (packfile)
|
|
259
626
|
*
|
|
260
627
|
* @param body - Request body as Uint8Array
|
|
261
628
|
* @returns Parsed commands, capabilities, and packfile
|
|
629
|
+
*
|
|
630
|
+
* @throws {Error} If the request is malformed
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```typescript
|
|
634
|
+
* const body = encoder.encode(
|
|
635
|
+
* '0077' + ZERO_SHA + ' abc123... refs/heads/new\0report-status\n' +
|
|
636
|
+
* '0000' +
|
|
637
|
+
* 'PACK...' // packfile data
|
|
638
|
+
* )
|
|
639
|
+
*
|
|
640
|
+
* const { commands, capabilities, packfile } = parseReceivePackRequest(body)
|
|
641
|
+
* // commands = [{ oldSha: ZERO_SHA, newSha: 'abc123...', refName: 'refs/heads/new' }]
|
|
642
|
+
* // capabilities = ['report-status']
|
|
643
|
+
* ```
|
|
262
644
|
*/
|
|
263
645
|
export declare function parseReceivePackRequest(body: Uint8Array): {
|
|
264
646
|
commands: RefUpdateCommand[];
|
|
@@ -268,54 +650,150 @@ export declare function parseReceivePackRequest(body: Uint8Array): {
|
|
|
268
650
|
/**
|
|
269
651
|
* Format upload-pack response.
|
|
270
652
|
*
|
|
653
|
+
* @description
|
|
271
654
|
* Creates the response body for git-upload-pack POST request,
|
|
272
655
|
* including NAK/ACK responses and packfile data with optional sideband.
|
|
656
|
+
* The response format is:
|
|
657
|
+
* 1. NAK or ACK lines (based on negotiation)
|
|
658
|
+
* 2. Packfile data (optionally wrapped in side-band)
|
|
659
|
+
* 3. Flush packet
|
|
273
660
|
*
|
|
274
661
|
* @param packData - The packfile data to send
|
|
275
|
-
* @param useSideBand - Whether to use side-band encoding
|
|
662
|
+
* @param useSideBand - Whether to use side-band encoding (channel 1 for data)
|
|
276
663
|
* @param hasCommonObjects - Whether there are common objects (for ACK vs NAK)
|
|
277
|
-
* @param haves - The have SHAs from the client
|
|
664
|
+
* @param haves - The have SHAs from the client (first one is ACKed if common)
|
|
278
665
|
* @returns Formatted response as Uint8Array
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```typescript
|
|
669
|
+
* // Simple NAK response with packfile
|
|
670
|
+
* const response = formatUploadPackResponse(packData, false, false, [])
|
|
671
|
+
*
|
|
672
|
+
* // Side-band response with ACK
|
|
673
|
+
* const response = formatUploadPackResponse(
|
|
674
|
+
* packData,
|
|
675
|
+
* true,
|
|
676
|
+
* true,
|
|
677
|
+
* ['abc123...']
|
|
678
|
+
* )
|
|
679
|
+
* ```
|
|
279
680
|
*/
|
|
280
681
|
export declare function formatUploadPackResponse(packData: Uint8Array, useSideBand?: boolean, hasCommonObjects?: boolean, haves?: string[]): Uint8Array;
|
|
281
682
|
/**
|
|
282
683
|
* Format receive-pack response.
|
|
283
684
|
*
|
|
685
|
+
* @description
|
|
284
686
|
* Creates the response body for git-receive-pack POST request,
|
|
285
|
-
* including unpack status and ref update results.
|
|
687
|
+
* including unpack status and ref update results. The format is:
|
|
688
|
+
* 1. Unpack status line: "unpack ok" or "unpack error"
|
|
689
|
+
* 2. Ref status lines: "ok <refname>" or "ng <refname> <error>"
|
|
690
|
+
* 3. Flush packet
|
|
286
691
|
*
|
|
287
692
|
* @param result - Result of the receive-pack operation
|
|
288
693
|
* @returns Formatted response as Uint8Array
|
|
694
|
+
*
|
|
695
|
+
* @example
|
|
696
|
+
* ```typescript
|
|
697
|
+
* const result: ReceivePackResult = {
|
|
698
|
+
* success: true,
|
|
699
|
+
* refResults: [
|
|
700
|
+
* { refName: 'refs/heads/main', success: true },
|
|
701
|
+
* { refName: 'refs/heads/feature', success: false, error: 'non-fast-forward' }
|
|
702
|
+
* ]
|
|
703
|
+
* }
|
|
704
|
+
*
|
|
705
|
+
* const response = formatReceivePackResponse(result)
|
|
706
|
+
* // "unpack ok\nok refs/heads/main\nng refs/heads/feature non-fast-forward\n0000"
|
|
707
|
+
* ```
|
|
289
708
|
*/
|
|
290
709
|
export declare function formatReceivePackResponse(result: ReceivePackResult): Uint8Array;
|
|
291
710
|
/**
|
|
292
711
|
* Convert ServerCapabilities to capability string list.
|
|
293
712
|
*
|
|
713
|
+
* @description
|
|
714
|
+
* Converts the ServerCapabilities object into an array of capability
|
|
715
|
+
* strings suitable for inclusion in ref advertisements. Boolean capabilities
|
|
716
|
+
* become simple strings, while capabilities with values become "name=value".
|
|
717
|
+
*
|
|
294
718
|
* @param capabilities - Server capabilities object
|
|
295
719
|
* @returns Array of capability strings
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```typescript
|
|
723
|
+
* const caps: ServerCapabilities = {
|
|
724
|
+
* sideBand64k: true,
|
|
725
|
+
* thinPack: true,
|
|
726
|
+
* agent: 'my-server/1.0'
|
|
727
|
+
* }
|
|
728
|
+
*
|
|
729
|
+
* const strings = capabilitiesToStrings(caps)
|
|
730
|
+
* // ['side-band-64k', 'thin-pack', 'agent=my-server/1.0']
|
|
731
|
+
* ```
|
|
296
732
|
*/
|
|
297
733
|
export declare function capabilitiesToStrings(capabilities: ServerCapabilities): string[];
|
|
298
734
|
/**
|
|
299
735
|
* Parse capability strings into ServerCapabilities object.
|
|
300
736
|
*
|
|
737
|
+
* @description
|
|
738
|
+
* Converts an array of capability strings (as received from a client or
|
|
739
|
+
* server) into a structured ServerCapabilities object for easier access.
|
|
740
|
+
*
|
|
301
741
|
* @param capStrings - Array of capability strings
|
|
302
742
|
* @returns Parsed capabilities object
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* ```typescript
|
|
746
|
+
* const strings = ['side-band-64k', 'thin-pack', 'agent=git/2.30.0']
|
|
747
|
+
* const caps = parseCapabilities(strings)
|
|
748
|
+
* // caps.sideBand64k === true
|
|
749
|
+
* // caps.thinPack === true
|
|
750
|
+
* // caps.agent === 'git/2.30.0'
|
|
751
|
+
* ```
|
|
303
752
|
*/
|
|
304
753
|
export declare function parseCapabilities(capStrings: string[]): ServerCapabilities;
|
|
305
754
|
/**
|
|
306
755
|
* Validate Content-Type header for a request.
|
|
307
756
|
*
|
|
308
|
-
* @
|
|
757
|
+
* @description
|
|
758
|
+
* Compares the provided Content-Type header against an expected value,
|
|
759
|
+
* handling case-insensitivity and stripping charset or other parameters.
|
|
760
|
+
*
|
|
761
|
+
* @param contentType - The Content-Type header value from the request
|
|
309
762
|
* @param expectedType - The expected Content-Type
|
|
310
|
-
* @returns true if
|
|
763
|
+
* @returns true if the content type matches, false otherwise
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
* ```typescript
|
|
767
|
+
* validateContentType(
|
|
768
|
+
* 'application/x-git-upload-pack-request; charset=utf-8',
|
|
769
|
+
* 'application/x-git-upload-pack-request'
|
|
770
|
+
* )
|
|
771
|
+
* // Returns true
|
|
772
|
+
*
|
|
773
|
+
* validateContentType('text/plain', 'application/x-git-upload-pack-request')
|
|
774
|
+
* // Returns false
|
|
775
|
+
* ```
|
|
311
776
|
*/
|
|
312
777
|
export declare function validateContentType(contentType: string | undefined, expectedType: string): boolean;
|
|
313
778
|
/**
|
|
314
779
|
* Create an error response with appropriate status code and message.
|
|
315
780
|
*
|
|
316
|
-
* @
|
|
317
|
-
*
|
|
318
|
-
*
|
|
781
|
+
* @description
|
|
782
|
+
* Helper function to create a properly formatted error response with
|
|
783
|
+
* the correct HTTP status code, status text, and plain text body.
|
|
784
|
+
*
|
|
785
|
+
* @param statusCode - HTTP status code (e.g., 400, 403, 404)
|
|
786
|
+
* @param message - Error message to include in the response body
|
|
787
|
+
* @returns SmartHTTPResponse with error information
|
|
788
|
+
*
|
|
789
|
+
* @example
|
|
790
|
+
* ```typescript
|
|
791
|
+
* const response = createErrorResponse(404, 'Repository not found')
|
|
792
|
+
* // response.status === 404
|
|
793
|
+
* // response.statusText === 'Not Found'
|
|
794
|
+
* // response.headers['Content-Type'] === 'text/plain'
|
|
795
|
+
* // response.body contains 'Repository not found'
|
|
796
|
+
* ```
|
|
319
797
|
*/
|
|
320
798
|
export declare function createErrorResponse(statusCode: number, message: string): SmartHTTPResponse;
|
|
321
799
|
//# sourceMappingURL=smart-http.d.ts.map
|