gitx.do 0.1.0 → 0.1.2
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/README.md +40 -353
- package/dist/do/logger.d.ts +50 -0
- package/dist/do/logger.d.ts.map +1 -0
- package/dist/do/logger.js +122 -0
- package/dist/do/logger.js.map +1 -0
- package/dist/{durable-object → do}/schema.d.ts +3 -3
- package/dist/do/schema.d.ts.map +1 -0
- package/dist/{durable-object → do}/schema.js +4 -3
- package/dist/do/schema.js.map +1 -0
- package/dist/do/types.d.ts +267 -0
- package/dist/do/types.d.ts.map +1 -0
- package/dist/do/types.js +62 -0
- package/dist/do/types.js.map +1 -0
- package/dist/index.d.ts +15 -415
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -483
- package/dist/index.js.map +1 -1
- package/package.json +13 -21
- package/dist/cli/commands/add.d.ts +0 -174
- package/dist/cli/commands/add.d.ts.map +0 -1
- package/dist/cli/commands/add.js +0 -131
- package/dist/cli/commands/add.js.map +0 -1
- package/dist/cli/commands/blame.d.ts +0 -259
- package/dist/cli/commands/blame.d.ts.map +0 -1
- package/dist/cli/commands/blame.js +0 -609
- package/dist/cli/commands/blame.js.map +0 -1
- package/dist/cli/commands/branch.d.ts +0 -249
- package/dist/cli/commands/branch.d.ts.map +0 -1
- package/dist/cli/commands/branch.js +0 -693
- package/dist/cli/commands/branch.js.map +0 -1
- package/dist/cli/commands/commit.d.ts +0 -182
- package/dist/cli/commands/commit.d.ts.map +0 -1
- package/dist/cli/commands/commit.js +0 -437
- package/dist/cli/commands/commit.js.map +0 -1
- package/dist/cli/commands/diff.d.ts +0 -464
- package/dist/cli/commands/diff.d.ts.map +0 -1
- package/dist/cli/commands/diff.js +0 -958
- package/dist/cli/commands/diff.js.map +0 -1
- package/dist/cli/commands/log.d.ts +0 -239
- package/dist/cli/commands/log.d.ts.map +0 -1
- package/dist/cli/commands/log.js +0 -535
- package/dist/cli/commands/log.js.map +0 -1
- package/dist/cli/commands/merge.d.ts +0 -106
- package/dist/cli/commands/merge.d.ts.map +0 -1
- package/dist/cli/commands/merge.js +0 -55
- package/dist/cli/commands/merge.js.map +0 -1
- package/dist/cli/commands/review.d.ts +0 -457
- package/dist/cli/commands/review.d.ts.map +0 -1
- package/dist/cli/commands/review.js +0 -533
- package/dist/cli/commands/review.js.map +0 -1
- package/dist/cli/commands/status.d.ts +0 -269
- package/dist/cli/commands/status.d.ts.map +0 -1
- package/dist/cli/commands/status.js +0 -493
- package/dist/cli/commands/status.js.map +0 -1
- package/dist/cli/commands/web.d.ts +0 -199
- package/dist/cli/commands/web.d.ts.map +0 -1
- package/dist/cli/commands/web.js +0 -696
- package/dist/cli/commands/web.js.map +0 -1
- package/dist/cli/fs-adapter.d.ts +0 -656
- package/dist/cli/fs-adapter.d.ts.map +0 -1
- package/dist/cli/fs-adapter.js +0 -1179
- package/dist/cli/fs-adapter.js.map +0 -1
- package/dist/cli/fsx-cli-adapter.d.ts +0 -359
- package/dist/cli/fsx-cli-adapter.d.ts.map +0 -1
- package/dist/cli/fsx-cli-adapter.js +0 -619
- package/dist/cli/fsx-cli-adapter.js.map +0 -1
- package/dist/cli/index.d.ts +0 -387
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -523
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/ui/components/DiffView.d.ts +0 -7
- package/dist/cli/ui/components/DiffView.d.ts.map +0 -1
- package/dist/cli/ui/components/DiffView.js +0 -11
- package/dist/cli/ui/components/DiffView.js.map +0 -1
- package/dist/cli/ui/components/ErrorDisplay.d.ts +0 -6
- package/dist/cli/ui/components/ErrorDisplay.d.ts.map +0 -1
- package/dist/cli/ui/components/ErrorDisplay.js +0 -11
- package/dist/cli/ui/components/ErrorDisplay.js.map +0 -1
- package/dist/cli/ui/components/FuzzySearch.d.ts +0 -9
- package/dist/cli/ui/components/FuzzySearch.d.ts.map +0 -1
- package/dist/cli/ui/components/FuzzySearch.js +0 -12
- package/dist/cli/ui/components/FuzzySearch.js.map +0 -1
- package/dist/cli/ui/components/LoadingSpinner.d.ts +0 -6
- package/dist/cli/ui/components/LoadingSpinner.d.ts.map +0 -1
- package/dist/cli/ui/components/LoadingSpinner.js +0 -10
- package/dist/cli/ui/components/LoadingSpinner.js.map +0 -1
- package/dist/cli/ui/components/NavigationList.d.ts +0 -9
- package/dist/cli/ui/components/NavigationList.d.ts.map +0 -1
- package/dist/cli/ui/components/NavigationList.js +0 -11
- package/dist/cli/ui/components/NavigationList.js.map +0 -1
- package/dist/cli/ui/components/ScrollableContent.d.ts +0 -8
- package/dist/cli/ui/components/ScrollableContent.d.ts.map +0 -1
- package/dist/cli/ui/components/ScrollableContent.js +0 -11
- package/dist/cli/ui/components/ScrollableContent.js.map +0 -1
- package/dist/cli/ui/components/index.d.ts +0 -7
- package/dist/cli/ui/components/index.d.ts.map +0 -1
- package/dist/cli/ui/components/index.js +0 -9
- package/dist/cli/ui/components/index.js.map +0 -1
- package/dist/cli/ui/terminal-ui.d.ts +0 -52
- package/dist/cli/ui/terminal-ui.d.ts.map +0 -1
- package/dist/cli/ui/terminal-ui.js +0 -121
- package/dist/cli/ui/terminal-ui.js.map +0 -1
- package/dist/do/BashModule.d.ts +0 -871
- package/dist/do/BashModule.d.ts.map +0 -1
- package/dist/do/BashModule.js +0 -1143
- package/dist/do/BashModule.js.map +0 -1
- package/dist/do/FsModule.d.ts +0 -601
- package/dist/do/FsModule.d.ts.map +0 -1
- package/dist/do/FsModule.js +0 -1120
- package/dist/do/FsModule.js.map +0 -1
- package/dist/do/GitModule.d.ts +0 -635
- package/dist/do/GitModule.d.ts.map +0 -1
- package/dist/do/GitModule.js +0 -781
- package/dist/do/GitModule.js.map +0 -1
- package/dist/do/GitRepoDO.d.ts +0 -281
- package/dist/do/GitRepoDO.d.ts.map +0 -1
- package/dist/do/GitRepoDO.js +0 -479
- package/dist/do/GitRepoDO.js.map +0 -1
- package/dist/do/bash-ast.d.ts +0 -246
- package/dist/do/bash-ast.d.ts.map +0 -1
- package/dist/do/bash-ast.js +0 -888
- package/dist/do/bash-ast.js.map +0 -1
- package/dist/do/container-executor.d.ts +0 -491
- package/dist/do/container-executor.d.ts.map +0 -1
- package/dist/do/container-executor.js +0 -730
- package/dist/do/container-executor.js.map +0 -1
- package/dist/do/index.d.ts +0 -53
- package/dist/do/index.d.ts.map +0 -1
- package/dist/do/index.js +0 -91
- package/dist/do/index.js.map +0 -1
- package/dist/do/tiered-storage.d.ts +0 -403
- package/dist/do/tiered-storage.d.ts.map +0 -1
- package/dist/do/tiered-storage.js +0 -689
- package/dist/do/tiered-storage.js.map +0 -1
- package/dist/do/withBash.d.ts +0 -231
- package/dist/do/withBash.d.ts.map +0 -1
- package/dist/do/withBash.js +0 -244
- package/dist/do/withBash.js.map +0 -1
- package/dist/do/withFs.d.ts +0 -237
- package/dist/do/withFs.d.ts.map +0 -1
- package/dist/do/withFs.js +0 -387
- package/dist/do/withFs.js.map +0 -1
- package/dist/do/withGit.d.ts +0 -180
- package/dist/do/withGit.d.ts.map +0 -1
- package/dist/do/withGit.js +0 -271
- package/dist/do/withGit.js.map +0 -1
- package/dist/durable-object/object-store.d.ts +0 -633
- package/dist/durable-object/object-store.d.ts.map +0 -1
- package/dist/durable-object/object-store.js +0 -1161
- package/dist/durable-object/object-store.js.map +0 -1
- package/dist/durable-object/schema.d.ts.map +0 -1
- package/dist/durable-object/schema.js.map +0 -1
- package/dist/durable-object/wal.d.ts +0 -416
- package/dist/durable-object/wal.d.ts.map +0 -1
- package/dist/durable-object/wal.js +0 -445
- package/dist/durable-object/wal.js.map +0 -1
- package/dist/mcp/adapter.d.ts +0 -772
- package/dist/mcp/adapter.d.ts.map +0 -1
- package/dist/mcp/adapter.js +0 -895
- package/dist/mcp/adapter.js.map +0 -1
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts +0 -22
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +0 -1
- package/dist/mcp/sandbox/miniflare-evaluator.js +0 -140
- package/dist/mcp/sandbox/miniflare-evaluator.js.map +0 -1
- package/dist/mcp/sandbox/object-store-proxy.d.ts +0 -32
- package/dist/mcp/sandbox/object-store-proxy.d.ts.map +0 -1
- package/dist/mcp/sandbox/object-store-proxy.js +0 -30
- package/dist/mcp/sandbox/object-store-proxy.js.map +0 -1
- package/dist/mcp/sandbox/template.d.ts +0 -17
- package/dist/mcp/sandbox/template.d.ts.map +0 -1
- package/dist/mcp/sandbox/template.js +0 -71
- package/dist/mcp/sandbox/template.js.map +0 -1
- package/dist/mcp/sandbox.d.ts +0 -764
- package/dist/mcp/sandbox.d.ts.map +0 -1
- package/dist/mcp/sandbox.js +0 -1362
- package/dist/mcp/sandbox.js.map +0 -1
- package/dist/mcp/sdk-adapter.d.ts +0 -835
- package/dist/mcp/sdk-adapter.d.ts.map +0 -1
- package/dist/mcp/sdk-adapter.js +0 -974
- package/dist/mcp/sdk-adapter.js.map +0 -1
- package/dist/mcp/tools/do.d.ts +0 -32
- package/dist/mcp/tools/do.d.ts.map +0 -1
- package/dist/mcp/tools/do.js +0 -115
- package/dist/mcp/tools/do.js.map +0 -1
- package/dist/mcp/tools.d.ts +0 -548
- package/dist/mcp/tools.d.ts.map +0 -1
- package/dist/mcp/tools.js +0 -1934
- package/dist/mcp/tools.js.map +0 -1
- package/dist/ops/blame.d.ts +0 -551
- package/dist/ops/blame.d.ts.map +0 -1
- package/dist/ops/blame.js +0 -1037
- package/dist/ops/blame.js.map +0 -1
- package/dist/ops/branch.d.ts +0 -766
- package/dist/ops/branch.d.ts.map +0 -1
- package/dist/ops/branch.js +0 -950
- package/dist/ops/branch.js.map +0 -1
- package/dist/ops/commit-traversal.d.ts +0 -349
- package/dist/ops/commit-traversal.d.ts.map +0 -1
- package/dist/ops/commit-traversal.js +0 -821
- package/dist/ops/commit-traversal.js.map +0 -1
- package/dist/ops/commit.d.ts +0 -555
- package/dist/ops/commit.d.ts.map +0 -1
- package/dist/ops/commit.js +0 -826
- package/dist/ops/commit.js.map +0 -1
- package/dist/ops/merge-base.d.ts +0 -397
- package/dist/ops/merge-base.d.ts.map +0 -1
- package/dist/ops/merge-base.js +0 -691
- package/dist/ops/merge-base.js.map +0 -1
- package/dist/ops/merge.d.ts +0 -855
- package/dist/ops/merge.d.ts.map +0 -1
- package/dist/ops/merge.js +0 -1551
- package/dist/ops/merge.js.map +0 -1
- package/dist/ops/tag.d.ts +0 -247
- package/dist/ops/tag.d.ts.map +0 -1
- package/dist/ops/tag.js +0 -649
- package/dist/ops/tag.js.map +0 -1
- package/dist/ops/tree-builder.d.ts +0 -178
- package/dist/ops/tree-builder.d.ts.map +0 -1
- package/dist/ops/tree-builder.js +0 -271
- package/dist/ops/tree-builder.js.map +0 -1
- package/dist/ops/tree-diff.d.ts +0 -291
- package/dist/ops/tree-diff.d.ts.map +0 -1
- package/dist/ops/tree-diff.js +0 -705
- package/dist/ops/tree-diff.js.map +0 -1
- package/dist/pack/delta.d.ts +0 -248
- package/dist/pack/delta.d.ts.map +0 -1
- package/dist/pack/delta.js +0 -736
- package/dist/pack/delta.js.map +0 -1
- package/dist/pack/format.d.ts +0 -446
- package/dist/pack/format.d.ts.map +0 -1
- package/dist/pack/format.js +0 -572
- package/dist/pack/format.js.map +0 -1
- package/dist/pack/full-generation.d.ts +0 -612
- package/dist/pack/full-generation.d.ts.map +0 -1
- package/dist/pack/full-generation.js +0 -1378
- package/dist/pack/full-generation.js.map +0 -1
- package/dist/pack/generation.d.ts +0 -441
- package/dist/pack/generation.d.ts.map +0 -1
- package/dist/pack/generation.js +0 -707
- package/dist/pack/generation.js.map +0 -1
- package/dist/pack/index.d.ts +0 -502
- package/dist/pack/index.d.ts.map +0 -1
- package/dist/pack/index.js +0 -833
- package/dist/pack/index.js.map +0 -1
- package/dist/refs/branch.d.ts +0 -668
- package/dist/refs/branch.d.ts.map +0 -1
- package/dist/refs/branch.js +0 -897
- package/dist/refs/branch.js.map +0 -1
- package/dist/refs/storage.d.ts +0 -833
- package/dist/refs/storage.d.ts.map +0 -1
- package/dist/refs/storage.js +0 -1023
- package/dist/refs/storage.js.map +0 -1
- package/dist/refs/tag.d.ts +0 -860
- package/dist/refs/tag.d.ts.map +0 -1
- package/dist/refs/tag.js +0 -996
- package/dist/refs/tag.js.map +0 -1
- package/dist/storage/backend.d.ts +0 -425
- package/dist/storage/backend.d.ts.map +0 -1
- package/dist/storage/backend.js +0 -41
- package/dist/storage/backend.js.map +0 -1
- package/dist/storage/fsx-adapter.d.ts +0 -204
- package/dist/storage/fsx-adapter.d.ts.map +0 -1
- package/dist/storage/fsx-adapter.js +0 -470
- package/dist/storage/fsx-adapter.js.map +0 -1
- package/dist/storage/lru-cache.d.ts +0 -691
- package/dist/storage/lru-cache.d.ts.map +0 -1
- package/dist/storage/lru-cache.js +0 -813
- package/dist/storage/lru-cache.js.map +0 -1
- package/dist/storage/object-index.d.ts +0 -585
- package/dist/storage/object-index.d.ts.map +0 -1
- package/dist/storage/object-index.js +0 -532
- package/dist/storage/object-index.js.map +0 -1
- package/dist/storage/r2-pack.d.ts +0 -1257
- package/dist/storage/r2-pack.d.ts.map +0 -1
- package/dist/storage/r2-pack.js +0 -1770
- package/dist/storage/r2-pack.js.map +0 -1
- package/dist/tiered/cdc-pipeline.d.ts +0 -1888
- package/dist/tiered/cdc-pipeline.d.ts.map +0 -1
- package/dist/tiered/cdc-pipeline.js +0 -1880
- package/dist/tiered/cdc-pipeline.js.map +0 -1
- package/dist/tiered/migration.d.ts +0 -1104
- package/dist/tiered/migration.d.ts.map +0 -1
- package/dist/tiered/migration.js +0 -1214
- package/dist/tiered/migration.js.map +0 -1
- package/dist/tiered/parquet-writer.d.ts +0 -1145
- package/dist/tiered/parquet-writer.d.ts.map +0 -1
- package/dist/tiered/parquet-writer.js +0 -1183
- package/dist/tiered/parquet-writer.js.map +0 -1
- package/dist/tiered/read-path.d.ts +0 -835
- package/dist/tiered/read-path.d.ts.map +0 -1
- package/dist/tiered/read-path.js +0 -487
- package/dist/tiered/read-path.js.map +0 -1
- package/dist/types/capability.d.ts +0 -1385
- package/dist/types/capability.d.ts.map +0 -1
- package/dist/types/capability.js +0 -36
- package/dist/types/capability.js.map +0 -1
- package/dist/types/index.d.ts +0 -13
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -18
- package/dist/types/index.js.map +0 -1
- package/dist/types/objects.d.ts +0 -692
- package/dist/types/objects.d.ts.map +0 -1
- package/dist/types/objects.js +0 -837
- package/dist/types/objects.js.map +0 -1
- package/dist/types/storage.d.ts +0 -603
- package/dist/types/storage.d.ts.map +0 -1
- package/dist/types/storage.js +0 -191
- package/dist/types/storage.js.map +0 -1
- package/dist/types/worker-loader.d.ts +0 -60
- package/dist/types/worker-loader.d.ts.map +0 -1
- package/dist/types/worker-loader.js +0 -62
- package/dist/types/worker-loader.js.map +0 -1
- package/dist/utils/hash.d.ts +0 -197
- package/dist/utils/hash.d.ts.map +0 -1
- package/dist/utils/hash.js +0 -268
- package/dist/utils/hash.js.map +0 -1
- package/dist/utils/sha1.d.ts +0 -290
- package/dist/utils/sha1.d.ts.map +0 -1
- package/dist/utils/sha1.js +0 -582
- package/dist/utils/sha1.js.map +0 -1
- package/dist/wire/capabilities.d.ts +0 -1044
- package/dist/wire/capabilities.d.ts.map +0 -1
- package/dist/wire/capabilities.js +0 -941
- package/dist/wire/capabilities.js.map +0 -1
- package/dist/wire/path-security.d.ts +0 -157
- package/dist/wire/path-security.d.ts.map +0 -1
- package/dist/wire/path-security.js +0 -307
- package/dist/wire/path-security.js.map +0 -1
- package/dist/wire/pkt-line.d.ts +0 -345
- package/dist/wire/pkt-line.d.ts.map +0 -1
- package/dist/wire/pkt-line.js +0 -381
- package/dist/wire/pkt-line.js.map +0 -1
- package/dist/wire/receive-pack.d.ts +0 -1059
- package/dist/wire/receive-pack.d.ts.map +0 -1
- package/dist/wire/receive-pack.js +0 -1414
- package/dist/wire/receive-pack.js.map +0 -1
- package/dist/wire/smart-http.d.ts +0 -799
- package/dist/wire/smart-http.d.ts.map +0 -1
- package/dist/wire/smart-http.js +0 -945
- package/dist/wire/smart-http.js.map +0 -1
- package/dist/wire/upload-pack.d.ts +0 -727
- package/dist/wire/upload-pack.d.ts.map +0 -1
- package/dist/wire/upload-pack.js +0 -1138
- package/dist/wire/upload-pack.js.map +0 -1
package/dist/wire/smart-http.js
DELETED
|
@@ -1,945 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Git Smart HTTP Protocol Implementation
|
|
3
|
-
*
|
|
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:
|
|
6
|
-
*
|
|
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
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
import { encodePktLine, pktLineStream, FLUSH_PKT } from './pkt-line';
|
|
39
|
-
/**
|
|
40
|
-
* Content-Type for git-upload-pack advertisement response.
|
|
41
|
-
* @see {@link https://git-scm.com/docs/http-protocol#_smart_server_response}
|
|
42
|
-
*/
|
|
43
|
-
export const CONTENT_TYPE_UPLOAD_PACK_ADVERTISEMENT = 'application/x-git-upload-pack-advertisement';
|
|
44
|
-
/**
|
|
45
|
-
* Content-Type for git-receive-pack advertisement response.
|
|
46
|
-
* @see {@link https://git-scm.com/docs/http-protocol#_smart_server_response}
|
|
47
|
-
*/
|
|
48
|
-
export const CONTENT_TYPE_RECEIVE_PACK_ADVERTISEMENT = 'application/x-git-receive-pack-advertisement';
|
|
49
|
-
/**
|
|
50
|
-
* Content-Type for git-upload-pack request body.
|
|
51
|
-
*/
|
|
52
|
-
export const CONTENT_TYPE_UPLOAD_PACK_REQUEST = 'application/x-git-upload-pack-request';
|
|
53
|
-
/**
|
|
54
|
-
* Content-Type for git-upload-pack response body.
|
|
55
|
-
*/
|
|
56
|
-
export const CONTENT_TYPE_UPLOAD_PACK_RESULT = 'application/x-git-upload-pack-result';
|
|
57
|
-
/**
|
|
58
|
-
* Content-Type for git-receive-pack request body.
|
|
59
|
-
*/
|
|
60
|
-
export const CONTENT_TYPE_RECEIVE_PACK_REQUEST = 'application/x-git-receive-pack-request';
|
|
61
|
-
/**
|
|
62
|
-
* Content-Type for git-receive-pack response body.
|
|
63
|
-
*/
|
|
64
|
-
export const CONTENT_TYPE_RECEIVE_PACK_RESULT = 'application/x-git-receive-pack-result';
|
|
65
|
-
/**
|
|
66
|
-
* Zero SHA constant used for ref creation/deletion.
|
|
67
|
-
*
|
|
68
|
-
* @description
|
|
69
|
-
* This 40-character string of zeros is used as a placeholder SHA:
|
|
70
|
-
* - In oldSha: indicates a ref is being created (doesn't exist yet)
|
|
71
|
-
* - In newSha: indicates a ref is being deleted
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* // Check if this is a create operation
|
|
76
|
-
* const isCreate = command.oldSha === ZERO_SHA
|
|
77
|
-
*
|
|
78
|
-
* // Check if this is a delete operation
|
|
79
|
-
* const isDelete = command.newSha === ZERO_SHA
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export const ZERO_SHA = '0000000000000000000000000000000000000000';
|
|
83
|
-
const encoder = new TextEncoder();
|
|
84
|
-
const decoder = new TextDecoder();
|
|
85
|
-
/**
|
|
86
|
-
* Get HTTP status text from status code.
|
|
87
|
-
*
|
|
88
|
-
* @param statusCode - HTTP status code
|
|
89
|
-
* @returns Human-readable status text
|
|
90
|
-
*
|
|
91
|
-
* @internal
|
|
92
|
-
*/
|
|
93
|
-
function getStatusText(statusCode) {
|
|
94
|
-
const statusTexts = {
|
|
95
|
-
200: 'OK',
|
|
96
|
-
400: 'Bad Request',
|
|
97
|
-
401: 'Unauthorized',
|
|
98
|
-
403: 'Forbidden',
|
|
99
|
-
404: 'Not Found',
|
|
100
|
-
415: 'Unsupported Media Type',
|
|
101
|
-
500: 'Internal Server Error',
|
|
102
|
-
};
|
|
103
|
-
return statusTexts[statusCode] || 'Unknown';
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Check if a string is a valid SHA-1 hex string (40 characters).
|
|
107
|
-
*
|
|
108
|
-
* @param sha - String to validate
|
|
109
|
-
* @returns true if the string is a valid SHA-1 hash
|
|
110
|
-
*
|
|
111
|
-
* @internal
|
|
112
|
-
*/
|
|
113
|
-
function isValidSha(sha) {
|
|
114
|
-
return /^[0-9a-f]{40}$/i.test(sha);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Handle GET /info/refs requests for ref discovery.
|
|
118
|
-
*
|
|
119
|
-
* @description
|
|
120
|
-
* This is the first endpoint called by git clients when initiating a fetch
|
|
121
|
-
* or push operation. It returns:
|
|
122
|
-
* 1. The service being requested
|
|
123
|
-
* 2. A list of all refs with their current SHA values
|
|
124
|
-
* 3. Server capabilities on the first ref line
|
|
125
|
-
*
|
|
126
|
-
* The response format is pkt-line encoded for compatibility with Git's
|
|
127
|
-
* smart HTTP protocol.
|
|
128
|
-
*
|
|
129
|
-
* @param request - The incoming HTTP request
|
|
130
|
-
* @param repository - Repository provider for fetching refs
|
|
131
|
-
* @param capabilities - Optional server capabilities to advertise
|
|
132
|
-
* @returns Promise resolving to HTTP response with ref advertisement
|
|
133
|
-
*
|
|
134
|
-
* @throws {SmartHTTPError} 400 if service parameter is missing or invalid
|
|
135
|
-
* @throws {SmartHTTPError} 403 if permission is denied
|
|
136
|
-
* @throws {SmartHTTPError} 404 if repository does not exist
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```typescript
|
|
140
|
-
* // Handle ref discovery request
|
|
141
|
-
* const request: SmartHTTPRequest = {
|
|
142
|
-
* method: 'GET',
|
|
143
|
-
* path: '/info/refs',
|
|
144
|
-
* query: { service: 'git-upload-pack' },
|
|
145
|
-
* headers: {},
|
|
146
|
-
* repository: 'my-repo'
|
|
147
|
-
* }
|
|
148
|
-
*
|
|
149
|
-
* const capabilities: ServerCapabilities = {
|
|
150
|
-
* sideBand64k: true,
|
|
151
|
-
* thinPack: true
|
|
152
|
-
* }
|
|
153
|
-
*
|
|
154
|
-
* const response = await handleInfoRefs(request, repoProvider, capabilities)
|
|
155
|
-
* // response.status === 200
|
|
156
|
-
* // response.headers['Content-Type'] === 'application/x-git-upload-pack-advertisement'
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
export async function handleInfoRefs(request, repository, capabilities) {
|
|
160
|
-
// Check service parameter
|
|
161
|
-
const service = request.query.service;
|
|
162
|
-
if (!service) {
|
|
163
|
-
return createErrorResponse(400, 'Missing service parameter');
|
|
164
|
-
}
|
|
165
|
-
if (service !== 'git-upload-pack' && service !== 'git-receive-pack') {
|
|
166
|
-
return createErrorResponse(400, 'Invalid service parameter');
|
|
167
|
-
}
|
|
168
|
-
// Check if repository exists
|
|
169
|
-
const exists = await repository.exists();
|
|
170
|
-
if (!exists) {
|
|
171
|
-
return createErrorResponse(404, 'Repository not found');
|
|
172
|
-
}
|
|
173
|
-
// Check permission
|
|
174
|
-
const hasPermission = await repository.hasPermission(service);
|
|
175
|
-
if (!hasPermission) {
|
|
176
|
-
return createErrorResponse(403, 'Permission denied');
|
|
177
|
-
}
|
|
178
|
-
// Get refs
|
|
179
|
-
const refs = await repository.getRefs();
|
|
180
|
-
// Format response
|
|
181
|
-
const body = formatRefAdvertisement(service, refs, capabilities);
|
|
182
|
-
// Get content type
|
|
183
|
-
const contentType = service === 'git-upload-pack'
|
|
184
|
-
? CONTENT_TYPE_UPLOAD_PACK_ADVERTISEMENT
|
|
185
|
-
: CONTENT_TYPE_RECEIVE_PACK_ADVERTISEMENT;
|
|
186
|
-
return {
|
|
187
|
-
status: 200,
|
|
188
|
-
statusText: 'OK',
|
|
189
|
-
headers: {
|
|
190
|
-
'Content-Type': contentType,
|
|
191
|
-
'Cache-Control': 'no-cache',
|
|
192
|
-
'Pragma': 'no-cache',
|
|
193
|
-
},
|
|
194
|
-
body,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Handle POST /git-upload-pack requests for fetch data transfer.
|
|
199
|
-
*
|
|
200
|
-
* @description
|
|
201
|
-
* This endpoint processes fetch requests from git clients. It:
|
|
202
|
-
* 1. Parses the client's wants (objects they need) and haves (objects they have)
|
|
203
|
-
* 2. Negotiates which objects need to be sent
|
|
204
|
-
* 3. Generates and returns a packfile containing the required objects
|
|
205
|
-
*
|
|
206
|
-
* The response includes ACK/NAK lines followed by the packfile data,
|
|
207
|
-
* optionally wrapped in side-band format for progress reporting.
|
|
208
|
-
*
|
|
209
|
-
* @param request - The incoming HTTP request with wants/haves
|
|
210
|
-
* @param repository - Repository provider for creating packfile
|
|
211
|
-
* @returns Promise resolving to HTTP response with packfile data
|
|
212
|
-
*
|
|
213
|
-
* @throws {SmartHTTPError} 400 if request body is missing or malformed
|
|
214
|
-
* @throws {SmartHTTPError} 403 if permission is denied
|
|
215
|
-
* @throws {SmartHTTPError} 415 if content type is invalid
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```typescript
|
|
219
|
-
* // Handle fetch request
|
|
220
|
-
* const request: SmartHTTPRequest = {
|
|
221
|
-
* method: 'POST',
|
|
222
|
-
* path: '/git-upload-pack',
|
|
223
|
-
* query: {},
|
|
224
|
-
* headers: { 'Content-Type': 'application/x-git-upload-pack-request' },
|
|
225
|
-
* body: requestBody, // pkt-line encoded wants/haves
|
|
226
|
-
* repository: 'my-repo'
|
|
227
|
-
* }
|
|
228
|
-
*
|
|
229
|
-
* const response = await handleUploadPack(request, repoProvider)
|
|
230
|
-
* // response.body contains NAK + packfile data
|
|
231
|
-
* ```
|
|
232
|
-
*/
|
|
233
|
-
export async function handleUploadPack(request, repository) {
|
|
234
|
-
// Check content type
|
|
235
|
-
const contentType = request.headers['Content-Type'];
|
|
236
|
-
if (!validateContentType(contentType, CONTENT_TYPE_UPLOAD_PACK_REQUEST)) {
|
|
237
|
-
return createErrorResponse(415, 'Invalid content type');
|
|
238
|
-
}
|
|
239
|
-
// Check body
|
|
240
|
-
if (!request.body) {
|
|
241
|
-
return createErrorResponse(400, 'Missing request body');
|
|
242
|
-
}
|
|
243
|
-
// Check permission
|
|
244
|
-
const hasPermission = await repository.hasPermission('git-upload-pack');
|
|
245
|
-
if (!hasPermission) {
|
|
246
|
-
return createErrorResponse(403, 'Permission denied');
|
|
247
|
-
}
|
|
248
|
-
// Parse request
|
|
249
|
-
let parsed;
|
|
250
|
-
try {
|
|
251
|
-
parsed = parseUploadPackRequest(request.body);
|
|
252
|
-
}
|
|
253
|
-
catch (e) {
|
|
254
|
-
return createErrorResponse(400, 'Malformed request');
|
|
255
|
-
}
|
|
256
|
-
// Validate SHA format
|
|
257
|
-
for (const want of parsed.wants) {
|
|
258
|
-
if (!isValidSha(want)) {
|
|
259
|
-
return createErrorResponse(400, 'Invalid SHA format in want');
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
for (const have of parsed.haves) {
|
|
263
|
-
if (!isValidSha(have)) {
|
|
264
|
-
return createErrorResponse(400, 'Invalid SHA format in have');
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
// Check for side-band capability
|
|
268
|
-
const useSideBand = parsed.capabilities.includes('side-band-64k') || parsed.capabilities.includes('side-band');
|
|
269
|
-
// Get packfile from repository
|
|
270
|
-
const packData = await repository.uploadPack(parsed.wants, parsed.haves, parsed.capabilities);
|
|
271
|
-
// Format response (with ACK if there are haves, NAK otherwise)
|
|
272
|
-
const hasCommonObjects = parsed.haves.length > 0;
|
|
273
|
-
const body = formatUploadPackResponse(packData, useSideBand, hasCommonObjects, parsed.haves);
|
|
274
|
-
return {
|
|
275
|
-
status: 200,
|
|
276
|
-
statusText: 'OK',
|
|
277
|
-
headers: {
|
|
278
|
-
'Content-Type': CONTENT_TYPE_UPLOAD_PACK_RESULT,
|
|
279
|
-
},
|
|
280
|
-
body,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Handle POST /git-receive-pack requests for push data transfer.
|
|
285
|
-
*
|
|
286
|
-
* @description
|
|
287
|
-
* This endpoint processes push requests from git clients. It:
|
|
288
|
-
* 1. Parses ref update commands (create, update, delete)
|
|
289
|
-
* 2. Extracts and validates the incoming packfile
|
|
290
|
-
* 3. Applies ref updates (if packfile is valid)
|
|
291
|
-
* 4. Returns a status report (if report-status capability was requested)
|
|
292
|
-
*
|
|
293
|
-
* The response includes unpack status and individual ref update results.
|
|
294
|
-
*
|
|
295
|
-
* @param request - The incoming HTTP request with commands and packfile
|
|
296
|
-
* @param repository - Repository provider for processing push
|
|
297
|
-
* @returns Promise resolving to HTTP response with status report
|
|
298
|
-
*
|
|
299
|
-
* @throws {SmartHTTPError} 400 if request body is missing or malformed
|
|
300
|
-
* @throws {SmartHTTPError} 403 if permission is denied
|
|
301
|
-
* @throws {SmartHTTPError} 415 if content type is invalid
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* ```typescript
|
|
305
|
-
* // Handle push request
|
|
306
|
-
* const request: SmartHTTPRequest = {
|
|
307
|
-
* method: 'POST',
|
|
308
|
-
* path: '/git-receive-pack',
|
|
309
|
-
* query: {},
|
|
310
|
-
* headers: { 'Content-Type': 'application/x-git-receive-pack-request' },
|
|
311
|
-
* body: requestBody, // commands + packfile
|
|
312
|
-
* repository: 'my-repo'
|
|
313
|
-
* }
|
|
314
|
-
*
|
|
315
|
-
* const response = await handleReceivePack(request, repoProvider)
|
|
316
|
-
* // response.body contains "unpack ok" + ref status lines
|
|
317
|
-
* ```
|
|
318
|
-
*/
|
|
319
|
-
export async function handleReceivePack(request, repository) {
|
|
320
|
-
// Check content type
|
|
321
|
-
const contentType = request.headers['Content-Type'];
|
|
322
|
-
if (!validateContentType(contentType, CONTENT_TYPE_RECEIVE_PACK_REQUEST)) {
|
|
323
|
-
return createErrorResponse(415, 'Invalid content type');
|
|
324
|
-
}
|
|
325
|
-
// Check body
|
|
326
|
-
if (!request.body) {
|
|
327
|
-
return createErrorResponse(400, 'Missing request body');
|
|
328
|
-
}
|
|
329
|
-
// Check permission
|
|
330
|
-
const hasPermission = await repository.hasPermission('git-receive-pack');
|
|
331
|
-
if (!hasPermission) {
|
|
332
|
-
return createErrorResponse(403, 'Permission denied');
|
|
333
|
-
}
|
|
334
|
-
// Parse request
|
|
335
|
-
let parsed;
|
|
336
|
-
try {
|
|
337
|
-
parsed = parseReceivePackRequest(request.body);
|
|
338
|
-
}
|
|
339
|
-
catch (e) {
|
|
340
|
-
return createErrorResponse(400, 'Malformed request');
|
|
341
|
-
}
|
|
342
|
-
// Validate SHA format in commands
|
|
343
|
-
for (const cmd of parsed.commands) {
|
|
344
|
-
if (!isValidSha(cmd.oldSha) || !isValidSha(cmd.newSha)) {
|
|
345
|
-
return createErrorResponse(400, 'Invalid SHA format in command');
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
// Process the push
|
|
349
|
-
const result = await repository.receivePack(parsed.packfile, parsed.commands);
|
|
350
|
-
// Format response
|
|
351
|
-
const body = formatReceivePackResponse(result);
|
|
352
|
-
return {
|
|
353
|
-
status: 200,
|
|
354
|
-
statusText: 'OK',
|
|
355
|
-
headers: {
|
|
356
|
-
'Content-Type': CONTENT_TYPE_RECEIVE_PACK_RESULT,
|
|
357
|
-
},
|
|
358
|
-
body,
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Format ref advertisement for info/refs response.
|
|
363
|
-
*
|
|
364
|
-
* @description
|
|
365
|
-
* Creates a pkt-line formatted ref advertisement that includes:
|
|
366
|
-
* 1. Service announcement line (e.g., "# service=git-upload-pack")
|
|
367
|
-
* 2. Flush packet
|
|
368
|
-
* 3. First ref with capabilities (or zero SHA for empty repos)
|
|
369
|
-
* 4. Remaining refs
|
|
370
|
-
* 5. Peeled refs for annotated tags
|
|
371
|
-
* 6. Final flush packet
|
|
372
|
-
*
|
|
373
|
-
* @param service - The git service (git-upload-pack or git-receive-pack)
|
|
374
|
-
* @param refs - Array of refs to advertise
|
|
375
|
-
* @param capabilities - Optional server capabilities to include
|
|
376
|
-
* @returns Formatted ref advertisement as Uint8Array
|
|
377
|
-
*
|
|
378
|
-
* @example
|
|
379
|
-
* ```typescript
|
|
380
|
-
* const refs: GitRef[] = [
|
|
381
|
-
* { sha: 'abc123...', name: 'refs/heads/main' },
|
|
382
|
-
* { sha: 'def456...', name: 'refs/heads/feature' }
|
|
383
|
-
* ]
|
|
384
|
-
*
|
|
385
|
-
* const advertisement = formatRefAdvertisement(
|
|
386
|
-
* 'git-upload-pack',
|
|
387
|
-
* refs,
|
|
388
|
-
* { sideBand64k: true, thinPack: true }
|
|
389
|
-
* )
|
|
390
|
-
* ```
|
|
391
|
-
*/
|
|
392
|
-
export function formatRefAdvertisement(service, refs, capabilities) {
|
|
393
|
-
let output = '';
|
|
394
|
-
// Service announcement
|
|
395
|
-
output += encodePktLine(`# service=${service}\n`);
|
|
396
|
-
output += FLUSH_PKT;
|
|
397
|
-
// Capabilities string
|
|
398
|
-
const capStrings = capabilities ? capabilitiesToStrings(capabilities) : [];
|
|
399
|
-
const capLine = capStrings.length > 0 ? capStrings.join(' ') : '';
|
|
400
|
-
if (refs.length === 0) {
|
|
401
|
-
// Empty repo - send capabilities with zero SHA
|
|
402
|
-
if (capLine) {
|
|
403
|
-
output += encodePktLine(`${ZERO_SHA} capabilities^{}\x00${capLine}\n`);
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
output += encodePktLine(`${ZERO_SHA} capabilities^{}\n`);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
else {
|
|
410
|
-
// First ref includes capabilities
|
|
411
|
-
const firstRef = refs[0];
|
|
412
|
-
if (capLine) {
|
|
413
|
-
output += encodePktLine(`${firstRef.sha} ${firstRef.name}\x00${capLine}\n`);
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
output += encodePktLine(`${firstRef.sha} ${firstRef.name}\n`);
|
|
417
|
-
}
|
|
418
|
-
// Remaining refs
|
|
419
|
-
for (let i = 1; i < refs.length; i++) {
|
|
420
|
-
const ref = refs[i];
|
|
421
|
-
output += encodePktLine(`${ref.sha} ${ref.name}\n`);
|
|
422
|
-
}
|
|
423
|
-
// Add peeled refs for annotated tags
|
|
424
|
-
for (const ref of refs) {
|
|
425
|
-
if (ref.peeled) {
|
|
426
|
-
output += encodePktLine(`${ref.peeled} ${ref.name}^{}\n`);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
output += FLUSH_PKT;
|
|
431
|
-
return encoder.encode(output);
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* Parse upload-pack request body.
|
|
435
|
-
*
|
|
436
|
-
* @description
|
|
437
|
-
* Extracts wants, haves, and capabilities from the pkt-line formatted
|
|
438
|
-
* request body sent by git fetch. The format is:
|
|
439
|
-
* 1. Want lines: "want <sha> [capabilities]" (caps only on first)
|
|
440
|
-
* 2. Shallow/filter commands (optional)
|
|
441
|
-
* 3. Flush packet
|
|
442
|
-
* 4. Have lines: "have <sha>"
|
|
443
|
-
* 5. "done" line (or flush for multi_ack)
|
|
444
|
-
*
|
|
445
|
-
* @param body - Request body as Uint8Array
|
|
446
|
-
* @returns Parsed wants, haves, capabilities, and done flag
|
|
447
|
-
*
|
|
448
|
-
* @throws {Error} If the request is malformed (invalid pkt-line format)
|
|
449
|
-
*
|
|
450
|
-
* @example
|
|
451
|
-
* ```typescript
|
|
452
|
-
* const body = encoder.encode(
|
|
453
|
-
* '0032want abc123... side-band-64k\n' +
|
|
454
|
-
* '0000' +
|
|
455
|
-
* '0032have def456...\n' +
|
|
456
|
-
* '0009done\n'
|
|
457
|
-
* )
|
|
458
|
-
*
|
|
459
|
-
* const { wants, haves, capabilities, done } = parseUploadPackRequest(body)
|
|
460
|
-
* // wants = ['abc123...']
|
|
461
|
-
* // haves = ['def456...']
|
|
462
|
-
* // capabilities = ['side-band-64k']
|
|
463
|
-
* // done = true
|
|
464
|
-
* ```
|
|
465
|
-
*/
|
|
466
|
-
export function parseUploadPackRequest(body) {
|
|
467
|
-
const text = decoder.decode(body);
|
|
468
|
-
// Check if the input starts with a valid pkt-line format
|
|
469
|
-
// Valid pkt-lines start with 4 hex characters (length) or special packets (0000, 0001)
|
|
470
|
-
if (text.length >= 4) {
|
|
471
|
-
const hexPrefix = text.slice(0, 4);
|
|
472
|
-
const length = parseInt(hexPrefix, 16);
|
|
473
|
-
// If the first 4 chars are not valid hex (NaN) and not a special packet, it's malformed
|
|
474
|
-
if (isNaN(length) && hexPrefix !== '0000' && hexPrefix !== '0001') {
|
|
475
|
-
throw new Error('Malformed pkt-line: invalid length prefix');
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
const { packets } = pktLineStream(text);
|
|
479
|
-
const wants = [];
|
|
480
|
-
const haves = [];
|
|
481
|
-
let capabilities = [];
|
|
482
|
-
let done = false;
|
|
483
|
-
let firstWant = true;
|
|
484
|
-
for (const packet of packets) {
|
|
485
|
-
if (packet.type === 'flush' || packet.type === 'delim') {
|
|
486
|
-
continue;
|
|
487
|
-
}
|
|
488
|
-
if (!packet.data)
|
|
489
|
-
continue;
|
|
490
|
-
const line = packet.data.trim();
|
|
491
|
-
if (line === 'done') {
|
|
492
|
-
done = true;
|
|
493
|
-
continue;
|
|
494
|
-
}
|
|
495
|
-
if (line.startsWith('want ')) {
|
|
496
|
-
const rest = line.slice(5);
|
|
497
|
-
// First want line may contain capabilities after SHA
|
|
498
|
-
const parts = rest.split(' ');
|
|
499
|
-
const sha = parts[0];
|
|
500
|
-
wants.push(sha);
|
|
501
|
-
if (firstWant && parts.length > 1) {
|
|
502
|
-
capabilities = parts.slice(1);
|
|
503
|
-
firstWant = false;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
else if (line.startsWith('have ')) {
|
|
507
|
-
const sha = line.slice(5).trim();
|
|
508
|
-
haves.push(sha);
|
|
509
|
-
}
|
|
510
|
-
else if (line.startsWith('deepen ') || line.startsWith('deepen-since ') || line.startsWith('filter ')) {
|
|
511
|
-
// Handle shallow/filter commands - just skip them for now
|
|
512
|
-
continue;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
return { wants, haves, capabilities, done };
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Parse receive-pack request body.
|
|
519
|
-
*
|
|
520
|
-
* @description
|
|
521
|
-
* Extracts ref update commands, capabilities, and packfile data from
|
|
522
|
-
* the request body sent by git push. The format is:
|
|
523
|
-
* 1. Command lines: "<old-sha> <new-sha> <refname>" (caps on first via NUL)
|
|
524
|
-
* 2. Flush packet
|
|
525
|
-
* 3. Push options (optional, if push-options capability)
|
|
526
|
-
* 4. Flush packet (if push options present)
|
|
527
|
-
* 5. PACK data (packfile)
|
|
528
|
-
*
|
|
529
|
-
* @param body - Request body as Uint8Array
|
|
530
|
-
* @returns Parsed commands, capabilities, and packfile
|
|
531
|
-
*
|
|
532
|
-
* @throws {Error} If the request is malformed
|
|
533
|
-
*
|
|
534
|
-
* @example
|
|
535
|
-
* ```typescript
|
|
536
|
-
* const body = encoder.encode(
|
|
537
|
-
* '0077' + ZERO_SHA + ' abc123... refs/heads/new\0report-status\n' +
|
|
538
|
-
* '0000' +
|
|
539
|
-
* 'PACK...' // packfile data
|
|
540
|
-
* )
|
|
541
|
-
*
|
|
542
|
-
* const { commands, capabilities, packfile } = parseReceivePackRequest(body)
|
|
543
|
-
* // commands = [{ oldSha: ZERO_SHA, newSha: 'abc123...', refName: 'refs/heads/new' }]
|
|
544
|
-
* // capabilities = ['report-status']
|
|
545
|
-
* ```
|
|
546
|
-
*/
|
|
547
|
-
export function parseReceivePackRequest(body) {
|
|
548
|
-
const text = decoder.decode(body);
|
|
549
|
-
const commands = [];
|
|
550
|
-
let capabilities = [];
|
|
551
|
-
let firstCommand = true;
|
|
552
|
-
// Parse pkt-lines manually to track byte offset for packfile extraction
|
|
553
|
-
let offset = 0;
|
|
554
|
-
let flushOffset = -1;
|
|
555
|
-
while (offset < text.length) {
|
|
556
|
-
// Need at least 4 bytes for length prefix
|
|
557
|
-
if (offset + 4 > text.length) {
|
|
558
|
-
throw new Error('Malformed pkt-line: incomplete length prefix');
|
|
559
|
-
}
|
|
560
|
-
const hexLength = text.slice(offset, offset + 4);
|
|
561
|
-
// Check for flush packet
|
|
562
|
-
if (hexLength === FLUSH_PKT) {
|
|
563
|
-
flushOffset = offset + 4;
|
|
564
|
-
break;
|
|
565
|
-
}
|
|
566
|
-
// Validate hex length
|
|
567
|
-
const length = parseInt(hexLength, 16);
|
|
568
|
-
if (isNaN(length) || length < 4) {
|
|
569
|
-
throw new Error('Malformed pkt-line: invalid length');
|
|
570
|
-
}
|
|
571
|
-
// Check if we have enough data
|
|
572
|
-
if (offset + length > text.length) {
|
|
573
|
-
throw new Error('Malformed pkt-line: incomplete packet');
|
|
574
|
-
}
|
|
575
|
-
// Extract packet data
|
|
576
|
-
let line = text.slice(offset + 4, offset + length);
|
|
577
|
-
offset += length;
|
|
578
|
-
// Remove trailing newline
|
|
579
|
-
if (line.endsWith('\n')) {
|
|
580
|
-
line = line.slice(0, -1);
|
|
581
|
-
}
|
|
582
|
-
// First command may have capabilities after NUL byte
|
|
583
|
-
let cmdLine = line;
|
|
584
|
-
if (firstCommand && line.includes('\x00')) {
|
|
585
|
-
const nullIndex = line.indexOf('\x00');
|
|
586
|
-
cmdLine = line.slice(0, nullIndex);
|
|
587
|
-
const capPart = line.slice(nullIndex + 1);
|
|
588
|
-
capabilities = capPart.split(' ').filter(c => c.length > 0);
|
|
589
|
-
firstCommand = false;
|
|
590
|
-
}
|
|
591
|
-
// Parse command: oldSha newSha refName
|
|
592
|
-
const parts = cmdLine.split(' ');
|
|
593
|
-
if (parts.length >= 3) {
|
|
594
|
-
commands.push({
|
|
595
|
-
oldSha: parts[0],
|
|
596
|
-
newSha: parts[1],
|
|
597
|
-
refName: parts.slice(2).join(' '),
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
// Extract packfile data after flush packet
|
|
602
|
-
let packfile = new Uint8Array(0);
|
|
603
|
-
if (flushOffset !== -1 && flushOffset < body.length) {
|
|
604
|
-
packfile = body.slice(flushOffset);
|
|
605
|
-
}
|
|
606
|
-
return { commands, capabilities, packfile };
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* Format upload-pack response.
|
|
610
|
-
*
|
|
611
|
-
* @description
|
|
612
|
-
* Creates the response body for git-upload-pack POST request,
|
|
613
|
-
* including NAK/ACK responses and packfile data with optional sideband.
|
|
614
|
-
* The response format is:
|
|
615
|
-
* 1. NAK or ACK lines (based on negotiation)
|
|
616
|
-
* 2. Packfile data (optionally wrapped in side-band)
|
|
617
|
-
* 3. Flush packet
|
|
618
|
-
*
|
|
619
|
-
* @param packData - The packfile data to send
|
|
620
|
-
* @param useSideBand - Whether to use side-band encoding (channel 1 for data)
|
|
621
|
-
* @param hasCommonObjects - Whether there are common objects (for ACK vs NAK)
|
|
622
|
-
* @param haves - The have SHAs from the client (first one is ACKed if common)
|
|
623
|
-
* @returns Formatted response as Uint8Array
|
|
624
|
-
*
|
|
625
|
-
* @example
|
|
626
|
-
* ```typescript
|
|
627
|
-
* // Simple NAK response with packfile
|
|
628
|
-
* const response = formatUploadPackResponse(packData, false, false, [])
|
|
629
|
-
*
|
|
630
|
-
* // Side-band response with ACK
|
|
631
|
-
* const response = formatUploadPackResponse(
|
|
632
|
-
* packData,
|
|
633
|
-
* true,
|
|
634
|
-
* true,
|
|
635
|
-
* ['abc123...']
|
|
636
|
-
* )
|
|
637
|
-
* ```
|
|
638
|
-
*/
|
|
639
|
-
export function formatUploadPackResponse(packData, useSideBand, hasCommonObjects, haves) {
|
|
640
|
-
let output = '';
|
|
641
|
-
// Send ACK or NAK
|
|
642
|
-
if (hasCommonObjects && haves && haves.length > 0) {
|
|
643
|
-
// ACK the first have
|
|
644
|
-
output += encodePktLine(`ACK ${haves[0]}\n`);
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
output += encodePktLine('NAK\n');
|
|
648
|
-
}
|
|
649
|
-
if (useSideBand) {
|
|
650
|
-
// Side-band format: data on channel 1, progress on channel 2, error on channel 3
|
|
651
|
-
// Each sideband packet: length (4 hex) + channel byte + data
|
|
652
|
-
const channel1 = new Uint8Array(1 + packData.length);
|
|
653
|
-
channel1[0] = 1; // Channel 1 for pack data
|
|
654
|
-
channel1.set(packData, 1);
|
|
655
|
-
// Encode as pkt-line
|
|
656
|
-
const pktLine = encodePktLine(channel1);
|
|
657
|
-
if (typeof pktLine === 'string') {
|
|
658
|
-
output += pktLine;
|
|
659
|
-
}
|
|
660
|
-
else {
|
|
661
|
-
// Binary data - need to handle differently
|
|
662
|
-
const headerBytes = encoder.encode(output);
|
|
663
|
-
const result = new Uint8Array(headerBytes.length + pktLine.length + 4);
|
|
664
|
-
result.set(headerBytes, 0);
|
|
665
|
-
result.set(pktLine, headerBytes.length);
|
|
666
|
-
result.set(encoder.encode(FLUSH_PKT), headerBytes.length + pktLine.length);
|
|
667
|
-
return result;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
else {
|
|
671
|
-
// No side-band - include pack data directly
|
|
672
|
-
// Pack data is binary, so encode it as pkt-line
|
|
673
|
-
const pktLine = encodePktLine(packData);
|
|
674
|
-
if (typeof pktLine === 'string') {
|
|
675
|
-
output += pktLine;
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
const headerBytes = encoder.encode(output);
|
|
679
|
-
const result = new Uint8Array(headerBytes.length + pktLine.length + 4);
|
|
680
|
-
result.set(headerBytes, 0);
|
|
681
|
-
result.set(pktLine, headerBytes.length);
|
|
682
|
-
result.set(encoder.encode(FLUSH_PKT), headerBytes.length + pktLine.length);
|
|
683
|
-
return result;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
output += FLUSH_PKT;
|
|
687
|
-
return encoder.encode(output);
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* Format receive-pack response.
|
|
691
|
-
*
|
|
692
|
-
* @description
|
|
693
|
-
* Creates the response body for git-receive-pack POST request,
|
|
694
|
-
* including unpack status and ref update results. The format is:
|
|
695
|
-
* 1. Unpack status line: "unpack ok" or "unpack error"
|
|
696
|
-
* 2. Ref status lines: "ok <refname>" or "ng <refname> <error>"
|
|
697
|
-
* 3. Flush packet
|
|
698
|
-
*
|
|
699
|
-
* @param result - Result of the receive-pack operation
|
|
700
|
-
* @returns Formatted response as Uint8Array
|
|
701
|
-
*
|
|
702
|
-
* @example
|
|
703
|
-
* ```typescript
|
|
704
|
-
* const result: ReceivePackResult = {
|
|
705
|
-
* success: true,
|
|
706
|
-
* refResults: [
|
|
707
|
-
* { refName: 'refs/heads/main', success: true },
|
|
708
|
-
* { refName: 'refs/heads/feature', success: false, error: 'non-fast-forward' }
|
|
709
|
-
* ]
|
|
710
|
-
* }
|
|
711
|
-
*
|
|
712
|
-
* const response = formatReceivePackResponse(result)
|
|
713
|
-
* // "unpack ok\nok refs/heads/main\nng refs/heads/feature non-fast-forward\n0000"
|
|
714
|
-
* ```
|
|
715
|
-
*/
|
|
716
|
-
export function formatReceivePackResponse(result) {
|
|
717
|
-
let output = '';
|
|
718
|
-
// Unpack status
|
|
719
|
-
if (result.success) {
|
|
720
|
-
output += encodePktLine('unpack ok\n');
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
output += encodePktLine('unpack error\n');
|
|
724
|
-
}
|
|
725
|
-
// Ref results
|
|
726
|
-
for (const refResult of result.refResults) {
|
|
727
|
-
if (refResult.success) {
|
|
728
|
-
output += encodePktLine(`ok ${refResult.refName}\n`);
|
|
729
|
-
}
|
|
730
|
-
else {
|
|
731
|
-
const error = refResult.error || 'failed';
|
|
732
|
-
output += encodePktLine(`ng ${refResult.refName} ${error}\n`);
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
output += FLUSH_PKT;
|
|
736
|
-
return encoder.encode(output);
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Convert ServerCapabilities to capability string list.
|
|
740
|
-
*
|
|
741
|
-
* @description
|
|
742
|
-
* Converts the ServerCapabilities object into an array of capability
|
|
743
|
-
* strings suitable for inclusion in ref advertisements. Boolean capabilities
|
|
744
|
-
* become simple strings, while capabilities with values become "name=value".
|
|
745
|
-
*
|
|
746
|
-
* @param capabilities - Server capabilities object
|
|
747
|
-
* @returns Array of capability strings
|
|
748
|
-
*
|
|
749
|
-
* @example
|
|
750
|
-
* ```typescript
|
|
751
|
-
* const caps: ServerCapabilities = {
|
|
752
|
-
* sideBand64k: true,
|
|
753
|
-
* thinPack: true,
|
|
754
|
-
* agent: 'my-server/1.0'
|
|
755
|
-
* }
|
|
756
|
-
*
|
|
757
|
-
* const strings = capabilitiesToStrings(caps)
|
|
758
|
-
* // ['side-band-64k', 'thin-pack', 'agent=my-server/1.0']
|
|
759
|
-
* ```
|
|
760
|
-
*/
|
|
761
|
-
export function capabilitiesToStrings(capabilities) {
|
|
762
|
-
const result = [];
|
|
763
|
-
if (capabilities.multiAck)
|
|
764
|
-
result.push('multi_ack');
|
|
765
|
-
if (capabilities.multiAckDetailed)
|
|
766
|
-
result.push('multi_ack_detailed');
|
|
767
|
-
if (capabilities.thinPack)
|
|
768
|
-
result.push('thin-pack');
|
|
769
|
-
if (capabilities.sideBand)
|
|
770
|
-
result.push('side-band');
|
|
771
|
-
if (capabilities.sideBand64k)
|
|
772
|
-
result.push('side-band-64k');
|
|
773
|
-
if (capabilities.ofsDelta)
|
|
774
|
-
result.push('ofs-delta');
|
|
775
|
-
if (capabilities.shallow)
|
|
776
|
-
result.push('shallow');
|
|
777
|
-
if (capabilities.deepenSince)
|
|
778
|
-
result.push('deepen-since');
|
|
779
|
-
if (capabilities.deepenNot)
|
|
780
|
-
result.push('deepen-not');
|
|
781
|
-
if (capabilities.deepenRelative)
|
|
782
|
-
result.push('deepen-relative');
|
|
783
|
-
if (capabilities.noProgress)
|
|
784
|
-
result.push('no-progress');
|
|
785
|
-
if (capabilities.includeTag)
|
|
786
|
-
result.push('include-tag');
|
|
787
|
-
if (capabilities.reportStatus)
|
|
788
|
-
result.push('report-status');
|
|
789
|
-
if (capabilities.reportStatusV2)
|
|
790
|
-
result.push('report-status-v2');
|
|
791
|
-
if (capabilities.deleteRefs)
|
|
792
|
-
result.push('delete-refs');
|
|
793
|
-
if (capabilities.quiet)
|
|
794
|
-
result.push('quiet');
|
|
795
|
-
if (capabilities.atomic)
|
|
796
|
-
result.push('atomic');
|
|
797
|
-
if (capabilities.pushOptions)
|
|
798
|
-
result.push('push-options');
|
|
799
|
-
if (capabilities.allowTipSha1InWant)
|
|
800
|
-
result.push('allow-tip-sha1-in-want');
|
|
801
|
-
if (capabilities.allowReachableSha1InWant)
|
|
802
|
-
result.push('allow-reachable-sha1-in-want');
|
|
803
|
-
if (capabilities.filter)
|
|
804
|
-
result.push('filter');
|
|
805
|
-
if (capabilities.agent)
|
|
806
|
-
result.push(`agent=${capabilities.agent}`);
|
|
807
|
-
if (capabilities.objectFormat)
|
|
808
|
-
result.push(`object-format=${capabilities.objectFormat}`);
|
|
809
|
-
return result;
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Parse capability strings into ServerCapabilities object.
|
|
813
|
-
*
|
|
814
|
-
* @description
|
|
815
|
-
* Converts an array of capability strings (as received from a client or
|
|
816
|
-
* server) into a structured ServerCapabilities object for easier access.
|
|
817
|
-
*
|
|
818
|
-
* @param capStrings - Array of capability strings
|
|
819
|
-
* @returns Parsed capabilities object
|
|
820
|
-
*
|
|
821
|
-
* @example
|
|
822
|
-
* ```typescript
|
|
823
|
-
* const strings = ['side-band-64k', 'thin-pack', 'agent=git/2.30.0']
|
|
824
|
-
* const caps = parseCapabilities(strings)
|
|
825
|
-
* // caps.sideBand64k === true
|
|
826
|
-
* // caps.thinPack === true
|
|
827
|
-
* // caps.agent === 'git/2.30.0'
|
|
828
|
-
* ```
|
|
829
|
-
*/
|
|
830
|
-
export function parseCapabilities(capStrings) {
|
|
831
|
-
const result = {};
|
|
832
|
-
for (const cap of capStrings) {
|
|
833
|
-
if (cap === 'multi_ack')
|
|
834
|
-
result.multiAck = true;
|
|
835
|
-
else if (cap === 'multi_ack_detailed')
|
|
836
|
-
result.multiAckDetailed = true;
|
|
837
|
-
else if (cap === 'thin-pack')
|
|
838
|
-
result.thinPack = true;
|
|
839
|
-
else if (cap === 'side-band')
|
|
840
|
-
result.sideBand = true;
|
|
841
|
-
else if (cap === 'side-band-64k')
|
|
842
|
-
result.sideBand64k = true;
|
|
843
|
-
else if (cap === 'ofs-delta')
|
|
844
|
-
result.ofsDelta = true;
|
|
845
|
-
else if (cap === 'shallow')
|
|
846
|
-
result.shallow = true;
|
|
847
|
-
else if (cap === 'deepen-since')
|
|
848
|
-
result.deepenSince = true;
|
|
849
|
-
else if (cap === 'deepen-not')
|
|
850
|
-
result.deepenNot = true;
|
|
851
|
-
else if (cap === 'deepen-relative')
|
|
852
|
-
result.deepenRelative = true;
|
|
853
|
-
else if (cap === 'no-progress')
|
|
854
|
-
result.noProgress = true;
|
|
855
|
-
else if (cap === 'include-tag')
|
|
856
|
-
result.includeTag = true;
|
|
857
|
-
else if (cap === 'report-status')
|
|
858
|
-
result.reportStatus = true;
|
|
859
|
-
else if (cap === 'report-status-v2')
|
|
860
|
-
result.reportStatusV2 = true;
|
|
861
|
-
else if (cap === 'delete-refs')
|
|
862
|
-
result.deleteRefs = true;
|
|
863
|
-
else if (cap === 'quiet')
|
|
864
|
-
result.quiet = true;
|
|
865
|
-
else if (cap === 'atomic')
|
|
866
|
-
result.atomic = true;
|
|
867
|
-
else if (cap === 'push-options')
|
|
868
|
-
result.pushOptions = true;
|
|
869
|
-
else if (cap === 'allow-tip-sha1-in-want')
|
|
870
|
-
result.allowTipSha1InWant = true;
|
|
871
|
-
else if (cap === 'allow-reachable-sha1-in-want')
|
|
872
|
-
result.allowReachableSha1InWant = true;
|
|
873
|
-
else if (cap === 'filter')
|
|
874
|
-
result.filter = true;
|
|
875
|
-
else if (cap.startsWith('agent='))
|
|
876
|
-
result.agent = cap.slice(6);
|
|
877
|
-
else if (cap.startsWith('object-format='))
|
|
878
|
-
result.objectFormat = cap.slice(14);
|
|
879
|
-
// Unknown capabilities are ignored
|
|
880
|
-
}
|
|
881
|
-
return result;
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Validate Content-Type header for a request.
|
|
885
|
-
*
|
|
886
|
-
* @description
|
|
887
|
-
* Compares the provided Content-Type header against an expected value,
|
|
888
|
-
* handling case-insensitivity and stripping charset or other parameters.
|
|
889
|
-
*
|
|
890
|
-
* @param contentType - The Content-Type header value from the request
|
|
891
|
-
* @param expectedType - The expected Content-Type
|
|
892
|
-
* @returns true if the content type matches, false otherwise
|
|
893
|
-
*
|
|
894
|
-
* @example
|
|
895
|
-
* ```typescript
|
|
896
|
-
* validateContentType(
|
|
897
|
-
* 'application/x-git-upload-pack-request; charset=utf-8',
|
|
898
|
-
* 'application/x-git-upload-pack-request'
|
|
899
|
-
* )
|
|
900
|
-
* // Returns true
|
|
901
|
-
*
|
|
902
|
-
* validateContentType('text/plain', 'application/x-git-upload-pack-request')
|
|
903
|
-
* // Returns false
|
|
904
|
-
* ```
|
|
905
|
-
*/
|
|
906
|
-
export function validateContentType(contentType, expectedType) {
|
|
907
|
-
if (!contentType) {
|
|
908
|
-
return false;
|
|
909
|
-
}
|
|
910
|
-
// Normalize: lowercase and strip charset or other parameters
|
|
911
|
-
const normalized = contentType.toLowerCase().split(';')[0].trim();
|
|
912
|
-
const expected = expectedType.toLowerCase();
|
|
913
|
-
return normalized === expected;
|
|
914
|
-
}
|
|
915
|
-
/**
|
|
916
|
-
* Create an error response with appropriate status code and message.
|
|
917
|
-
*
|
|
918
|
-
* @description
|
|
919
|
-
* Helper function to create a properly formatted error response with
|
|
920
|
-
* the correct HTTP status code, status text, and plain text body.
|
|
921
|
-
*
|
|
922
|
-
* @param statusCode - HTTP status code (e.g., 400, 403, 404)
|
|
923
|
-
* @param message - Error message to include in the response body
|
|
924
|
-
* @returns SmartHTTPResponse with error information
|
|
925
|
-
*
|
|
926
|
-
* @example
|
|
927
|
-
* ```typescript
|
|
928
|
-
* const response = createErrorResponse(404, 'Repository not found')
|
|
929
|
-
* // response.status === 404
|
|
930
|
-
* // response.statusText === 'Not Found'
|
|
931
|
-
* // response.headers['Content-Type'] === 'text/plain'
|
|
932
|
-
* // response.body contains 'Repository not found'
|
|
933
|
-
* ```
|
|
934
|
-
*/
|
|
935
|
-
export function createErrorResponse(statusCode, message) {
|
|
936
|
-
return {
|
|
937
|
-
status: statusCode,
|
|
938
|
-
statusText: getStatusText(statusCode),
|
|
939
|
-
headers: {
|
|
940
|
-
'Content-Type': 'text/plain',
|
|
941
|
-
},
|
|
942
|
-
body: encoder.encode(message),
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
//# sourceMappingURL=smart-http.js.map
|