@statewalker/vcs-commands 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/commands/add-command.d.ts +32 -0
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-patch.d.ts +7 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-backend.d.ts +2 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-modes.d.ts +6 -2
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-session.d.ts +4 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -1
- package/dist/commands/am/am-command.d.ts +88 -2
- package/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-command.d.ts +2 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.d.ts +7 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -1
- package/dist/commands/apply/index.d.ts +1 -1
- package/dist/commands/apply/index.d.ts.map +1 -1
- package/dist/commands/archive/archive-command.d.ts +169 -0
- package/dist/commands/archive/archive-command.d.ts.map +1 -0
- package/dist/commands/archive/archive-entry.d.ts +60 -0
- package/dist/commands/archive/archive-entry.d.ts.map +1 -0
- package/dist/commands/archive/index.d.ts +8 -0
- package/dist/commands/archive/index.d.ts.map +1 -0
- package/dist/commands/archive/remote-archive-command.d.ts +56 -0
- package/dist/commands/archive/remote-archive-command.d.ts.map +1 -0
- package/dist/commands/archive/tar-archive.d.ts +31 -0
- package/dist/commands/archive/tar-archive.d.ts.map +1 -0
- package/dist/commands/archive/tar-commit-id.d.ts +13 -0
- package/dist/commands/archive/tar-commit-id.d.ts.map +1 -0
- package/dist/commands/archive/upload-archive-writer.d.ts +48 -0
- package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -0
- package/dist/commands/archive/zip-archive.d.ts +42 -0
- package/dist/commands/archive/zip-archive.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +10 -0
- package/dist/commands/attributes-source.d.ts.map +1 -1
- package/dist/commands/blame-command.d.ts +345 -8
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/blame-ignore.d.ts +48 -0
- package/dist/commands/blame-ignore.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-create-command.d.ts +67 -0
- package/dist/commands/bundle/bundle-create-command.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-format.d.ts +89 -0
- package/dist/commands/bundle/bundle-format.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-list.d.ts +92 -0
- package/dist/commands/bundle/bundle-list.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-read-commands.d.ts +81 -0
- package/dist/commands/bundle/bundle-read-commands.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-support.d.ts +32 -0
- package/dist/commands/bundle/bundle-support.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-transport.d.ts +38 -0
- package/dist/commands/bundle/bundle-transport.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-uri-host.d.ts +43 -0
- package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-uri.d.ts +55 -0
- package/dist/commands/bundle/bundle-uri.d.ts.map +1 -0
- package/dist/commands/bundle/bundle-verify.d.ts +63 -0
- package/dist/commands/bundle/bundle-verify.d.ts.map +1 -0
- package/dist/commands/bundle/index.d.ts +14 -0
- package/dist/commands/bundle/index.d.ts.map +1 -0
- package/dist/commands/cat-file/batch-format.d.ts +58 -0
- package/dist/commands/cat-file/batch-format.d.ts.map +1 -0
- package/dist/commands/cat-file/cat-file-command.d.ts +135 -0
- package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -0
- package/dist/commands/cat-file/index.d.ts +3 -0
- package/dist/commands/cat-file/index.d.ts.map +1 -0
- package/dist/commands/check-attr-command.d.ts +66 -0
- package/dist/commands/check-attr-command.d.ts.map +1 -0
- package/dist/commands/check-ignore-command.d.ts +58 -0
- package/dist/commands/check-ignore-command.d.ts.map +1 -0
- package/dist/commands/check-mailmap-command.d.ts +49 -0
- package/dist/commands/check-mailmap-command.d.ts.map +1 -0
- package/dist/commands/check-ref-format-command.d.ts +60 -0
- package/dist/commands/check-ref-format-command.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +7 -0
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-index-command.d.ts +96 -0
- package/dist/commands/checkout-index-command.d.ts.map +1 -0
- package/dist/commands/checkout-paths.d.ts +4 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -1
- package/dist/commands/cherry-command.d.ts +61 -0
- package/dist/commands/cherry-command.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +33 -1
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +32 -0
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clean-interactive.d.ts +56 -0
- package/dist/commands/clean-interactive.d.ts.map +1 -0
- package/dist/commands/clone-command.d.ts +135 -2
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +59 -3
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/config-command.d.ts +2 -0
- package/dist/commands/config-command.d.ts.map +1 -1
- package/dist/commands/daemon-access-hook.d.ts +36 -0
- package/dist/commands/daemon-access-hook.d.ts.map +1 -0
- package/dist/commands/default-branch.d.ts +42 -0
- package/dist/commands/default-branch.d.ts.map +1 -1
- package/dist/commands/describe-command.d.ts +71 -64
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +249 -10
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-external.d.ts +43 -0
- package/dist/commands/diff-external.d.ts.map +1 -0
- package/dist/commands/diff-plumbing/diff-pairs-command.d.ts +27 -0
- package/dist/commands/diff-plumbing/diff-pairs-command.d.ts.map +1 -0
- package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts +129 -0
- package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts.map +1 -0
- package/dist/commands/diff-plumbing/index.d.ts +3 -0
- package/dist/commands/diff-plumbing/index.d.ts.map +1 -0
- package/dist/commands/diff-textconv.d.ts +5 -1
- package/dist/commands/diff-textconv.d.ts.map +1 -1
- package/dist/commands/fast-export/fast-export-command.d.ts +135 -0
- package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -0
- package/dist/commands/fast-export/fast-import-command.d.ts +182 -0
- package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -0
- package/dist/commands/fast-export/fast-stream-support.d.ts +64 -0
- package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -0
- package/dist/commands/fast-export/index.d.ts +4 -0
- package/dist/commands/fast-export/index.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +125 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fetch-multiple-command.d.ts +193 -0
- package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
- package/dist/commands/format-patch-command.d.ts +28 -2
- package/dist/commands/format-patch-command.d.ts.map +1 -1
- package/dist/commands/format-rev-command.d.ts +58 -0
- package/dist/commands/format-rev-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-msg-ids.d.ts +18 -3
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -1
- package/dist/commands/fsmonitor-refresh.d.ts +69 -0
- package/dist/commands/fsmonitor-refresh.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +5 -0
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-describe.d.ts +77 -4
- package/dist/commands/git-describe.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +47 -1
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/git-paths.d.ts +26 -0
- package/dist/commands/git-paths.d.ts.map +1 -0
- package/dist/commands/grep/grep-command.d.ts +2 -1
- package/dist/commands/grep/grep-command.d.ts.map +1 -1
- package/dist/commands/history-command.d.ts +156 -0
- package/dist/commands/history-command.d.ts.map +1 -0
- package/dist/commands/http-config.d.ts +38 -0
- package/dist/commands/http-config.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +12 -1
- package/dist/commands/index-adder.d.ts.map +1 -1
- package/dist/commands/index-host.d.ts.map +1 -1
- package/dist/commands/index.d.ts +56 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +6 -3
- package/dist/commands/init-command.d.ts +89 -0
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/last-modified-command.d.ts +102 -0
- package/dist/commands/last-modified-command.d.ts.map +1 -0
- package/dist/commands/lfs/go-url.d.ts +43 -0
- package/dist/commands/lfs/go-url.d.ts.map +1 -0
- package/dist/commands/lfs/index.d.ts +3 -0
- package/dist/commands/lfs/index.d.ts.map +1 -0
- package/dist/commands/lfs/lfs-config.d.ts +174 -0
- package/dist/commands/lfs/lfs-config.d.ts.map +1 -0
- package/dist/commands/lfs/lfs-endpoint-command.d.ts +83 -0
- package/dist/commands/lfs/lfs-endpoint-command.d.ts.map +1 -0
- package/dist/commands/line-log.d.ts +161 -0
- package/dist/commands/line-log.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts.map +1 -1
- package/dist/commands/log-command.d.ts +261 -6
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +4 -2
- package/dist/commands/log-graph.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +88 -2
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/ls-files-command.d.ts +153 -0
- package/dist/commands/ls-files-command.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +5 -0
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/ls-tree-command.d.ts +105 -0
- package/dist/commands/ls-tree-command.d.ts.map +1 -0
- package/dist/commands/mailmap.d.ts +24 -1
- package/dist/commands/mailmap.d.ts.map +1 -1
- package/dist/commands/maintenance-run-command.d.ts +122 -0
- package/dist/commands/maintenance-run-command.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +58 -1
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +7 -0
- package/dist/commands/merge-config.d.ts.map +1 -1
- package/dist/commands/merge-drivers.d.ts +69 -5
- package/dist/commands/merge-drivers.d.ts.map +1 -1
- package/dist/commands/merge-strategy-options.d.ts +69 -0
- package/dist/commands/merge-strategy-options.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +16 -0
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/merge-tree-command.d.ts +122 -0
- package/dist/commands/merge-tree-command.d.ts.map +1 -0
- package/dist/commands/message-cleanup.d.ts +2 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -1
- package/dist/commands/mktag-command.d.ts +51 -0
- package/dist/commands/mktag-command.d.ts.map +1 -0
- package/dist/commands/name-rev-command.d.ts +65 -0
- package/dist/commands/name-rev-command.d.ts.map +1 -0
- package/dist/commands/name-rev.d.ts +110 -22
- package/dist/commands/name-rev.d.ts.map +1 -1
- package/dist/commands/object-store/count-objects-command.d.ts +58 -0
- package/dist/commands/object-store/count-objects-command.d.ts.map +1 -0
- package/dist/commands/object-store/index.d.ts +5 -0
- package/dist/commands/object-store/index.d.ts.map +1 -0
- package/dist/commands/object-store/objects-directory.d.ts +12 -0
- package/dist/commands/object-store/objects-directory.d.ts.map +1 -0
- package/dist/commands/object-store/prune-command.d.ts +38 -0
- package/dist/commands/object-store/prune-command.d.ts.map +1 -0
- package/dist/commands/object-store/show-index-command.d.ts +23 -0
- package/dist/commands/object-store/show-index-command.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +26 -1
- package/dist/commands/octopus-merge.d.ts.map +1 -1
- package/dist/commands/ort-merge.d.ts +40 -0
- package/dist/commands/ort-merge.d.ts.map +1 -1
- package/dist/commands/ort-recursive.d.ts.map +1 -1
- package/dist/commands/patch-id-command.d.ts +30 -0
- package/dist/commands/patch-id-command.d.ts.map +1 -0
- package/dist/commands/patch-id.d.ts +82 -0
- package/dist/commands/patch-id.d.ts.map +1 -1
- package/dist/commands/plumbing-command.d.ts +66 -0
- package/dist/commands/plumbing-command.d.ts.map +1 -0
- package/dist/commands/plumbing-input.d.ts +38 -0
- package/dist/commands/plumbing-input.d.ts.map +1 -0
- package/dist/commands/promisor-remote-reply.d.ts +35 -0
- package/dist/commands/promisor-remote-reply.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts +182 -38
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +82 -2
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/range-diff/index.d.ts +4 -0
- package/dist/commands/range-diff/index.d.ts.map +1 -0
- package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
- package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
- package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff.d.ts +106 -0
- package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
- package/dist/commands/read-tree-command.d.ts +14 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +129 -4
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/refs-command.d.ts +81 -0
- package/dist/commands/refs-command.d.ts.map +1 -0
- package/dist/commands/remerge-diff.d.ts +59 -0
- package/dist/commands/remerge-diff.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +41 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-object-info-command.d.ts +55 -0
- package/dist/commands/remote-object-info-command.d.ts.map +1 -0
- package/dist/commands/remote-show-command.d.ts +204 -0
- package/dist/commands/remote-show-command.d.ts.map +1 -0
- package/dist/commands/remote-transport.d.ts +40 -3
- package/dist/commands/remote-transport.d.ts.map +1 -1
- package/dist/commands/repack-command.d.ts +115 -0
- package/dist/commands/repack-command.d.ts.map +1 -0
- package/dist/commands/replace-command.d.ts +143 -0
- package/dist/commands/replace-command.d.ts.map +1 -0
- package/dist/commands/replay-command.d.ts +117 -0
- package/dist/commands/replay-command.d.ts.map +1 -0
- package/dist/commands/repo-command.d.ts +136 -0
- package/dist/commands/repo-command.d.ts.map +1 -0
- package/dist/commands/request-pull-command.d.ts +82 -0
- package/dist/commands/request-pull-command.d.ts.map +1 -0
- package/dist/commands/rerere-command.d.ts +36 -0
- package/dist/commands/rerere-command.d.ts.map +1 -0
- package/dist/commands/rerere.d.ts +102 -0
- package/dist/commands/rerere.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +19 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +7 -0
- package/dist/commands/restore-command.d.ts.map +1 -1
- package/dist/commands/rev-filter/commit-grep.d.ts +3 -1
- package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -1
- package/dist/commands/rev-list-command.d.ts +78 -3
- package/dist/commands/rev-list-command.d.ts.map +1 -1
- package/dist/commands/rev-parse-command.d.ts +9 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -1
- package/dist/commands/revert-command.d.ts +32 -1
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +7 -0
- package/dist/commands/revision-range.d.ts.map +1 -1
- package/dist/commands/revision-resolver.d.ts +12 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +120 -1
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts +10 -1
- package/dist/commands/sequencer-support.d.ts.map +1 -1
- package/dist/commands/serve-repository.d.ts +23 -1
- package/dist/commands/serve-repository.d.ts.map +1 -1
- package/dist/commands/session-id.d.ts +18 -0
- package/dist/commands/session-id.d.ts.map +1 -0
- package/dist/commands/shortlog-command.d.ts +109 -0
- package/dist/commands/shortlog-command.d.ts.map +1 -0
- package/dist/commands/shortlog.d.ts +151 -0
- package/dist/commands/shortlog.d.ts.map +1 -0
- package/dist/commands/show-branch-command.d.ts +59 -0
- package/dist/commands/show-branch-command.d.ts.map +1 -0
- package/dist/commands/show-ref-command.d.ts +112 -0
- package/dist/commands/show-ref-command.d.ts.map +1 -0
- package/dist/commands/signature-check.d.ts +9 -2
- package/dist/commands/signature-check.d.ts.map +1 -1
- package/dist/commands/signing.d.ts +22 -1
- package/dist/commands/signing.d.ts.map +1 -1
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-export-command.d.ts +115 -0
- package/dist/commands/stash-export-command.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +33 -3
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/stripspace-command.d.ts +44 -0
- package/dist/commands/stripspace-command.d.ts.map +1 -0
- package/dist/commands/submodule-add-command.d.ts +10 -1
- package/dist/commands/submodule-add-command.d.ts.map +1 -1
- package/dist/commands/submodule-auth.d.ts +3 -1
- package/dist/commands/submodule-auth.d.ts.map +1 -1
- package/dist/commands/submodule-commands.d.ts +99 -3
- package/dist/commands/submodule-commands.d.ts.map +1 -1
- package/dist/commands/submodule-fetch.d.ts +149 -0
- package/dist/commands/submodule-fetch.d.ts.map +1 -0
- package/dist/commands/submodule-model.d.ts +8 -0
- package/dist/commands/submodule-model.d.ts.map +1 -1
- package/dist/commands/submodule-unpack.d.ts +120 -0
- package/dist/commands/submodule-unpack.d.ts.map +1 -0
- package/dist/commands/submodule-update-command.d.ts +21 -1
- package/dist/commands/submodule-update-command.d.ts.map +1 -1
- package/dist/commands/subtree-shift.d.ts +27 -0
- package/dist/commands/subtree-shift.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +3 -0
- package/dist/commands/switch-command.d.ts.map +1 -1
- package/dist/commands/textconv-cache.d.ts +58 -0
- package/dist/commands/textconv-cache.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +5 -0
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/unpack-objects-command.d.ts +47 -0
- package/dist/commands/unpack-objects-command.d.ts.map +1 -0
- package/dist/commands/update-index-command.d.ts +110 -0
- package/dist/commands/update-index-command.d.ts.map +1 -0
- package/dist/commands/uri-protocols.d.ts +13 -0
- package/dist/commands/uri-protocols.d.ts.map +1 -0
- package/dist/commands/url-parse-command.d.ts +30 -0
- package/dist/commands/url-parse-command.d.ts.map +1 -0
- package/dist/commands/var-command.d.ts +42 -0
- package/dist/commands/var-command.d.ts.map +1 -0
- package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/{commands-ISM52N0n.js → commands-Mlo1dxQN.js} +56133 -70269
- package/dist/errors/command-errors.d.ts +58 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/index.js +67 -1
- package/dist/fsck-CrhVMNIH.js +5179 -0
- package/dist/git-command.d.ts +89 -3
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +628 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/guarded-transport-command.d.ts +84 -0
- package/dist/guarded-transport-command.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/maintenance-run-command-Bw21HEkH.js +13539 -0
- package/dist/remote-transport-Bu4PGSMD.js +2605 -0
- package/dist/rename/detect-renames.d.ts +20 -0
- package/dist/rename/detect-renames.d.ts.map +1 -1
- package/dist/rename/diffcore-break.d.ts +51 -0
- package/dist/rename/diffcore-break.d.ts.map +1 -0
- package/dist/rename/index.d.ts +1 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/blame-format.d.ts +62 -1
- package/dist/results/blame-format.d.ts.map +1 -1
- package/dist/results/cherry-pick-result.d.ts +6 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +9 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/diff-dirstat.d.ts +36 -0
- package/dist/results/diff-dirstat.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +20 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-output.d.ts +67 -3
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/fetch-result.d.ts +24 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +2 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/init-result.d.ts +8 -1
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/line-range-hunks.d.ts +27 -0
- package/dist/results/line-range-hunks.d.ts.map +1 -0
- package/dist/results/merge-result.d.ts +13 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +11 -0
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +10 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/rebase-result.d.ts +7 -0
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +6 -0
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +5 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +1 -1
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-ERo9vELd.js +49673 -0
- package/dist/transport-command.d.ts +93 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/commands/add-command.ts +118 -0
- package/src/commands/add-patch/add-patch.ts +8 -0
- package/src/commands/add-patch/patch-backend.ts +24 -3
- package/src/commands/add-patch/patch-modes.ts +26 -2
- package/src/commands/add-patch/patch-session.ts +6 -0
- package/src/commands/am/am-command.ts +301 -12
- package/src/commands/apply/apply-command.ts +52 -9
- package/src/commands/apply/apply-parse.ts +10 -0
- package/src/commands/apply/index.ts +9 -1
- package/src/commands/archive/archive-command.ts +1148 -0
- package/src/commands/archive/archive-entry.ts +93 -0
- package/src/commands/archive/index.ts +7 -0
- package/src/commands/archive/remote-archive-command.ts +140 -0
- package/src/commands/archive/tar-archive.ts +207 -0
- package/src/commands/archive/tar-commit-id.ts +72 -0
- package/src/commands/archive/upload-archive-writer.ts +213 -0
- package/src/commands/archive/zip-archive.ts +317 -0
- package/src/commands/attributes-source.ts +26 -12
- package/src/commands/blame-command.ts +1551 -53
- package/src/commands/blame-ignore.ts +307 -0
- package/src/commands/bundle/bundle-create-command.ts +405 -0
- package/src/commands/bundle/bundle-format.ts +228 -0
- package/src/commands/bundle/bundle-list.ts +276 -0
- package/src/commands/bundle/bundle-read-commands.ts +157 -0
- package/src/commands/bundle/bundle-support.ts +85 -0
- package/src/commands/bundle/bundle-transport.ts +107 -0
- package/src/commands/bundle/bundle-uri-host.ts +204 -0
- package/src/commands/bundle/bundle-uri.ts +236 -0
- package/src/commands/bundle/bundle-verify.ts +152 -0
- package/src/commands/bundle/index.ts +14 -0
- package/src/commands/cat-file/batch-format.ts +193 -0
- package/src/commands/cat-file/cat-file-command.ts +857 -0
- package/src/commands/cat-file/index.ts +2 -0
- package/src/commands/check-attr-command.ts +333 -0
- package/src/commands/check-ignore-command.ts +261 -0
- package/src/commands/check-mailmap-command.ts +129 -0
- package/src/commands/check-ref-format-command.ts +129 -0
- package/src/commands/checkout-command.ts +131 -28
- package/src/commands/checkout-index-command.ts +568 -0
- package/src/commands/checkout-paths.ts +35 -0
- package/src/commands/cherry-command.ts +187 -0
- package/src/commands/cherry-pick-command.ts +63 -2
- package/src/commands/clean-command.ts +92 -12
- package/src/commands/clean-interactive.ts +522 -0
- package/src/commands/clone-command.ts +803 -50
- package/src/commands/commit-command.ts +202 -51
- package/src/commands/config-command.ts +9 -0
- package/src/commands/daemon-access-hook.ts +78 -0
- package/src/commands/default-branch.ts +99 -1
- package/src/commands/describe-command.ts +341 -254
- package/src/commands/diff-command.ts +1186 -99
- package/src/commands/diff-external.ts +131 -0
- package/src/commands/diff-plumbing/diff-pairs-command.ts +193 -0
- package/src/commands/diff-plumbing/diff-plumbing-command.ts +424 -0
- package/src/commands/diff-plumbing/index.ts +2 -0
- package/src/commands/diff-textconv.ts +5 -1
- package/src/commands/fast-export/fast-export-command.ts +911 -0
- package/src/commands/fast-export/fast-import-command.ts +1553 -0
- package/src/commands/fast-export/fast-stream-support.ts +162 -0
- package/src/commands/fast-export/index.ts +3 -0
- package/src/commands/fetch-command.ts +665 -14
- package/src/commands/fetch-multiple-command.ts +668 -0
- package/src/commands/format-patch-command.ts +189 -77
- package/src/commands/format-rev-command.ts +251 -0
- package/src/commands/fsck/fsck-command.ts +47 -20
- package/src/commands/fsck/fsck-msg-ids.ts +19 -3
- package/src/commands/fsck/fsck-pack.ts +2 -2
- package/src/commands/fsmonitor-refresh.ts +315 -0
- package/src/commands/gc-command.ts +10 -0
- package/src/commands/git-describe.ts +456 -217
- package/src/commands/git-hooks.ts +165 -9
- package/src/commands/git-paths.ts +136 -0
- package/src/commands/grep/grep-command.ts +38 -15
- package/src/commands/history-command.ts +617 -0
- package/src/commands/http-config.ts +139 -0
- package/src/commands/index-adder.ts +37 -3
- package/src/commands/index-host.ts +6 -1
- package/src/commands/index.ts +62 -0
- package/src/commands/init-command.ts +617 -49
- package/src/commands/last-modified-command.ts +804 -0
- package/src/commands/lfs/go-url.ts +370 -0
- package/src/commands/lfs/index.ts +2 -0
- package/src/commands/lfs/lfs-config.ts +738 -0
- package/src/commands/lfs/lfs-endpoint-command.ts +180 -0
- package/src/commands/line-log.ts +931 -0
- package/src/commands/local-transport.ts +252 -4
- package/src/commands/log-command.ts +1518 -182
- package/src/commands/log-graph.ts +6 -3
- package/src/commands/log-output.ts +228 -15
- package/src/commands/ls-files-command.ts +1177 -0
- package/src/commands/ls-remote-command.ts +6 -0
- package/src/commands/ls-tree-command.ts +684 -0
- package/src/commands/mailmap.ts +41 -5
- package/src/commands/maintenance-run-command.ts +949 -0
- package/src/commands/merge-command.ts +351 -47
- package/src/commands/merge-config.ts +23 -1
- package/src/commands/merge-drivers.ts +112 -20
- package/src/commands/merge-strategy-options.ts +224 -0
- package/src/commands/merge-support.ts +130 -26
- package/src/commands/merge-tree-command.ts +786 -0
- package/src/commands/message-cleanup.ts +1 -1
- package/src/commands/mktag-command.ts +149 -0
- package/src/commands/name-rev-command.ts +184 -0
- package/src/commands/name-rev.ts +700 -109
- package/src/commands/object-store/count-objects-command.ts +404 -0
- package/src/commands/object-store/index.ts +4 -0
- package/src/commands/object-store/objects-directory.ts +24 -0
- package/src/commands/object-store/prune-command.ts +129 -0
- package/src/commands/object-store/show-index-command.ts +151 -0
- package/src/commands/octopus-merge.ts +35 -11
- package/src/commands/ort-merge.ts +124 -23
- package/src/commands/ort-recursive.ts +40 -2
- package/src/commands/patch-id-command.ts +65 -0
- package/src/commands/patch-id.ts +327 -0
- package/src/commands/plumbing-command.ts +141 -0
- package/src/commands/plumbing-input.ts +87 -0
- package/src/commands/promisor-remote-reply.ts +276 -0
- package/src/commands/promisor-remote.ts +25 -2
- package/src/commands/pull-command.ts +720 -224
- package/src/commands/push-command.ts +440 -8
- package/src/commands/range-diff/index.ts +3 -0
- package/src/commands/range-diff/linear-assignment.ts +203 -0
- package/src/commands/range-diff/range-diff-command.ts +433 -0
- package/src/commands/range-diff/range-diff.ts +617 -0
- package/src/commands/read-tree-command.ts +74 -3
- package/src/commands/rebase-command.ts +647 -83
- package/src/commands/refs-command.ts +274 -0
- package/src/commands/remerge-diff.ts +241 -0
- package/src/commands/remote-command.ts +98 -10
- package/src/commands/remote-object-info-command.ts +109 -0
- package/src/commands/remote-show-command.ts +836 -0
- package/src/commands/remote-transport.ts +116 -1
- package/src/commands/repack-command.ts +383 -0
- package/src/commands/replace-command.ts +816 -0
- package/src/commands/replay-command.ts +674 -0
- package/src/commands/repo-command.ts +967 -0
- package/src/commands/request-pull-command.ts +356 -0
- package/src/commands/rerere-command.ts +179 -0
- package/src/commands/rerere.ts +925 -0
- package/src/commands/reset-command.ts +78 -3
- package/src/commands/restore-command.ts +15 -0
- package/src/commands/rev-filter/commit-grep.ts +7 -2
- package/src/commands/rev-list-command.ts +196 -11
- package/src/commands/rev-parse-command.ts +62 -4
- package/src/commands/revert-command.ts +62 -2
- package/src/commands/revision-range.ts +10 -3
- package/src/commands/revision-resolver.ts +44 -3
- package/src/commands/sequencer-pick.ts +370 -29
- package/src/commands/sequencer-support.ts +164 -2
- package/src/commands/serve-repository.ts +65 -0
- package/src/commands/session-id.ts +31 -0
- package/src/commands/shortlog-command.ts +354 -0
- package/src/commands/shortlog.ts +361 -0
- package/src/commands/show-branch-command.ts +981 -0
- package/src/commands/show-command.ts +3 -2
- package/src/commands/show-ref-command.ts +439 -0
- package/src/commands/signature-check.ts +37 -5
- package/src/commands/signing.ts +122 -16
- package/src/commands/stash-apply-command.ts +3 -0
- package/src/commands/stash-export-command.ts +397 -0
- package/src/commands/status-command.ts +158 -31
- package/src/commands/status-format.ts +1 -1
- package/src/commands/stripspace-command.ts +118 -0
- package/src/commands/submodule-add-command.ts +22 -1
- package/src/commands/submodule-auth.ts +61 -6
- package/src/commands/submodule-commands.ts +333 -5
- package/src/commands/submodule-fetch.ts +789 -0
- package/src/commands/submodule-model.ts +9 -1
- package/src/commands/submodule-unpack.ts +265 -0
- package/src/commands/submodule-update-command.ts +68 -5
- package/src/commands/subtree-shift.ts +215 -0
- package/src/commands/switch-command.ts +9 -0
- package/src/commands/textconv-cache.ts +143 -0
- package/src/commands/tree-restore.ts +20 -1
- package/src/commands/unpack-objects-command.ts +235 -0
- package/src/commands/update-index-command.ts +1016 -0
- package/src/commands/uri-protocols.ts +13 -0
- package/src/commands/url-parse-command.ts +67 -0
- package/src/commands/var-command.ts +219 -0
- package/src/commands/worktree-overwrite-checks.ts +5 -0
- package/src/errors/command-errors.ts +80 -0
- package/src/git-command.ts +218 -2
- package/src/git.ts +1033 -80
- package/src/guarded-transport-command.ts +176 -0
- package/src/index.ts +1 -0
- package/src/rename/detect-renames.ts +42 -8
- package/src/rename/diffcore-break.ts +166 -0
- package/src/rename/index.ts +1 -0
- package/src/results/blame-format.ts +268 -43
- package/src/results/cherry-pick-result.ts +6 -0
- package/src/results/clone-result.ts +6 -0
- package/src/results/diff-dirstat.ts +117 -0
- package/src/results/diff-entry.ts +24 -0
- package/src/results/diff-formatter.ts +8 -4
- package/src/results/diff-output.ts +239 -8
- package/src/results/diff-pickaxe.ts +1 -1
- package/src/results/fetch-result.ts +24 -1
- package/src/results/index.ts +2 -0
- package/src/results/init-result.ts +10 -1
- package/src/results/line-range-hunks.ts +126 -0
- package/src/results/merge-result.ts +14 -0
- package/src/results/pull-result.ts +7 -0
- package/src/results/push-result.ts +10 -0
- package/src/results/rebase-result.ts +7 -0
- package/src/results/revert-result.ts +6 -0
- package/src/results/stash-result.ts +6 -0
- package/src/results/status-result.ts +2 -2
- package/src/transport-command.ts +216 -4
- package/dist/fsck-DLRpbwTj.js +0 -13405
- package/dist/results-TB2IJ64h.js +0 -4700
|
@@ -0,0 +1,2605 @@
|
|
|
1
|
+
import { I as __exportAll, m as receiveFsckOf } from "./fsck-CrhVMNIH.js";
|
|
2
|
+
import { GitApiError, InvalidConfigError, InvalidPathError, ReadTreeFailedError, TransportError as TransportError$1 } from "./errors/index.js";
|
|
3
|
+
import { Bc as IndexCaseFolding, Cs as quoteCStyleBody, Fa as GitCommand, Ga as signingConfigFromEntries, Gc as pruneEmptyParents, It as resetMerge, Kc as removeCaseVariants, Mc as pushSparseWarnings, Nn as checkSignatureWith, R as StatusCommand, Vc as entryNotUptodate, Xc as untrackedUnder, Xt as SubmoduleUnpack, Zt as recursesIntoSubmodules, _n as worktreeAdminWorkingCopy, aa as planPathsRestore, ca as rewriteIndex, ea as firstPlainError, eu as hostEnvironmentOf, fa as switchTrees, fn as repositoryPlaceOf, fu as RemoteConfigStore, gn as usesBranch, ia as plainUnpackError, il as firstInvalidPath, jl as worktreeModeTrust, kc as SparseUnpack, kl as coreBool, ll as HookSession, nl as restoreCaseOptions, ol as withTreePathRefusal, pn as requireWorktrees, rl as writeTreeRestorePlan, sl as worktreePathRules, ta as flatTree, ul as LOCAL_REPO_ENV, un as parseExpiry, vl as hookHostOf, vn as worktreeUsingBranch, wl as refTransactionHookOf, xl as hookSettingsFromEntries } from "./results-ERo9vELd.js";
|
|
4
|
+
import { FileMode, historyWithoutLazyFetch } from "@statewalker/vcs-core";
|
|
5
|
+
import { compareGitPaths, decodeGitPath, encodeGitPath, parseGitBool, parseGitInt } from "@statewalker/vcs-utils/encoding";
|
|
6
|
+
import { attributesIndexOf, cacheTreeOfTree, entryStatOf, isIndexUnborn, repairCacheTree, sparseFilterMatcher } from "@statewalker/vcs-working-tree";
|
|
7
|
+
import { parseGitInt as parseGitInt$1 } from "@statewalker/vcs-utils";
|
|
8
|
+
import { readFile as readFile$1 } from "@statewalker/vcs-utils/files";
|
|
9
|
+
import { SHA1_OBJECT_FORMAT as SHA1_OBJECT_FORMAT$1, objectFormatByName as objectFormatByName$1 } from "@statewalker/vcs-utils/hash";
|
|
10
|
+
import { configFilesApiOf, gc, parseExpiryDate, readConfinedFile, updateServerInfo } from "@statewalker/vcs-store-files";
|
|
11
|
+
import { ReceivePackDiedError, connectivityErrors, createRepositoryFacade, createTransportRefStore, isGitUrl, openDuplexConnection, openDuplexReceivePackConnection, openReceivePack, openUploadPack, parseGitUrl, protocolVersionFor, pushCertificateEnv, serveOverDuplex, serverSettingsFromConfig } from "@statewalker/vcs-transport";
|
|
12
|
+
//#region src/commands/bundle/bundle-format.ts
|
|
13
|
+
/**
|
|
14
|
+
* git's bundle files (bundle.c, `Documentation/gitformat-bundle.adoc`): a header naming the
|
|
15
|
+
* refs the bundle carries and the commits it needs, then a pack.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // # v3 git bundle
|
|
20
|
+
* // @object-format=sha256
|
|
21
|
+
* // -<id> <subject> (a prerequisite)
|
|
22
|
+
* // <id> refs/heads/main (a ref)
|
|
23
|
+
* // (an empty line, then the pack)
|
|
24
|
+
* const header = parseBundleHeader(bytes);
|
|
25
|
+
* if (header.ok) for (const ref of header.header.references) console.log(ref.id, ref.name);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
/** The first line of a v2 bundle. */
|
|
29
|
+
const V2_BUNDLE_SIGNATURE = "# v2 git bundle\n";
|
|
30
|
+
/** The first line of a v3 bundle (capabilities may follow). */
|
|
31
|
+
const V3_BUNDLE_SIGNATURE = "# v3 git bundle\n";
|
|
32
|
+
/** git's sane_ctype isspace: SP, HT, LF, CR */
|
|
33
|
+
const SPACE = (c) => c === 32 || c === 9 || c === 10 || c === 13;
|
|
34
|
+
const HEX = /^[0-9a-fA-F]$/;
|
|
35
|
+
/**
|
|
36
|
+
* bundle.c's `read_bundle_header_fd`: the signature, then lines up to an empty one (or the
|
|
37
|
+
* end): v3 capabilities (`@object-format=`, `@filter=`), prerequisites (`-<id>` optionally
|
|
38
|
+
* followed by a space and a comment) and refs (`<id> <name>`), each line right-trimmed.
|
|
39
|
+
* `name` is how a bad signature is reported (git's `report_path`).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const parsed = parseBundleHeader(bytes, "repo.bundle");
|
|
44
|
+
* if (!parsed.ok) console.error(`error: ${parsed.error}`);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
function parseBundleHeader(bytes, name = "<bundle>") {
|
|
48
|
+
let at = 0;
|
|
49
|
+
/** strbuf_getwholeline_fd: the next line with its LF; undefined at the end */
|
|
50
|
+
const nextLine = () => {
|
|
51
|
+
if (at >= bytes.length) return void 0;
|
|
52
|
+
const lf = bytes.indexOf(10, at);
|
|
53
|
+
const end = lf < 0 ? bytes.length : lf + 1;
|
|
54
|
+
const line = bytes.subarray(at, end);
|
|
55
|
+
at = end;
|
|
56
|
+
return line;
|
|
57
|
+
};
|
|
58
|
+
const first = nextLine();
|
|
59
|
+
const signature = first ? latin1(first) : "";
|
|
60
|
+
const version = signature === "# v2 git bundle\n" ? 2 : signature === "# v3 git bundle\n" ? 3 : 0;
|
|
61
|
+
if (version === 0) return {
|
|
62
|
+
ok: false,
|
|
63
|
+
error: `'${name}' does not look like a v2 or v3 bundle file`,
|
|
64
|
+
notABundle: true
|
|
65
|
+
};
|
|
66
|
+
let objectFormat = SHA1_OBJECT_FORMAT$1;
|
|
67
|
+
let filter;
|
|
68
|
+
const prerequisites = [];
|
|
69
|
+
const references = [];
|
|
70
|
+
const fail = (error) => ({
|
|
71
|
+
ok: false,
|
|
72
|
+
error,
|
|
73
|
+
notABundle: false
|
|
74
|
+
});
|
|
75
|
+
for (let line = nextLine(); line !== void 0; line = nextLine()) {
|
|
76
|
+
if (line.length === 0 || line[0] === 10) break;
|
|
77
|
+
let end = line.length;
|
|
78
|
+
while (end > 0 && SPACE(line[end - 1])) end--;
|
|
79
|
+
let text = line.subarray(0, end);
|
|
80
|
+
if (version === 3 && text[0] === 64) {
|
|
81
|
+
const capability = decodeGitPath(text.subarray(1));
|
|
82
|
+
if (capability.startsWith("object-format=")) {
|
|
83
|
+
const format = objectFormatByName$1(capability.slice(14));
|
|
84
|
+
if (!format) return fail(`unrecognized bundle hash algorithm: ${capability.slice(14)}`);
|
|
85
|
+
objectFormat = format;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (capability.startsWith("filter=")) {
|
|
89
|
+
filter = capability.slice(7);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
return fail(`unknown capability '${capability}'`);
|
|
93
|
+
}
|
|
94
|
+
const prereq = text[0] === 45;
|
|
95
|
+
if (prereq) text = text.subarray(1);
|
|
96
|
+
const hex = objectFormat.hexLength;
|
|
97
|
+
let valid = text.length >= hex;
|
|
98
|
+
for (let i = 0; valid && i < hex; i++) valid = HEX.test(String.fromCharCode(text[i]));
|
|
99
|
+
const rest = text.subarray(hex);
|
|
100
|
+
if (valid && rest.length > 0 && !SPACE(rest[0])) valid = false;
|
|
101
|
+
if (valid && !prereq && rest.length === 0) valid = false;
|
|
102
|
+
if (!valid) return fail(`unrecognized header: ${prereq ? "-" : ""}${decodeGitPath(text)} (${text.length})`);
|
|
103
|
+
const id = latin1(text.subarray(0, hex)).toLowerCase();
|
|
104
|
+
if (prereq) prerequisites.push({
|
|
105
|
+
id,
|
|
106
|
+
comment: decodeGitPath(rest.subarray(1)).trim()
|
|
107
|
+
});
|
|
108
|
+
else references.push({
|
|
109
|
+
id,
|
|
110
|
+
name: decodeGitPath(rest.subarray(1))
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
ok: true,
|
|
115
|
+
header: {
|
|
116
|
+
version,
|
|
117
|
+
objectFormat,
|
|
118
|
+
...filter !== void 0 ? { filter } : {},
|
|
119
|
+
prerequisites,
|
|
120
|
+
references
|
|
121
|
+
},
|
|
122
|
+
packOffset: at
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The header `create_bundle` writes: the signature (v3 with `@object-format=` and, for a
|
|
127
|
+
* filtered bundle, `@filter=`), `-<id> <comment>` per prerequisite, `<id> <name>` per ref,
|
|
128
|
+
* then the empty line the pack follows.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const bytes = encodeBundleHeader({ version: 2, objectFormat: SHA1_OBJECT_FORMAT,
|
|
133
|
+
* prerequisites: [], references: [{ id, name: "refs/heads/main" }] });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
function encodeBundleHeader(header) {
|
|
137
|
+
const parts = [];
|
|
138
|
+
const text = (s) => parts.push(encodeGitPath(s));
|
|
139
|
+
if (header.version === 2) text(V2_BUNDLE_SIGNATURE);
|
|
140
|
+
else {
|
|
141
|
+
text(V3_BUNDLE_SIGNATURE);
|
|
142
|
+
text(`@object-format=${header.objectFormat.name}\n`);
|
|
143
|
+
if (header.filter !== void 0) text(`@filter=${header.filter}\n`);
|
|
144
|
+
}
|
|
145
|
+
for (const p of header.prerequisites) text(`-${p.id} ${p.comment}\n`);
|
|
146
|
+
for (const r of header.references) text(`${r.id} ${r.name}\n`);
|
|
147
|
+
text("\n");
|
|
148
|
+
let length = 0;
|
|
149
|
+
for (const p of parts) length += p.length;
|
|
150
|
+
const out = new Uint8Array(length);
|
|
151
|
+
let at = 0;
|
|
152
|
+
for (const p of parts) {
|
|
153
|
+
out.set(p, at);
|
|
154
|
+
at += p.length;
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* bundle.c's `list_refs`: `<id> <name>` per ref, only those named in `names` when any are
|
|
160
|
+
* (exact names, as `git bundle list-heads <file> <refname>...` and `unbundle` take them).
|
|
161
|
+
* A prerequisite is listed with an empty name (`<id> `), as `git bundle verify` prints it.
|
|
162
|
+
*/
|
|
163
|
+
function listBundleRefs(refs, names = []) {
|
|
164
|
+
let out = "";
|
|
165
|
+
for (const ref of refs) {
|
|
166
|
+
const name = "name" in ref ? ref.name : "";
|
|
167
|
+
if (names.length > 0 && !names.includes(name)) continue;
|
|
168
|
+
out += `${ref.id} ${name}\n`;
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
function latin1(bytes) {
|
|
173
|
+
let s = "";
|
|
174
|
+
for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);
|
|
175
|
+
return s;
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/commands/bundle/bundle-verify.ts
|
|
179
|
+
/**
|
|
180
|
+
* bundle.c's reading side without a command: a bundle's bytes read (`read_bundle_header`)
|
|
181
|
+
* and checked against a repository (`verify_bundle`), as the bundle commands and the bundle
|
|
182
|
+
* transport do.
|
|
183
|
+
*/
|
|
184
|
+
/** The bytes of a {@link BundleInput}, collected. */
|
|
185
|
+
async function bundleBytes(input) {
|
|
186
|
+
if (input instanceof Uint8Array) return input;
|
|
187
|
+
const chunks = [];
|
|
188
|
+
let length = 0;
|
|
189
|
+
for await (const chunk of input) {
|
|
190
|
+
chunks.push(chunk);
|
|
191
|
+
length += chunk.length;
|
|
192
|
+
}
|
|
193
|
+
const out = new Uint8Array(length);
|
|
194
|
+
let at = 0;
|
|
195
|
+
for (const chunk of chunks) {
|
|
196
|
+
out.set(chunk, at);
|
|
197
|
+
at += chunk.length;
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* builtin/bundle.c's `open_bundle` (`read_bundle_header`): the header and the pack, or git's
|
|
203
|
+
* `error:` line (the bundle reported as `name`: its path, `<stdin>` for `-`).
|
|
204
|
+
*/
|
|
205
|
+
function openBundle(bytes, name) {
|
|
206
|
+
const parsed = parseBundleHeader(bytes, name);
|
|
207
|
+
if (!parsed.ok) return {
|
|
208
|
+
ok: false,
|
|
209
|
+
error: `error: ${parsed.error}\n`
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
ok: true,
|
|
213
|
+
bundle: {
|
|
214
|
+
header: parsed.header,
|
|
215
|
+
pack: bytes.subarray(parsed.packOffset)
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* bundle.c's `verify_bundle`: every prerequisite must be an object here (each missing one
|
|
221
|
+
* on an `error:` line after `Repository lacks these prerequisite commits:`, unless quiet),
|
|
222
|
+
* then connected to the refs (`check_connected` of the prerequisites, `--not --all`); with
|
|
223
|
+
* `verbose`, what the bundle holds on stdout.
|
|
224
|
+
*/
|
|
225
|
+
async function verifyBundleIn(repository, header, options = {}) {
|
|
226
|
+
const objects = historyWithoutLazyFetch(repository.history);
|
|
227
|
+
let stderr = "";
|
|
228
|
+
let missing = 0;
|
|
229
|
+
for (const prerequisite of header.prerequisites) {
|
|
230
|
+
if (await objectExists(objects, prerequisite.id)) continue;
|
|
231
|
+
missing++;
|
|
232
|
+
if (options.quiet) continue;
|
|
233
|
+
if (missing === 1) stderr += "error: Repository lacks these prerequisite commits:\n";
|
|
234
|
+
stderr += `error: ${prerequisite.id} \n`;
|
|
235
|
+
}
|
|
236
|
+
if (missing > 0) return {
|
|
237
|
+
ok: false,
|
|
238
|
+
stdout: "",
|
|
239
|
+
stderr
|
|
240
|
+
};
|
|
241
|
+
let ok = true;
|
|
242
|
+
const tips = header.prerequisites.map((p) => p.id);
|
|
243
|
+
if (tips.length > 0) {
|
|
244
|
+
const facade = createRepositoryFacade({ history: objects });
|
|
245
|
+
if (await connectivityErrors(facade, tips, {
|
|
246
|
+
known: await repository.refValues(),
|
|
247
|
+
shallow: new Set(await repository.shallow())
|
|
248
|
+
})) {
|
|
249
|
+
ok = false;
|
|
250
|
+
stderr += "error: some prerequisite commits exist in the object store, but are not connected to the repository's history\n";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
let stdout = "";
|
|
254
|
+
if (options.verbose) {
|
|
255
|
+
const refs = header.references;
|
|
256
|
+
stdout += refs.length === 1 ? "The bundle contains this ref:\n" : `The bundle contains these ${refs.length} refs:\n`;
|
|
257
|
+
stdout += listBundleRefs(refs);
|
|
258
|
+
const prereqs = header.prerequisites;
|
|
259
|
+
if (prereqs.length === 0) stdout += "The bundle records a complete history.\n";
|
|
260
|
+
else {
|
|
261
|
+
stdout += prereqs.length === 1 ? "The bundle requires this ref:\n" : `The bundle requires these ${prereqs.length} refs:\n`;
|
|
262
|
+
stdout += listBundleRefs(prereqs);
|
|
263
|
+
}
|
|
264
|
+
stdout += `The bundle uses this hash algorithm: ${header.objectFormat.name}\n`;
|
|
265
|
+
if (header.filter !== void 0) stdout += `The bundle uses this filter: ${header.filter}\n`;
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
ok,
|
|
269
|
+
stdout,
|
|
270
|
+
stderr
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/** git's `parse_object` succeeds: the object is here, whatever its type. */
|
|
274
|
+
async function objectExists(history, id) {
|
|
275
|
+
const objects = history.objects;
|
|
276
|
+
if (objects) return objects.has(id).catch(() => false);
|
|
277
|
+
for (const store of [
|
|
278
|
+
history.commits,
|
|
279
|
+
history.trees,
|
|
280
|
+
history.blobs,
|
|
281
|
+
history.tags
|
|
282
|
+
]) if (await store.has(id).catch(() => false)) return true;
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/commands/bundle/bundle-transport.ts
|
|
287
|
+
/**
|
|
288
|
+
* git's bundle transport (transport.c's `bundle_vtable`): a remote URL that is a path to a
|
|
289
|
+
* bundle file is read as a repository whose refs are the bundle's and whose only pack is the
|
|
290
|
+
* bundle's. Fetch, clone, pull and ls-remote reach it through an upload-pack served in
|
|
291
|
+
* process from the bundle: its refs advertised (in git's order: the bundle's refs reversed,
|
|
292
|
+
* as `get_refs_from_bundle` prepends each), and any fetch answered with the bundle's pack,
|
|
293
|
+
* once the fetching repository has the bundle's prerequisites (`unbundle`'s `verify_bundle`).
|
|
294
|
+
*/
|
|
295
|
+
/**
|
|
296
|
+
* A fetch from a bundle the repository lacks the prerequisites of: `verify_bundle`'s lines
|
|
297
|
+
* (`git fetch` exits 1; `git clone` adds `fatal: remote transport reported error`, 128).
|
|
298
|
+
*/
|
|
299
|
+
var BundlePrerequisitesError = class extends TransportError$1 {
|
|
300
|
+
lines;
|
|
301
|
+
constructor(lines) {
|
|
302
|
+
super(lines.replace(/\n$/, ""), void 0, { exitCode: 1 });
|
|
303
|
+
this.lines = lines;
|
|
304
|
+
this.name = "BundlePrerequisitesError";
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
/** Bytes per chunk the served pack is cut into. */
|
|
308
|
+
const CHUNK = 65536;
|
|
309
|
+
/**
|
|
310
|
+
* Runs `run` over a connection to an upload-pack serving the bundle (protocol v0). A fetch
|
|
311
|
+
* that needs the pack verifies the bundle first: when the repository lacks its prerequisites
|
|
312
|
+
* the fetch fails with git's lines (exit 1, as `git fetch` returns).
|
|
313
|
+
*/
|
|
314
|
+
async function withBundleUploadPack(remote, createPair, run) {
|
|
315
|
+
const { header, pack } = remote.bundle;
|
|
316
|
+
let refused;
|
|
317
|
+
const facade = {
|
|
318
|
+
objectFormat: header.objectFormat,
|
|
319
|
+
importPack: () => Promise.reject(/* @__PURE__ */ new Error("a bundle cannot be written to")),
|
|
320
|
+
async *exportPack() {
|
|
321
|
+
const verified = await remote.verify();
|
|
322
|
+
if (!verified.ok) {
|
|
323
|
+
refused = verified.stderr;
|
|
324
|
+
throw new Error("bundle prerequisites missing");
|
|
325
|
+
}
|
|
326
|
+
for (let at = 0; at < pack.length; at += CHUNK) yield pack.subarray(at, at + CHUNK);
|
|
327
|
+
},
|
|
328
|
+
has: async (oid) => header.references.some((r) => r.id === oid),
|
|
329
|
+
async *walkAncestors() {}
|
|
330
|
+
};
|
|
331
|
+
const [client, server] = createPair();
|
|
332
|
+
const serving = serveOverDuplex({
|
|
333
|
+
duplex: server,
|
|
334
|
+
repository: facade,
|
|
335
|
+
refStore: bundleRefStore(header),
|
|
336
|
+
service: "git-upload-pack"
|
|
337
|
+
}).finally(() => server.close?.());
|
|
338
|
+
try {
|
|
339
|
+
const connection = await openDuplexConnection(client, { closeDuplex: true });
|
|
340
|
+
try {
|
|
341
|
+
return await run(connection);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
if (refused !== void 0) throw new BundlePrerequisitesError(refused);
|
|
344
|
+
throw error;
|
|
345
|
+
} finally {
|
|
346
|
+
await connection.close();
|
|
347
|
+
}
|
|
348
|
+
} finally {
|
|
349
|
+
await client.close?.();
|
|
350
|
+
await serving.catch(() => void 0);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/** The refs a bundle advertises: read-only, in `get_refs_from_bundle`'s (reversed) order. */
|
|
354
|
+
function bundleRefStore(header) {
|
|
355
|
+
const refs = [...header.references].reverse();
|
|
356
|
+
return {
|
|
357
|
+
get: async (name) => refs.find((r) => r.name === name)?.id,
|
|
358
|
+
update: () => Promise.reject(/* @__PURE__ */ new Error("a bundle cannot be written to")),
|
|
359
|
+
listAll: async () => refs.map((r) => [r.name, r.id]),
|
|
360
|
+
isRefTip: async (oid) => refs.some((r) => r.id === oid)
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/commands/worktree-prune-command.ts
|
|
365
|
+
/**
|
|
366
|
+
* Prune the administrative files of worktrees that are gone.
|
|
367
|
+
*
|
|
368
|
+
* Equivalent to `git worktree prune [-n] [-v] [--expire <expire>]`.
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```typescript
|
|
372
|
+
* const { pruned } = await git.worktreePrune().setDryRun(true).call();
|
|
373
|
+
* await git.worktreePrune().setExpire("3.months.ago").call();
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* As git's `should_prune_worktree`, `.git/worktrees/<id>` goes when it is not a directory,
|
|
377
|
+
* has no `gitdir` file, an empty one, or one naming a place that no longer exists and whose
|
|
378
|
+
* `index` is not newer than `--expire` (default: every such worktree). A locked worktree is
|
|
379
|
+
* kept whatever its state. Of the kept worktrees, those whose `gitdir` names the same
|
|
380
|
+
* place as another (or as the repository) are pruned as `duplicate entry`, the first by
|
|
381
|
+
* name kept. The empty `.git/worktrees` goes too. `git gc` runs this with
|
|
382
|
+
* `gc.worktreePruneExpire` (default `3.months.ago`).
|
|
383
|
+
*/
|
|
384
|
+
var WorktreePruneCommand = class extends GitCommand {
|
|
385
|
+
dryRun = false;
|
|
386
|
+
verbose = false;
|
|
387
|
+
expire = Number.POSITIVE_INFINITY;
|
|
388
|
+
/** `-n`: report, remove nothing. */
|
|
389
|
+
setDryRun(dryRun) {
|
|
390
|
+
this.checkCallable();
|
|
391
|
+
this.dryRun = dryRun;
|
|
392
|
+
return this;
|
|
393
|
+
}
|
|
394
|
+
/** `-v`: report what is removed. */
|
|
395
|
+
setVerbose(verbose) {
|
|
396
|
+
this.checkCallable();
|
|
397
|
+
this.verbose = verbose;
|
|
398
|
+
return this;
|
|
399
|
+
}
|
|
400
|
+
/** `--expire <time>`: missing worktrees whose index is newer are kept. */
|
|
401
|
+
setExpire(expire) {
|
|
402
|
+
this.checkCallable();
|
|
403
|
+
this.expire = expire;
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
async call() {
|
|
407
|
+
this.checkCallable();
|
|
408
|
+
this.setCallable(false);
|
|
409
|
+
const worktrees = requireWorktrees(this.workingCopy, "prune");
|
|
410
|
+
const expire = parseExpiry(this.expire);
|
|
411
|
+
const pruned = [];
|
|
412
|
+
const messages = [];
|
|
413
|
+
const prune = async (id, reason) => {
|
|
414
|
+
if (this.dryRun || this.verbose) messages.push(`Removing worktrees/${id}: ${reason}`);
|
|
415
|
+
if (!this.dryRun) await worktrees.deleteAdminDir(id).catch(() => void 0);
|
|
416
|
+
pruned.push({
|
|
417
|
+
id,
|
|
418
|
+
reason
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
const kept = [];
|
|
422
|
+
for (const id of await worktrees.adminIds()) {
|
|
423
|
+
const check = await worktrees.pruneCheck(id, expire);
|
|
424
|
+
if (check.reason !== void 0) await prune(id, check.reason);
|
|
425
|
+
else if (check.gitdirPath !== void 0) kept.push({
|
|
426
|
+
path: check.gitdirPath,
|
|
427
|
+
id
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
kept.push({ path: worktrees.commonDirPath().replace(/\/\.$/, "") });
|
|
431
|
+
kept.sort((a, b) => {
|
|
432
|
+
if (a.path !== b.path) return a.path < b.path ? -1 : 1;
|
|
433
|
+
if (a.id === void 0) return -1;
|
|
434
|
+
if (b.id === void 0) return 1;
|
|
435
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
436
|
+
});
|
|
437
|
+
for (let i = 1; i < kept.length; i++) {
|
|
438
|
+
const id = kept[i].id;
|
|
439
|
+
if (kept[i].path === kept[i - 1].path && id !== void 0) await prune(id, "duplicate entry");
|
|
440
|
+
}
|
|
441
|
+
if (!this.dryRun) await worktrees.deleteAdminRootIfEmpty();
|
|
442
|
+
return {
|
|
443
|
+
pruned,
|
|
444
|
+
messages
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/commands/gc-command.ts
|
|
450
|
+
/** git's defaults: `gc.auto` loose objects, `gc.autoPackLimit` packs. */
|
|
451
|
+
const GC_AUTO_DEFAULT = 6700;
|
|
452
|
+
const GC_AUTO_PACK_LIMIT_DEFAULT = 50;
|
|
453
|
+
/**
|
|
454
|
+
* Run garbage collection on the repository: `git gc`.
|
|
455
|
+
*
|
|
456
|
+
* Over a files repository it runs what `git gc` runs, in git's order (builtin/gc.c): `pack-refs
|
|
457
|
+
* --all --prune` (`gc.packRefs`), `reflog expire --all` (`gc.reflogExpire*`), `worktree prune
|
|
458
|
+
* --expire <gc.worktreePruneExpire>` and `rerere gc` (`gc.rerereResolved`/`Unresolved`), the
|
|
459
|
+
* repack (`repack -d -l` with `--cruft --cruft-expiration=<gc.pruneExpire>` (`gc.cruftPacks`,
|
|
460
|
+
* default), `-A --unpack-unreachable=<expire>` without cruft packs, or `-a` for `--prune=now`;
|
|
461
|
+
* `--keep-pack` for `--keep-largest-pack`/`gc.bigPackThreshold`; `-f --depth --window` for
|
|
462
|
+
* `--aggressive`; a bitmap in a bare repository), `update-server-info`, `prune --expire
|
|
463
|
+
* <expire>` (with `prune_shallow`), and the commit-graph (`gc.writeCommitGraph`). git 2.43 runs
|
|
464
|
+
* the worktree prune and rerere gc after the prune, 2.5x before the repack: the hook runner's
|
|
465
|
+
* compatibility decides. Without a files repository only refs are packed and worktrees pruned.
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```typescript
|
|
469
|
+
* const result = await git.gc().call();
|
|
470
|
+
* console.log(`Removed ${result.objectsRemoved} objects`);
|
|
471
|
+
*
|
|
472
|
+
* // git gc --aggressive --prune=now
|
|
473
|
+
* await git.gc().setAggressive(true).setPrune("now").call();
|
|
474
|
+
*
|
|
475
|
+
* // git gc --no-prune
|
|
476
|
+
* await git.gc().setPrune(false).call();
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
var GarbageCollectCommand = class extends GitCommand {
|
|
480
|
+
_packRefs;
|
|
481
|
+
/** git's fsck and gc read the objects as stored, never through replace refs. */
|
|
482
|
+
readsReplacedObjects() {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
_aggressive = false;
|
|
486
|
+
_expire;
|
|
487
|
+
_prune;
|
|
488
|
+
_auto = false;
|
|
489
|
+
_quiet = false;
|
|
490
|
+
_cruft;
|
|
491
|
+
_maxCruftSize;
|
|
492
|
+
_keepLargestPack;
|
|
493
|
+
_force = false;
|
|
494
|
+
/**
|
|
495
|
+
* `git gc --auto`: housekeeping only when needed (git's `need_to_gc`: more loose objects
|
|
496
|
+
* than `gc.auto`, estimated from `objects/17` as git does, default 6700, or more packs
|
|
497
|
+
* without a `.keep` than `gc.autoPackLimit`, default 50; 0 or less turns either check
|
|
498
|
+
* off, `gc.auto=0` all of auto gc), and only when the pre-auto-gc hook, run first, agrees.
|
|
499
|
+
* With too many packs the repack is a full one, else an incremental one (the reachable loose
|
|
500
|
+
* objects into a new pack). No command runs it by itself: callers decide when (git's
|
|
501
|
+
* `maintenance.auto` after a commit, merge or fetch is not reproduced).
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```typescript
|
|
505
|
+
* const result = await git.gc().setAuto(true).call();
|
|
506
|
+
* if (result.autoSkipped) console.log(`nothing done: ${result.autoSkipped}`);
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
setAuto(auto) {
|
|
510
|
+
this.checkCallable();
|
|
511
|
+
this._auto = auto;
|
|
512
|
+
return this;
|
|
513
|
+
}
|
|
514
|
+
/** `--quiet`: no "Auto packing the repository ..." messages. */
|
|
515
|
+
setQuiet(quiet) {
|
|
516
|
+
this.checkCallable();
|
|
517
|
+
this._quiet = quiet;
|
|
518
|
+
return this;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* `--prune=<date>` (a git expiry date: `now`, `never`, `2.weeks.ago`, a `Date`), `--prune`
|
|
522
|
+
* (true: `gc.pruneExpire`, default two weeks) or `--no-prune` (false: nothing unreachable
|
|
523
|
+
* expires, `git prune` does not run).
|
|
524
|
+
*/
|
|
525
|
+
setPrune(prune) {
|
|
526
|
+
this.checkCallable();
|
|
527
|
+
if (prune instanceof Date) this._expire = prune;
|
|
528
|
+
else this._prune = prune;
|
|
529
|
+
return this;
|
|
530
|
+
}
|
|
531
|
+
/** `--cruft` / `--no-cruft` (default `gc.cruftPacks`, true). */
|
|
532
|
+
setCruft(cruft) {
|
|
533
|
+
this.checkCallable();
|
|
534
|
+
this._cruft = cruft;
|
|
535
|
+
return this;
|
|
536
|
+
}
|
|
537
|
+
/** `--max-cruft-size=<bytes>` (default `gc.maxCruftSize`). */
|
|
538
|
+
setMaxCruftSize(bytes) {
|
|
539
|
+
this.checkCallable();
|
|
540
|
+
this._maxCruftSize = bytes;
|
|
541
|
+
return this;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* `--keep-largest-pack` (true) / `--no-keep-largest-pack` (false): the largest non-cruft
|
|
545
|
+
* pack is kept as it is; false also ignores `gc.bigPackThreshold`.
|
|
546
|
+
*/
|
|
547
|
+
setKeepLargestPack(keep) {
|
|
548
|
+
this.checkCallable();
|
|
549
|
+
this._keepLargestPack = keep;
|
|
550
|
+
return this;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* git's `need_to_gc`: whether `gc --auto` has work to do (the maintenance gc task's `--auto`
|
|
554
|
+
* condition). Reads only the configuration and the objects directory.
|
|
555
|
+
*/
|
|
556
|
+
async isAutoGcNeeded() {
|
|
557
|
+
return this.needsAutoGc();
|
|
558
|
+
}
|
|
559
|
+
/** git's `need_to_gc`: whether `gc --auto` has work to do. */
|
|
560
|
+
async needsAutoGc() {
|
|
561
|
+
const config = RemoteConfigStore.from(this.workingCopy);
|
|
562
|
+
const int = (key, fallback) => {
|
|
563
|
+
const value = config.value(key);
|
|
564
|
+
if (value === void 0) return fallback;
|
|
565
|
+
const n = parseGitInt$1(value);
|
|
566
|
+
if (n === void 0) throw new GitApiError(`fatal: bad numeric config value '${value}' for '${key.toLowerCase()}': invalid unit`);
|
|
567
|
+
return n;
|
|
568
|
+
};
|
|
569
|
+
const gcAuto = int("gc.auto", GC_AUTO_DEFAULT);
|
|
570
|
+
if (gcAuto <= 0) return false;
|
|
571
|
+
const packLimit = int("gc.autoPackLimit", GC_AUTO_PACK_LIMIT_DEFAULT);
|
|
572
|
+
const objects = await this.hooks.commonGitFile("objects");
|
|
573
|
+
if (!objects) return false;
|
|
574
|
+
const names = async (dir) => {
|
|
575
|
+
const out = [];
|
|
576
|
+
try {
|
|
577
|
+
for await (const info of objects.files.list(`${objects.path}/${dir}`)) out.push(info.name);
|
|
578
|
+
} catch {}
|
|
579
|
+
return out;
|
|
580
|
+
};
|
|
581
|
+
if (packLimit > 0) {
|
|
582
|
+
const files = new Set(await names("pack"));
|
|
583
|
+
let packs = 0;
|
|
584
|
+
for (const name of files) {
|
|
585
|
+
if (!name.endsWith(".pack")) continue;
|
|
586
|
+
const base = name.slice(0, -5);
|
|
587
|
+
if (files.has(`${base}.idx`) && !files.has(`${base}.keep`)) packs++;
|
|
588
|
+
}
|
|
589
|
+
if (packs > packLimit) return true;
|
|
590
|
+
}
|
|
591
|
+
const loose = new RegExp(`^[0-9a-f]{${this.objectFormat.hexLength - 2}}$`);
|
|
592
|
+
return (await names("17")).filter((n) => loose.test(n)).length * 256 > Math.ceil(gcAuto / 256) * 256;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* `--force`: run even when `gc.pid` says another gc is running (git's `lock_repo_for_gc`
|
|
596
|
+
* with `force`); `gc.pid.lock` must still be free.
|
|
597
|
+
*/
|
|
598
|
+
setForce(force) {
|
|
599
|
+
this.checkCallable();
|
|
600
|
+
this._force = force;
|
|
601
|
+
return this;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* `--aggressive`: deltas searched again (`repack -f`) with `gc.aggressiveWindow` (250) and
|
|
605
|
+
* `gc.aggressiveDepth` (50).
|
|
606
|
+
*/
|
|
607
|
+
setAggressive(aggressive) {
|
|
608
|
+
this.checkCallable();
|
|
609
|
+
this._aggressive = aggressive;
|
|
610
|
+
return this;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Whether to pack refs (`git pack-refs --all --prune`). Default: `gc.packRefs` (true;
|
|
614
|
+
* `notbare` packs them only in a repository with a worktree).
|
|
615
|
+
*/
|
|
616
|
+
setPackRefs(packRefs) {
|
|
617
|
+
this.checkCallable();
|
|
618
|
+
this._packRefs = packRefs;
|
|
619
|
+
return this;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* `--prune=<date>`: unreachable objects older than this date expire; younger ones stay
|
|
623
|
+
* (loose, or in a cruft pack) in case a write in progress needs them.
|
|
624
|
+
*/
|
|
625
|
+
setExpire(expire) {
|
|
626
|
+
this.checkCallable();
|
|
627
|
+
this._expire = expire;
|
|
628
|
+
return this;
|
|
629
|
+
}
|
|
630
|
+
/** The repository's files backend: its FilesApi, common git directory and history. */
|
|
631
|
+
async filesRepository() {
|
|
632
|
+
const history = this.workingCopy.history;
|
|
633
|
+
if (!history?.objects || !history.packs) return void 0;
|
|
634
|
+
const objects = await this.hooks.commonGitFile("objects");
|
|
635
|
+
if (!objects) return void 0;
|
|
636
|
+
return {
|
|
637
|
+
files: objects.files,
|
|
638
|
+
gitDir: objects.path.replace(/\/?objects$/, ""),
|
|
639
|
+
history
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
/** The prune expiry in milliseconds before now, undefined for the config's. */
|
|
643
|
+
pruneExpireMs() {
|
|
644
|
+
if (this._expire) return Math.max(0, Date.now() - this._expire.getTime());
|
|
645
|
+
if (typeof this._prune !== "string") return void 0;
|
|
646
|
+
const nowMs = Date.now();
|
|
647
|
+
const cutoff = parseExpiryDate(this._prune, Math.floor(nowMs / 1e3), "--prune");
|
|
648
|
+
if (cutoff === 0) return Number.POSITIVE_INFINITY;
|
|
649
|
+
if (cutoff === Number.POSITIVE_INFINITY) return 0;
|
|
650
|
+
return Math.max(0, nowMs - cutoff * 1e3);
|
|
651
|
+
}
|
|
652
|
+
/** `gc.packRefs`: a boolean, or `notbare` (packed unless the repository is bare). */
|
|
653
|
+
packRefsConfigured() {
|
|
654
|
+
if (this._packRefs !== void 0) return this._packRefs;
|
|
655
|
+
const config = RemoteConfigStore.from(this.workingCopy);
|
|
656
|
+
const value = config.value("gc.packRefs");
|
|
657
|
+
if (value === void 0) return true;
|
|
658
|
+
if (value === "notbare") {
|
|
659
|
+
const bare = config.value("core.bare");
|
|
660
|
+
return !(bare !== void 0 && (parseGitBool(bare) ?? false));
|
|
661
|
+
}
|
|
662
|
+
return parseGitBool(value) ?? true;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Execute the garbage collection.
|
|
666
|
+
*
|
|
667
|
+
* @returns GC result with statistics
|
|
668
|
+
*/
|
|
669
|
+
async call() {
|
|
670
|
+
this.checkCallable();
|
|
671
|
+
this.setCallable(false);
|
|
672
|
+
const startTime = Date.now();
|
|
673
|
+
let refsPacked = false;
|
|
674
|
+
const messages = [];
|
|
675
|
+
const skipped = (autoSkipped) => ({
|
|
676
|
+
objectsRemoved: 0,
|
|
677
|
+
bytesFreed: 0,
|
|
678
|
+
refsPacked,
|
|
679
|
+
durationMs: Date.now() - startTime,
|
|
680
|
+
worktreesPruned: [],
|
|
681
|
+
autoSkipped
|
|
682
|
+
});
|
|
683
|
+
if (this._auto) {
|
|
684
|
+
if (!await this.needsAutoGc()) return skipped("not-needed");
|
|
685
|
+
const hook = await this.hooks.run("pre-auto-gc");
|
|
686
|
+
if (hook && hook.exitCode !== 0) return skipped("hook");
|
|
687
|
+
if (!this._quiet) messages.push("Auto packing the repository for optimum performance.", "See \"git help gc\" for manual housekeeping.");
|
|
688
|
+
}
|
|
689
|
+
const errors = [];
|
|
690
|
+
const packRefs = async () => {
|
|
691
|
+
if (!this.refsStore.packRefs) return;
|
|
692
|
+
await this.refsStore.packRefs([], {
|
|
693
|
+
all: true,
|
|
694
|
+
deleteLoose: true,
|
|
695
|
+
...this._auto && this.hooks.compatibility !== "2.43" ? { auto: true } : {},
|
|
696
|
+
onError: (line) => {
|
|
697
|
+
errors.push(line);
|
|
698
|
+
this.hooks.append(`${line}\n`);
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
refsPacked = true;
|
|
702
|
+
};
|
|
703
|
+
const worktreesPruned = [];
|
|
704
|
+
const pruneWorktrees = async () => {
|
|
705
|
+
if (!this.workingCopy.worktrees) return;
|
|
706
|
+
const expire = RemoteConfigStore.from(this.workingCopy).value("gc.worktreePruneExpire") ?? "3.months.ago";
|
|
707
|
+
const { pruned } = await new WorktreePruneCommand(this.workingCopy).setExpire(expire).call();
|
|
708
|
+
for (const p of pruned) worktreesPruned.push(p.id);
|
|
709
|
+
};
|
|
710
|
+
const repository = await this.filesRepository();
|
|
711
|
+
if (!repository) {
|
|
712
|
+
if (this.packRefsConfigured()) await packRefs();
|
|
713
|
+
await pruneWorktrees();
|
|
714
|
+
return {
|
|
715
|
+
objectsRemoved: 0,
|
|
716
|
+
bytesFreed: 0,
|
|
717
|
+
refsPacked,
|
|
718
|
+
durationMs: Date.now() - startTime,
|
|
719
|
+
worktreesPruned,
|
|
720
|
+
...this._auto ? { messages } : {},
|
|
721
|
+
...errors.length > 0 || this.alternatesErrors().length > 0 ? { errors: [...this.alternatesErrors(), ...errors] } : {}
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
const environment = hostEnvironmentOf(this.workingCopy);
|
|
725
|
+
const pruneExpireMs = this.pruneExpireMs();
|
|
726
|
+
const details = await gc({
|
|
727
|
+
history: repository.history,
|
|
728
|
+
files: repository.files,
|
|
729
|
+
gitDir: repository.gitDir,
|
|
730
|
+
compatibility: this.hooks.compatibility,
|
|
731
|
+
...environment ? { environment } : {},
|
|
732
|
+
...this.progress && !this._quiet ? { progress: this.progress } : {},
|
|
733
|
+
packRefs: this.packRefsConfigured(),
|
|
734
|
+
packRefsStep: packRefs,
|
|
735
|
+
beforeObjects: pruneWorktrees,
|
|
736
|
+
afterObjects: pruneWorktrees,
|
|
737
|
+
...this._prune === false ? { prune: false } : {},
|
|
738
|
+
...pruneExpireMs !== void 0 ? { pruneExpireMs } : {},
|
|
739
|
+
...this._cruft !== void 0 ? { cruftPacks: this._cruft } : {},
|
|
740
|
+
...this._maxCruftSize !== void 0 ? { maxCruftSize: this._maxCruftSize } : {},
|
|
741
|
+
...this._keepLargestPack !== void 0 ? { keepLargestPack: this._keepLargestPack } : {},
|
|
742
|
+
...this._aggressive ? { aggressive: true } : {},
|
|
743
|
+
...this._auto ? { auto: true } : {},
|
|
744
|
+
...this._force ? { force: true } : {}
|
|
745
|
+
});
|
|
746
|
+
if (details.skipped) {
|
|
747
|
+
if (details.lockFileExists) throw new GitApiError(this.gcLockFileMessage());
|
|
748
|
+
if (this._auto) return skipped("running");
|
|
749
|
+
const holder = details.lockHolder;
|
|
750
|
+
throw new GitApiError(`fatal: gc is already running on machine '${holder?.machine}' pid ${holder?.pid} (use --force if not)`);
|
|
751
|
+
}
|
|
752
|
+
const storage = details.storage;
|
|
753
|
+
const allErrors = [
|
|
754
|
+
...this.alternatesErrors(),
|
|
755
|
+
...errors,
|
|
756
|
+
...details.errors ?? []
|
|
757
|
+
];
|
|
758
|
+
const uniqueErrors = allErrors.filter((line, i) => !this.alternatesErrors().includes(line) || allErrors.indexOf(line) === i);
|
|
759
|
+
return {
|
|
760
|
+
objectsRemoved: storage ? storage.before.objects - storage.after.objects : 0,
|
|
761
|
+
bytesFreed: storage ? storage.before.bytes - storage.after.bytes : 0,
|
|
762
|
+
refsPacked,
|
|
763
|
+
durationMs: Date.now() - startTime,
|
|
764
|
+
worktreesPruned,
|
|
765
|
+
...this._auto ? { messages } : {},
|
|
766
|
+
...uniqueErrors.length > 0 ? { errors: uniqueErrors } : {},
|
|
767
|
+
...details.warnings ? { warnings: details.warnings } : {},
|
|
768
|
+
details
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
/** git's `unable_to_lock_die` for `gc.pid.lock` (2.43's longer advice under its compatibility). */
|
|
772
|
+
gcLockFileMessage() {
|
|
773
|
+
const gitDir = this.workingCopy.config?.hostGitDir;
|
|
774
|
+
return `fatal: Unable to create '${gitDir ? `${gitDir.replace(/\/+$/, "")}/gc.pid.lock` : ".git/gc.pid.lock"}': File exists.\n\n${this.hooks.compatibility === "2.43" ? "Another git process seems to be running in this repository, e.g.\nan editor opened by 'git commit'. Please make sure all processes\nare terminated then try again. If it still fails, a git process\nmay have crashed in this repository earlier:\nremove the file manually to continue." : "Another git process seems to be running in this repository, or the lock file may be stale"}`;
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/commands/read-tree-command.ts
|
|
779
|
+
/**
|
|
780
|
+
* `git read-tree` (builtin/read-tree.c over unpack-trees.c): read trees into the index,
|
|
781
|
+
* merging them with it (`-m`: one-, two- and three-way), optionally updating the worktree.
|
|
782
|
+
*/
|
|
783
|
+
/** unpack-trees' `MAX_UNPACK_TREES`. */
|
|
784
|
+
const MAX_UNPACK_TREES = 8;
|
|
785
|
+
const same = (a, b) => a === void 0 || b === void 0 ? a === b : a.objectId === b.objectId && a.mode === b.mode;
|
|
786
|
+
/**
|
|
787
|
+
* Read trees into the index (`git read-tree`).
|
|
788
|
+
*
|
|
789
|
+
* ```typescript
|
|
790
|
+
* // the index becomes HEAD's tree (stat data and flags gone)
|
|
791
|
+
* await git.readTree().addTree("HEAD").call();
|
|
792
|
+
*
|
|
793
|
+
* // a fast-forward of the index and the worktree from HEAD to `next`
|
|
794
|
+
* await git.readTree().setMerge(true).setUpdate(true).addTree("HEAD").addTree("next").call();
|
|
795
|
+
*
|
|
796
|
+
* // a three-way merge leaving the conflicts as stages 1-3
|
|
797
|
+
* await git.readTree().setMerge(true).addTree(base).addTree("HEAD").addTree(other).call();
|
|
798
|
+
* ```
|
|
799
|
+
*
|
|
800
|
+
* A refusal is unpack-trees' plain message for the first path refused (`error: Entry 'x'
|
|
801
|
+
* would be overwritten by merge. Cannot merge.`), thrown as {@link ReadTreeFailedError}
|
|
802
|
+
* before anything changed. One tree read without `--prefix` leaves the index's cache-tree
|
|
803
|
+
* primed with it (`prime_cache_tree`); otherwise each directory is valid where its tree is
|
|
804
|
+
* stored (`cache_tree_update` with `WRITE_TREE_REPAIR`), none while conflicts remain.
|
|
805
|
+
*/
|
|
806
|
+
var ReadTreeCommand = class extends GitCommand {
|
|
807
|
+
treeishes = [];
|
|
808
|
+
merge = false;
|
|
809
|
+
reset = false;
|
|
810
|
+
prefix;
|
|
811
|
+
update = false;
|
|
812
|
+
indexOnly = false;
|
|
813
|
+
empty = false;
|
|
814
|
+
trivial = false;
|
|
815
|
+
aggressive = false;
|
|
816
|
+
skipSparseCheckout = false;
|
|
817
|
+
recurseSubmodules;
|
|
818
|
+
dryRun = false;
|
|
819
|
+
superPrefix = "";
|
|
820
|
+
/** A tree-ish to read (up to eight). */
|
|
821
|
+
addTree(treeish) {
|
|
822
|
+
this.checkCallable();
|
|
823
|
+
this.treeishes.push(treeish);
|
|
824
|
+
return this;
|
|
825
|
+
}
|
|
826
|
+
/** `-m`: merge the trees with the index (one-, two- or three-way by their number). */
|
|
827
|
+
setMerge(merge) {
|
|
828
|
+
this.checkCallable();
|
|
829
|
+
this.merge = merge;
|
|
830
|
+
return this;
|
|
831
|
+
}
|
|
832
|
+
/** `--reset`: as `-m`, unmerged entries discarded and local changes no refusal. */
|
|
833
|
+
setReset(reset) {
|
|
834
|
+
this.checkCallable();
|
|
835
|
+
this.reset = reset;
|
|
836
|
+
return this;
|
|
837
|
+
}
|
|
838
|
+
/** `--prefix=<dir>/`: the tree read under `<dir>/` (bound into the index, which keeps the rest). */
|
|
839
|
+
setPrefix(prefix) {
|
|
840
|
+
this.checkCallable();
|
|
841
|
+
this.prefix = prefix;
|
|
842
|
+
return this;
|
|
843
|
+
}
|
|
844
|
+
/** `-u`: the worktree updated with the merge's result. */
|
|
845
|
+
setUpdate(update) {
|
|
846
|
+
this.checkCallable();
|
|
847
|
+
this.update = update;
|
|
848
|
+
return this;
|
|
849
|
+
}
|
|
850
|
+
/** `-i`: the worktree is not looked at (no up-to-date check). */
|
|
851
|
+
setIndexOnly(indexOnly) {
|
|
852
|
+
this.checkCallable();
|
|
853
|
+
this.indexOnly = indexOnly;
|
|
854
|
+
return this;
|
|
855
|
+
}
|
|
856
|
+
/** `--empty`: empty the index. */
|
|
857
|
+
setEmpty(empty) {
|
|
858
|
+
this.checkCallable();
|
|
859
|
+
this.empty = empty;
|
|
860
|
+
return this;
|
|
861
|
+
}
|
|
862
|
+
/** `--trivial`: a three-way merge only where no path needs a file-level merge. */
|
|
863
|
+
setTrivial(trivial) {
|
|
864
|
+
this.checkCallable();
|
|
865
|
+
this.trivial = trivial;
|
|
866
|
+
return this;
|
|
867
|
+
}
|
|
868
|
+
/** `--aggressive`: a three-way merge also resolving deletions and identical additions. */
|
|
869
|
+
setAggressive(aggressive) {
|
|
870
|
+
this.checkCallable();
|
|
871
|
+
this.aggressive = aggressive;
|
|
872
|
+
return this;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* `-v`: accepted for parity. git shows only a delayed progress meter ("Updating files"),
|
|
876
|
+
* which an update shorter than two seconds never prints; nothing is reported here.
|
|
877
|
+
*/
|
|
878
|
+
setVerbose(_verbose) {
|
|
879
|
+
this.checkCallable();
|
|
880
|
+
return this;
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* `--[no-]recurse-submodules` (default `submodule.recurse`): the active submodules' worktrees
|
|
884
|
+
* are checked and moved with the superproject's (unpack-trees' `check_submodule_move_head`,
|
|
885
|
+
* entry.c's `submodule_move_head`).
|
|
886
|
+
*/
|
|
887
|
+
setRecurseSubmodules(recurse) {
|
|
888
|
+
this.checkCallable();
|
|
889
|
+
this.recurseSubmodules = recurse;
|
|
890
|
+
return this;
|
|
891
|
+
}
|
|
892
|
+
/** `-n` / `--dry-run`: everything checked, neither the index nor the worktree written. */
|
|
893
|
+
setDryRun(dryRun) {
|
|
894
|
+
this.checkCallable();
|
|
895
|
+
this.dryRun = dryRun;
|
|
896
|
+
return this;
|
|
897
|
+
}
|
|
898
|
+
/** @internal git's `--super-prefix`: the submodule's path in its superproject, in messages. */
|
|
899
|
+
setSuperPrefix(prefix) {
|
|
900
|
+
this.superPrefix = prefix;
|
|
901
|
+
return this;
|
|
902
|
+
}
|
|
903
|
+
/** `--no-sparse-checkout`: the sparse-checkout patterns are not applied. */
|
|
904
|
+
setSkipSparseCheckout(skip) {
|
|
905
|
+
this.checkCallable();
|
|
906
|
+
this.skipSparseCheckout = skip;
|
|
907
|
+
return this;
|
|
908
|
+
}
|
|
909
|
+
async call() {
|
|
910
|
+
const trees = [];
|
|
911
|
+
if (this.dryRun) try {
|
|
912
|
+
return await this.callChecked(trees);
|
|
913
|
+
} finally {
|
|
914
|
+
await this.staging.read();
|
|
915
|
+
}
|
|
916
|
+
return this.callChecked(trees);
|
|
917
|
+
}
|
|
918
|
+
callChecked(trees) {
|
|
919
|
+
return withTreePathRefusal(this.trees, () => trees, worktreePathRules(this.workingCopy, this.update ? this.worktreeAccess : void 0), () => this.callOnce(trees), (refusal) => refusal instanceof InvalidPathError ? new ReadTreeFailedError(refusal.message, [refusal.path]) : refusal);
|
|
920
|
+
}
|
|
921
|
+
/** {@link call}, collecting the trees it reads into `read`. */
|
|
922
|
+
async callOnce(read) {
|
|
923
|
+
this.checkCallable();
|
|
924
|
+
this.setCallable(false);
|
|
925
|
+
const fatal = (message) => {
|
|
926
|
+
throw new ReadTreeFailedError(`fatal: ${message}`);
|
|
927
|
+
};
|
|
928
|
+
const result = {
|
|
929
|
+
warnings: [],
|
|
930
|
+
unmerged: []
|
|
931
|
+
};
|
|
932
|
+
const prefixSet = this.prefix !== void 0;
|
|
933
|
+
if (Number(this.merge) + Number(this.reset) + Number(prefixSet) > 1) fatal("Which one? -m, --reset, or --prefix?");
|
|
934
|
+
if (this.prefix?.startsWith("/")) fatal("Invalid prefix, prefix cannot start with '/'");
|
|
935
|
+
await this.readCurrentIndex();
|
|
936
|
+
let merge = this.merge;
|
|
937
|
+
let unmergedIndex = false;
|
|
938
|
+
for await (const e of this.staging.entries()) if (e.stage !== 0) {
|
|
939
|
+
unmergedIndex = true;
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
942
|
+
if (this.reset || merge || prefixSet) {
|
|
943
|
+
if (unmergedIndex && (prefixSet || merge)) fatal("You need to resolve your current index first");
|
|
944
|
+
merge = true;
|
|
945
|
+
}
|
|
946
|
+
const treeIds = [];
|
|
947
|
+
for (const name of this.treeishes) {
|
|
948
|
+
if (treeIds.length >= MAX_UNPACK_TREES) fatal(`I cannot read more than ${MAX_UNPACK_TREES} trees`);
|
|
949
|
+
const id = await this.resolveRevision(name).catch(() => void 0);
|
|
950
|
+
const tree = id ? await this.revisionResolver().peelToType(id, "tree") : void 0;
|
|
951
|
+
if (!id) fatal(`Not a valid object name ${name}`);
|
|
952
|
+
if (!tree) fatal(`failed to unpack tree object ${name}`);
|
|
953
|
+
treeIds.push(tree);
|
|
954
|
+
read.push(tree);
|
|
955
|
+
}
|
|
956
|
+
if (treeIds.length === 0 && !this.empty && !merge) result.warnings.push("warning: read-tree: emptying the index with no arguments is deprecated; use --empty");
|
|
957
|
+
else if (treeIds.length > 0 && this.empty) fatal("passing trees as arguments contradicts --empty");
|
|
958
|
+
if (this.update && this.indexOnly) fatal("-u and -i at the same time makes no sense");
|
|
959
|
+
if ((this.update || this.indexOnly) && !merge) fatal(`${this.update ? "-u" : "-i"} is meaningless without -m, --reset, or --prefix`);
|
|
960
|
+
if (merge && treeIds.length === 0) fatal("you must specify at least one tree to merge");
|
|
961
|
+
const checked = this.indexOnly ? void 0 : this.worktreeAccess;
|
|
962
|
+
const sequencerCtx = {
|
|
963
|
+
workingCopy: this.workingCopy,
|
|
964
|
+
worktree: checked,
|
|
965
|
+
staging: this.staging,
|
|
966
|
+
blobs: this.blobs,
|
|
967
|
+
trees: this.trees,
|
|
968
|
+
commits: this.commits,
|
|
969
|
+
refs: this.refsStore,
|
|
970
|
+
sparseWarnings: result.warnings
|
|
971
|
+
};
|
|
972
|
+
const refused = (message, paths = []) => {
|
|
973
|
+
if (!message) return;
|
|
974
|
+
let text = message;
|
|
975
|
+
if (this.superPrefix) for (const p of new Set(paths)) text = text.split(`'${p}'`).join(`'${this.superPrefix}${p}'`);
|
|
976
|
+
throw new ReadTreeFailedError(text, paths);
|
|
977
|
+
};
|
|
978
|
+
const submodules = merge && !prefixSet && treeIds.length <= 2 && !this.indexOnly ? await SubmoduleUnpack.start(this.workingCopy, {
|
|
979
|
+
recurse: recursesIntoSubmodules(this.workingCopy, this.recurseSubmodules),
|
|
980
|
+
reset: this.reset,
|
|
981
|
+
superPrefix: this.superPrefix
|
|
982
|
+
}) : void 0;
|
|
983
|
+
const update = this.update;
|
|
984
|
+
const dryRunOptions = this.dryRun ? {
|
|
985
|
+
writeIndex: false,
|
|
986
|
+
checkOnly: true
|
|
987
|
+
} : {};
|
|
988
|
+
if (!merge) await this.readWithoutMerge(treeIds);
|
|
989
|
+
else if (prefixSet) {
|
|
990
|
+
const prefix = this.prefix.replace(/\/*$/, "/");
|
|
991
|
+
await this.bindMerge(sequencerCtx, treeIds, prefix === "/" ? "" : prefix, result);
|
|
992
|
+
} else if (treeIds.length === 1) {
|
|
993
|
+
const tree = treeIds[0];
|
|
994
|
+
const refusal = await resetMerge(sequencerCtx, tree, tree, {
|
|
995
|
+
hard: this.reset,
|
|
996
|
+
update,
|
|
997
|
+
submodules,
|
|
998
|
+
...dryRunOptions,
|
|
999
|
+
overwriteUntracked: this.reset,
|
|
1000
|
+
skipSparseCheckout: this.skipSparseCheckout,
|
|
1001
|
+
targetTree: tree,
|
|
1002
|
+
plain: true
|
|
1003
|
+
});
|
|
1004
|
+
refused(refusal?.message, refusal?.paths);
|
|
1005
|
+
} else if (treeIds.length === 2) {
|
|
1006
|
+
const [h, m] = treeIds;
|
|
1007
|
+
const refusal = await switchTrees(sequencerCtx, await flatTree(this.trees, h), await flatTree(this.trees, m), {
|
|
1008
|
+
action: "merge",
|
|
1009
|
+
operation: "read-tree",
|
|
1010
|
+
update,
|
|
1011
|
+
submodules,
|
|
1012
|
+
...dryRunOptions,
|
|
1013
|
+
skipSparseCheckout: this.skipSparseCheckout,
|
|
1014
|
+
plainErrors: true,
|
|
1015
|
+
initialCheckout: await isIndexUnborn(this.staging)
|
|
1016
|
+
});
|
|
1017
|
+
refused(refusal?.message, refusal?.paths);
|
|
1018
|
+
} else await this.threewayMerge(sequencerCtx, treeIds, result);
|
|
1019
|
+
if (this.dryRun) return result;
|
|
1020
|
+
this.staging.clearResolveUndo?.();
|
|
1021
|
+
if (treeIds.length === 1 && !prefixSet) this.staging.setCacheTree?.(await cacheTreeOfTree(this.trees, treeIds[0]));
|
|
1022
|
+
else this.staging.setCacheTree?.(await this.repairedCacheTree());
|
|
1023
|
+
await this.staging.write();
|
|
1024
|
+
for await (const e of this.staging.entries()) if (e.stage !== 0 && result.unmerged[result.unmerged.length - 1] !== e.path) result.unmerged.push(e.path);
|
|
1025
|
+
return result;
|
|
1026
|
+
}
|
|
1027
|
+
/** `cache_tree_update(WRITE_TREE_SILENT | WRITE_TREE_REPAIR)` of the index as it is. */
|
|
1028
|
+
async repairedCacheTree() {
|
|
1029
|
+
const entries = await this.entryList();
|
|
1030
|
+
const trees = this.trees;
|
|
1031
|
+
return repairCacheTree({ has: async (id) => id === this.objectFormat.emptyTreeId || await trees.has(id) }, entries, this.objectFormat);
|
|
1032
|
+
}
|
|
1033
|
+
async entryList() {
|
|
1034
|
+
const list = this.staging.entryList?.();
|
|
1035
|
+
if (list) return list;
|
|
1036
|
+
const out = [];
|
|
1037
|
+
for await (const e of this.staging.entries()) out.push(e);
|
|
1038
|
+
return out;
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* unpack-trees without `-m`: the index is the trees' entries, at stage 0, without stat
|
|
1042
|
+
* data or flags, added in `traverse_trees` order (at each name the trees' files in their
|
|
1043
|
+
* order, then what a directory of that name holds), each with `add_index_entry`'s
|
|
1044
|
+
* `OK_TO_REPLACE`: a later tree's entry replaces an earlier one's, a directory's files
|
|
1045
|
+
* replace a file of its name, whichever tree holds which.
|
|
1046
|
+
*/
|
|
1047
|
+
async readWithoutMerge(treeIds) {
|
|
1048
|
+
const flat = await Promise.all(treeIds.map((id) => flatTree(this.trees, id)));
|
|
1049
|
+
const all = /* @__PURE__ */ new Set();
|
|
1050
|
+
for (const m of flat) for (const p of m.keys()) all.add(p);
|
|
1051
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1052
|
+
for (const path of traversalOrder(all)) for (const m of flat) {
|
|
1053
|
+
const e = m.get(path);
|
|
1054
|
+
if (!e) continue;
|
|
1055
|
+
for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) entries.delete(path.slice(0, at));
|
|
1056
|
+
entries.set(path, e);
|
|
1057
|
+
}
|
|
1058
|
+
const invalid = firstInvalidPath(entries, /* @__PURE__ */ new Map(), worktreePathRules(this.workingCopy, this.update ? this.worktreeAccess : void 0));
|
|
1059
|
+
if (invalid !== void 0) throw new ReadTreeFailedError(`error: invalid path '${invalid}'`, [invalid]);
|
|
1060
|
+
assertNoStageZeroClash(new Set(entries.keys()));
|
|
1061
|
+
const builder = this.staging.createBuilder();
|
|
1062
|
+
for (const path of [...entries.keys()].sort(compareGitPaths)) {
|
|
1063
|
+
const e = entries.get(path);
|
|
1064
|
+
builder.add({
|
|
1065
|
+
path,
|
|
1066
|
+
objectId: e.objectId,
|
|
1067
|
+
mode: e.mode,
|
|
1068
|
+
size: 0,
|
|
1069
|
+
mtime: 0
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
await builder.finish();
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* `bind_merge` (`--prefix=<dir>/`): the tree's entries under `<dir>/`, every index entry
|
|
1076
|
+
* kept; a path both have is refused ("Entry 'x' overlaps with 'x'. Cannot bind."). The
|
|
1077
|
+
* entries are added in `traverse_trees` order with `add_index_entry`'s `OK_TO_REPLACE`, so
|
|
1078
|
+
* where a file and a directory clash the directory's entries, added after, win: an index
|
|
1079
|
+
* file in place of a bound leading directory is dropped, and so is a bound file with index
|
|
1080
|
+
* entries beneath it. With `-u` the new files are written: a file in the way is refused
|
|
1081
|
+
* first, tracked or not ("Untracked working tree file 'a' would be overwritten by merge.",
|
|
1082
|
+
* as `check_ok_to_remove` finds it kept in the result); where a bound file finds a
|
|
1083
|
+
* directory, its tracked files must be up to date and go (`verify_clean_subdirectory` marks
|
|
1084
|
+
* them removed), and the bound file is written in its place.
|
|
1085
|
+
*/
|
|
1086
|
+
async bindMerge(ctx, treeIds, prefix, result) {
|
|
1087
|
+
if (treeIds.length !== 1) throw new ReadTreeFailedError(`error: Cannot do a bind merge of ${treeIds.length} trees`);
|
|
1088
|
+
const tree = await flatTree(this.trees, treeIds[0]);
|
|
1089
|
+
const index = /* @__PURE__ */ new Map();
|
|
1090
|
+
for (const e of await this.entryList()) index.set(e.path, e);
|
|
1091
|
+
const target = /* @__PURE__ */ new Map();
|
|
1092
|
+
for (const [p, e] of tree) target.set(`${prefix}${p}`, e);
|
|
1093
|
+
const targetDirs = directoriesOf(target);
|
|
1094
|
+
const dropped = /* @__PURE__ */ new Set();
|
|
1095
|
+
const beneath = /* @__PURE__ */ new Map();
|
|
1096
|
+
for (const p of index.keys()) {
|
|
1097
|
+
if (targetDirs.has(p)) dropped.add(p);
|
|
1098
|
+
for (let at = p.indexOf("/"); at >= 0; at = p.indexOf("/", at + 1)) {
|
|
1099
|
+
const dir = p.slice(0, at);
|
|
1100
|
+
if (target.has(dir)) {
|
|
1101
|
+
const list = beneath.get(dir) ?? [];
|
|
1102
|
+
list.push(p);
|
|
1103
|
+
beneath.set(dir, list);
|
|
1104
|
+
break;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
const checking = traversalOrder(target.keys());
|
|
1109
|
+
const worktree = this.update ? ctx.worktree : void 0;
|
|
1110
|
+
const sparse = worktree && !this.skipSparseCheckout ? await SparseUnpack.start(ctx) : void 0;
|
|
1111
|
+
const trust = worktree ? worktreeModeTrust(this.workingCopy, worktree) : void 0;
|
|
1112
|
+
const indexTime = this.staging.getUpdateTime();
|
|
1113
|
+
const removing = [];
|
|
1114
|
+
const folding = await this.caseFolding(worktree, index);
|
|
1115
|
+
const caseVariants = [];
|
|
1116
|
+
for (const path of checking) {
|
|
1117
|
+
if (index.has(path)) throw new ReadTreeFailedError(`error: Entry '${path}' overlaps with '${path}'. Cannot bind.`, [path]);
|
|
1118
|
+
if (!worktree || sparse?.leavesAlone(path)) continue;
|
|
1119
|
+
const entry = await worktree.getEntry(path).catch(() => void 0);
|
|
1120
|
+
if (entry?.isDirectory && entry.mode !== FileMode.GITLINK) {
|
|
1121
|
+
const under = beneath.get(path) ?? [];
|
|
1122
|
+
for (const old of under) {
|
|
1123
|
+
const e = index.get(old);
|
|
1124
|
+
if (await entryNotUptodate(worktree, old, e, trust, indexTime)) throw new ReadTreeFailedError(plainUnpackError("notUptodate", old), [old]);
|
|
1125
|
+
removing.push(old);
|
|
1126
|
+
dropped.add(old);
|
|
1127
|
+
}
|
|
1128
|
+
beneath.delete(path);
|
|
1129
|
+
}
|
|
1130
|
+
const error = await verifyAbsent(worktree, path, (p) => index.has(p), "untracked", {
|
|
1131
|
+
folding,
|
|
1132
|
+
caseVariants
|
|
1133
|
+
});
|
|
1134
|
+
if (error) throw new ReadTreeFailedError(error, [path]);
|
|
1135
|
+
}
|
|
1136
|
+
const paths = checking.filter((p) => !beneath.has(p));
|
|
1137
|
+
const stage0 = new Set(paths);
|
|
1138
|
+
for (const p of index.keys()) if (!dropped.has(p)) stage0.add(p);
|
|
1139
|
+
assertNoStageZeroClash(stage0);
|
|
1140
|
+
if (this.dryRun) return;
|
|
1141
|
+
const writing = new Set(paths.filter((p) => !sparse || sparse.writes(p)));
|
|
1142
|
+
if (worktree) {
|
|
1143
|
+
if (sparse) {
|
|
1144
|
+
const unlink = await sparse.leaving(worktree, (p) => (beneath.has(p) ? void 0 : target.get(p)) ?? (dropped.has(p) ? void 0 : index.get(p)), { trust });
|
|
1145
|
+
await sparse.unlink(worktree, unlink);
|
|
1146
|
+
}
|
|
1147
|
+
for (const old of removing) {
|
|
1148
|
+
const entry = await worktree.getEntry(old).catch(() => void 0);
|
|
1149
|
+
if (entry && !entry.isDirectory) {
|
|
1150
|
+
await worktree.remove(old);
|
|
1151
|
+
await pruneEmptyParents(worktree, old);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
await removeCaseVariants(worktree, caseVariants);
|
|
1155
|
+
if (writing.size > 0) await this.writeFiles(ctx, worktree, target, writing, index);
|
|
1156
|
+
}
|
|
1157
|
+
const changes = /* @__PURE__ */ new Map();
|
|
1158
|
+
for (const p of dropped) changes.set(p, []);
|
|
1159
|
+
for (const path of paths) {
|
|
1160
|
+
const e = target.get(path);
|
|
1161
|
+
const stat = worktree && writing.has(path) ? await worktree.getEntry(path) : void 0;
|
|
1162
|
+
changes.set(path, [{
|
|
1163
|
+
path,
|
|
1164
|
+
objectId: e.objectId,
|
|
1165
|
+
mode: e.mode,
|
|
1166
|
+
...entryStatOf(stat && !stat.isDirectory ? stat : {})
|
|
1167
|
+
}]);
|
|
1168
|
+
}
|
|
1169
|
+
await rewriteIndex(this.staging, changes);
|
|
1170
|
+
if (sparse && worktree) {
|
|
1171
|
+
const outcome = await sparse.finish(ctx, { written: writing });
|
|
1172
|
+
pushSparseWarnings(result.warnings, sparse, outcome, false);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
/** The source index's case-folding lookups under `core.ignorecase` (undefined: off). */
|
|
1176
|
+
async caseFolding(worktree, index) {
|
|
1177
|
+
if (!worktree || !coreBool(this.workingCopy, "ignorecase", false)) return void 0;
|
|
1178
|
+
return new IndexCaseFolding(index, await restoreCaseOptions(worktree, true));
|
|
1179
|
+
}
|
|
1180
|
+
/** The files of `writing` written from `target` (smudged with the result's attributes). */
|
|
1181
|
+
async writeFiles(ctx, worktree, target, writing, index) {
|
|
1182
|
+
const plan = await planPathsRestore(ctx, target, void 0, writing, "read-tree");
|
|
1183
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
1184
|
+
for (const [p, e] of index) if (p.endsWith(".gitattributes")) attributes.set(p, e.objectId);
|
|
1185
|
+
for (const p of writing) if (p.endsWith(".gitattributes")) attributes.set(p, target.get(p).objectId);
|
|
1186
|
+
await writeTreeRestorePlan(worktree, ctx.blobs, plan, "read-tree", {
|
|
1187
|
+
symlinks: worktreeModeTrust(this.workingCopy, worktree).symlinks,
|
|
1188
|
+
gitlinks: true,
|
|
1189
|
+
replaceInTheWay: true,
|
|
1190
|
+
attributes: {
|
|
1191
|
+
direction: "checkout",
|
|
1192
|
+
index: attributesIndexOf(attributes)
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* `threeway_merge` over `<base>... <head> <remote>`: the trivial cases resolved (the
|
|
1198
|
+
* index must hold the head's entry, or the result's where `#14ALT`/`#2ALT` allow it),
|
|
1199
|
+
* the rest left as stages 1 (the first base), 2 and 3, the worktree untouched there.
|
|
1200
|
+
* `--aggressive` resolves deletions on one side with the other unchanged, deletions on
|
|
1201
|
+
* both, and identical additions. `--trivial` fails where a file-level merge is needed.
|
|
1202
|
+
*
|
|
1203
|
+
* A path that is a file in some trees and a directory in others is unpack-trees'
|
|
1204
|
+
* file/directory conflict: the trees holding the directory (or a file in place of one of
|
|
1205
|
+
* the path's leading directories) stand as `df_conflict_entry` there, which matches
|
|
1206
|
+
* nothing, is no stage, and keeps `#14`/`#2ALT` (a conflicting head) and `#13`/`#3ALT`
|
|
1207
|
+
* (a conflicting remote) from resolving. Every check runs before anything is written.
|
|
1208
|
+
*/
|
|
1209
|
+
async threewayMerge(ctx, treeIds, result) {
|
|
1210
|
+
const flat = await Promise.all(treeIds.map((id) => flatTree(this.trees, id)));
|
|
1211
|
+
const dirs = flat.map(directoriesOf);
|
|
1212
|
+
const bases = flat.slice(0, -2);
|
|
1213
|
+
const indexEntries = /* @__PURE__ */ new Map();
|
|
1214
|
+
for (const e of await this.entryList()) if (e.stage === 0) indexEntries.set(e.path, e);
|
|
1215
|
+
const checkedWorktree = ctx.worktree;
|
|
1216
|
+
const worktree = this.update ? checkedWorktree : void 0;
|
|
1217
|
+
const sparse = worktree && !this.skipSparseCheckout ? await SparseUnpack.start(ctx) : void 0;
|
|
1218
|
+
const quiet = (p) => sparse?.leavesAlone(p) === true;
|
|
1219
|
+
const trust = checkedWorktree ? worktreeModeTrust(this.workingCopy, checkedWorktree) : void 0;
|
|
1220
|
+
const indexTime = this.staging.getUpdateTime();
|
|
1221
|
+
const folding = await this.caseFolding(worktree, indexEntries);
|
|
1222
|
+
const caseVariants = [];
|
|
1223
|
+
const paths = new Set(indexEntries.keys());
|
|
1224
|
+
for (const m of flat) for (const p of m.keys()) paths.add(p);
|
|
1225
|
+
const sorted = traversalOrder(paths);
|
|
1226
|
+
/** The entry tree `k` stands with at `path` (df_conflict_entry, a file, or none). */
|
|
1227
|
+
const stageOf = (k, path, anyTree) => {
|
|
1228
|
+
const m = flat[k];
|
|
1229
|
+
const e = m.get(path);
|
|
1230
|
+
if (e) return e;
|
|
1231
|
+
if (!anyTree) return void 0;
|
|
1232
|
+
if (dirs[k].has(path)) return DF_CONFLICT;
|
|
1233
|
+
for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) if (m.has(path.slice(0, at))) return DF_CONFLICT;
|
|
1234
|
+
};
|
|
1235
|
+
const changes = /* @__PURE__ */ new Map();
|
|
1236
|
+
const writes = /* @__PURE__ */ new Set();
|
|
1237
|
+
const removes = /* @__PURE__ */ new Set();
|
|
1238
|
+
const conflicted = [];
|
|
1239
|
+
let nontrivial = false;
|
|
1240
|
+
const fail = (message, path) => {
|
|
1241
|
+
throw new ReadTreeFailedError(message, [path]);
|
|
1242
|
+
};
|
|
1243
|
+
const verifyUptodate = async (old) => {
|
|
1244
|
+
if (!checkedWorktree || quiet(old.path)) return;
|
|
1245
|
+
if (await entryNotUptodate(checkedWorktree, old.path, old, trust, indexTime)) fail(`error: Entry '${old.path}' not uptodate. Cannot merge.`, old.path);
|
|
1246
|
+
};
|
|
1247
|
+
const removedHere = (p) => removes.has(p);
|
|
1248
|
+
const absent = async (path, kind) => {
|
|
1249
|
+
if (!worktree || quiet(path)) return;
|
|
1250
|
+
const error = await verifyAbsent(worktree, path, (p) => indexEntries.has(p), kind, {
|
|
1251
|
+
leadingOk: removedHere,
|
|
1252
|
+
folding,
|
|
1253
|
+
caseVariants
|
|
1254
|
+
});
|
|
1255
|
+
if (error) fail(error, path);
|
|
1256
|
+
};
|
|
1257
|
+
const absentIfDirectory = async (path, old) => {
|
|
1258
|
+
if (!worktree || quiet(path) || old.skipWorktree || sparse?.outside(path)) return;
|
|
1259
|
+
const entry = await worktree.getEntry(path).catch(() => void 0);
|
|
1260
|
+
if (!entry?.isDirectory || entry.mode === FileMode.GITLINK) return;
|
|
1261
|
+
if (await untrackedUnder(worktree, path, (p) => indexEntries.has(p))) fail(plainUnpackError("lostDir", path), path);
|
|
1262
|
+
};
|
|
1263
|
+
const mergedEntry = async (ce, old, path) => {
|
|
1264
|
+
if (!old) {
|
|
1265
|
+
await absent(path, "untracked");
|
|
1266
|
+
changes.set(path, [{
|
|
1267
|
+
path,
|
|
1268
|
+
objectId: ce.objectId,
|
|
1269
|
+
mode: ce.mode,
|
|
1270
|
+
size: 0,
|
|
1271
|
+
mtime: 0
|
|
1272
|
+
}]);
|
|
1273
|
+
writes.add(path);
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
if (same(old, ce)) return;
|
|
1277
|
+
await verifyUptodate(old);
|
|
1278
|
+
changes.set(path, [{
|
|
1279
|
+
path,
|
|
1280
|
+
objectId: ce.objectId,
|
|
1281
|
+
mode: ce.mode,
|
|
1282
|
+
size: 0,
|
|
1283
|
+
mtime: 0,
|
|
1284
|
+
...old.skipWorktree ? { skipWorktree: true } : {}
|
|
1285
|
+
}]);
|
|
1286
|
+
writes.add(path);
|
|
1287
|
+
};
|
|
1288
|
+
const deletedEntry = async (old, path) => {
|
|
1289
|
+
await absentIfDirectory(path, old);
|
|
1290
|
+
await verifyUptodate(old);
|
|
1291
|
+
changes.set(path, []);
|
|
1292
|
+
removes.add(path);
|
|
1293
|
+
};
|
|
1294
|
+
for (const path of sorted) {
|
|
1295
|
+
const index = indexEntries.get(path);
|
|
1296
|
+
const anyTree = flat.some((m) => m.has(path)) || dirs.some((d) => d.has(path));
|
|
1297
|
+
const stages = bases.map((_, k) => stageOf(k, path, anyTree));
|
|
1298
|
+
let h = stageOf(flat.length - 2, path, anyTree);
|
|
1299
|
+
let r = stageOf(flat.length - 1, path, anyTree);
|
|
1300
|
+
const anyAncMissing = stages.some((s) => !s || s === DF_CONFLICT);
|
|
1301
|
+
const noAncExists = stages.every((s) => !s || s === DF_CONFLICT);
|
|
1302
|
+
const dfHead = h === DF_CONFLICT;
|
|
1303
|
+
const dfRemote = r === DF_CONFLICT;
|
|
1304
|
+
if (dfHead) h = void 0;
|
|
1305
|
+
if (dfRemote) r = void 0;
|
|
1306
|
+
let headMatch = 0;
|
|
1307
|
+
let remoteMatch = 0;
|
|
1308
|
+
if (!same(r, h)) stages.forEach((s, k) => {
|
|
1309
|
+
if (same(s, h)) headMatch = k + 1;
|
|
1310
|
+
if (same(s, r)) remoteMatch = k + 1;
|
|
1311
|
+
});
|
|
1312
|
+
if (r && !dfHead && headMatch && !remoteMatch) {
|
|
1313
|
+
if (index && !same(index, r) && !same(index, h)) fail(`error: Entry '${path}' would be overwritten by merge. Cannot merge.`, path);
|
|
1314
|
+
await mergedEntry(r, index, path);
|
|
1315
|
+
continue;
|
|
1316
|
+
}
|
|
1317
|
+
if (index && !same(index, h)) fail(`error: Entry '${path}' would be overwritten by merge. Cannot merge.`, path);
|
|
1318
|
+
if (h) {
|
|
1319
|
+
if (same(h, r)) {
|
|
1320
|
+
await mergedEntry(h, index, path);
|
|
1321
|
+
continue;
|
|
1322
|
+
}
|
|
1323
|
+
if (!dfRemote && remoteMatch && !headMatch) {
|
|
1324
|
+
await mergedEntry(h, index, path);
|
|
1325
|
+
continue;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
if (!h && !r && anyAncMissing) continue;
|
|
1329
|
+
if (this.aggressive) {
|
|
1330
|
+
const headDeleted = !h;
|
|
1331
|
+
const remoteDeleted = !r;
|
|
1332
|
+
const ce = index ?? h ?? r ?? stages.find((s) => s && s !== DF_CONFLICT);
|
|
1333
|
+
if (headDeleted && remoteDeleted || headDeleted && r && remoteMatch || remoteDeleted && h && headMatch) {
|
|
1334
|
+
if (index) {
|
|
1335
|
+
await deletedEntry(index, path);
|
|
1336
|
+
continue;
|
|
1337
|
+
}
|
|
1338
|
+
if (ce && !headDeleted) await absent(path, "untrackedRemoved");
|
|
1339
|
+
continue;
|
|
1340
|
+
}
|
|
1341
|
+
if (noAncExists && h && r && same(h, r)) {
|
|
1342
|
+
await mergedEntry(h, index, path);
|
|
1343
|
+
continue;
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
if (index) await verifyUptodate(index);
|
|
1347
|
+
nontrivial = true;
|
|
1348
|
+
const list = [];
|
|
1349
|
+
if (!headMatch || !remoteMatch) {
|
|
1350
|
+
const base = stages.find((s) => s !== void 0 && s !== DF_CONFLICT);
|
|
1351
|
+
if (base) list.push({
|
|
1352
|
+
path,
|
|
1353
|
+
objectId: base.objectId,
|
|
1354
|
+
mode: base.mode,
|
|
1355
|
+
stage: 1
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
if (h) list.push({
|
|
1359
|
+
path,
|
|
1360
|
+
objectId: h.objectId,
|
|
1361
|
+
mode: h.mode,
|
|
1362
|
+
stage: 2
|
|
1363
|
+
});
|
|
1364
|
+
if (r) list.push({
|
|
1365
|
+
path,
|
|
1366
|
+
objectId: r.objectId,
|
|
1367
|
+
mode: r.mode,
|
|
1368
|
+
stage: 3
|
|
1369
|
+
});
|
|
1370
|
+
for (const e of list) Object.assign(e, {
|
|
1371
|
+
size: 0,
|
|
1372
|
+
mtime: 0
|
|
1373
|
+
});
|
|
1374
|
+
changes.set(path, list);
|
|
1375
|
+
conflicted.push(path);
|
|
1376
|
+
}
|
|
1377
|
+
if (this.trivial && nontrivial) throw new ReadTreeFailedError("error: Merge requires file-level merging");
|
|
1378
|
+
const stage0 = /* @__PURE__ */ new Set();
|
|
1379
|
+
for (const p of indexEntries.keys()) if (!changes.has(p)) stage0.add(p);
|
|
1380
|
+
for (const [p, list] of changes) if (list.some((e) => !e.stage)) stage0.add(p);
|
|
1381
|
+
assertNoStageZeroClash(stage0);
|
|
1382
|
+
if (this.dryRun) return;
|
|
1383
|
+
sparse?.conflict(conflicted);
|
|
1384
|
+
const target = /* @__PURE__ */ new Map();
|
|
1385
|
+
for (const path of writes) {
|
|
1386
|
+
const e = changes.get(path)?.[0];
|
|
1387
|
+
if (e) target.set(path, e);
|
|
1388
|
+
}
|
|
1389
|
+
const writing = new Set([...writes].filter((p) => !sparse || sparse.writes(p)));
|
|
1390
|
+
if (worktree) {
|
|
1391
|
+
if (sparse) {
|
|
1392
|
+
const unlink = await sparse.leaving(worktree, (p) => removes.has(p) ? void 0 : target.get(p) ?? indexEntries.get(p), { trust });
|
|
1393
|
+
await sparse.unlink(worktree, unlink);
|
|
1394
|
+
}
|
|
1395
|
+
for (const path of removes) {
|
|
1396
|
+
if (quiet(path)) continue;
|
|
1397
|
+
const entry = await worktree.getEntry(path);
|
|
1398
|
+
if (entry && !entry.isDirectory) {
|
|
1399
|
+
await worktree.remove(path);
|
|
1400
|
+
await pruneEmptyParents(worktree, path);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
await removeCaseVariants(worktree, caseVariants);
|
|
1404
|
+
if (writing.size > 0) await this.writeFiles(ctx, worktree, target, writing, indexEntries);
|
|
1405
|
+
for (const path of writing) {
|
|
1406
|
+
const stat = await worktree.getEntry(path);
|
|
1407
|
+
const e = changes.get(path)?.[0];
|
|
1408
|
+
if (e && stat && !stat.isDirectory) Object.assign(e, entryStatOf(stat));
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
await rewriteIndex(this.staging, changes);
|
|
1412
|
+
if (sparse && worktree) {
|
|
1413
|
+
const outcome = await sparse.finish(ctx, { written: worktree ? writing : /* @__PURE__ */ new Set() });
|
|
1414
|
+
pushSparseWarnings(result.warnings, sparse, outcome, false);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
/** unpack-trees' `df_conflict_entry`: mode 0, no id; matches only itself, never a stage. */
|
|
1419
|
+
const DF_CONFLICT = Object.freeze({
|
|
1420
|
+
objectId: "",
|
|
1421
|
+
mode: 0
|
|
1422
|
+
});
|
|
1423
|
+
/** The directories a flat tree holds (every leading path of its files). */
|
|
1424
|
+
function directoriesOf(tree) {
|
|
1425
|
+
const out = /* @__PURE__ */ new Set();
|
|
1426
|
+
for (const p of tree.keys()) for (let at = p.indexOf("/"); at >= 0; at = p.indexOf("/", at + 1)) out.add(p.slice(0, at));
|
|
1427
|
+
return out;
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* `paths` in `traverse_trees` order: the index's (a directory named as `<name>/`), except
|
|
1431
|
+
* that a directory some path also names as a file comes right after that file (unpack-trees
|
|
1432
|
+
* looks ahead for it), before the names that sort between the two.
|
|
1433
|
+
*/
|
|
1434
|
+
function traversalOrder(paths) {
|
|
1435
|
+
const all = new Set(paths);
|
|
1436
|
+
const keys = /* @__PURE__ */ new Map();
|
|
1437
|
+
const keyOf = (path) => {
|
|
1438
|
+
let key = keys.get(path);
|
|
1439
|
+
if (!key) {
|
|
1440
|
+
const parts = path.split("/");
|
|
1441
|
+
key = parts.map((part, k) => k < parts.length - 1 && !all.has(parts.slice(0, k + 1).join("/")) ? `${part}/` : part);
|
|
1442
|
+
keys.set(path, key);
|
|
1443
|
+
}
|
|
1444
|
+
return key;
|
|
1445
|
+
};
|
|
1446
|
+
return [...all].sort((a, b) => {
|
|
1447
|
+
const x = keyOf(a);
|
|
1448
|
+
const y = keyOf(b);
|
|
1449
|
+
for (let k = 0; k < Math.min(x.length, y.length); k++) {
|
|
1450
|
+
const c = compareGitPaths(x[k], y[k]);
|
|
1451
|
+
if (c !== 0) return c;
|
|
1452
|
+
}
|
|
1453
|
+
return x.length - y.length;
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* The last guard before an index is written: no stage-0 path may also be a leading
|
|
1458
|
+
* directory of another (git's `add_index_entry` never leaves one; a tree written from such an
|
|
1459
|
+
* index would hold two entries of one name).
|
|
1460
|
+
*/
|
|
1461
|
+
function assertNoStageZeroClash(paths) {
|
|
1462
|
+
for (const path of paths) for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) {
|
|
1463
|
+
const dir = path.slice(0, at);
|
|
1464
|
+
if (paths.has(dir)) throw new ReadTreeFailedError(`fatal: BUG: the index would hold both '${dir}' and '${path}'`, [dir, path]);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* unpack-trees' `verify_absent` of a path the merge adds (or, `untrackedRemoved`, removes)
|
|
1469
|
+
* with no index entry there: an untracked file or link in the way (ignored files are
|
|
1470
|
+
* expendable: `preserve_ignored` is off with `-u`), or a directory holding untracked files.
|
|
1471
|
+
* A file in place of a leading directory is in the way even when tracked, unless the merge
|
|
1472
|
+
* removes its entry (`leadingOk`: `check_ok_to_remove` finds it `CE_REMOVE` in the result).
|
|
1473
|
+
* Returns git's plain message, or undefined.
|
|
1474
|
+
*/
|
|
1475
|
+
async function verifyAbsent(worktree, path, tracked, kind, options = {}) {
|
|
1476
|
+
const parts = path.split("/");
|
|
1477
|
+
for (let k = 1; k < parts.length; k++) {
|
|
1478
|
+
const prefix = parts.slice(0, k).join("/");
|
|
1479
|
+
const entry = await worktree.getEntry(prefix).catch(() => void 0);
|
|
1480
|
+
if (!entry) return void 0;
|
|
1481
|
+
if (entry.isDirectory) continue;
|
|
1482
|
+
if (options.leadingOk?.(prefix) || await worktree.isIgnored(prefix)) return void 0;
|
|
1483
|
+
if (await options.folding?.exists(worktree, prefix, entry)) return void 0;
|
|
1484
|
+
return firstPlainError({ [kind]: [prefix] });
|
|
1485
|
+
}
|
|
1486
|
+
const entry = await worktree.getEntry(path).catch(() => void 0);
|
|
1487
|
+
if (!entry) return void 0;
|
|
1488
|
+
if (entry.isDirectory) {
|
|
1489
|
+
if (entry.mode === FileMode.GITLINK) return void 0;
|
|
1490
|
+
const variants = options.caseVariants ? options.folding?.variants() : void 0;
|
|
1491
|
+
if (await untrackedUnder(worktree, path, tracked, false, variants)) return firstPlainError({ lostDir: [path] });
|
|
1492
|
+
if (variants) options.caseVariants?.push(...variants.found);
|
|
1493
|
+
return;
|
|
1494
|
+
}
|
|
1495
|
+
if (await worktree.isIgnored(path)) return void 0;
|
|
1496
|
+
if (await options.folding?.exists(worktree, path, entry)) return void 0;
|
|
1497
|
+
return firstPlainError({ [kind]: [path] });
|
|
1498
|
+
}
|
|
1499
|
+
//#endregion
|
|
1500
|
+
//#region src/commands/local-transport.ts
|
|
1501
|
+
/**
|
|
1502
|
+
* git's local transport: a repository named by a path (or a `file://` URL) is opened through
|
|
1503
|
+
* the working copy's storage and served by upload-pack (or receive-pack) in process, over an
|
|
1504
|
+
* in-memory duplex, where git spawns `git-upload-pack '<path>'`. Which transport a URL takes
|
|
1505
|
+
* is decided in `remote-transport.ts` (`resolveRemote`).
|
|
1506
|
+
*/
|
|
1507
|
+
/** The client's lines when the remote end of a local transport died. */
|
|
1508
|
+
const COULD_NOT_READ = "fatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.";
|
|
1509
|
+
const NOT_A_REPOSITORY = (path) => `fatal: '${path}' does not appear to be a git repository\n${COULD_NOT_READ}`;
|
|
1510
|
+
/**
|
|
1511
|
+
* A connected pair of in-memory duplex streams: what one side writes, the other reads. `end`
|
|
1512
|
+
* half-closes a side (the other one reads to its end and can still answer); `close` ends it.
|
|
1513
|
+
*/
|
|
1514
|
+
function createDuplexPair() {
|
|
1515
|
+
const make = () => {
|
|
1516
|
+
const queue = [];
|
|
1517
|
+
let ended = false;
|
|
1518
|
+
let wake;
|
|
1519
|
+
const push = (chunk) => {
|
|
1520
|
+
if (chunk === null) ended = true;
|
|
1521
|
+
else queue.push(chunk);
|
|
1522
|
+
wake?.();
|
|
1523
|
+
wake = void 0;
|
|
1524
|
+
};
|
|
1525
|
+
async function* read() {
|
|
1526
|
+
while (true) {
|
|
1527
|
+
const next = queue.shift();
|
|
1528
|
+
if (next) {
|
|
1529
|
+
yield next;
|
|
1530
|
+
continue;
|
|
1531
|
+
}
|
|
1532
|
+
if (ended) return;
|
|
1533
|
+
await new Promise((resolve) => {
|
|
1534
|
+
wake = resolve;
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
return {
|
|
1539
|
+
push,
|
|
1540
|
+
read
|
|
1541
|
+
};
|
|
1542
|
+
};
|
|
1543
|
+
const a = make();
|
|
1544
|
+
const b = make();
|
|
1545
|
+
let aClosed = false;
|
|
1546
|
+
let bClosed = false;
|
|
1547
|
+
const endLeft = async () => {
|
|
1548
|
+
if (aClosed) return;
|
|
1549
|
+
aClosed = true;
|
|
1550
|
+
b.push(null);
|
|
1551
|
+
};
|
|
1552
|
+
const endRight = async () => {
|
|
1553
|
+
if (bClosed) return;
|
|
1554
|
+
bClosed = true;
|
|
1555
|
+
a.push(null);
|
|
1556
|
+
};
|
|
1557
|
+
return [{
|
|
1558
|
+
[Symbol.asyncIterator]: () => a.read()[Symbol.asyncIterator](),
|
|
1559
|
+
write: (data) => {
|
|
1560
|
+
if (!aClosed) b.push(data.slice());
|
|
1561
|
+
},
|
|
1562
|
+
end: endLeft,
|
|
1563
|
+
close: endLeft
|
|
1564
|
+
}, {
|
|
1565
|
+
[Symbol.asyncIterator]: () => b.read()[Symbol.asyncIterator](),
|
|
1566
|
+
write: (data) => {
|
|
1567
|
+
if (!bClosed) a.push(data.slice());
|
|
1568
|
+
},
|
|
1569
|
+
end: endRight,
|
|
1570
|
+
close: endRight
|
|
1571
|
+
}];
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Opens the repository a local remote names (see `Worktree.openRepository`), or throws
|
|
1575
|
+
* git's "does not appear to be a git repository" lines (exit 128).
|
|
1576
|
+
*/
|
|
1577
|
+
async function openLocalRemote(workingCopy, path) {
|
|
1578
|
+
const opened = await repositoryPlaceOf(workingCopy)?.openRepository?.(path, {
|
|
1579
|
+
checkOwnership: false,
|
|
1580
|
+
commandLineConfig: false
|
|
1581
|
+
}).catch(() => void 0);
|
|
1582
|
+
if (!opened) throw new TransportError$1(NOT_A_REPOSITORY(path));
|
|
1583
|
+
return opened;
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Runs `run` over a connection to upload-pack serving a local repository (opened by
|
|
1587
|
+
* {@link openLocalRemote}) with protocol v2, git's default `protocol.version` (v0 when the
|
|
1588
|
+
* option says 0, v1 when it says 1), as git's local transport runs `git-upload-pack '<path>'`,
|
|
1589
|
+
* in process.
|
|
1590
|
+
*/
|
|
1591
|
+
async function withLocalUploadPack(remote, run, options = {}) {
|
|
1592
|
+
const head = await remote.history.refs.get("HEAD").catch(() => void 0);
|
|
1593
|
+
const settings = serverSettingsOf(remote);
|
|
1594
|
+
const [client, server] = createDuplexPair();
|
|
1595
|
+
const serving = (async () => serveOverDuplex({
|
|
1596
|
+
duplex: server,
|
|
1597
|
+
repository: createRepositoryFacade({
|
|
1598
|
+
history: historyWithoutLazyFetch(remote.history),
|
|
1599
|
+
useBitmaps: servedUseBitmaps(remote),
|
|
1600
|
+
sparseFilterPatterns: sparseFilterMatcher,
|
|
1601
|
+
maxTreeDepth: servedMaxTreeDepth(remote)
|
|
1602
|
+
}),
|
|
1603
|
+
refStore: createTransportRefStore(remote.history.refs),
|
|
1604
|
+
service: "git-upload-pack",
|
|
1605
|
+
...(options.protocolVersion ?? 2) === 2 ? { protocolVersion: "2" } : {},
|
|
1606
|
+
...options.protocolVersion === 1 ? { announceVersion1: true } : {},
|
|
1607
|
+
uploadPackHideRefs: settings.uploadPackHideRefs,
|
|
1608
|
+
...settings.uploadPackFilter ? { uploadPackFilter: settings.uploadPackFilter } : {},
|
|
1609
|
+
...settings.uploadPackRequestPolicy ? { uploadPackRequestPolicy: settings.uploadPackRequestPolicy } : {},
|
|
1610
|
+
...settings.allowRefInWant ? { allowRefInWant: true } : {},
|
|
1611
|
+
...settings.allowSidebandAll ? { allowSidebandAll: true } : {},
|
|
1612
|
+
...settings.blobPackfileUris?.length ? { blobPackfileUris: settings.blobPackfileUris } : {},
|
|
1613
|
+
...settings.bundleUris !== void 0 ? { bundleUris: settings.bundleUris } : {},
|
|
1614
|
+
...settings.advertiseSID ? { advertiseSID: true } : {},
|
|
1615
|
+
...settings.advertiseObjectInfo ? { advertiseObjectInfo: true } : {},
|
|
1616
|
+
...settings.promisorRemoteInfo !== void 0 ? { promisorRemoteInfo: settings.promisorRemoteInfo } : {},
|
|
1617
|
+
...head && "target" in head ? { currentBranch: head.target } : {}
|
|
1618
|
+
}))().finally(() => server.close?.());
|
|
1619
|
+
try {
|
|
1620
|
+
const connection = await openDuplexConnection(client, { closeDuplex: true });
|
|
1621
|
+
try {
|
|
1622
|
+
return await run(connection);
|
|
1623
|
+
} catch (error) {
|
|
1624
|
+
throw packFailure(error) ?? error;
|
|
1625
|
+
} finally {
|
|
1626
|
+
await connection.close();
|
|
1627
|
+
}
|
|
1628
|
+
} finally {
|
|
1629
|
+
await client.close?.();
|
|
1630
|
+
await serving.catch(() => void 0);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
/**
|
|
1634
|
+
* The lines git prints when upload-pack's pack-objects fails on an object it cannot read
|
|
1635
|
+
* (upload-pack.c's create_pack_file): its own error and death (upload-pack's stderr, which
|
|
1636
|
+
* the local transport shares), the abort message it sends on band 3, then the client's
|
|
1637
|
+
* deaths. The pack failure reaches the client as a band-3 `ERR <reason>` (`sendPackStream`).
|
|
1638
|
+
*/
|
|
1639
|
+
function packFailure(error) {
|
|
1640
|
+
const message = error instanceof Error ? error.message : "";
|
|
1641
|
+
if (!(error instanceof Error) || error.name !== "ServerError" || !message.startsWith("ERR ")) return;
|
|
1642
|
+
const abort = "aborting due to possible repository corruption on the remote side.";
|
|
1643
|
+
return new TransportError$1([
|
|
1644
|
+
"error: git upload-pack: git-pack-objects died with error.",
|
|
1645
|
+
`fatal: git upload-pack: ${abort}`,
|
|
1646
|
+
`remote: ${abort}`,
|
|
1647
|
+
"fatal: early EOF",
|
|
1648
|
+
"fatal: fetch-pack: invalid index-pack output"
|
|
1649
|
+
].join("\n"), void 0, { cause: error });
|
|
1650
|
+
}
|
|
1651
|
+
/** git's defaults, for a repository whose configuration cannot be read. */
|
|
1652
|
+
const DEFAULT_SETTINGS = {
|
|
1653
|
+
allowDeletes: true,
|
|
1654
|
+
allowNonFastForward: true,
|
|
1655
|
+
denyCurrentBranch: "unconfigured",
|
|
1656
|
+
denyDeleteCurrent: "unconfigured",
|
|
1657
|
+
shallowUpdate: false,
|
|
1658
|
+
advertisePushOptions: false,
|
|
1659
|
+
uploadPackHideRefs: [],
|
|
1660
|
+
receivePackHideRefs: []
|
|
1661
|
+
};
|
|
1662
|
+
/**
|
|
1663
|
+
* The served repository's `pack.useBitmaps` (default true): its pack-objects (upload-pack's)
|
|
1664
|
+
* lists through a bitmap only while it allows.
|
|
1665
|
+
*/
|
|
1666
|
+
function servedUseBitmaps(remote) {
|
|
1667
|
+
const value = remote.config?.getAll("pack.useBitmaps").at(-1);
|
|
1668
|
+
if (value === void 0 || value === null) return true;
|
|
1669
|
+
return parseGitBool(String(value)) ?? true;
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* The served repository's `core.maxTreeDepth` (git's repo settings, default 2048): its
|
|
1673
|
+
* pack-objects dies on a deeper tree. Undefined when unset or unreadable (the default then).
|
|
1674
|
+
*/
|
|
1675
|
+
function servedMaxTreeDepth(remote) {
|
|
1676
|
+
const value = remote.config?.getAll("core.maxTreeDepth").at(-1);
|
|
1677
|
+
if (value === void 0 || value === null) return void 0;
|
|
1678
|
+
return parseGitInt(value);
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* receive-pack's check of a push certificate's signature (`prepare_push_cert_sha1`'s
|
|
1682
|
+
* `check_signature`): the served repository's `gpg.*`, the host's verifier (none: git's result
|
|
1683
|
+
* when its program cannot run). A signature of no known format dies as git dies.
|
|
1684
|
+
*/
|
|
1685
|
+
function pushCertVerifierOf(remote, hooks) {
|
|
1686
|
+
return async (payload, signature) => {
|
|
1687
|
+
const environment = hooks?.hostEnvironment;
|
|
1688
|
+
const entries = () => (remote.config?.listWithOrigin?.() ?? remote.config?.list() ?? []).map((e) => ({
|
|
1689
|
+
key: e.key.toLowerCase(),
|
|
1690
|
+
text: e.value ?? void 0,
|
|
1691
|
+
...e.file !== void 0 ? { file: e.file } : {},
|
|
1692
|
+
...e.line !== void 0 ? { line: e.line } : {}
|
|
1693
|
+
}));
|
|
1694
|
+
const cwd = await hooks?.hostGitDir().catch(() => void 0);
|
|
1695
|
+
const check = await checkSignatureWith(() => signingConfigFromEntries(entries(), environment), environment?.verifier, payload, signature, {
|
|
1696
|
+
payloadType: "push-cert",
|
|
1697
|
+
...cwd !== void 0 ? { cwd } : {}
|
|
1698
|
+
});
|
|
1699
|
+
return {
|
|
1700
|
+
result: check.result,
|
|
1701
|
+
...check.signer !== void 0 ? { signer: check.signer } : {},
|
|
1702
|
+
...check.key !== void 0 ? { key: check.key } : {}
|
|
1703
|
+
};
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
/** What git's upload-pack and receive-pack read from the served repository's config. */
|
|
1707
|
+
function serverSettingsOf(remote) {
|
|
1708
|
+
const config = remote.config;
|
|
1709
|
+
if (!config) return DEFAULT_SETTINGS;
|
|
1710
|
+
const listWithOrigin = config.listWithOrigin?.bind(config);
|
|
1711
|
+
if (!listWithOrigin) return serverSettingsFromConfig(config);
|
|
1712
|
+
const gitDir = `${remote.gitDir.replace(/^\/+/, "").replace(/\/+$/, "")}/`;
|
|
1713
|
+
return serverSettingsFromConfig({
|
|
1714
|
+
getAll: (key) => config.getAll(key),
|
|
1715
|
+
list: () => config.list(),
|
|
1716
|
+
listWithOrigin: () => listWithOrigin().map((e) => e.file?.replace(/^\/+/, "").startsWith(gitDir) ? {
|
|
1717
|
+
...e,
|
|
1718
|
+
file: e.file.replace(/^\/+/, "").slice(gitDir.length)
|
|
1719
|
+
} : e)
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* The branches the HEAD of a non-bare worktree of the repository uses, the main one and
|
|
1724
|
+
* every linked one (git's `find_shared_symref(get_worktrees(), "HEAD", ref)`, a worktree
|
|
1725
|
+
* being rebased or bisected on a branch included); undefined without the worktree list.
|
|
1726
|
+
*/
|
|
1727
|
+
async function checkedOutBranches(worktrees) {
|
|
1728
|
+
if (!worktrees) return void 0;
|
|
1729
|
+
const list = await worktrees.list().catch(() => void 0);
|
|
1730
|
+
if (!list) return void 0;
|
|
1731
|
+
const out = /* @__PURE__ */ new Set();
|
|
1732
|
+
for (const wt of list) for (const ref of [
|
|
1733
|
+
wt.headRef,
|
|
1734
|
+
wt.rebasing,
|
|
1735
|
+
wt.bisecting
|
|
1736
|
+
]) if (ref !== void 0 && usesBranch(wt, ref)) out.add(ref);
|
|
1737
|
+
return [...out];
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* receive.denyCurrentBranch=updateInstead (receive-pack.c's `update_worktree`, without the
|
|
1741
|
+
* push-to-checkout hook: `push_to_deploy`): the worktree that has `ref` checked out is
|
|
1742
|
+
* refused while it has unstaged or staged changes, else brought to `newOid` by
|
|
1743
|
+
* `read-tree -u -m`; the ref itself is updated afterwards by receive-pack.
|
|
1744
|
+
*
|
|
1745
|
+
* @returns the refusal reason, as git reports it; undefined when the worktree was updated
|
|
1746
|
+
*/
|
|
1747
|
+
async function pushToDeploy(worktrees, ref, newOid) {
|
|
1748
|
+
const wt = await worktreeUsingBranch(worktrees, ref);
|
|
1749
|
+
if (!wt) return "denyCurrentBranch = updateInstead needs a worktree";
|
|
1750
|
+
let workingCopy;
|
|
1751
|
+
try {
|
|
1752
|
+
workingCopy = await worktrees.open(wt);
|
|
1753
|
+
} catch {
|
|
1754
|
+
return "Up-to-date check failed";
|
|
1755
|
+
}
|
|
1756
|
+
const status = await new StatusCommand(workingCopy).setUntrackedFiles("no").setIgnoreSubmodules("all").call();
|
|
1757
|
+
if (status.modified.size > 0 || status.missing.size > 0 || status.conflicting.size > 0) return "Working directory has unstaged changes";
|
|
1758
|
+
if (status.added.size > 0 || status.changed.size > 0 || status.removed.size > 0) return "Working directory has staged changes";
|
|
1759
|
+
try {
|
|
1760
|
+
await new ReadTreeCommand(workingCopy).addTree(newOid).setMerge(true).setUpdate(true).call();
|
|
1761
|
+
} catch {
|
|
1762
|
+
return "Could not update working tree to new HEAD";
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
/**
|
|
1766
|
+
* Runs `run` over a connection to receive-pack serving a local repository (opened by
|
|
1767
|
+
* {@link openLocalRemote}), as git's local transport runs `git-receive-pack '<path>'`, in
|
|
1768
|
+
* process: the pushed objects go into that repository and its refs are updated there, under
|
|
1769
|
+
* the settings git's receive-pack reads from that repository's config (see
|
|
1770
|
+
* `serverSettingsFromConfig`: deletes, forced updates, the current branch, hidden refs,
|
|
1771
|
+
* shallow updates). A branch checked out in any non-bare worktree of it, linked ones
|
|
1772
|
+
* included, is the current branch `receive.denyCurrentBranch` rules on.
|
|
1773
|
+
*/
|
|
1774
|
+
async function withLocalReceivePack(remote, run, hooks, transactionHooks = hooks, options = {}) {
|
|
1775
|
+
try {
|
|
1776
|
+
await remote.checkOwnership?.();
|
|
1777
|
+
} catch (error) {
|
|
1778
|
+
if (error instanceof Error && error.name === "DubiousOwnershipError") throw new TransportError$1(`${error.message}\n${COULD_NOT_READ}`);
|
|
1779
|
+
throw error;
|
|
1780
|
+
}
|
|
1781
|
+
const receiveHooks = hooks?.enabled ? scriptReceiveHooks(hooks) : void 0;
|
|
1782
|
+
return withReceiveTransactionHook(remote, transactionHooks, () => receiveOver(remote, run, hooks, receiveHooks, options.protocolVersion === 1, options));
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* The receive-side reference-transaction hooks installed on a ref store, oldest first, and
|
|
1786
|
+
* the hook the store had before the first of them: overlapping receive-packs on one store
|
|
1787
|
+
* (two served pushes at once) each put theirs in and take theirs out, whatever the order
|
|
1788
|
+
* they end in, and the last one out puts back the store's own.
|
|
1789
|
+
*/
|
|
1790
|
+
const receiveTransactionHooks = /* @__PURE__ */ new WeakMap();
|
|
1791
|
+
/**
|
|
1792
|
+
* Runs `body` with the reference-transaction hook of `hooks` (a receiving repository's
|
|
1793
|
+
* session) installed on `remote`'s ref store, as git's receive-pack runs it: in the git
|
|
1794
|
+
* directory with `GIT_DIR=.` and no `GIT_PREFIX`. The hook that was there before is put
|
|
1795
|
+
* back after (once every overlapping receive on the store has ended). Without a hook
|
|
1796
|
+
* runner, or a ref store that cannot take one, `body` alone.
|
|
1797
|
+
*/
|
|
1798
|
+
async function withReceiveTransactionHook(remote, hooks, body) {
|
|
1799
|
+
const store = remote.history.refs;
|
|
1800
|
+
if (!hooks?.enabled || store.setTransactionHook === void 0) return body();
|
|
1801
|
+
const transactionHook = refTransactionHookOf(hooks, {
|
|
1802
|
+
env: { GIT_DIR: "." },
|
|
1803
|
+
prefix: false
|
|
1804
|
+
});
|
|
1805
|
+
let installed = receiveTransactionHooks.get(store);
|
|
1806
|
+
if (!installed) {
|
|
1807
|
+
installed = {
|
|
1808
|
+
active: [],
|
|
1809
|
+
previous: store.getTransactionHook?.()
|
|
1810
|
+
};
|
|
1811
|
+
receiveTransactionHooks.set(store, installed);
|
|
1812
|
+
}
|
|
1813
|
+
installed.active.push(transactionHook);
|
|
1814
|
+
store.setTransactionHook(transactionHook);
|
|
1815
|
+
try {
|
|
1816
|
+
return await body();
|
|
1817
|
+
} finally {
|
|
1818
|
+
const { active, previous } = installed;
|
|
1819
|
+
active.splice(active.indexOf(transactionHook), 1);
|
|
1820
|
+
const current = store.getTransactionHook?.();
|
|
1821
|
+
const ours = current === transactionHook || current === void 0;
|
|
1822
|
+
if (active.length === 0) {
|
|
1823
|
+
receiveTransactionHooks.delete(store);
|
|
1824
|
+
if (ours) store.setTransactionHook(previous);
|
|
1825
|
+
} else if (ours) store.setTransactionHook(active[active.length - 1]);
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* receive-pack's `receive.fsckObjects` / `transfer.fsckObjects` settings of the repository it
|
|
1830
|
+
* serves (`receiveFsckOf`): skip lists named by a relative path are read from its git
|
|
1831
|
+
* directory (receive-pack's working directory), absolute ones from the host; with
|
|
1832
|
+
* `confineFiles` (a served repository) only files inside its own git directories, where their
|
|
1833
|
+
* links lead and capped as confined includes (`readConfinedFile`), anything else unreadable.
|
|
1834
|
+
*/
|
|
1835
|
+
function receiveFsckSettingsOf(remote, host = {}) {
|
|
1836
|
+
const config = remote.config;
|
|
1837
|
+
if (!config) return { warnings: [] };
|
|
1838
|
+
const gitDir = remote.gitDir.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
1839
|
+
const files = remote.files;
|
|
1840
|
+
const environment = host.environment;
|
|
1841
|
+
const listWithOrigin = config.listWithOrigin?.bind(config);
|
|
1842
|
+
const entries = () => listWithOrigin ? listWithOrigin().map((e) => e.file?.replace(/^\/+/, "").startsWith(`${gitDir}/`) ? {
|
|
1843
|
+
...e,
|
|
1844
|
+
file: e.file.replace(/^\/+/, "").slice(gitDir.length + 1)
|
|
1845
|
+
} : e) : config.list();
|
|
1846
|
+
if (host.confineFiles) {
|
|
1847
|
+
const roots = [gitDir];
|
|
1848
|
+
const common = remote.commonDir?.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
1849
|
+
if (common !== void 0 && common !== gitDir) roots.push(common);
|
|
1850
|
+
const confined = files ? configFilesApiOf(files) : void 0;
|
|
1851
|
+
return receiveFsckOf({
|
|
1852
|
+
entries,
|
|
1853
|
+
compatibility: host.compatibility ?? "2.56",
|
|
1854
|
+
readFile: async (path) => confined ? readConfinedFile(confined, path, {
|
|
1855
|
+
baseDir: gitDir,
|
|
1856
|
+
roots
|
|
1857
|
+
}).catch(() => void 0) : void 0
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
return receiveFsckOf({
|
|
1861
|
+
entries,
|
|
1862
|
+
compatibility: host.compatibility ?? "2.56",
|
|
1863
|
+
...environment?.home ? { home: environment.home } : {},
|
|
1864
|
+
readFile: async (path) => {
|
|
1865
|
+
if (path.startsWith("/") && environment) return environment.readFile(path);
|
|
1866
|
+
if (!files) return void 0;
|
|
1867
|
+
const full = path.startsWith("/") ? path : `${gitDir}/${path}`;
|
|
1868
|
+
if ((await files.stats(full).catch(() => void 0))?.kind !== "file") return void 0;
|
|
1869
|
+
return readFile$1(files, full);
|
|
1870
|
+
}
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* The settings git's receive-pack takes from the repository it serves: the policies and hidden
|
|
1875
|
+
* refs of its config (`serverSettingsFromConfig`), its current branch and the branches its
|
|
1876
|
+
* worktrees have checked out, `updateInstead` (push-to-checkout, push-to-deploy), the fsck of
|
|
1877
|
+
* pushed objects (`receive.fsckObjects`, {@link receiveFsckSettingsOf}) and, with hooks,
|
|
1878
|
+
* pre-receive / update / post-receive run as git's receive-pack runs them.
|
|
1879
|
+
*/
|
|
1880
|
+
async function receivePackSettingsOf(remote, hooks, receiveHooks = hooks?.enabled ? scriptReceiveHooks(hooks) : void 0, host = {}) {
|
|
1881
|
+
const head = await remote.history.refs.get("HEAD").catch(() => void 0);
|
|
1882
|
+
const settings = serverSettingsOf(remote);
|
|
1883
|
+
const fsck = receiveFsckSettingsOf(remote, {
|
|
1884
|
+
compatibility: hooks?.compatibility,
|
|
1885
|
+
...host
|
|
1886
|
+
});
|
|
1887
|
+
const configError = settings.receivePackConfigError ?? fsck.configError;
|
|
1888
|
+
const checkedOut = await checkedOutBranches(remote.worktrees);
|
|
1889
|
+
const worktrees = remote.worktrees;
|
|
1890
|
+
return {
|
|
1891
|
+
bare: remote.bare,
|
|
1892
|
+
...head && "target" in head ? { currentBranch: head.target } : {},
|
|
1893
|
+
allowDeletes: settings.allowDeletes,
|
|
1894
|
+
allowNonFastForward: settings.allowNonFastForward,
|
|
1895
|
+
denyCurrentBranch: settings.denyCurrentBranch,
|
|
1896
|
+
denyDeleteCurrent: settings.denyDeleteCurrent,
|
|
1897
|
+
shallowUpdate: settings.shallowUpdate,
|
|
1898
|
+
advertisePushOptions: settings.advertisePushOptions,
|
|
1899
|
+
...settings.advertiseSID ? { advertiseSID: true } : {},
|
|
1900
|
+
...settings.advertiseAtomic !== void 0 ? { advertiseAtomic: settings.advertiseAtomic } : {},
|
|
1901
|
+
...settings.maxInputSize !== void 0 ? { maxInputSize: settings.maxInputSize } : {},
|
|
1902
|
+
...settings.certNonceSeed !== void 0 ? { certNonceSeed: settings.certNonceSeed } : {},
|
|
1903
|
+
...settings.certNonceSlop !== void 0 ? { certNonceSlop: settings.certNonceSlop } : {},
|
|
1904
|
+
pushCertificates: { verify: pushCertVerifierOf(remote, hooks) },
|
|
1905
|
+
...settings.unpackLimit !== void 0 ? { unpackLimit: settings.unpackLimit } : {},
|
|
1906
|
+
...settings.receiveKeepAliveMs !== void 0 ? { receiveKeepAliveMs: settings.receiveKeepAliveMs } : {},
|
|
1907
|
+
uploadPackHideRefs: settings.uploadPackHideRefs,
|
|
1908
|
+
receivePackHideRefs: settings.receivePackHideRefs,
|
|
1909
|
+
...receiveHooks ? {
|
|
1910
|
+
hooks: receiveHooks,
|
|
1911
|
+
relayPostReceive: true
|
|
1912
|
+
} : {},
|
|
1913
|
+
publishBeforeUpdate: true,
|
|
1914
|
+
preReceiveSeesRefused: true,
|
|
1915
|
+
...settings.procReceiveRefs?.length ? { procReceiveRefs: settings.procReceiveRefs } : {},
|
|
1916
|
+
...configError !== void 0 ? { receivePackConfigError: configError } : {},
|
|
1917
|
+
...fsck.fsckObjects ? { fsckObjects: fsck.fsckObjects } : {},
|
|
1918
|
+
...hooks?.enabled && hooks.compatibility !== "2.43" ? { batchNonAtomic: true } : {},
|
|
1919
|
+
...hooks?.enabled && hooks.compatibility === "2.43" ? { interleaveUpdateHook: true } : {},
|
|
1920
|
+
...checkedOut ? { checkedOutBranches: checkedOut } : {},
|
|
1921
|
+
...afterPushOf(remote, hooks),
|
|
1922
|
+
...worktrees ? { updateWorktree: async (ref, newOid, ctx) => {
|
|
1923
|
+
const verdict = await pushToCheckout(hooks, worktrees, ref, newOid, ctx);
|
|
1924
|
+
return verdict === null ? pushToDeploy(worktrees, ref, newOid) : verdict;
|
|
1925
|
+
} } : {}
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1928
|
+
/** git's `git_config_bool` of the last value of `key` in `remote`'s config, else `fallback`. */
|
|
1929
|
+
function remoteBool(remote, key, fallback) {
|
|
1930
|
+
const value = remote.config?.getAll(key).at(-1);
|
|
1931
|
+
if (value === void 0) return fallback;
|
|
1932
|
+
if (value === null) return true;
|
|
1933
|
+
return parseGitBool(value) ?? fallback;
|
|
1934
|
+
}
|
|
1935
|
+
/**
|
|
1936
|
+
* run-command.c's `prepare_auto_maintenance`: whether git runs `maintenance run --auto` after a
|
|
1937
|
+
* command (`maintenance.auto`, else `gc.auto` greater than 0, else yes).
|
|
1938
|
+
*/
|
|
1939
|
+
function autoMaintenanceEnabled(remote) {
|
|
1940
|
+
const auto = remote.config?.getAll("maintenance.auto").at(-1);
|
|
1941
|
+
if (auto !== void 0) return auto === null ? true : parseGitBool(auto) ?? true;
|
|
1942
|
+
const gcAuto = remote.config?.getAll("gc.auto").at(-1);
|
|
1943
|
+
if (gcAuto !== void 0 && gcAuto !== null) {
|
|
1944
|
+
const n = parseGitInt(gcAuto);
|
|
1945
|
+
if (n !== void 0) return n > 0;
|
|
1946
|
+
}
|
|
1947
|
+
return true;
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* What git's receive-pack does once a push is done (`ReceivePackConfig.afterPush`), after
|
|
1951
|
+
* post-receive and post-update: `receive.autogc` (default true) runs the auto maintenance:
|
|
1952
|
+
* git 2.5x's `maintenance run --auto --quiet` when `prepare_auto_maintenance` allows it
|
|
1953
|
+
* (`maintenance.auto`, else `gc.auto` above 0), with the maintenance strategy and each task's
|
|
1954
|
+
* condition (`MaintenanceRunCommand`), git 2.43's `gc --auto --quiet` (the receive side's
|
|
1955
|
+
* hook runner tells the version); `receive.updateServerInfo` (default false)
|
|
1956
|
+
* `update-server-info`. Nothing when neither applies.
|
|
1957
|
+
*/
|
|
1958
|
+
function afterPushOf(remote, hooks) {
|
|
1959
|
+
const v243 = hooks?.compatibility === "2.43";
|
|
1960
|
+
const autoGc = remoteBool(remote, "receive.autogc", true) && (v243 || autoMaintenanceEnabled(remote)) && remote.worktrees !== void 0 && remote.history.packs !== void 0;
|
|
1961
|
+
const serverInfo = remoteBool(remote, "receive.updateServerInfo", false) && remote.files !== void 0 && remote.history.objects !== void 0 && remote.history.packs !== void 0;
|
|
1962
|
+
if (!autoGc && !serverInfo) return {};
|
|
1963
|
+
return { afterPush: async (ctx) => {
|
|
1964
|
+
if (autoGc && remote.worktrees) {
|
|
1965
|
+
const admin = await remote.worktrees.openAdmin();
|
|
1966
|
+
const workingCopy = withEnvironment(worktreeAdminWorkingCopy(admin), hooks?.hostEnvironment);
|
|
1967
|
+
let lines;
|
|
1968
|
+
if (v243) {
|
|
1969
|
+
const result = await new GarbageCollectCommand(workingCopy).setAuto(true).setQuiet(true).call();
|
|
1970
|
+
lines = [...result.errors ?? [], ...result.warnings ?? []];
|
|
1971
|
+
} else {
|
|
1972
|
+
const { MaintenanceRunCommand } = await import("./maintenance-run-command-Bw21HEkH.js").then((n) => n.r);
|
|
1973
|
+
lines = (await new MaintenanceRunCommand(workingCopy).setAuto(true).setQuiet(true).call()).stderr.split("\n").filter((l) => l.length > 0);
|
|
1974
|
+
}
|
|
1975
|
+
if (lines.length > 0) await ctx.message(`${lines.join("\n")}\n`);
|
|
1976
|
+
}
|
|
1977
|
+
const { files } = remote;
|
|
1978
|
+
const { objects, packs } = remote.history;
|
|
1979
|
+
if (serverInfo && files && objects && packs) {
|
|
1980
|
+
const gitDir = (remote.commonDir ?? remote.gitDir).replace(/^\/+/, "").replace(/\/+$/, "");
|
|
1981
|
+
await updateServerInfo({
|
|
1982
|
+
files,
|
|
1983
|
+
gitDir,
|
|
1984
|
+
objects,
|
|
1985
|
+
packs
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
} };
|
|
1989
|
+
}
|
|
1990
|
+
/**
|
|
1991
|
+
* `workingCopy` whose configuration answers `environment` (see `hostEnvironmentOf`) with
|
|
1992
|
+
* `environment`; itself without one.
|
|
1993
|
+
*/
|
|
1994
|
+
function withEnvironment(workingCopy, environment) {
|
|
1995
|
+
if (!environment) return workingCopy;
|
|
1996
|
+
const own = (target, key) => {
|
|
1997
|
+
const value = Reflect.get(target, key, target);
|
|
1998
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
1999
|
+
};
|
|
2000
|
+
const config = new Proxy(workingCopy.config, { get: (target, key) => key === "environment" ? environment : own(target, key) });
|
|
2001
|
+
return new Proxy(workingCopy, { get: (target, key) => key === "config" ? config : own(target, key) });
|
|
2002
|
+
}
|
|
2003
|
+
async function receiveOver(remote, run, hooks, receiveHooks, version1, options = {}) {
|
|
2004
|
+
const [client, server] = createDuplexPair();
|
|
2005
|
+
const host = options.host ?? {};
|
|
2006
|
+
const settings = await receivePackSettingsOf(remote, hooks, receiveHooks, host);
|
|
2007
|
+
if (options.onWarning) for (const line of receiveFsckSettingsOf(remote, host).warnings) options.onWarning(line);
|
|
2008
|
+
const serving = serveOverDuplex({
|
|
2009
|
+
...settings,
|
|
2010
|
+
duplex: server,
|
|
2011
|
+
repository: createRepositoryFacade({
|
|
2012
|
+
history: historyWithoutLazyFetch(remote.history),
|
|
2013
|
+
useBitmaps: servedUseBitmaps(remote),
|
|
2014
|
+
sparseFilterPatterns: sparseFilterMatcher,
|
|
2015
|
+
maxTreeDepth: servedMaxTreeDepth(remote)
|
|
2016
|
+
}),
|
|
2017
|
+
refStore: createTransportRefStore(remote.history.refs),
|
|
2018
|
+
service: "git-receive-pack",
|
|
2019
|
+
...version1 ? { announceVersion1: true } : {}
|
|
2020
|
+
}).finally(() => server.close?.());
|
|
2021
|
+
const died = async (cause) => {
|
|
2022
|
+
await client.close?.();
|
|
2023
|
+
const served = await serving.catch(() => void 0);
|
|
2024
|
+
if (!served?.error?.startsWith("fatal: ")) return void 0;
|
|
2025
|
+
return new TransportError$1(`${served.error}\nsend-pack: unexpected disconnect while reading sideband packet\nfatal: the remote end hung up unexpectedly`, void 0, cause === void 0 ? void 0 : { cause });
|
|
2026
|
+
};
|
|
2027
|
+
try {
|
|
2028
|
+
const connection = await openDuplexReceivePackConnection(client, { closeDuplex: true });
|
|
2029
|
+
let value;
|
|
2030
|
+
try {
|
|
2031
|
+
value = await run(connection);
|
|
2032
|
+
} finally {
|
|
2033
|
+
await connection.close();
|
|
2034
|
+
}
|
|
2035
|
+
const death = await died();
|
|
2036
|
+
if (death) throw death;
|
|
2037
|
+
return value;
|
|
2038
|
+
} catch (error) {
|
|
2039
|
+
const early = settings.receivePackConfigError;
|
|
2040
|
+
if (early !== void 0) {
|
|
2041
|
+
await client.close?.();
|
|
2042
|
+
await serving.catch(() => void 0);
|
|
2043
|
+
throw new TransportError$1(`${early}\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights
|
|
2044
|
+
and the repository exists.`, void 0, { cause: error });
|
|
2045
|
+
}
|
|
2046
|
+
if (error instanceof TransportError$1) throw error;
|
|
2047
|
+
throw await died(error) ?? error;
|
|
2048
|
+
} finally {
|
|
2049
|
+
await client.close?.();
|
|
2050
|
+
await serving.catch(() => void 0);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* The hooks of a repository a local push reaches (git's receive-pack runs them there): found
|
|
2055
|
+
* in its git directory (or its `core.hooksPath`), run in its git directory, through the host
|
|
2056
|
+
* environment of the working copy pushing. Undefined without a runner or a FilesApi.
|
|
2057
|
+
*
|
|
2058
|
+
* With `localPush` (a push to a path: git's connect.c starts receive-pack with
|
|
2059
|
+
* `local_repo_env` cleared), the hooks run without the pushing side's repository variables
|
|
2060
|
+
* ({@link LOCAL_REPO_ENV}: `GIT_ALTERNATE_OBJECT_DIRECTORIES`, `GIT_DIR`, `GIT_INDEX_FILE`,
|
|
2061
|
+
* `GIT_CONFIG_COUNT`, ...), so a quarantined pre-receive's alternates name the receiving
|
|
2062
|
+
* repository's objects alone. Without it (a served push over HTTP or git://, where the
|
|
2063
|
+
* server's own environment is receive-pack's) the host's variables reach them.
|
|
2064
|
+
*/
|
|
2065
|
+
function remoteHookSession(workingCopy, remote, options = {}) {
|
|
2066
|
+
const local = hookHostOf(workingCopy);
|
|
2067
|
+
if (!local.environment()?.hookRunner) return void 0;
|
|
2068
|
+
let files;
|
|
2069
|
+
try {
|
|
2070
|
+
files = repositoryPlaceOf(workingCopy)?.getFiles?.();
|
|
2071
|
+
} catch {
|
|
2072
|
+
files = void 0;
|
|
2073
|
+
}
|
|
2074
|
+
if (!files) return void 0;
|
|
2075
|
+
const gitDir = remote.gitDir.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
2076
|
+
const top = !remote.bare && gitDir.endsWith("/.git") ? gitDir.slice(0, -5) : gitDir;
|
|
2077
|
+
const setting = (key) => {
|
|
2078
|
+
const values = remote.config?.getAll(key) ?? [];
|
|
2079
|
+
const last = values[values.length - 1];
|
|
2080
|
+
return last === null ? "" : last;
|
|
2081
|
+
};
|
|
2082
|
+
return new HookSession({
|
|
2083
|
+
layout: async () => ({
|
|
2084
|
+
files,
|
|
2085
|
+
top,
|
|
2086
|
+
gitDir,
|
|
2087
|
+
cwd: gitDir,
|
|
2088
|
+
bare: remote.bare
|
|
2089
|
+
}),
|
|
2090
|
+
configValue: setting,
|
|
2091
|
+
environment: () => local.environment(),
|
|
2092
|
+
...options.localPush ? { unsetEnv: LOCAL_REPO_ENV } : {},
|
|
2093
|
+
hookSettings: () => {
|
|
2094
|
+
const config = remote.config;
|
|
2095
|
+
if (!config) return [];
|
|
2096
|
+
return hookSettingsFromEntries(config.listWithOrigin?.() ?? config.list());
|
|
2097
|
+
}
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* receive-pack's `push_to_checkout` (`receive.denyCurrentBranch=updateInstead`): when the
|
|
2102
|
+
* push-to-checkout hook exists it updates the worktree in place of git's own push-to-deploy,
|
|
2103
|
+
* told the pushed commit, with `GIT_DIR` and `GIT_WORK_TREE` the worktree's (absolute):
|
|
2104
|
+
* undefined when it accepts, git's "push-to-checkout hook declined" when it refuses; null
|
|
2105
|
+
* when there is no hook (push-to-deploy decides).
|
|
2106
|
+
*/
|
|
2107
|
+
async function pushToCheckout(hooks, worktrees, ref, newOid, ctx) {
|
|
2108
|
+
if (!hooks?.enabled || !await hooks.exists("push-to-checkout")) return null;
|
|
2109
|
+
const wt = await worktreeUsingBranch(worktrees, ref);
|
|
2110
|
+
if (!wt || wt.bare) return "denyCurrentBranch = updateInstead needs a worktree";
|
|
2111
|
+
const gitDir = await hooks.hostGitDir();
|
|
2112
|
+
const env = {
|
|
2113
|
+
...hookClientEnv(hooks, ctx),
|
|
2114
|
+
GIT_WORK_TREE: wt.path
|
|
2115
|
+
};
|
|
2116
|
+
if (gitDir) env.GIT_DIR = wt.id ? `${gitDir}/worktrees/${wt.id}` : `${gitDir}/.`;
|
|
2117
|
+
const result = await hooks.run("push-to-checkout", {
|
|
2118
|
+
args: [newOid],
|
|
2119
|
+
env,
|
|
2120
|
+
prefix: false
|
|
2121
|
+
});
|
|
2122
|
+
return result && result.exitCode !== 0 ? "push-to-checkout hook declined" : void 0;
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* tmp-objdir.c's `tmp_objdir_env` for a hook run while the push's objects are quarantined
|
|
2126
|
+
* (`ctx.quarantinePath`: pre-receive, as git's receive-pack hands `odb_transaction_env` to
|
|
2127
|
+
* it): `GIT_QUARANTINE_PATH` and `GIT_OBJECT_DIRECTORY` name the quarantine,
|
|
2128
|
+
* `GIT_ALTERNATE_OBJECT_DIRECTORIES` the repository's objects, appended to the host's own
|
|
2129
|
+
* (`env_append`: after a `:`, C-quoted when the directory holds a `:` or starts with `"`),
|
|
2130
|
+
* absolute where the repository's files have a host path, so native git run by the hook
|
|
2131
|
+
* reads the pushed objects. Nothing once the objects are published.
|
|
2132
|
+
*/
|
|
2133
|
+
async function quarantineEnv(hooks, ctx) {
|
|
2134
|
+
const quarantine = ctx.quarantinePath;
|
|
2135
|
+
if (quarantine === void 0) return {};
|
|
2136
|
+
const objects = await hooks.commonGitFile("objects");
|
|
2137
|
+
const trim = (p) => p.replace(/^\/+|\/+$/g, "");
|
|
2138
|
+
const host = await hooks.hostGitDir();
|
|
2139
|
+
const below = objects && trim(quarantine).startsWith(`${trim(objects.path)}/`);
|
|
2140
|
+
const path = host && objects && below ? `${host}/./objects/${trim(quarantine).slice(trim(objects.path).length + 1)}` : await hooks.hookPathOf(quarantine);
|
|
2141
|
+
const env = {
|
|
2142
|
+
GIT_QUARANTINE_PATH: path,
|
|
2143
|
+
GIT_OBJECT_DIRECTORY: path
|
|
2144
|
+
};
|
|
2145
|
+
if (objects) {
|
|
2146
|
+
const dir = host && below ? `${host}/./objects` : await hooks.hookPathOf(objects.path);
|
|
2147
|
+
const value = dir.includes(":") || dir.startsWith("\"") ? `"${quoteCStyleBody(dir) ?? dir}"` : dir;
|
|
2148
|
+
const old = hooks.hostAlternateObjectDirectories;
|
|
2149
|
+
env.GIT_ALTERNATE_OBJECT_DIRECTORIES = old === void 0 ? value : `${old}:${value}`;
|
|
2150
|
+
}
|
|
2151
|
+
return env;
|
|
2152
|
+
}
|
|
2153
|
+
/**
|
|
2154
|
+
* The variables git's http-backend hands receive-pack, and so every hook it runs
|
|
2155
|
+
* (http-backend.c `run_service`), for a push served over smart HTTP: the web server's
|
|
2156
|
+
* `REMOTE_USER` and `REMOTE_ADDR` (inherited), and, where the host sets none,
|
|
2157
|
+
* `GIT_COMMITTER_NAME=<user>` and `GIT_COMMITTER_EMAIL=<user>@http.<addr>` (`anonymous` and
|
|
2158
|
+
* `(none)` when unknown). Nothing for a push not over HTTP.
|
|
2159
|
+
*/
|
|
2160
|
+
function httpBackendEnv(hooks, client) {
|
|
2161
|
+
if (!client?.http) return {};
|
|
2162
|
+
const env = {};
|
|
2163
|
+
if (client.remoteUser) env.REMOTE_USER = client.remoteUser;
|
|
2164
|
+
if (client.remoteAddr) env.REMOTE_ADDR = client.remoteAddr;
|
|
2165
|
+
const user = client.remoteUser || "anonymous";
|
|
2166
|
+
const addr = client.remoteAddr || "(none)";
|
|
2167
|
+
const committer = hooks.hostCommitter;
|
|
2168
|
+
if (committer.name === void 0) env.GIT_COMMITTER_NAME = user;
|
|
2169
|
+
if (committer.email === void 0) env.GIT_COMMITTER_EMAIL = `${user}@http.${addr}`;
|
|
2170
|
+
return env;
|
|
2171
|
+
}
|
|
2172
|
+
/** {@link httpBackendEnv} of a push its hook context describes (HTTP: it has a request). */
|
|
2173
|
+
function hookClientEnv(hooks, ctx) {
|
|
2174
|
+
return httpBackendEnv(hooks, ctx?.request ? {
|
|
2175
|
+
http: true,
|
|
2176
|
+
...ctx.remoteUser !== void 0 ? { remoteUser: ctx.remoteUser } : {},
|
|
2177
|
+
...ctx.remoteAddr !== void 0 ? { remoteAddr: ctx.remoteAddr } : {}
|
|
2178
|
+
} : void 0);
|
|
2179
|
+
}
|
|
2180
|
+
/**
|
|
2181
|
+
* receive-pack's hooks as scripts (builtin/receive-pack.c `run_receive_hook`,
|
|
2182
|
+
* `run_update_hook`, `run_update_post_hook`, `run_proc_receive_hook`): pre-receive and
|
|
2183
|
+
* post-receive read `<old> <new> <ref>` lines on stdin (with `GIT_PUSH_OPTION_COUNT` and the
|
|
2184
|
+
* options; post-receive the proc-receive hook's reports in place of their commands), update
|
|
2185
|
+
* is told one ref, post-update the refs that moved, proc-receive is started and talked to
|
|
2186
|
+
* over its stdin and stdout (found as `find_hook` finds it: no configured hook); each runs
|
|
2187
|
+
* with `GIT_DIR=.` and its output goes to the pushing user (side-band, git's "remote: "
|
|
2188
|
+
* lines).
|
|
2189
|
+
*/
|
|
2190
|
+
function scriptReceiveHooks(hooks) {
|
|
2191
|
+
const lines = (commands) => commands.map((c) => `${c.oldOid} ${c.newOid} ${c.refName}\n`).join("");
|
|
2192
|
+
const optionEnv = (ctx) => {
|
|
2193
|
+
const env = { GIT_PUSH_OPTION_COUNT: String(ctx.pushOptions.length) };
|
|
2194
|
+
ctx.pushOptions.forEach((option, i) => {
|
|
2195
|
+
env[`GIT_PUSH_OPTION_${i}`] = option;
|
|
2196
|
+
});
|
|
2197
|
+
return env;
|
|
2198
|
+
};
|
|
2199
|
+
const certEnv = async (name, ctx) => {
|
|
2200
|
+
if (!ctx.pushCertificate) return {};
|
|
2201
|
+
try {
|
|
2202
|
+
if (!await hooks.exists(name)) return {};
|
|
2203
|
+
return pushCertificateEnv(await ctx.pushCertificate());
|
|
2204
|
+
} catch (error) {
|
|
2205
|
+
if (error instanceof GitApiError && error.message.startsWith("fatal: ")) throw new ReceivePackDiedError(error.message.slice(7));
|
|
2206
|
+
throw error;
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
const run = async (name, ctx, options) => {
|
|
2210
|
+
const result = await hooks.run(name, {
|
|
2211
|
+
...options,
|
|
2212
|
+
env: {
|
|
2213
|
+
...hookClientEnv(hooks, ctx),
|
|
2214
|
+
GIT_DIR: ".",
|
|
2215
|
+
...await quarantineEnv(hooks, ctx),
|
|
2216
|
+
...name === "update" ? {} : await certEnv(name, ctx),
|
|
2217
|
+
...options.env ?? {}
|
|
2218
|
+
},
|
|
2219
|
+
prefix: false
|
|
2220
|
+
}).catch((error) => {
|
|
2221
|
+
if (error instanceof GitApiError && error.message.startsWith("fatal: ")) throw new ReceivePackDiedError(error.message.slice(7));
|
|
2222
|
+
throw error;
|
|
2223
|
+
});
|
|
2224
|
+
if (result?.stderr) await ctx.message(result.stderr);
|
|
2225
|
+
return result;
|
|
2226
|
+
};
|
|
2227
|
+
return {
|
|
2228
|
+
preReceive: async (commands, ctx) => {
|
|
2229
|
+
const result = await run("pre-receive", ctx, {
|
|
2230
|
+
stdin: lines(commands),
|
|
2231
|
+
env: optionEnv(ctx)
|
|
2232
|
+
});
|
|
2233
|
+
return !result || result.exitCode === 0;
|
|
2234
|
+
},
|
|
2235
|
+
update: async (refName, oldOid, newOid, ctx) => {
|
|
2236
|
+
const result = await run("update", ctx, { args: [
|
|
2237
|
+
refName,
|
|
2238
|
+
oldOid,
|
|
2239
|
+
newOid
|
|
2240
|
+
] });
|
|
2241
|
+
return !result || result.exitCode === 0;
|
|
2242
|
+
},
|
|
2243
|
+
postReceive: async (commands, ctx) => {
|
|
2244
|
+
await run("post-receive", ctx, {
|
|
2245
|
+
stdin: lines(commands),
|
|
2246
|
+
env: optionEnv(ctx)
|
|
2247
|
+
});
|
|
2248
|
+
const refs = commands.filter((c) => !c.report).map((c) => c.pushedRef ?? c.refName);
|
|
2249
|
+
if (refs.length > 0) await run("post-update", ctx, { args: refs });
|
|
2250
|
+
},
|
|
2251
|
+
...hooks.compatibility === "2.43" ? {} : { receiveReport: async (report, ctx) => {
|
|
2252
|
+
const started = await hooks.start("receive-report", {
|
|
2253
|
+
env: {
|
|
2254
|
+
...hookClientEnv(hooks, ctx),
|
|
2255
|
+
GIT_DIR: "."
|
|
2256
|
+
},
|
|
2257
|
+
prefix: false,
|
|
2258
|
+
onStderr: (text) => ctx.message(text)
|
|
2259
|
+
});
|
|
2260
|
+
if (!started) return void 0;
|
|
2261
|
+
const chunks = [];
|
|
2262
|
+
const reading = (async () => {
|
|
2263
|
+
for await (const chunk of started.stdout) chunks.push(chunk);
|
|
2264
|
+
})().catch(() => {});
|
|
2265
|
+
await started.write(report).catch(() => {});
|
|
2266
|
+
await started.closeStdin().catch(() => {});
|
|
2267
|
+
await reading;
|
|
2268
|
+
if (await started.wait() !== 0) return false;
|
|
2269
|
+
const out = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));
|
|
2270
|
+
let at = 0;
|
|
2271
|
+
for (const c of chunks) {
|
|
2272
|
+
out.set(c, at);
|
|
2273
|
+
at += c.length;
|
|
2274
|
+
}
|
|
2275
|
+
return out;
|
|
2276
|
+
} },
|
|
2277
|
+
procReceive: async (ctx) => hooks.start("proc-receive", {
|
|
2278
|
+
env: {
|
|
2279
|
+
...hookClientEnv(hooks, ctx),
|
|
2280
|
+
GIT_DIR: ".",
|
|
2281
|
+
...await certEnv("proc-receive", ctx)
|
|
2282
|
+
},
|
|
2283
|
+
prefix: false,
|
|
2284
|
+
onStderr: (text) => ctx.message(text)
|
|
2285
|
+
})
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
//#endregion
|
|
2289
|
+
//#region src/commands/remote-transport.ts
|
|
2290
|
+
/**
|
|
2291
|
+
* How a remote command reaches a remote, as git's `transport_get` and `git_connect` decide:
|
|
2292
|
+
* the URL (already rewritten by `url.<base>.insteadOf`, see `RemoteConfigStore`) is checked
|
|
2293
|
+
* against `protocol.allow`; a path or `file://` URL is git's local transport (served in
|
|
2294
|
+
* process, see `local-transport.ts`); anything else goes to the connector the transport
|
|
2295
|
+
* registry names for it (smart HTTP by default).
|
|
2296
|
+
*/
|
|
2297
|
+
var remote_transport_exports = /* @__PURE__ */ __exportAll({
|
|
2298
|
+
bundleRemoteOf: () => bundleRemoteOf,
|
|
2299
|
+
checkTransportAllowed: () => checkTransportAllowed,
|
|
2300
|
+
httpSessionSettings: () => httpSessionSettings,
|
|
2301
|
+
isTransportAllowed: () => isTransportAllowed,
|
|
2302
|
+
openBundleRemote: () => openBundleRemote,
|
|
2303
|
+
openResolvedRemote: () => openResolvedRemote,
|
|
2304
|
+
prepareRemote: () => prepareRemote,
|
|
2305
|
+
protocolVersionOf: () => protocolVersionOf,
|
|
2306
|
+
remoteContextOf: () => remoteContextOf,
|
|
2307
|
+
resolveRemote: () => resolveRemote,
|
|
2308
|
+
withRemoteReceivePack: () => withRemoteReceivePack,
|
|
2309
|
+
withRemoteSession: () => withRemoteSession,
|
|
2310
|
+
withRemoteUploadPack: () => withRemoteUploadPack
|
|
2311
|
+
});
|
|
2312
|
+
const NO_PATH = "fatal: no path specified; see 'git help pull' for valid url syntax";
|
|
2313
|
+
/** transport.c's `parse_protocol_config`. */
|
|
2314
|
+
function parsePolicy(key, value) {
|
|
2315
|
+
const lower = value.toLowerCase();
|
|
2316
|
+
if (lower === "always" || lower === "never" || lower === "user") return lower;
|
|
2317
|
+
throw new InvalidConfigError(key, `fatal: unknown value for config '${key}': ${value}`);
|
|
2318
|
+
}
|
|
2319
|
+
/**
|
|
2320
|
+
* transport.c's `is_transport_allowed`: `GIT_ALLOW_PROTOCOL` when set (the only transports
|
|
2321
|
+
* allowed); else `protocol.<type>.allow`, then `protocol.allow`, then git's defaults (http,
|
|
2322
|
+
* https, git and ssh always; ext never; any other, `file` included, only when
|
|
2323
|
+
* `GIT_PROTOCOL_FROM_USER` is not false).
|
|
2324
|
+
*
|
|
2325
|
+
* @example
|
|
2326
|
+
* ```ts
|
|
2327
|
+
* isTransportAllowed("ext", store); // false
|
|
2328
|
+
* isTransportAllowed("file", store, { protocolFromUser: false } as GitHostEnvironment); // false
|
|
2329
|
+
* ```
|
|
2330
|
+
*/
|
|
2331
|
+
function isTransportAllowed(type, config, environment) {
|
|
2332
|
+
if (environment?.allowProtocol !== void 0) return environment.allowProtocol.split(":").includes(type);
|
|
2333
|
+
const key = `protocol.${type}.allow`;
|
|
2334
|
+
const own = config.value(key);
|
|
2335
|
+
const fallback = config.value("protocol.allow");
|
|
2336
|
+
let policy;
|
|
2337
|
+
if (own !== void 0) policy = parsePolicy(key, own);
|
|
2338
|
+
else if (fallback !== void 0) policy = parsePolicy("protocol.allow", fallback);
|
|
2339
|
+
else if ([
|
|
2340
|
+
"http",
|
|
2341
|
+
"https",
|
|
2342
|
+
"git",
|
|
2343
|
+
"ssh"
|
|
2344
|
+
].includes(type)) policy = "always";
|
|
2345
|
+
else if (type === "ext") policy = "never";
|
|
2346
|
+
else policy = "user";
|
|
2347
|
+
if (policy === "user") return environment?.protocolFromUser ?? true;
|
|
2348
|
+
return policy === "always";
|
|
2349
|
+
}
|
|
2350
|
+
/** transport.c's `transport_check_allowed`: git's "transport '<type>' not allowed". */
|
|
2351
|
+
function checkTransportAllowed(type, config, environment) {
|
|
2352
|
+
if (!isTransportAllowed(type, config, environment)) throw new TransportError$1(`fatal: transport '${type}' not allowed`);
|
|
2353
|
+
}
|
|
2354
|
+
/**
|
|
2355
|
+
* `protocol.version` (git's `get_protocol_version_config`): 0, 1 or 2, default 2; any other
|
|
2356
|
+
* value is git's "unknown value for config 'protocol.version'".
|
|
2357
|
+
*/
|
|
2358
|
+
function protocolVersionOf(config) {
|
|
2359
|
+
const value = config.value("protocol.version");
|
|
2360
|
+
if (value === void 0) return 2;
|
|
2361
|
+
if (value === "0" || value === "1" || value === "2") return Number(value);
|
|
2362
|
+
throw new InvalidConfigError("protocol.version", `fatal: unknown value for config 'protocol.version': ${value}`);
|
|
2363
|
+
}
|
|
2364
|
+
/**
|
|
2365
|
+
* Resolves a remote URL (already rewritten by `insteadOf`) to its transport, in git's order
|
|
2366
|
+
* (transport_get, then git_connect): a `<helper>::<address>` URL goes to the connector for
|
|
2367
|
+
* the helper; `rsync:` is refused; a path or `file://` URL is the local transport (its path
|
|
2368
|
+
* checked first, then `protocol.file.allow`); `ssh`/`git` URLs (path, then
|
|
2369
|
+
* `protocol.<scheme>.allow`) and any other `<scheme>://` (`protocol.<scheme>.allow`) go to
|
|
2370
|
+
* the registry's connector. Without one, git's words: "unable to find remote helper" where
|
|
2371
|
+
* git would run a remote helper, ours for ssh and git:// (git would connect directly).
|
|
2372
|
+
*
|
|
2373
|
+
* @throws TransportError git's lines (exit 128)
|
|
2374
|
+
*/
|
|
2375
|
+
function resolveRemote(url, context) {
|
|
2376
|
+
const { config, environment, transports } = context;
|
|
2377
|
+
const parsed = parseGitUrl(url);
|
|
2378
|
+
const viaConnector = (type) => {
|
|
2379
|
+
checkTransportAllowed(type, config, environment);
|
|
2380
|
+
const connector = transports.resolve(parsed);
|
|
2381
|
+
return connector ? {
|
|
2382
|
+
kind: "connector",
|
|
2383
|
+
url,
|
|
2384
|
+
parsed,
|
|
2385
|
+
connector
|
|
2386
|
+
} : void 0;
|
|
2387
|
+
};
|
|
2388
|
+
const helperMissing = (helper) => new TransportError$1(`fatal: unable to find remote helper for '${helper}'`);
|
|
2389
|
+
if (parsed.address !== void 0) return viaConnector(parsed.scheme) ?? throwError(helperMissing(parsed.scheme));
|
|
2390
|
+
if (url.startsWith("rsync:")) throw new TransportError$1("fatal: git-over-rsync is no longer supported");
|
|
2391
|
+
if (!(!isGitUrl(url) || /^(?:file|git|ssh|git\+ssh|ssh\+git):\/\//.test(url) || url === "")) {
|
|
2392
|
+
const scheme = url.slice(0, url.indexOf(":"));
|
|
2393
|
+
return viaConnector(scheme) ?? throwError(helperMissing(scheme));
|
|
2394
|
+
}
|
|
2395
|
+
if (!parsed.path && !parsed.scpLike) throw new TransportError$1(NO_PATH);
|
|
2396
|
+
if (parsed.scheme === "ssh" || parsed.local) checkNotAnOption("pathname", parsed.path);
|
|
2397
|
+
if (parsed.scheme === "file") {
|
|
2398
|
+
checkTransportAllowed("file", config, environment);
|
|
2399
|
+
return {
|
|
2400
|
+
kind: "local",
|
|
2401
|
+
url,
|
|
2402
|
+
path: parsed.path
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
if (parsed.scheme === "ssh") {
|
|
2406
|
+
checkTransportAllowed("ssh", config, environment);
|
|
2407
|
+
checkNotAnOption("hostname", `${parsed.user !== void 0 ? `${parsed.user}@` : ""}${parsed.host ?? ""}`);
|
|
2408
|
+
}
|
|
2409
|
+
return viaConnector(parsed.scheme) ?? throwError(new TransportError$1(`fatal: cannot connect to '${url}': only http(s) and local repositories are reachable here`));
|
|
2410
|
+
}
|
|
2411
|
+
/**
|
|
2412
|
+
* connect.c's `looks_like_command_line_option` checks: git's "strange hostname '<host>'
|
|
2413
|
+
* blocked" (and pathname), so a remote URL cannot smuggle an option into the command git
|
|
2414
|
+
* runs (`ssh -oProxyCommand=...`).
|
|
2415
|
+
*
|
|
2416
|
+
* @throws TransportError git's line (exit 128)
|
|
2417
|
+
*/
|
|
2418
|
+
function checkNotAnOption(what, value) {
|
|
2419
|
+
if (value.startsWith("-")) throw new TransportError$1(`fatal: strange ${what} '${value}' blocked`);
|
|
2420
|
+
}
|
|
2421
|
+
function throwError(error) {
|
|
2422
|
+
throw error;
|
|
2423
|
+
}
|
|
2424
|
+
/**
|
|
2425
|
+
* {@link resolveRemote}, then a local remote's repository opened (git's "does not appear to
|
|
2426
|
+
* be a git repository" when it cannot be).
|
|
2427
|
+
*/
|
|
2428
|
+
async function prepareRemote(workingCopy, url, transports) {
|
|
2429
|
+
return openResolvedRemote(workingCopy, resolveRemote(url, remoteContextOf(workingCopy, transports)));
|
|
2430
|
+
}
|
|
2431
|
+
/** A resolved remote with its local repository opened ({@link prepareRemote}'s second half). */
|
|
2432
|
+
async function openResolvedRemote(workingCopy, resolved) {
|
|
2433
|
+
if (resolved.kind !== "local") return resolved;
|
|
2434
|
+
const bundle = await openBundleRemote(workingCopy, resolved.url, resolved.path);
|
|
2435
|
+
if (bundle) return {
|
|
2436
|
+
kind: "bundle",
|
|
2437
|
+
url: resolved.url,
|
|
2438
|
+
path: resolved.path,
|
|
2439
|
+
remote: bundle
|
|
2440
|
+
};
|
|
2441
|
+
return {
|
|
2442
|
+
...resolved,
|
|
2443
|
+
repository: await openLocalRemote(workingCopy, resolved.path)
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2446
|
+
/**
|
|
2447
|
+
* transport_get's `url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)`: a path
|
|
2448
|
+
* (not a `file://` URL) to a regular file whose header reads as a bundle's, with what checks
|
|
2449
|
+
* it against `workingCopy` (the repository fetching); undefined for anything else.
|
|
2450
|
+
*/
|
|
2451
|
+
async function openBundleRemote(workingCopy, url, path) {
|
|
2452
|
+
if (/^file:/i.test(url)) return void 0;
|
|
2453
|
+
const bytes = await repositoryPlaceOf(workingCopy)?.readLocalFile?.(path).catch(() => void 0);
|
|
2454
|
+
if (!bytes) return void 0;
|
|
2455
|
+
return bundleRemoteOf(workingCopy, bytes, path);
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* A bundle's bytes as a remote of `workingCopy` (the repository fetching): undefined when
|
|
2459
|
+
* they do not read as a bundle. `name` is how git reports it (its path as given).
|
|
2460
|
+
*/
|
|
2461
|
+
function bundleRemoteOf(workingCopy, bytes, name) {
|
|
2462
|
+
const opened = openBundle(bytes, name);
|
|
2463
|
+
if (!opened.ok) return void 0;
|
|
2464
|
+
const history = workingCopy.history;
|
|
2465
|
+
return {
|
|
2466
|
+
bundle: opened.bundle,
|
|
2467
|
+
verify: () => verifyBundleIn({
|
|
2468
|
+
history,
|
|
2469
|
+
refValues: () => refValuesOf(history.refs),
|
|
2470
|
+
shallow: async () => await history.refs.getShallow?.().catch(() => void 0) ?? []
|
|
2471
|
+
}, opened.bundle.header)
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
/** Every ref's value and HEAD's (what `rev-list --all` starts from). */
|
|
2475
|
+
async function refValuesOf(refs) {
|
|
2476
|
+
const out = /* @__PURE__ */ new Set();
|
|
2477
|
+
for await (const ref of refs.list()) {
|
|
2478
|
+
const id = "objectId" in ref && ref.objectId ? ref.objectId : (await refs.resolve(ref.name).catch(() => void 0))?.objectId;
|
|
2479
|
+
if (id) out.add(id);
|
|
2480
|
+
}
|
|
2481
|
+
const head = (await refs.resolve("HEAD").catch(() => void 0))?.objectId;
|
|
2482
|
+
if (head) out.add(head);
|
|
2483
|
+
return [...out];
|
|
2484
|
+
}
|
|
2485
|
+
/** The resolution context of a working copy: its configuration and host environment. */
|
|
2486
|
+
function remoteContextOf(workingCopy, transports) {
|
|
2487
|
+
const environment = hostEnvironmentOf(workingCopy);
|
|
2488
|
+
return {
|
|
2489
|
+
config: RemoteConfigStore.from(workingCopy),
|
|
2490
|
+
...environment ? { environment } : {},
|
|
2491
|
+
transports
|
|
2492
|
+
};
|
|
2493
|
+
}
|
|
2494
|
+
/**
|
|
2495
|
+
* The dumb-HTTP settings a session takes from the configuration and the environment
|
|
2496
|
+
* (`http.followRedirects` and the other `http.*` keys come with `httpSettings`): which
|
|
2497
|
+
* alternates a dumb fetch may use (http-walker's `is_transport_allowed(<scheme>, 0)`: as a
|
|
2498
|
+
* transport not from the user) and `$GIT_SMART_HTTP`.
|
|
2499
|
+
*/
|
|
2500
|
+
function httpSessionSettings(workingCopy) {
|
|
2501
|
+
const config = RemoteConfigStore.from(workingCopy);
|
|
2502
|
+
const environment = hostEnvironmentOf(workingCopy);
|
|
2503
|
+
const notFromUser = {
|
|
2504
|
+
...environment,
|
|
2505
|
+
protocolFromUser: false
|
|
2506
|
+
};
|
|
2507
|
+
return {
|
|
2508
|
+
alternateAllowed: (scheme) => isTransportAllowed(scheme, config, notFromUser),
|
|
2509
|
+
...environment?.smartHttp === false ? { smartHttp: false } : {}
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
function connectRequest(remote, service, options) {
|
|
2513
|
+
return {
|
|
2514
|
+
url: remote.parsed,
|
|
2515
|
+
service,
|
|
2516
|
+
protocolVersion: protocolVersionFor(service, options.protocolVersion),
|
|
2517
|
+
...options.program !== void 0 ? { program: options.program } : {},
|
|
2518
|
+
...options.credentials ? { credentials: options.credentials } : {},
|
|
2519
|
+
...options.headers ? { headers: options.headers } : {},
|
|
2520
|
+
...options.timeout !== void 0 ? { timeout: options.timeout } : {},
|
|
2521
|
+
...options.signal ? { signal: options.signal } : {},
|
|
2522
|
+
...options.httpSettings ? { http: options.httpSettings(remote.url) } : {},
|
|
2523
|
+
...options.credentialHelper ? { credentialHelper: options.credentialHelper } : {}
|
|
2524
|
+
};
|
|
2525
|
+
}
|
|
2526
|
+
/**
|
|
2527
|
+
* A native session whose stream closes once: the connection opened over it closes the stream
|
|
2528
|
+
* (`closeDuplex`), and {@link withRemoteSession} closes it again for a `run` that opened none
|
|
2529
|
+
* or failed before; the second close does nothing.
|
|
2530
|
+
*/
|
|
2531
|
+
function closingOnce(session) {
|
|
2532
|
+
if (session.kind !== "native") return session;
|
|
2533
|
+
const inner = session.duplex;
|
|
2534
|
+
let closing;
|
|
2535
|
+
const duplex = {
|
|
2536
|
+
[Symbol.asyncIterator]: () => inner[Symbol.asyncIterator](),
|
|
2537
|
+
write: (data) => inner.write(data),
|
|
2538
|
+
...inner.end ? { end: () => inner.end?.() ?? Promise.resolve() } : {},
|
|
2539
|
+
close: () => {
|
|
2540
|
+
closing ??= inner.close?.() ?? Promise.resolve();
|
|
2541
|
+
return closing;
|
|
2542
|
+
}
|
|
2543
|
+
};
|
|
2544
|
+
return {
|
|
2545
|
+
...session,
|
|
2546
|
+
duplex
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
/**
|
|
2550
|
+
* Runs `run` over a session the remote's connector opens for `service` (the request's
|
|
2551
|
+
* protocol version as git_connect asks for it: v0 for receive-pack when v2 is configured); a
|
|
2552
|
+
* native session's stream is closed afterwards, once, whether or not `run` closed it.
|
|
2553
|
+
*/
|
|
2554
|
+
async function withRemoteSession(remote, service, options, run) {
|
|
2555
|
+
const request = connectRequest(remote, service, options);
|
|
2556
|
+
const session = closingOnce(await remote.connector.connect(request));
|
|
2557
|
+
try {
|
|
2558
|
+
return await run(session, request);
|
|
2559
|
+
} finally {
|
|
2560
|
+
if (session.kind === "native") await session.duplex.close?.().catch(() => void 0);
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
/**
|
|
2564
|
+
* Runs `run` over a connection to upload-pack of a remote: in process for a local one
|
|
2565
|
+
* (`withLocalUploadPack`, protocol v2 unless `protocol.version` says otherwise), else over
|
|
2566
|
+
* the session its connector opens (`openUploadPack`).
|
|
2567
|
+
*/
|
|
2568
|
+
async function withRemoteUploadPack(remote, options, run) {
|
|
2569
|
+
if (remote.kind === "local") return withLocalUploadPack(remote.repository, run, { protocolVersion: options.protocolVersion });
|
|
2570
|
+
if (remote.kind === "bundle") return withBundleUploadPack(remote.remote, createDuplexPair, run);
|
|
2571
|
+
return withRemoteSession(remote, "git-upload-pack", options, async (session, request) => {
|
|
2572
|
+
const connection = await openUploadPack(session, request, {
|
|
2573
|
+
...options.gzipRequests !== void 0 ? { gzipRequests: options.gzipRequests } : {},
|
|
2574
|
+
...options.alternateAllowed ? { alternateAllowed: options.alternateAllowed } : {},
|
|
2575
|
+
...options.smartHttp === false ? { smartHttp: false } : {}
|
|
2576
|
+
});
|
|
2577
|
+
try {
|
|
2578
|
+
return await run(connection);
|
|
2579
|
+
} finally {
|
|
2580
|
+
await connection.close();
|
|
2581
|
+
}
|
|
2582
|
+
});
|
|
2583
|
+
}
|
|
2584
|
+
/**
|
|
2585
|
+
* Runs `run` over a connection to receive-pack of a remote: in process for a local one
|
|
2586
|
+
* (`withLocalReceivePack`, with the remote repository's hooks), else over the session its
|
|
2587
|
+
* connector opens (`openReceivePack`).
|
|
2588
|
+
*/
|
|
2589
|
+
async function withRemoteReceivePack(remote, options, run, hooks, transactionHooks, local = {}) {
|
|
2590
|
+
if (remote.kind === "bundle") throw new TransportError$1(`error: failed to push some refs to '${remote.url}'`, void 0, { exitCode: 1 });
|
|
2591
|
+
if (remote.kind === "local") return withLocalReceivePack(remote.repository, run, hooks, transactionHooks, {
|
|
2592
|
+
protocolVersion: options.protocolVersion,
|
|
2593
|
+
...local
|
|
2594
|
+
});
|
|
2595
|
+
return withRemoteSession(remote, "git-receive-pack", options, async (session, request) => {
|
|
2596
|
+
const connection = await openReceivePack(session, request, { ...options.streamRequestBody !== void 0 ? { streamRequestBody: options.streamRequestBody } : {} });
|
|
2597
|
+
try {
|
|
2598
|
+
return await run(connection);
|
|
2599
|
+
} finally {
|
|
2600
|
+
await connection.close();
|
|
2601
|
+
}
|
|
2602
|
+
});
|
|
2603
|
+
}
|
|
2604
|
+
//#endregion
|
|
2605
|
+
export { V3_BUNDLE_SIGNATURE as A, WorktreePruneCommand as C, openBundle as D, bundleBytes as E, listBundleRefs as M, parseBundleHeader as N, verifyBundleIn as O, GarbageCollectCommand as S, withBundleUploadPack as T, remoteHookSession as _, protocolVersionOf as a, withReceiveTransactionHook as b, resolveRemote as c, withRemoteUploadPack as d, createDuplexPair as f, receivePackSettingsOf as g, receiveFsckSettingsOf as h, prepareRemote as i, encodeBundleHeader as j, V2_BUNDLE_SIGNATURE as k, withRemoteReceivePack as l, quarantineEnv as m, httpSessionSettings as n, remoteContextOf as o, httpBackendEnv as p, openResolvedRemote as r, remote_transport_exports as s, bundleRemoteOf as t, withRemoteSession as u, servedMaxTreeDepth as v, BundlePrerequisitesError as w, ReadTreeCommand as x, servedUseBitmaps as y };
|