@statewalker/vcs-commands 0.9.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.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 +41 -2
- package/dist/commands/am/am-command.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 +43 -1
- package/dist/commands/blame-command.d.ts.map +1 -1
- 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-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.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/cherry-pick-command.d.ts +10 -0
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +19 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +9 -1
- 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/diff-command.d.ts +132 -5
- 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 +65 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fetch-multiple-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-hooks.d.ts +32 -0
- 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 +44 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +6 -5
- 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/local-transport.d.ts.map +1 -1
- package/dist/commands/log-command.d.ts +26 -0
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +22 -1
- 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/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 +7 -0
- 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 +67 -5
- package/dist/commands/merge-drivers.d.ts.map +1 -1
- package/dist/commands/merge-support.d.ts +6 -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/mktag-command.d.ts +51 -0
- package/dist/commands/mktag-command.d.ts.map +1 -0
- 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/ort-merge.d.ts +24 -0
- package/dist/commands/ort-merge.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 +24 -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.map +1 -1
- package/dist/commands/push-command.d.ts +17 -2
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +108 -2
- 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/remote-object-info-command.d.ts +55 -0
- package/dist/commands/remote-object-info-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/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 +3 -0
- 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 +10 -0
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +5 -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 +18 -0
- package/dist/commands/sequencer-pick.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/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 +2 -1
- 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 +9 -1
- package/dist/commands/submodule-commands.d.ts.map +1 -1
- package/dist/commands/submodule-update-command.d.ts +13 -1
- package/dist/commands/submodule-update-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-CNvli5bl.js → commands-Mlo1dxQN.js} +52078 -44471
- package/dist/errors/command-errors.d.ts +33 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/index.js +39 -1
- package/dist/{fsck-CPeDh9fh.js → fsck-CrhVMNIH.js} +184 -143
- package/dist/git-command.d.ts +58 -2
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +532 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/guarded-transport-command.d.ts +3 -1
- package/dist/guarded-transport-command.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/maintenance-run-command-Bw21HEkH.js +13539 -0
- package/dist/{remote-transport-CCmBadm-.js → remote-transport-Bu4PGSMD.js} +1009 -10
- package/dist/results/cherry-pick-result.d.ts +6 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/diff-entry.d.ts +10 -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 +49 -3
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/fetch-result.d.ts +12 -0
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/merge-result.d.ts +5 -0
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +5 -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-BDuEgdLU.js → results-ERo9vELd.js} +28511 -25685
- package/dist/transport-command.d.ts +79 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/commands/add-command.ts +3 -0
- package/src/commands/add-patch/patch-backend.ts +4 -1
- 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 +163 -8
- package/src/commands/apply/index.ts +1 -0
- 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 +118 -19
- 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-ref-format-command.ts +129 -0
- package/src/commands/checkout-command.ts +39 -21
- package/src/commands/checkout-index-command.ts +568 -0
- package/src/commands/checkout-paths.ts +7 -0
- package/src/commands/cherry-pick-command.ts +21 -1
- package/src/commands/clone-command.ts +208 -7
- package/src/commands/commit-command.ts +22 -4
- 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/diff-command.ts +573 -46
- 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 +312 -8
- package/src/commands/fetch-multiple-command.ts +4 -1
- 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-hooks.ts +123 -6
- 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 +45 -0
- package/src/commands/init-command.ts +14 -0
- 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/local-transport.ts +252 -4
- package/src/commands/log-command.ts +104 -5
- package/src/commands/log-output.ts +55 -5
- 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/maintenance-run-command.ts +949 -0
- package/src/commands/merge-command.ts +78 -32
- package/src/commands/merge-config.ts +23 -1
- package/src/commands/merge-drivers.ts +109 -20
- package/src/commands/merge-support.ts +29 -5
- package/src/commands/merge-tree-command.ts +786 -0
- package/src/commands/mktag-command.ts +149 -0
- 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/ort-merge.ts +92 -25
- package/src/commands/patch-id-command.ts +65 -0
- package/src/commands/patch-id.ts +218 -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 +2 -0
- package/src/commands/push-command.ts +87 -5
- package/src/commands/rebase-command.ts +507 -19
- package/src/commands/refs-command.ts +274 -0
- package/src/commands/remote-object-info-command.ts +109 -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/rev-filter/commit-grep.ts +7 -2
- package/src/commands/rev-list-command.ts +9 -0
- package/src/commands/rev-parse-command.ts +62 -4
- package/src/commands/revert-command.ts +21 -1
- package/src/commands/revision-range.ts +7 -2
- package/src/commands/revision-resolver.ts +44 -3
- package/src/commands/sequencer-pick.ts +47 -0
- package/src/commands/serve-repository.ts +65 -0
- package/src/commands/session-id.ts +31 -0
- package/src/commands/show-branch-command.ts +981 -0
- package/src/commands/show-command.ts +1 -1
- 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 +43 -6
- 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 +12 -2
- package/src/commands/submodule-update-command.ts +29 -0
- package/src/commands/textconv-cache.ts +143 -0
- package/src/commands/tree-restore.ts +14 -0
- 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/errors/command-errors.ts +45 -0
- package/src/git-command.ts +131 -1
- package/src/git.ts +808 -1
- package/src/guarded-transport-command.ts +6 -1
- package/src/results/cherry-pick-result.ts +6 -0
- package/src/results/diff-entry.ts +12 -0
- package/src/results/diff-formatter.ts +7 -4
- package/src/results/diff-output.ts +117 -11
- package/src/results/diff-pickaxe.ts +1 -1
- package/src/results/fetch-result.ts +12 -0
- package/src/results/merge-result.ts +5 -0
- package/src/results/push-result.ts +5 -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/transport-command.ts +182 -1
|
@@ -0,0 +1,1148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git archive` (archive.c, builtin/archive.c): a tar or zip archive of a tree, with git's
|
|
3
|
+
* `--prefix`, `--add-file`/`--add-virtual-file`, pathspecs, `--mtime`, compression levels,
|
|
4
|
+
* the `export-ignore` and `export-subst` attributes, and tar filters (`tar.<format>.command`,
|
|
5
|
+
* the builtin gzip of `tgz` and `tar.gz`).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // git archive --format=zip --prefix=project/ HEAD -- src
|
|
10
|
+
* const zip = await git.archive().setFormat("zip").setPrefix("project/").setTree("HEAD")
|
|
11
|
+
* .addPath("src").call();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { ObjectId, TreeEntry } from "@statewalker/vcs-core";
|
|
16
|
+
import { approxidateCareful, parseGitBool, parseGitInt } from "@statewalker/vcs-utils";
|
|
17
|
+
import { deflateSync } from "@statewalker/vcs-utils/compression";
|
|
18
|
+
import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
19
|
+
import {
|
|
20
|
+
type AttributesResolver,
|
|
21
|
+
type AttributeValue,
|
|
22
|
+
attributesIndexOfTree,
|
|
23
|
+
type ContentAttributesContext,
|
|
24
|
+
type ConversionSettings,
|
|
25
|
+
convAttrsOf,
|
|
26
|
+
crlfToWorktree,
|
|
27
|
+
FilterDriverError,
|
|
28
|
+
type FilterDriverRegistry,
|
|
29
|
+
identToWorktree,
|
|
30
|
+
readConversionSettings,
|
|
31
|
+
reencode,
|
|
32
|
+
smudgeContent,
|
|
33
|
+
type Worktree,
|
|
34
|
+
} from "@statewalker/vcs-working-tree";
|
|
35
|
+
import { GitApiError, InvalidPathError } from "../../errors/index.js";
|
|
36
|
+
import { GitCommand } from "../../git-command.js";
|
|
37
|
+
import { RemoteConfigStore } from "../../remote-config/index.js";
|
|
38
|
+
import { cUnquote, latin1ToBytes, latin1ToPath, pathToLatin1 } from "../apply/index.js";
|
|
39
|
+
import { bareAttributesResolver } from "../attributes-source.js";
|
|
40
|
+
import { createIdAbbreviator } from "../core-config.js";
|
|
41
|
+
import { createDescriber } from "../git-describe.js";
|
|
42
|
+
import { configValue } from "../merge-config.js";
|
|
43
|
+
import {
|
|
44
|
+
DO_MATCH_DIRECTORY,
|
|
45
|
+
DO_MATCH_LEADING_PATHSPEC,
|
|
46
|
+
matchPathspec,
|
|
47
|
+
type PathspecItem,
|
|
48
|
+
parsePathspec,
|
|
49
|
+
} from "../pathspec.js";
|
|
50
|
+
import { formatCommitPretty } from "../pretty-format.js";
|
|
51
|
+
import { treePathRefusal, withTreePathRefusal, worktreePathRules } from "../worktree-path-rules.js";
|
|
52
|
+
import {
|
|
53
|
+
type ArchiveEntry,
|
|
54
|
+
type ArchiveWriter,
|
|
55
|
+
isDirMode,
|
|
56
|
+
isGitlinkMode,
|
|
57
|
+
isLinkMode,
|
|
58
|
+
isRegMode,
|
|
59
|
+
} from "./archive-entry.js";
|
|
60
|
+
import { TarArchiveWriter } from "./tar-archive.js";
|
|
61
|
+
import { ZipArchiveWriter } from "./zip-archive.js";
|
|
62
|
+
|
|
63
|
+
/** git's builtin gzip filter (`tar.tgz.command`, `tar.tar.gz.command`). */
|
|
64
|
+
export const INTERNAL_GZIP_COMMAND = "git archive gzip";
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Runs a tar filter (`tar.<format>.command`, with ` -<level>` added for a compression
|
|
68
|
+
* level, as git runs it through the shell): the tar archive in, the filtered bytes out.
|
|
69
|
+
* Throwing is git's `'<command>' filter reported error`.
|
|
70
|
+
*/
|
|
71
|
+
export type ArchiveFilterRunner = (command: string, input: Uint8Array) => Promise<Uint8Array>;
|
|
72
|
+
|
|
73
|
+
/** An archive format git knows (`git archive --list`). */
|
|
74
|
+
interface Archiver {
|
|
75
|
+
name: string;
|
|
76
|
+
/** A tar filter's command; undefined for tar and zip */
|
|
77
|
+
command?: string;
|
|
78
|
+
/** git's `ARCHIVER_REMOTE`: served to `git archive --remote` (`tar.<format>.remote`) */
|
|
79
|
+
remote?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A file added with `--add-file` or `--add-virtual-file`. */
|
|
83
|
+
interface ExtraFile {
|
|
84
|
+
/** `--add-virtual-file`'s path, or `--add-file`'s file as given */
|
|
85
|
+
path: string;
|
|
86
|
+
/** `--add-virtual-file`'s content; read from the worktree for `--add-file` */
|
|
87
|
+
content?: Uint8Array;
|
|
88
|
+
/** The last `--prefix` before it */
|
|
89
|
+
base: string;
|
|
90
|
+
executable?: boolean;
|
|
91
|
+
/** `--add-virtual-file`: archived at its path, the prefix not applied */
|
|
92
|
+
virtual: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const USAGE =
|
|
96
|
+
"usage: git archive [<options>] <tree-ish> [<path>...]\n" +
|
|
97
|
+
" or: git archive --list\n" +
|
|
98
|
+
" or: git archive --remote <repo> [--exec <cmd>] [<options>] <tree-ish> [<path>...]\n" +
|
|
99
|
+
" or: git archive --remote <repo> [--exec <cmd>] --list";
|
|
100
|
+
|
|
101
|
+
/** git's default `core.bigFileThreshold` (512 MiB). */
|
|
102
|
+
const DEFAULT_BIG_FILE_THRESHOLD = 512 * 1024 * 1024;
|
|
103
|
+
|
|
104
|
+
const EXPORT_ATTRS = ["export-ignore", "export-subst"] as const;
|
|
105
|
+
/** The attributes convert.c's `convert_attrs` reads. */
|
|
106
|
+
const CONVERT_ATTRS = ["crlf", "ident", "filter", "eol", "text", "working-tree-encoding"] as const;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* `git archive <tree-ish> [<path>...]`: the archive's bytes. Messages git prints on stderr
|
|
110
|
+
* (`-v`'s paths, warnings) are in {@link getMessages}; where git dies, a {@link GitApiError}
|
|
111
|
+
* carries its message and exit status.
|
|
112
|
+
*
|
|
113
|
+
* Deflated data (zip entries, `tgz`) comes from pako's zlib port, whose bytes differ from
|
|
114
|
+
* the system zlib git links: the archives match git's byte for byte except for those
|
|
115
|
+
* compressed streams (`-0` zips and tar archives match whole).
|
|
116
|
+
*/
|
|
117
|
+
export class ArchiveCommand extends GitCommand<Uint8Array> {
|
|
118
|
+
private tree?: string;
|
|
119
|
+
private format?: string;
|
|
120
|
+
private outputName?: string;
|
|
121
|
+
private base = "";
|
|
122
|
+
private readonly paths: string[] = [];
|
|
123
|
+
private readonly extraFiles: ExtraFile[] = [];
|
|
124
|
+
private mtime?: string;
|
|
125
|
+
private compressionLevel = -1;
|
|
126
|
+
private verbose = false;
|
|
127
|
+
private worktreeAttributes = false;
|
|
128
|
+
private currentDirectory = "";
|
|
129
|
+
private filterRunner?: ArchiveFilterRunner;
|
|
130
|
+
private userUmask = 0o022;
|
|
131
|
+
private localTzOffset?: (time: number) => number;
|
|
132
|
+
private filterDrivers?: FilterDriverRegistry;
|
|
133
|
+
private compatibility: "2.43" | "2.56" = "2.56";
|
|
134
|
+
private readonly messages: string[] = [];
|
|
135
|
+
/** Run by upload-archive (`write_archive`'s `remote`): `allowUnreachable` its setting */
|
|
136
|
+
private uploadArchive?: { allowUnreachable: boolean };
|
|
137
|
+
|
|
138
|
+
/** The tree-ish archived (a commit, a tag, a tree). */
|
|
139
|
+
setTree(name: string): this {
|
|
140
|
+
this.checkCallable();
|
|
141
|
+
this.tree = name;
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** `--format=<fmt>`: `tar`, `zip`, `tgz`, `tar.gz` or a configured tar filter. */
|
|
146
|
+
setFormat(format: string): this {
|
|
147
|
+
this.checkCallable();
|
|
148
|
+
this.format = format;
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* `-o <file>`'s name: the format is inferred from its extension when none is set
|
|
154
|
+
* (git's `archive_format_from_filename`). Nothing is written: the bytes are returned.
|
|
155
|
+
*/
|
|
156
|
+
setOutputName(name: string): this {
|
|
157
|
+
this.checkCallable();
|
|
158
|
+
this.outputName = name;
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** `--prefix=<prefix>`: the last one prefixes the tree's paths, each one the added files after it. */
|
|
163
|
+
setPrefix(prefix: string): this {
|
|
164
|
+
this.checkCallable();
|
|
165
|
+
this.base = prefix;
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* `--add-file=<file>`: a file of the worktree (relative to {@link setCurrentDirectory}),
|
|
171
|
+
* added under the current prefix and its base name; `content` gives its bytes instead.
|
|
172
|
+
*/
|
|
173
|
+
addFile(path: string, content?: Uint8Array, options: { executable?: boolean } = {}): this {
|
|
174
|
+
this.checkCallable();
|
|
175
|
+
this.extraFiles.push({
|
|
176
|
+
path,
|
|
177
|
+
base: this.base,
|
|
178
|
+
virtual: false,
|
|
179
|
+
...(content ? { content } : {}),
|
|
180
|
+
...(options.executable ? { executable: true } : {}),
|
|
181
|
+
});
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** `--add-virtual-file=<path>:<content>` (a C-quoted path allowed, as git reads it). */
|
|
186
|
+
addVirtualFile(spec: string): this {
|
|
187
|
+
this.checkCallable();
|
|
188
|
+
// parsed over the argument's bytes, as git does (`\\303\\251` is one character)
|
|
189
|
+
const raw = pathToLatin1(spec);
|
|
190
|
+
let path: string;
|
|
191
|
+
let rest: string;
|
|
192
|
+
if (raw.startsWith('"')) {
|
|
193
|
+
const unquoted = cUnquote(raw);
|
|
194
|
+
if (!unquoted) throw new GitApiError(`fatal: unclosed quote: '${spec}'`);
|
|
195
|
+
path = latin1ToPath(unquoted.name);
|
|
196
|
+
rest = raw.slice(unquoted.end);
|
|
197
|
+
if (!rest.startsWith(":")) throw new GitApiError(`fatal: missing colon: '${spec}'`);
|
|
198
|
+
} else {
|
|
199
|
+
const colon = raw.indexOf(":");
|
|
200
|
+
if (colon < 0) throw new GitApiError(`fatal: missing colon: '${spec}'`);
|
|
201
|
+
if (colon === 0) throw new GitApiError(`fatal: empty file name: '${spec}'`);
|
|
202
|
+
path = latin1ToPath(raw.slice(0, colon));
|
|
203
|
+
rest = raw.slice(colon);
|
|
204
|
+
}
|
|
205
|
+
// xstrdup: the content ends at a NUL
|
|
206
|
+
const content = rest.slice(1).split("\0")[0] as string;
|
|
207
|
+
this.extraFiles.push({
|
|
208
|
+
path,
|
|
209
|
+
base: this.base,
|
|
210
|
+
content: latin1ToBytes(content),
|
|
211
|
+
virtual: true,
|
|
212
|
+
});
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** A pathspec element (`git archive <tree-ish> <path>...`). */
|
|
217
|
+
addPath(path: string): this {
|
|
218
|
+
this.checkCallable();
|
|
219
|
+
this.paths.push(path);
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** `--mtime=<time>`: the entries' time (git's approxidate). */
|
|
224
|
+
setMtime(time: string): this {
|
|
225
|
+
this.checkCallable();
|
|
226
|
+
this.mtime = time;
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** `-<n>`: the compression level (zip: 0 to 9, tar filters: any). */
|
|
231
|
+
setCompressionLevel(level: number): this {
|
|
232
|
+
this.checkCallable();
|
|
233
|
+
// git's `-<digits>`: a non-negative number
|
|
234
|
+
if (!Number.isInteger(level) || level < 0) {
|
|
235
|
+
throw new RangeError(`bad compression level ${level}`);
|
|
236
|
+
}
|
|
237
|
+
this.compressionLevel = level;
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** `-v`: each path archived is reported in {@link getMessages}. */
|
|
242
|
+
setVerbose(verbose: boolean): this {
|
|
243
|
+
this.checkCallable();
|
|
244
|
+
this.verbose = verbose;
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** `--worktree-attributes`: attributes read from the worktree (and the index), not the tree. */
|
|
249
|
+
setWorktreeAttributes(on: boolean): this {
|
|
250
|
+
this.checkCallable();
|
|
251
|
+
this.worktreeAttributes = on;
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* The directory git runs in, relative to the worktree's top (`git -C <dir> archive`):
|
|
257
|
+
* only what lies below it is archived, its paths relative to it.
|
|
258
|
+
*/
|
|
259
|
+
setCurrentDirectory(dir: string): this {
|
|
260
|
+
this.checkCallable();
|
|
261
|
+
const trimmed = dir.replace(/^\/+|\/+$/g, "");
|
|
262
|
+
this.currentDirectory = trimmed && trimmed !== "." ? `${trimmed}/` : "";
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Runs the tar filters' commands (git's shell); without it only the builtin gzip works. */
|
|
267
|
+
setFilterRunner(runner: ArchiveFilterRunner): this {
|
|
268
|
+
this.checkCallable();
|
|
269
|
+
this.filterRunner = runner;
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** The umask `tar.umask=user` stands for (default 022). */
|
|
274
|
+
setUserUmask(umask: number): this {
|
|
275
|
+
this.checkCallable();
|
|
276
|
+
this.userUmask = umask;
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** The local time zone (zip's DOS times): its offset east of UTC in minutes at a time. */
|
|
281
|
+
setLocalTimezone(offset: (time: number) => number): this {
|
|
282
|
+
this.checkCallable();
|
|
283
|
+
this.localTzOffset = offset;
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* The git version whose behaviour to follow (default 2.56): 2.43 ends a tree holding a
|
|
289
|
+
* path `verify_path` refuses with the `error:` line alone and exit 255, 2.5x adds
|
|
290
|
+
* `fatal: failed to unpack tree object <tree>` (exit 128).
|
|
291
|
+
*/
|
|
292
|
+
setCompatibility(version: "2.43" | "2.56"): this {
|
|
293
|
+
this.checkCallable();
|
|
294
|
+
this.compatibility = version;
|
|
295
|
+
return this;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** What git printed on stderr (`-v`'s paths, warnings). */
|
|
299
|
+
getMessages(): string[] {
|
|
300
|
+
return [...this.messages];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** `git archive --list`: the formats, as git lists them. */
|
|
304
|
+
listFormats(): string[] {
|
|
305
|
+
return this.archivers().map((a) => a.name);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Runs the command as git's upload-archive runs it for `git archive --remote` (its
|
|
310
|
+
* `upload-archive--writer`): only formats served remotely (tar, zip, the tar filters with
|
|
311
|
+
* `tar.<format>.remote`, by default `tgz` and `tar.gz`), and, unless `allowUnreachable`
|
|
312
|
+
* (`uploadarchive.allowUnreachable`), only a tree-ish a ref names (`no such ref: <name>`).
|
|
313
|
+
* See {@link runArchiveWriter}.
|
|
314
|
+
*/
|
|
315
|
+
setUploadArchive(options: { allowUnreachable: boolean }): this {
|
|
316
|
+
this.checkCallable();
|
|
317
|
+
this.uploadArchive = { allowUnreachable: options.allowUnreachable };
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* The format `name`'s extension names (archive.c's `archive_format_from_filename`: the
|
|
323
|
+
* archivers of this repository's configuration), or undefined.
|
|
324
|
+
*/
|
|
325
|
+
formatFromFilename(name: string): string | undefined {
|
|
326
|
+
return this.archivers().find((a) => matchExtension(name, a.name))?.name;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* The archivers in git's registration order: tar, the tar filters, zip; upload-archive's
|
|
331
|
+
* only those served remotely.
|
|
332
|
+
*/
|
|
333
|
+
private archivers(): Archiver[] {
|
|
334
|
+
const filters = new Map<string, Archiver>();
|
|
335
|
+
const define = (name: string, command: string | undefined, remote?: boolean) => {
|
|
336
|
+
const known = filters.get(name) ?? { name };
|
|
337
|
+
if (command !== undefined) known.command = command;
|
|
338
|
+
if (remote !== undefined) known.remote = remote;
|
|
339
|
+
filters.set(name, known);
|
|
340
|
+
};
|
|
341
|
+
define("tgz", INTERNAL_GZIP_COMMAND, true);
|
|
342
|
+
define("tar.gz", INTERNAL_GZIP_COMMAND, true);
|
|
343
|
+
for (const { key, value } of this.tarConfig()) {
|
|
344
|
+
const last = key.lastIndexOf(".");
|
|
345
|
+
const name = key.slice(4, last);
|
|
346
|
+
if (last <= 4 || !name) continue;
|
|
347
|
+
const type = key.slice(last + 1);
|
|
348
|
+
if (type === "command") {
|
|
349
|
+
if (value !== undefined) define(name, value);
|
|
350
|
+
} else if (type === "remote") {
|
|
351
|
+
// git_config_bool: a key without a value is true, a bad one dies
|
|
352
|
+
const remote = value === undefined ? true : parseGitBool(value);
|
|
353
|
+
if (remote === undefined) {
|
|
354
|
+
throw new GitApiError(`fatal: bad boolean config value '${value}' for '${key}'`);
|
|
355
|
+
}
|
|
356
|
+
define(name, undefined, remote);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const all: Archiver[] = [
|
|
360
|
+
{ name: "tar", remote: true },
|
|
361
|
+
...[...filters.values()].filter((a) => a.command !== undefined),
|
|
362
|
+
{ name: "zip", remote: true },
|
|
363
|
+
];
|
|
364
|
+
return this.uploadArchive ? all.filter((a) => a.remote) : all;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** The `tar.*` variables in configuration order. */
|
|
368
|
+
private tarConfig(): { key: string; value: string | undefined }[] {
|
|
369
|
+
return RemoteConfigStore.from(this._workingCopy).entriesWithPrefix("tar.") ?? [];
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** `tar.umask`. */
|
|
373
|
+
private tarUmask(): number {
|
|
374
|
+
let umask = 0o002;
|
|
375
|
+
for (const { key, value } of this.tarConfig()) {
|
|
376
|
+
if (key !== "tar.umask") continue;
|
|
377
|
+
if (value === "user") umask = this.userUmask;
|
|
378
|
+
else {
|
|
379
|
+
const n = parseGitInt(value);
|
|
380
|
+
if (n === undefined)
|
|
381
|
+
throw new GitApiError(
|
|
382
|
+
`fatal: bad numeric config value '${value}' for 'tar.umask': invalid unit`,
|
|
383
|
+
);
|
|
384
|
+
umask = n;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return umask;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** The archive's bytes. */
|
|
391
|
+
async call(): Promise<Uint8Array> {
|
|
392
|
+
this.checkCallable();
|
|
393
|
+
this.setCallable(false);
|
|
394
|
+
const extras = await this.readExtraFiles();
|
|
395
|
+
let format = this.format;
|
|
396
|
+
if (format === undefined && this.outputName !== undefined) {
|
|
397
|
+
format = this.formatFromFilename(this.outputName);
|
|
398
|
+
}
|
|
399
|
+
format ??= "tar";
|
|
400
|
+
if (this.tree === undefined) throw new GitApiError(USAGE, { exitCode: 129 });
|
|
401
|
+
const archiver = this.archivers().find((a) => a.name === format);
|
|
402
|
+
if (!archiver) throw new GitApiError(`fatal: Unknown archive format '${format}'`);
|
|
403
|
+
let level = -1;
|
|
404
|
+
if (this.compressionLevel !== -1) {
|
|
405
|
+
const levelsOk = archiver.name !== "tar";
|
|
406
|
+
const highOk = archiver.command !== undefined;
|
|
407
|
+
if (levelsOk && (this.compressionLevel <= 9 || highOk)) level = this.compressionLevel;
|
|
408
|
+
else {
|
|
409
|
+
throw new GitApiError(
|
|
410
|
+
`fatal: Argument not supported for format '${format}': -${this.compressionLevel}`,
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return this.inOneOperation(async () => {
|
|
415
|
+
const target = await this.resolveTreeish(this.tree as string);
|
|
416
|
+
const settings = {
|
|
417
|
+
time: target.time,
|
|
418
|
+
compressionLevel: level,
|
|
419
|
+
...(target.commitId ? { commitId: target.commitId } : {}),
|
|
420
|
+
};
|
|
421
|
+
const writer: ArchiveWriter =
|
|
422
|
+
archiver.name === "zip"
|
|
423
|
+
? new ZipArchiveWriter({
|
|
424
|
+
...settings,
|
|
425
|
+
hexLength: this.objectFormat.hexLength,
|
|
426
|
+
...(this.localTzOffset ? { localTzOffset: this.localTzOffset } : {}),
|
|
427
|
+
onWarning: (m) => this.messages.push(m),
|
|
428
|
+
})
|
|
429
|
+
: new TarArchiveWriter({ ...settings, umask: this.tarUmask() });
|
|
430
|
+
const run = new ArchiveRun(this, target, writer, extras);
|
|
431
|
+
// with --worktree-attributes a name the tree decoder refuses (`..`, `a/b`) is only met
|
|
432
|
+
// here: refused as verify_path would (git archives it; such paths escape on extraction)
|
|
433
|
+
await withTreePathRefusal(
|
|
434
|
+
this.trees,
|
|
435
|
+
[target.tree],
|
|
436
|
+
worktreePathRules(this._workingCopy),
|
|
437
|
+
async () => {
|
|
438
|
+
await run.prepare();
|
|
439
|
+
await run.writeEntries();
|
|
440
|
+
},
|
|
441
|
+
(refusal) =>
|
|
442
|
+
refusal instanceof InvalidPathError
|
|
443
|
+
? new GitApiError(refusal.message, { exitCode: 255 })
|
|
444
|
+
: refusal,
|
|
445
|
+
);
|
|
446
|
+
const archive = writer.finish();
|
|
447
|
+
if (archiver.command === undefined) return archive;
|
|
448
|
+
return this.filter(archiver.command, archive, level);
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private async filter(command: string, archive: Uint8Array, level: number): Promise<Uint8Array> {
|
|
453
|
+
if (command === INTERNAL_GZIP_COMMAND) {
|
|
454
|
+
// zlib refuses the levels the tar filters' option parsing lets through
|
|
455
|
+
if (level > 9) {
|
|
456
|
+
throw new GitApiError("fatal: deflateInit2: stream consistency error (no message)");
|
|
457
|
+
}
|
|
458
|
+
return deflateSync([archive], { format: "gzip", level });
|
|
459
|
+
}
|
|
460
|
+
const cmd = level >= 0 ? `${command} -${level}` : command;
|
|
461
|
+
// an empty command: start_command finds nothing to run
|
|
462
|
+
if (!cmd) throw new GitApiError("fatal: unable to start '' filter: No such file or directory");
|
|
463
|
+
if (!this.filterRunner) throw new GitApiError(`fatal: unable to start '${cmd}' filter`);
|
|
464
|
+
try {
|
|
465
|
+
return await this.filterRunner(cmd, archive);
|
|
466
|
+
} catch {
|
|
467
|
+
throw new GitApiError(`fatal: '${cmd}' filter reported error`);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** `--add-file`'s files read (git stats them while parsing its options). */
|
|
472
|
+
private async readExtraFiles(): Promise<ResolvedExtra[]> {
|
|
473
|
+
const out: ResolvedExtra[] = [];
|
|
474
|
+
for (const extra of this.extraFiles) {
|
|
475
|
+
const path = `${this.currentDirectory}${extra.path}`;
|
|
476
|
+
if (extra.content) {
|
|
477
|
+
out.push({
|
|
478
|
+
path,
|
|
479
|
+
base: extra.base,
|
|
480
|
+
content: extra.content,
|
|
481
|
+
mode: extra.executable ? 0o100755 : 0o100644,
|
|
482
|
+
virtual: extra.virtual,
|
|
483
|
+
});
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
const worktree = this.worktreeAccess;
|
|
487
|
+
// prefix_filename: `..` resolved against the current directory, the worktree's top kept
|
|
488
|
+
const resolved = normalizeWorktreePath(path);
|
|
489
|
+
const entry =
|
|
490
|
+
resolved === undefined
|
|
491
|
+
? undefined
|
|
492
|
+
: await worktree?.getEntry(resolved).catch(() => undefined);
|
|
493
|
+
if (!entry) throw new GitApiError(`fatal: File not found: ${path}`);
|
|
494
|
+
if (entry.isDirectory || (entry.mode & 0o170000) !== 0o100000) {
|
|
495
|
+
throw new GitApiError(`fatal: Not a regular file: ${path}`);
|
|
496
|
+
}
|
|
497
|
+
const chunks: Uint8Array[] = [];
|
|
498
|
+
for await (const c of (worktree as Worktree).readContent(resolved as string)) chunks.push(c);
|
|
499
|
+
out.push({
|
|
500
|
+
path,
|
|
501
|
+
base: extra.base,
|
|
502
|
+
content: join(chunks),
|
|
503
|
+
mode: entry.mode & 0o100 ? 0o100755 : 0o100644,
|
|
504
|
+
virtual: false,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
return out;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** `parse_treeish_arg`: the tree, the commit (if any) and the archive's time. */
|
|
511
|
+
private async resolveTreeish(name: string): Promise<ArchiveTarget> {
|
|
512
|
+
const resolver = this.revisionResolver();
|
|
513
|
+
if (this.uploadArchive && !this.uploadArchive.allowUnreachable) {
|
|
514
|
+
// remotes are only allowed to fetch actual refs
|
|
515
|
+
const colon = name.indexOf(":");
|
|
516
|
+
const refName = colon < 0 ? name : name.slice(0, colon);
|
|
517
|
+
const found = await resolver.dwimRef(refName).catch(() => []);
|
|
518
|
+
if (found.length === 0) throw new GitApiError(`fatal: no such ref: ${refName}`);
|
|
519
|
+
}
|
|
520
|
+
const id = await resolver.resolve(name).catch(() => undefined);
|
|
521
|
+
if (id === undefined) throw new GitApiError(`fatal: not a valid object name: ${name}`);
|
|
522
|
+
const peeled = await resolver.peelTags(id);
|
|
523
|
+
let commitId: ObjectId | undefined;
|
|
524
|
+
let time: number;
|
|
525
|
+
if (peeled.type === "commit") {
|
|
526
|
+
commitId = peeled.id;
|
|
527
|
+
const commit = await this.commits.load(commitId);
|
|
528
|
+
time = commit?.committer.timestamp ?? 0;
|
|
529
|
+
} else time = this.clock();
|
|
530
|
+
if (this.mtime !== undefined) time = approxidateCareful(this.mtime, this.clock()).timestamp;
|
|
531
|
+
const tree = await resolver.peelToType(id, "tree").catch(() => undefined);
|
|
532
|
+
if (tree === undefined) throw new GitApiError(`fatal: not a tree object: ${id}`);
|
|
533
|
+
if (!this.worktreeAttributes) {
|
|
534
|
+
// the tree is unpacked into an index first: verify_path refuses what git refuses
|
|
535
|
+
const refusal = await treePathRefusal(this.trees, tree, worktreePathRules(this._workingCopy));
|
|
536
|
+
if (refusal instanceof InvalidPathError) {
|
|
537
|
+
// 2.43: unpack_trees' error, then write_archive's -1 (255); 2.5x dies after it
|
|
538
|
+
if (this.compatibility === "2.43") {
|
|
539
|
+
throw new GitApiError(refusal.message, { exitCode: 255 });
|
|
540
|
+
}
|
|
541
|
+
throw new GitApiError(`${refusal.message}\nfatal: failed to unpack tree object ${tree}`, {
|
|
542
|
+
exitCode: 128,
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
if (refusal) throw refusal;
|
|
546
|
+
}
|
|
547
|
+
return { tree, time, ...(commitId ? { commitId } : {}) };
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// ---- what the run reads through the command ----
|
|
551
|
+
|
|
552
|
+
/** @internal */
|
|
553
|
+
get archiveWorktree(): Worktree | undefined {
|
|
554
|
+
return "worktree" in this._workingCopy ? this.worktreeAccess : undefined;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** @internal */
|
|
558
|
+
archiveSettings() {
|
|
559
|
+
return {
|
|
560
|
+
base: this.base,
|
|
561
|
+
paths: this.paths,
|
|
562
|
+
verbose: this.verbose,
|
|
563
|
+
worktreeAttributes: this.worktreeAttributes,
|
|
564
|
+
currentDirectory: this.currentDirectory,
|
|
565
|
+
messages: this.messages,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/** @internal */
|
|
570
|
+
archiveEntries(id: ObjectId): Promise<readonly TreeEntry[]> {
|
|
571
|
+
return this.treeEntries(id);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/** @internal */
|
|
575
|
+
async archiveBlob(id: ObjectId): Promise<Uint8Array | undefined> {
|
|
576
|
+
const content = await this.blobs.load(id).catch(() => undefined);
|
|
577
|
+
if (!content) return undefined;
|
|
578
|
+
const chunks: Uint8Array[] = [];
|
|
579
|
+
try {
|
|
580
|
+
for await (const c of content) chunks.push(c);
|
|
581
|
+
} catch {
|
|
582
|
+
return undefined;
|
|
583
|
+
}
|
|
584
|
+
return join(chunks);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* The host's filter drivers (`filter=<name>`) for a repository without a worktree; a
|
|
589
|
+
* worktree's content filter brings its own.
|
|
590
|
+
*/
|
|
591
|
+
setFilterDrivers(drivers: FilterDriverRegistry): this {
|
|
592
|
+
this.checkCallable();
|
|
593
|
+
this.filterDrivers = drivers;
|
|
594
|
+
return this;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** @internal */
|
|
598
|
+
archiveDrivers(): FilterDriverRegistry | undefined {
|
|
599
|
+
return this.filterDrivers;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** @internal */
|
|
603
|
+
archiveConfigObject() {
|
|
604
|
+
return this._workingCopy.config;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** @internal */
|
|
608
|
+
archiveConfig(key: string): string | undefined {
|
|
609
|
+
return configValue(this._workingCopy, key);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/** @internal The attributes git reads without a worktree (bare, or `GIT_ATTR_INDEX`). */
|
|
613
|
+
archiveBareAttributes(indexTree: ObjectId | undefined): AttributesResolver {
|
|
614
|
+
return bareAttributesResolver({
|
|
615
|
+
workingCopy: this._workingCopy,
|
|
616
|
+
trees: this.trees as never,
|
|
617
|
+
blobs: this.blobs,
|
|
618
|
+
revisions: () => this.revisionResolver(),
|
|
619
|
+
...(indexTree ? { indexTree } : {}),
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** @internal `%h` and friends, `%(describe)`, for `export-subst`. */
|
|
624
|
+
async archiveSubstitute(format: string, commitId: ObjectId, describe: boolean): Promise<string> {
|
|
625
|
+
const commit = await this.commits.load(commitId);
|
|
626
|
+
if (!commit) return "";
|
|
627
|
+
const abbreviator = createIdAbbreviator(this._workingCopy);
|
|
628
|
+
const abbreviate = async (id: ObjectId, length?: number) => {
|
|
629
|
+
if (length === 0) return id;
|
|
630
|
+
const lengths = await abbreviator.lengths([id], length);
|
|
631
|
+
return id.slice(0, lengths.get(id) ?? 7);
|
|
632
|
+
};
|
|
633
|
+
const tags = this.tagsStore;
|
|
634
|
+
return formatCommitPretty(format, commit, commitId, {
|
|
635
|
+
now: this.clock(),
|
|
636
|
+
abbreviate: (id) => abbreviate(id),
|
|
637
|
+
...(describe
|
|
638
|
+
? {
|
|
639
|
+
describe: createDescriber({
|
|
640
|
+
refs: this.refsStore,
|
|
641
|
+
...(tags ? { tags } : {}),
|
|
642
|
+
commits: this.commits,
|
|
643
|
+
abbreviate,
|
|
644
|
+
}),
|
|
645
|
+
}
|
|
646
|
+
: {}),
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/** @internal */
|
|
651
|
+
get archiveTreeLookup() {
|
|
652
|
+
return this.trees;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** An extra file ready to write. */
|
|
657
|
+
interface ResolvedExtra {
|
|
658
|
+
path: string;
|
|
659
|
+
base: string;
|
|
660
|
+
content: Uint8Array;
|
|
661
|
+
mode: number;
|
|
662
|
+
virtual: boolean;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
interface ArchiveTarget {
|
|
666
|
+
tree: ObjectId;
|
|
667
|
+
commitId?: ObjectId;
|
|
668
|
+
time: number;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/** A queued directory (archive.c's `struct directory`). */
|
|
672
|
+
interface Pending {
|
|
673
|
+
path: string;
|
|
674
|
+
id: ObjectId;
|
|
675
|
+
mode: number;
|
|
676
|
+
written: boolean;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/** git's `match_extension`: `<name>.<ext>`, the name not empty. */
|
|
680
|
+
function matchExtension(filename: string, ext: string): boolean {
|
|
681
|
+
const prefixlen = filename.length - ext.length;
|
|
682
|
+
if (prefixlen < 2 || filename[prefixlen - 1] !== ".") return false;
|
|
683
|
+
return filename.slice(prefixlen) === ext;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function join(chunks: Uint8Array[]): Uint8Array {
|
|
687
|
+
if (chunks.length === 1) return chunks[0] as Uint8Array;
|
|
688
|
+
let size = 0;
|
|
689
|
+
for (const c of chunks) size += c.length;
|
|
690
|
+
const out = new Uint8Array(size);
|
|
691
|
+
let at = 0;
|
|
692
|
+
for (const c of chunks) {
|
|
693
|
+
out.set(c, at);
|
|
694
|
+
at += c.length;
|
|
695
|
+
}
|
|
696
|
+
return out;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* A worktree path with `.`, `..` and empty components resolved; undefined when it climbs
|
|
701
|
+
* above the top (reached only through the host's file system, which the worktree does not
|
|
702
|
+
* give: pass such files to `addFile` with their content).
|
|
703
|
+
*/
|
|
704
|
+
function normalizeWorktreePath(path: string): string | undefined {
|
|
705
|
+
const out: string[] = [];
|
|
706
|
+
for (const part of path.split("/")) {
|
|
707
|
+
if (part === "" || part === ".") continue;
|
|
708
|
+
if (part === "..") {
|
|
709
|
+
if (out.length === 0) return undefined;
|
|
710
|
+
out.pop();
|
|
711
|
+
} else out.push(part);
|
|
712
|
+
}
|
|
713
|
+
return out.join("/");
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/** The base name of a path (`basename`). */
|
|
717
|
+
function baseName(path: string): string {
|
|
718
|
+
const trimmed = path.replace(/\/+$/, "");
|
|
719
|
+
const slash = trimmed.lastIndexOf("/");
|
|
720
|
+
return slash < 0 ? trimmed : trimmed.slice(slash + 1);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/** The pathspec elements as git reads them from `prefix` (`PATHSPEC_PREFER_CWD`). */
|
|
724
|
+
function prefixedElement(elem: string, prefix: string): string {
|
|
725
|
+
if (!prefix) return elem;
|
|
726
|
+
if (elem.startsWith(":(")) {
|
|
727
|
+
const close = elem.indexOf(")");
|
|
728
|
+
if (close < 0) return elem;
|
|
729
|
+
const magic = elem.slice(2, close).split(",");
|
|
730
|
+
if (magic.includes("top")) return elem;
|
|
731
|
+
return `${elem.slice(0, close + 1)}${prefix}${elem.slice(close + 1)}`;
|
|
732
|
+
}
|
|
733
|
+
if (elem.startsWith(":/")) return elem;
|
|
734
|
+
if (elem.startsWith(":!") || elem.startsWith(":^")) {
|
|
735
|
+
return `${elem.slice(0, 2)}${prefix}${elem.slice(2)}`;
|
|
736
|
+
}
|
|
737
|
+
return `${prefix}${elem}`;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/** One `write_archive`: the tree walked, its entries filtered and handed to the writer. */
|
|
741
|
+
class ArchiveRun {
|
|
742
|
+
private readonly settings: ReturnType<ArchiveCommand["archiveSettings"]>;
|
|
743
|
+
private pathspec: PathspecItem[] = [];
|
|
744
|
+
private readonly attrCache = new Map<string, ReadonlyMap<string, AttributeValue>>();
|
|
745
|
+
private bareResolver?: AttributesResolver;
|
|
746
|
+
private filterContext?: ContentAttributesContext;
|
|
747
|
+
private bigFileThreshold = DEFAULT_BIG_FILE_THRESHOLD;
|
|
748
|
+
private describeBudget = 1;
|
|
749
|
+
private conversionSettings?: ConversionSettings;
|
|
750
|
+
private readonly base: Uint8Array;
|
|
751
|
+
private readonly baseText: string;
|
|
752
|
+
|
|
753
|
+
constructor(
|
|
754
|
+
private readonly cmd: ArchiveCommand,
|
|
755
|
+
private readonly target: ArchiveTarget,
|
|
756
|
+
private readonly writer: ArchiveWriter,
|
|
757
|
+
private readonly extras: ResolvedExtra[],
|
|
758
|
+
) {
|
|
759
|
+
this.settings = cmd.archiveSettings();
|
|
760
|
+
this.baseText = this.settings.base;
|
|
761
|
+
this.base = encodeGitPath(this.baseText);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
private get worktree(): Worktree | undefined {
|
|
765
|
+
return this.cmd.archiveWorktree;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/** `parse_pathspec_arg` and the attribute sources. */
|
|
769
|
+
async prepare(): Promise<void> {
|
|
770
|
+
const threshold = parseGitInt(this.cmd.archiveConfig("core.bigFileThreshold"));
|
|
771
|
+
if (threshold !== undefined && threshold > 0) this.bigFileThreshold = threshold;
|
|
772
|
+
const worktree = this.worktree;
|
|
773
|
+
if (!this.settings.worktreeAttributes) {
|
|
774
|
+
if (worktree?.contentFilter) {
|
|
775
|
+
this.filterContext = {
|
|
776
|
+
direction: "index",
|
|
777
|
+
index: attributesIndexOfTree(this.cmd.archiveTreeLookup as never, this.target.tree),
|
|
778
|
+
};
|
|
779
|
+
} else this.bareResolver = this.cmd.archiveBareAttributes(this.target.tree);
|
|
780
|
+
} else if (!worktree?.contentFilter) {
|
|
781
|
+
this.bareResolver = this.cmd.archiveBareAttributes(undefined);
|
|
782
|
+
} else this.filterContext = { direction: "checkin" };
|
|
783
|
+
|
|
784
|
+
const prefix = this.settings.currentDirectory;
|
|
785
|
+
const given = this.settings.paths;
|
|
786
|
+
const elements =
|
|
787
|
+
given.length > 0 ? given.map((p) => prefixedElement(p, prefix)) : prefix ? [prefix] : [];
|
|
788
|
+
this.pathspec = this.parse(elements);
|
|
789
|
+
for (let i = 0; i < given.length; i++) {
|
|
790
|
+
const original = given[i] as string;
|
|
791
|
+
if (!original) continue;
|
|
792
|
+
const items = this.parse([elements[i] as string]);
|
|
793
|
+
if (prefix && (await this.matchesOutside(items, prefix))) {
|
|
794
|
+
throw new GitApiError(
|
|
795
|
+
`fatal: pathspec '${original}' matches files outside the current directory`,
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
if (!(await this.pathExists(items))) {
|
|
799
|
+
throw new GitApiError(`fatal: pathspec '${original}' did not match any files`);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
private parse(elements: string[]): PathspecItem[] {
|
|
805
|
+
let items: PathspecItem[];
|
|
806
|
+
try {
|
|
807
|
+
items = parsePathspec(elements, { attr: true });
|
|
808
|
+
} catch (e) {
|
|
809
|
+
throw new GitApiError(`fatal: ${(e as Error).message}`);
|
|
810
|
+
}
|
|
811
|
+
for (const item of items) if (item.attr) item.attrLookup = (p) => this.attrCache.get(p);
|
|
812
|
+
return items;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/** The attributes of `path` (a directory with `isDirectory`). */
|
|
816
|
+
private async attributes(
|
|
817
|
+
path: string,
|
|
818
|
+
names: readonly string[],
|
|
819
|
+
isDirectory = false,
|
|
820
|
+
): Promise<ReadonlyMap<string, AttributeValue>> {
|
|
821
|
+
if (this.bareResolver) return this.bareResolver.get(path, names, { isDirectory });
|
|
822
|
+
const filter = this.worktree?.contentFilter as
|
|
823
|
+
| {
|
|
824
|
+
attributes?(
|
|
825
|
+
path: string,
|
|
826
|
+
names: readonly string[],
|
|
827
|
+
context?: ContentAttributesContext,
|
|
828
|
+
): Promise<Map<string, AttributeValue>>;
|
|
829
|
+
}
|
|
830
|
+
| undefined;
|
|
831
|
+
if (!filter?.attributes) return new Map();
|
|
832
|
+
return filter.attributes(path, names, {
|
|
833
|
+
...(this.filterContext ?? { direction: "checkin" }),
|
|
834
|
+
...(isDirectory ? { isDirectory } : {}),
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** Whether `items` match the file or directory `path` (relative to the tree's top). */
|
|
839
|
+
private async matches(items: PathspecItem[], path: string, isDir: boolean): Promise<boolean> {
|
|
840
|
+
if (items.length === 0) return true;
|
|
841
|
+
if (isDir) {
|
|
842
|
+
// a directory is entered when something below it may match (its attributes aside)
|
|
843
|
+
const plain = items.map((i) => (i.attr ? { ...i, attr: undefined } : i));
|
|
844
|
+
return matchPathspec(plain, path, DO_MATCH_DIRECTORY | DO_MATCH_LEADING_PATHSPEC) > 0;
|
|
845
|
+
}
|
|
846
|
+
await this.loadAttributes(items, path);
|
|
847
|
+
return matchPathspec(items, path, 0) > 0;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/** The attributes `:(attr)` elements ask of `path`, read once (git asks them as a file's). */
|
|
851
|
+
private async loadAttributes(items: PathspecItem[], path: string): Promise<void> {
|
|
852
|
+
if (this.attrCache.has(path)) return;
|
|
853
|
+
const names = [...new Set(items.flatMap((i) => i.attr?.map((a) => a.name) ?? []))];
|
|
854
|
+
if (names.length > 0) this.attrCache.set(path, await this.attributes(path, names));
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** `path_exists`' `reject_entry` walk: a file, or a directory the element itself names. */
|
|
858
|
+
private async pathExists(items: PathspecItem[]): Promise<boolean> {
|
|
859
|
+
const walk = async (tree: ObjectId, base: string): Promise<boolean> => {
|
|
860
|
+
for (const entry of await this.cmd.archiveEntries(tree)) {
|
|
861
|
+
const path = `${base}${entry.name}`;
|
|
862
|
+
if (isDirMode(entry.mode)) {
|
|
863
|
+
if (!(await this.matches(items, path, true))) continue;
|
|
864
|
+
// match_pathspec of the directory's own name, its attributes included
|
|
865
|
+
await this.loadAttributes(items, path);
|
|
866
|
+
if (matchPathspec(items, path, DO_MATCH_DIRECTORY) > 0) return true;
|
|
867
|
+
if (await walk(entry.id, `${path}/`)) return true;
|
|
868
|
+
} else if (await this.matches(items, path, false)) return true;
|
|
869
|
+
}
|
|
870
|
+
return false;
|
|
871
|
+
};
|
|
872
|
+
return walk(this.target.tree, "");
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/** `reject_outside`: a file the element matches lies outside `prefix`. */
|
|
876
|
+
private async matchesOutside(items: PathspecItem[], prefix: string): Promise<boolean> {
|
|
877
|
+
const walk = async (tree: ObjectId, base: string): Promise<boolean> => {
|
|
878
|
+
for (const entry of await this.cmd.archiveEntries(tree)) {
|
|
879
|
+
const path = `${base}${entry.name}`;
|
|
880
|
+
if (isDirMode(entry.mode)) {
|
|
881
|
+
if (!(await this.matches(items, path, true))) continue;
|
|
882
|
+
if (await walk(entry.id, `${path}/`)) return true;
|
|
883
|
+
} else if ((await this.matches(items, path, false)) && !path.startsWith(prefix)) {
|
|
884
|
+
return true;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return false;
|
|
888
|
+
};
|
|
889
|
+
return walk(this.target.tree, "");
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
private report(path: Uint8Array): void {
|
|
893
|
+
if (this.settings.verbose) this.settings.messages.push(decodeGitPath(path));
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
private emit(entry: ArchiveEntry): void {
|
|
897
|
+
const error = this.writer.entry(entry);
|
|
898
|
+
if (error) throw new GitApiError(`error: ${error}`, { exitCode: 255 });
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/** `write_archive_entries`. */
|
|
902
|
+
async writeEntries(): Promise<void> {
|
|
903
|
+
const base = this.baseText;
|
|
904
|
+
if (base.length > 0 && base.endsWith("/")) {
|
|
905
|
+
let len = base.length;
|
|
906
|
+
while (len > 1 && base[len - 2] === "/") len--;
|
|
907
|
+
const path = this.base.subarray(0, encodeGitPath(base.slice(0, len)).length);
|
|
908
|
+
this.report(path);
|
|
909
|
+
this.emit({ path, mode: 0o40777, id: this.target.tree, content: new Uint8Array(0) });
|
|
910
|
+
}
|
|
911
|
+
await this.walk(this.target.tree, "", []);
|
|
912
|
+
const hexLength = this.target.commitId?.length ?? this.target.tree.length;
|
|
913
|
+
const entries: ArchiveEntry[] = [];
|
|
914
|
+
const binaries: Promise<boolean | undefined>[] = [];
|
|
915
|
+
this.extras.forEach((extra, i) => {
|
|
916
|
+
const id = (i + 1).toString(16).padStart(16, "0").padEnd(hexLength, "0");
|
|
917
|
+
const text = extra.virtual ? extra.path : `${extra.base}${baseName(extra.path)}`;
|
|
918
|
+
const path = encodeGitPath(text);
|
|
919
|
+
const entry: ArchiveEntry = { path, mode: extra.mode, id, content: extra.content };
|
|
920
|
+
// zip asks the diff driver of the path less the prefix's length (archive-zip.c)
|
|
921
|
+
binaries.push(this.binaryOf(decodeGitPath(path.subarray(this.base.length))));
|
|
922
|
+
entries.push(entry);
|
|
923
|
+
});
|
|
924
|
+
for (let i = 0; i < entries.length; i++) {
|
|
925
|
+
const entry = entries[i] as ArchiveEntry;
|
|
926
|
+
const binary = await binaries[i];
|
|
927
|
+
if (binary !== undefined) entry.binary = binary;
|
|
928
|
+
this.emit(entry);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/** `read_tree` with `queue_or_write_archive_entry`. */
|
|
933
|
+
private async walk(tree: ObjectId, base: string, ancestors: Pending[]): Promise<void> {
|
|
934
|
+
for (const entry of await this.cmd.archiveEntries(tree)) {
|
|
935
|
+
const path = `${base}${entry.name}`;
|
|
936
|
+
if (isDirMode(entry.mode)) {
|
|
937
|
+
if (!(await this.matches(this.pathspec, path, true))) continue;
|
|
938
|
+
// git asks for `<dir>/`: a directory
|
|
939
|
+
const attrs = await this.attributes(path, EXPORT_ATTRS, true);
|
|
940
|
+
if (attrs.get("export-ignore") === true) continue;
|
|
941
|
+
ancestors.push({ path, id: entry.id, mode: entry.mode, written: false });
|
|
942
|
+
await this.walk(entry.id, `${path}/`, ancestors);
|
|
943
|
+
ancestors.pop();
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
if (!(await this.matches(this.pathspec, path, false))) continue;
|
|
947
|
+
// write_directory: the queued directories above it, outermost first
|
|
948
|
+
for (const dir of ancestors) {
|
|
949
|
+
if (dir.written) continue;
|
|
950
|
+
dir.written = true;
|
|
951
|
+
await this.writeEntry(dir.id, dir.path, dir.mode);
|
|
952
|
+
}
|
|
953
|
+
await this.writeEntry(entry.id, path, entry.mode);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/** `write_archive_entry` for `path` (relative to the tree's top). */
|
|
958
|
+
private async writeEntry(id: ObjectId, path: string, mode: number): Promise<void> {
|
|
959
|
+
const isDir = isDirMode(mode) || isGitlinkMode(mode);
|
|
960
|
+
let convert = false;
|
|
961
|
+
if (!isDirMode(mode)) {
|
|
962
|
+
const attrs = await this.attributes(path, EXPORT_ATTRS, isGitlinkMode(mode));
|
|
963
|
+
if (attrs.get("export-ignore") === true) return;
|
|
964
|
+
convert = attrs.get("export-subst") === true;
|
|
965
|
+
}
|
|
966
|
+
let rel = isDir ? `${path}/` : path;
|
|
967
|
+
const prefix = this.settings.currentDirectory;
|
|
968
|
+
if (prefix) {
|
|
969
|
+
if (!rel.startsWith(prefix) || rel === prefix) return;
|
|
970
|
+
rel = rel.slice(prefix.length);
|
|
971
|
+
}
|
|
972
|
+
const archivePath = encodeGitPath(`${this.baseText}${rel}`);
|
|
973
|
+
// git converts and asks the diff driver by the path less the prefix (`path_without_prefix`
|
|
974
|
+
// after the current directory's rewrite)
|
|
975
|
+
const convertPath = rel;
|
|
976
|
+
this.report(archivePath);
|
|
977
|
+
if (isDir) {
|
|
978
|
+
this.emit({ path: archivePath, mode, id, content: new Uint8Array(0) });
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
let content = await this.cmd.archiveBlob(id);
|
|
982
|
+
if (!content) throw new GitApiError(`error: cannot read '${id}'`, { exitCode: 255 });
|
|
983
|
+
const streamed = isRegMode(mode) && !convert && content.length > this.bigFileThreshold;
|
|
984
|
+
if (isRegMode(mode) && !streamed) {
|
|
985
|
+
content = await this.smudge(convertPath, id, content, mode);
|
|
986
|
+
if (convert && this.target.commitId) content = await this.substitute(content);
|
|
987
|
+
}
|
|
988
|
+
const entry: ArchiveEntry = { path: archivePath, mode, id, content };
|
|
989
|
+
if (streamed) entry.streamed = true;
|
|
990
|
+
if (this.writer instanceof ZipArchiveWriter && (isRegMode(mode) || isLinkMode(mode))) {
|
|
991
|
+
const binary = await this.binaryOf(convertPath);
|
|
992
|
+
if (binary !== undefined) entry.binary = binary;
|
|
993
|
+
}
|
|
994
|
+
this.emit(entry);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/** zip's `entry_is_binary`: the diff driver's `binary`, undefined to look at the content. */
|
|
998
|
+
private async binaryOf(path: string): Promise<boolean | undefined> {
|
|
999
|
+
if (!(this.writer instanceof ZipArchiveWriter)) return undefined;
|
|
1000
|
+
const value = (await this.attributes(path, ["diff"])).get("diff");
|
|
1001
|
+
// userdiff.c's driver_false and driver_true
|
|
1002
|
+
if (value === false) return true;
|
|
1003
|
+
if (value === true) return false;
|
|
1004
|
+
const name = typeof value === "string" ? value : "default";
|
|
1005
|
+
const setting = this.cmd.archiveConfig(`diff.${name}.binary`);
|
|
1006
|
+
return setting === undefined ? undefined : parseGitBool(setting);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/** `convert_to_working_tree` with the archive's attributes. */
|
|
1010
|
+
private async smudge(
|
|
1011
|
+
path: string,
|
|
1012
|
+
id: ObjectId,
|
|
1013
|
+
content: Uint8Array,
|
|
1014
|
+
mode: number,
|
|
1015
|
+
): Promise<Uint8Array> {
|
|
1016
|
+
if (this.bareResolver) {
|
|
1017
|
+
// no worktree: convert.c's convert_to_working_tree with the archive's attributes and
|
|
1018
|
+
// the host's filter drivers (`setFilterDrivers`)
|
|
1019
|
+
const attrs = await this.bareResolver.get(path, CONVERT_ATTRS);
|
|
1020
|
+
this.conversionSettings ??= readConversionSettings(this.cmd.archiveConfigObject(), "lf");
|
|
1021
|
+
const ca = asGitDeath(() =>
|
|
1022
|
+
convAttrsOf(
|
|
1023
|
+
new Map(attrs),
|
|
1024
|
+
this.conversionSettings as ConversionSettings,
|
|
1025
|
+
this.cmd.archiveDrivers(),
|
|
1026
|
+
),
|
|
1027
|
+
);
|
|
1028
|
+
let out = content;
|
|
1029
|
+
if (ca.ident) out = identToWorktree(out, id);
|
|
1030
|
+
out = crlfToWorktree(out, ca.crlfAction, this.conversionSettings);
|
|
1031
|
+
if (ca.workingTreeEncoding && out.length > 0) {
|
|
1032
|
+
const encoded = reencode(out, ca.workingTreeEncoding, "UTF-8");
|
|
1033
|
+
if (encoded) out = encoded;
|
|
1034
|
+
else {
|
|
1035
|
+
this.settings.messages.push(
|
|
1036
|
+
`error: failed to encode '${path}' from UTF-8 to ${ca.workingTreeEncoding}`,
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
const smudge = ca.driver?.host?.smudge;
|
|
1041
|
+
let filtered: Uint8Array | undefined;
|
|
1042
|
+
if (smudge) {
|
|
1043
|
+
filtered = await smudge.call(ca.driver?.host, out, { path }).catch(() => undefined);
|
|
1044
|
+
}
|
|
1045
|
+
if (filtered === undefined && ca.driver?.required) {
|
|
1046
|
+
throw new GitApiError(`fatal: ${path}: smudge filter ${ca.driver.name} failed`);
|
|
1047
|
+
}
|
|
1048
|
+
return filtered ?? out;
|
|
1049
|
+
}
|
|
1050
|
+
const filter = this.worktree?.contentFilter;
|
|
1051
|
+
if (!filter) return content;
|
|
1052
|
+
let out: Awaited<ReturnType<typeof smudgeContent>>;
|
|
1053
|
+
try {
|
|
1054
|
+
out = await smudgeContent(filter, path, content, mode, this.filterContext);
|
|
1055
|
+
} catch (error) {
|
|
1056
|
+
if (error instanceof FilterDriverError || isEncodingAttributeError(error)) {
|
|
1057
|
+
throw new GitApiError(`fatal: ${(error as Error).message}`);
|
|
1058
|
+
}
|
|
1059
|
+
throw error;
|
|
1060
|
+
}
|
|
1061
|
+
if (out instanceof Uint8Array) return out;
|
|
1062
|
+
const chunks: Uint8Array[] = [];
|
|
1063
|
+
for await (const c of out as AsyncIterable<Uint8Array>) chunks.push(c);
|
|
1064
|
+
return join(chunks);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
/** `format_subst`: each `$Format:<fmt>$` expanded for the commit. */
|
|
1068
|
+
private async substitute(content: Uint8Array): Promise<Uint8Array> {
|
|
1069
|
+
const text = latin1(content);
|
|
1070
|
+
let out = "";
|
|
1071
|
+
let at = 0;
|
|
1072
|
+
for (;;) {
|
|
1073
|
+
const b = text.indexOf("$Format:", at);
|
|
1074
|
+
if (b < 0) break;
|
|
1075
|
+
const c = text.indexOf("$", b + 8);
|
|
1076
|
+
if (c < 0) break;
|
|
1077
|
+
out += text.slice(at, b);
|
|
1078
|
+
const { format, describe } = this.limitDescribe(text.slice(b + 8, c));
|
|
1079
|
+
const expanded = await this.cmd.archiveSubstitute(
|
|
1080
|
+
decodeGitPath(latin1Bytes(format)),
|
|
1081
|
+
this.target.commitId as ObjectId,
|
|
1082
|
+
describe,
|
|
1083
|
+
);
|
|
1084
|
+
out += latin1(encodeGitPath(expanded));
|
|
1085
|
+
at = c + 1;
|
|
1086
|
+
}
|
|
1087
|
+
out += text.slice(at);
|
|
1088
|
+
return latin1Bytes(out);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/**
|
|
1092
|
+
* `%(describe)` expands once per archive (`describe_status.max_invocations`): later ones
|
|
1093
|
+
* stay as written, escaped here so the formatter keeps them.
|
|
1094
|
+
*/
|
|
1095
|
+
private limitDescribe(format: string): { format: string; describe: boolean } {
|
|
1096
|
+
let out = "";
|
|
1097
|
+
let describe = false;
|
|
1098
|
+
for (let i = 0; i < format.length; i++) {
|
|
1099
|
+
if (format[i] === "%" && format[i + 1] === "%") {
|
|
1100
|
+
out += "%%";
|
|
1101
|
+
i++;
|
|
1102
|
+
continue;
|
|
1103
|
+
}
|
|
1104
|
+
if (format.startsWith("%(describe", i)) {
|
|
1105
|
+
if (this.describeBudget > 0) {
|
|
1106
|
+
this.describeBudget--;
|
|
1107
|
+
describe = true;
|
|
1108
|
+
out += "%";
|
|
1109
|
+
} else out += "%%";
|
|
1110
|
+
continue;
|
|
1111
|
+
}
|
|
1112
|
+
out += format[i];
|
|
1113
|
+
}
|
|
1114
|
+
return { format: out, describe };
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/** convert.c's death for `working-tree-encoding` set or unset (no value). */
|
|
1119
|
+
function isEncodingAttributeError(error: unknown): boolean {
|
|
1120
|
+
return (
|
|
1121
|
+
error instanceof Error && error.message === "true/false are no valid working-tree-encodings"
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
/** `fn`'s result, convert.c's attribute deaths turned into git's `fatal:`. */
|
|
1126
|
+
function asGitDeath<T>(fn: () => T): T {
|
|
1127
|
+
try {
|
|
1128
|
+
return fn();
|
|
1129
|
+
} catch (error) {
|
|
1130
|
+
if (isEncodingAttributeError(error))
|
|
1131
|
+
throw new GitApiError(`fatal: ${(error as Error).message}`);
|
|
1132
|
+
throw error;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
function latin1(bytes: Uint8Array): string {
|
|
1137
|
+
let s = "";
|
|
1138
|
+
for (let i = 0; i < bytes.length; i += 0x8000) {
|
|
1139
|
+
s += String.fromCharCode.apply(null, bytes.subarray(i, i + 0x8000) as unknown as number[]);
|
|
1140
|
+
}
|
|
1141
|
+
return s;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
function latin1Bytes(text: string): Uint8Array {
|
|
1145
|
+
const out = new Uint8Array(text.length);
|
|
1146
|
+
for (let i = 0; i < text.length; i++) out[i] = text.charCodeAt(i) & 0xff;
|
|
1147
|
+
return out;
|
|
1148
|
+
}
|