@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,1016 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git update-index` (builtin/update-index.c): index entries added, replaced, removed or
|
|
3
|
+
* re-flagged one argument at a time, as git processes its command line in order.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // git update-index --add a --chmod=+x b
|
|
8
|
+
* await git.updateIndex().setAdd(true).addPath("a").setChmod("+x").addPath("b").call();
|
|
9
|
+
*
|
|
10
|
+
* // git update-index --cacheinfo 100644,<id>,c --assume-unchanged a
|
|
11
|
+
* await git.updateIndex().addCacheInfo(0o100644, id, "c").setAssumeUnchanged(true).addPath("a").call();
|
|
12
|
+
*
|
|
13
|
+
* // git update-index --refresh
|
|
14
|
+
* const { output, exitCode } = await git.updateIndex().refresh().call();
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
FileMode,
|
|
20
|
+
type FileModeValue,
|
|
21
|
+
isValidWorktreePath,
|
|
22
|
+
type ObjectId,
|
|
23
|
+
} from "@statewalker/vcs-core";
|
|
24
|
+
import { encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
25
|
+
import {
|
|
26
|
+
basicStatMatches,
|
|
27
|
+
compareWithWorktree,
|
|
28
|
+
entryStatOf,
|
|
29
|
+
invalidateCacheTreePath,
|
|
30
|
+
modeFromWorktree,
|
|
31
|
+
type ResolveUndoRecord,
|
|
32
|
+
type StagingEntry,
|
|
33
|
+
storeWorktreeFile,
|
|
34
|
+
type Worktree,
|
|
35
|
+
type WorktreeEntry,
|
|
36
|
+
type WorktreeModeTrust,
|
|
37
|
+
wholeSeconds,
|
|
38
|
+
} from "@statewalker/vcs-working-tree";
|
|
39
|
+
import { UpdateIndexFailedError } from "../errors/index.js";
|
|
40
|
+
import { GitCommand } from "../git-command.js";
|
|
41
|
+
import { worktreeModeTrust } from "./core-config.js";
|
|
42
|
+
import { configBool } from "./merge-config.js";
|
|
43
|
+
import { inputLines, inputPaths, unquoteLine } from "./plumbing-input.js";
|
|
44
|
+
import { worktreePathRules } from "./worktree-path-rules.js";
|
|
45
|
+
|
|
46
|
+
/** Result of {@link UpdateIndexCommand}. */
|
|
47
|
+
export interface UpdateIndexResult {
|
|
48
|
+
/** What git prints on stdout: `--verbose`'s report, the refresh's `<path>: needs update` */
|
|
49
|
+
output: string;
|
|
50
|
+
/** What git prints on stderr without dying (`Ignoring path <path>`, `error:` lines) */
|
|
51
|
+
errors: string;
|
|
52
|
+
/** git's exit status: 1 when a refresh found entries to update or merge, else 0 */
|
|
53
|
+
exitCode: 0 | 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** One index entry as the command edits it (a stage-0 entry or a conflict stage). */
|
|
57
|
+
type Entry = StagingEntry;
|
|
58
|
+
|
|
59
|
+
type Step =
|
|
60
|
+
| { kind: "set"; apply: (state: State) => void }
|
|
61
|
+
| { kind: "path"; path: string }
|
|
62
|
+
| { kind: "cacheinfo"; mode: number; id: string; path: string }
|
|
63
|
+
| { kind: "refresh"; really: boolean };
|
|
64
|
+
|
|
65
|
+
/** The flags git keeps in its globals as it parses the command line. */
|
|
66
|
+
interface State {
|
|
67
|
+
add: boolean;
|
|
68
|
+
remove: boolean;
|
|
69
|
+
replace: boolean;
|
|
70
|
+
forceRemove: boolean;
|
|
71
|
+
infoOnly: boolean;
|
|
72
|
+
verbose: boolean;
|
|
73
|
+
/** `--[no-]assume-unchanged`: true marks, false unmarks, undefined neither */
|
|
74
|
+
markValid?: boolean;
|
|
75
|
+
/** `--[no-]skip-worktree` */
|
|
76
|
+
markSkipWorktree?: boolean;
|
|
77
|
+
ignoreSkipWorktreeEntries: boolean;
|
|
78
|
+
chmod?: "+x" | "-x";
|
|
79
|
+
quiet: boolean;
|
|
80
|
+
unmerged: boolean;
|
|
81
|
+
ignoreMissing: boolean;
|
|
82
|
+
ignoreSubmodules: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A death (`die()`): git's message, without the `fatal: ` prefix. */
|
|
86
|
+
class Death extends Error {}
|
|
87
|
+
|
|
88
|
+
const S_IFMT = 0o170000;
|
|
89
|
+
const S_IFREG = 0o100000;
|
|
90
|
+
|
|
91
|
+
/** git's index order: the names' bytes, then the stage. */
|
|
92
|
+
function compareNames(a: string, b: string): number {
|
|
93
|
+
const n = Math.min(a.length, b.length);
|
|
94
|
+
for (let i = 0; i < n; i++) {
|
|
95
|
+
const x = a.charCodeAt(i);
|
|
96
|
+
const y = b.charCodeAt(i);
|
|
97
|
+
if (x === y) continue;
|
|
98
|
+
if (x < 0xd800 && y < 0xd800) return x - y;
|
|
99
|
+
const ea = encodeGitPath(a);
|
|
100
|
+
const eb = encodeGitPath(b);
|
|
101
|
+
const m = Math.min(ea.length, eb.length);
|
|
102
|
+
for (let j = 0; j < m; j++) {
|
|
103
|
+
if (ea[j] !== eb[j]) return (ea[j] as number) - (eb[j] as number);
|
|
104
|
+
}
|
|
105
|
+
return ea.length - eb.length;
|
|
106
|
+
}
|
|
107
|
+
return a.length - b.length;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Edits the index as `git update-index` does (builtin/update-index.c).
|
|
112
|
+
*
|
|
113
|
+
* Options and paths apply in the order they are given, as git parses its command line: a
|
|
114
|
+
* setter changes how the paths after it are handled ({@link setAdd} before {@link addPath}),
|
|
115
|
+
* {@link refresh} and {@link addCacheInfo} act where they stand, and {@link setIndexInfo} or
|
|
116
|
+
* {@link setStdin} input is read after everything else. Each path is `update_one`:
|
|
117
|
+
*
|
|
118
|
+
* - with {@link setAssumeUnchanged} or {@link setSkipWorktree}, its stage-0 entry is flagged
|
|
119
|
+
* or unflagged (`Unable to mark file <path>` when it has none);
|
|
120
|
+
* - with {@link setForceRemove}, every stage of it is removed;
|
|
121
|
+
* - otherwise the file is hashed into the index (`--add` needed for a new path), a missing
|
|
122
|
+
* file removed only with {@link setRemove}, a directory taken as a submodule's commit.
|
|
123
|
+
*
|
|
124
|
+
* git's deaths are thrown as {@link UpdateIndexFailedError} (exit status 128) before the
|
|
125
|
+
* index is written, carrying what was printed until then. A refresh that finds entries to
|
|
126
|
+
* update or merge prints them and ends with exit status 1, the index written all the same.
|
|
127
|
+
*/
|
|
128
|
+
export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
|
|
129
|
+
private readonly steps: Step[] = [];
|
|
130
|
+
private indexInfo?: { text: Uint8Array | string };
|
|
131
|
+
private stdinPaths?: Uint8Array | string;
|
|
132
|
+
private nulTerminated = false;
|
|
133
|
+
private indexVersion?: number;
|
|
134
|
+
private showIndexVersion = false;
|
|
135
|
+
private forceWrite = false;
|
|
136
|
+
|
|
137
|
+
private set(apply: (state: State) => void): this {
|
|
138
|
+
this.checkCallable();
|
|
139
|
+
this.steps.push({ kind: "set", apply });
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** `--add`: paths not in the index yet are added (from here on). */
|
|
144
|
+
setAdd(add = true): this {
|
|
145
|
+
return this.set((s) => {
|
|
146
|
+
s.add = add;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** `--remove`: paths missing from the worktree are removed from the index. */
|
|
151
|
+
setRemove(remove = true): this {
|
|
152
|
+
return this.set((s) => {
|
|
153
|
+
s.remove = remove;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** `--replace`: a file may replace a directory of its name in the index, and the reverse. */
|
|
158
|
+
setReplace(replace = true): this {
|
|
159
|
+
return this.set((s) => {
|
|
160
|
+
s.replace = replace;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** `--force-remove`: paths are removed from the index whether or not their file exists. */
|
|
165
|
+
setForceRemove(forceRemove = true): this {
|
|
166
|
+
return this.set((s) => {
|
|
167
|
+
s.forceRemove = forceRemove;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** `--info-only`: files are hashed into the index without storing their blobs. */
|
|
172
|
+
setInfoOnly(infoOnly = true): this {
|
|
173
|
+
return this.set((s) => {
|
|
174
|
+
s.infoOnly = infoOnly;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** `--verbose`: `add '<path>'`, `remove '<path>'`, `chmod +x '<path>'` reported. */
|
|
179
|
+
setVerbose(verbose = true): this {
|
|
180
|
+
return this.set((s) => {
|
|
181
|
+
s.verbose = verbose;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** `--chmod=(+|-)x`: the executable bit of the paths after it set or cleared in the index. */
|
|
186
|
+
setChmod(flip: "+x" | "-x"): this {
|
|
187
|
+
return this.set((s) => {
|
|
188
|
+
s.chmod = flip;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** `--assume-unchanged` (true) / `--no-assume-unchanged` (false) for the paths after it. */
|
|
193
|
+
setAssumeUnchanged(mark: boolean): this {
|
|
194
|
+
return this.set((s) => {
|
|
195
|
+
s.markValid = mark;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** `--skip-worktree` (true) / `--no-skip-worktree` (false) for the paths after it. */
|
|
200
|
+
setSkipWorktree(mark: boolean): this {
|
|
201
|
+
return this.set((s) => {
|
|
202
|
+
s.markSkipWorktree = mark;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** `--ignore-skip-worktree-entries`: `--remove` leaves skip-worktree entries alone. */
|
|
207
|
+
setIgnoreSkipWorktreeEntries(ignore = true): this {
|
|
208
|
+
return this.set((s) => {
|
|
209
|
+
s.ignoreSkipWorktreeEntries = ignore;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** `-q`: a refresh after it prints nothing about entries needing an update. */
|
|
214
|
+
setQuiet(quiet = true): this {
|
|
215
|
+
return this.set((s) => {
|
|
216
|
+
s.quiet = quiet;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** `--unmerged`: a refresh after it passes over unmerged entries quietly. */
|
|
221
|
+
setUnmerged(unmerged = true): this {
|
|
222
|
+
return this.set((s) => {
|
|
223
|
+
s.unmerged = unmerged;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** `--ignore-missing`: a refresh after it passes over missing files. */
|
|
228
|
+
setIgnoreMissing(ignore = true): this {
|
|
229
|
+
return this.set((s) => {
|
|
230
|
+
s.ignoreMissing = ignore;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** `--ignore-submodules`: a refresh after it passes over submodules. */
|
|
235
|
+
setIgnoreSubmodules(ignore = true): this {
|
|
236
|
+
return this.set((s) => {
|
|
237
|
+
s.ignoreSubmodules = ignore;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** A path to update (git's `<file>` argument), relative to the worktree top. */
|
|
242
|
+
addPath(path: string): this {
|
|
243
|
+
this.checkCallable();
|
|
244
|
+
this.steps.push({ kind: "path", path });
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** `--cacheinfo <mode>,<object>,<path>`: an entry put in the index as given. */
|
|
249
|
+
addCacheInfo(mode: number, objectId: string, path: string): this {
|
|
250
|
+
this.checkCallable();
|
|
251
|
+
this.steps.push({ kind: "cacheinfo", mode, id: objectId, path });
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** `--refresh`: the stat data of unchanged files refreshed, the changed ones reported. */
|
|
256
|
+
refresh(): this {
|
|
257
|
+
this.checkCallable();
|
|
258
|
+
this.steps.push({ kind: "refresh", really: false });
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** `--really-refresh`: as {@link refresh}, assume-unchanged entries checked too. */
|
|
263
|
+
reallyRefresh(): this {
|
|
264
|
+
this.checkCallable();
|
|
265
|
+
this.steps.push({ kind: "refresh", really: true });
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* `--index-info`: entries read from `input` (`<mode> <id>\t<path>`, `<mode> <type>
|
|
271
|
+
* <id>\t<path>` or `<mode> <id> <stage>\t<path>`; mode 0 removes the path), after
|
|
272
|
+
* everything else.
|
|
273
|
+
*/
|
|
274
|
+
setIndexInfo(input: string | Uint8Array): this {
|
|
275
|
+
this.checkCallable();
|
|
276
|
+
this.indexInfo = { text: input };
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** `--stdin`: paths read from `input`, one per line, after everything else. */
|
|
281
|
+
setStdin(input: string | Uint8Array): this {
|
|
282
|
+
this.checkCallable();
|
|
283
|
+
this.stdinPaths = input;
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** `-z`: {@link setIndexInfo} and {@link setStdin} input is NUL-separated. */
|
|
288
|
+
setNulTerminated(nul = true): this {
|
|
289
|
+
this.checkCallable();
|
|
290
|
+
this.nulTerminated = nul;
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** `--index-version <n>`: the index written in format 2, 3 or 4. */
|
|
295
|
+
setIndexVersion(version: number): this {
|
|
296
|
+
this.checkCallable();
|
|
297
|
+
this.indexVersion = version;
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** `--show-index-version`: the index's format version printed. */
|
|
302
|
+
setShowIndexVersion(show = true): this {
|
|
303
|
+
this.checkCallable();
|
|
304
|
+
this.showIndexVersion = show;
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** `--force-write-index`: the index written even when nothing changed. */
|
|
309
|
+
setForceWriteIndex(force = true): this {
|
|
310
|
+
this.checkCallable();
|
|
311
|
+
this.forceWrite = force;
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async call(): Promise<UpdateIndexResult> {
|
|
316
|
+
this.checkCallable();
|
|
317
|
+
this.setCallable(false);
|
|
318
|
+
await this.readCurrentIndex();
|
|
319
|
+
const run = new UpdateIndexRun(this.context());
|
|
320
|
+
try {
|
|
321
|
+
await this.inOneOperation(async () => {
|
|
322
|
+
for (const step of this.steps) await run.step(step);
|
|
323
|
+
if (this.indexInfo) await run.readIndexInfo(this.indexInfo.text, this.nulTerminated);
|
|
324
|
+
this.applyIndexVersion(run);
|
|
325
|
+
if (this.stdinPaths !== undefined) {
|
|
326
|
+
const badlyQuoted = (): never => {
|
|
327
|
+
throw new Death("line is badly quoted");
|
|
328
|
+
};
|
|
329
|
+
for (const path of inputPaths(this.stdinPaths, this.nulTerminated, badlyQuoted)) {
|
|
330
|
+
await run.updateOne(path);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
} catch (error) {
|
|
335
|
+
if (error instanceof Death) {
|
|
336
|
+
throw new UpdateIndexFailedError(
|
|
337
|
+
[...run.stderr, `fatal: ${error.message}`].join("\n"),
|
|
338
|
+
run.stdout.join(""),
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
throw error;
|
|
342
|
+
}
|
|
343
|
+
if (run.changed || this.forceWrite) {
|
|
344
|
+
try {
|
|
345
|
+
await run.write();
|
|
346
|
+
} catch (error) {
|
|
347
|
+
if (error instanceof Death) {
|
|
348
|
+
throw new UpdateIndexFailedError(
|
|
349
|
+
[...run.stderr, `fatal: ${error.message}`].join("\n"),
|
|
350
|
+
run.stdout.join(""),
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
output: run.stdout.join(""),
|
|
358
|
+
errors: run.stderr.map((l) => `${l}\n`).join(""),
|
|
359
|
+
exitCode: run.hasErrors ? 1 : 0,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
private applyIndexVersion(run: UpdateIndexRun): void {
|
|
364
|
+
const staging = this.staging as unknown as {
|
|
365
|
+
_getVersion?(): number;
|
|
366
|
+
_setVersion?(version: number): void;
|
|
367
|
+
};
|
|
368
|
+
const current = staging._getVersion?.() ?? 2;
|
|
369
|
+
if (this.showIndexVersion) run.stdout.push(`${current}\n`);
|
|
370
|
+
const wanted = this.indexVersion;
|
|
371
|
+
if (wanted === undefined || wanted === 0) return;
|
|
372
|
+
if (wanted < 2 || wanted > 4) throw new Death(`index-version ${wanted} not in range: 2..4`);
|
|
373
|
+
if (current !== wanted) run.changed = true;
|
|
374
|
+
run.report(`index-version: was ${current}, set to ${wanted}`);
|
|
375
|
+
run.version = wanted;
|
|
376
|
+
if (staging._setVersion) run.setVersion = (v) => staging._setVersion?.(v);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private context(): RunContext {
|
|
380
|
+
const worktree = this.worktreeAccess;
|
|
381
|
+
return {
|
|
382
|
+
staging: this.staging,
|
|
383
|
+
worktree,
|
|
384
|
+
blobs: this.blobs,
|
|
385
|
+
trust: worktree
|
|
386
|
+
? worktreeModeTrust(this.workingCopy, worktree)
|
|
387
|
+
: { executable: true, symlinks: true },
|
|
388
|
+
pathRules: worktreePathRules(this.workingCopy),
|
|
389
|
+
nullId: this.objectFormat.nullId,
|
|
390
|
+
ignoreStat: configBool(this.workingCopy, "core.ignoreStat", false),
|
|
391
|
+
hexLength: this.objectFormat.hexLength,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
interface RunContext {
|
|
397
|
+
staging: UpdateIndexCommand["staging"];
|
|
398
|
+
worktree: Worktree | undefined;
|
|
399
|
+
blobs: UpdateIndexCommand["blobs"];
|
|
400
|
+
trust: WorktreeModeTrust;
|
|
401
|
+
pathRules: ReturnType<typeof worktreePathRules>;
|
|
402
|
+
nullId: string;
|
|
403
|
+
/** `core.ignoreStat` (git's `assume_unchanged`) */
|
|
404
|
+
ignoreStat: boolean;
|
|
405
|
+
hexLength: number;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** One run of `update-index` over the index read at its start (git's `the_index`). */
|
|
409
|
+
class UpdateIndexRun {
|
|
410
|
+
readonly stdout: string[] = [];
|
|
411
|
+
readonly stderr: string[] = [];
|
|
412
|
+
changed = false;
|
|
413
|
+
hasErrors = false;
|
|
414
|
+
version?: number;
|
|
415
|
+
setVersion?: (version: number) => void;
|
|
416
|
+
private readonly state: State = {
|
|
417
|
+
add: false,
|
|
418
|
+
remove: false,
|
|
419
|
+
replace: false,
|
|
420
|
+
forceRemove: false,
|
|
421
|
+
infoOnly: false,
|
|
422
|
+
verbose: false,
|
|
423
|
+
ignoreSkipWorktreeEntries: false,
|
|
424
|
+
quiet: false,
|
|
425
|
+
unmerged: false,
|
|
426
|
+
ignoreMissing: false,
|
|
427
|
+
ignoreSubmodules: false,
|
|
428
|
+
};
|
|
429
|
+
private entries: Entry[] = [];
|
|
430
|
+
private loaded = false;
|
|
431
|
+
private readonly invalidated = new Set<string>();
|
|
432
|
+
private readonly resolveUndo = new Map<string, ResolveUndoRecord>();
|
|
433
|
+
private indexTime = 0;
|
|
434
|
+
|
|
435
|
+
constructor(private readonly ctx: RunContext) {}
|
|
436
|
+
|
|
437
|
+
private async load(): Promise<void> {
|
|
438
|
+
if (this.loaded) return;
|
|
439
|
+
this.loaded = true;
|
|
440
|
+
const staging = this.ctx.staging;
|
|
441
|
+
const list = staging.entryList?.();
|
|
442
|
+
if (list) this.entries = [...list];
|
|
443
|
+
else for await (const e of staging.entries()) this.entries.push(e);
|
|
444
|
+
this.indexTime = staging.getUpdateTime();
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
report(line: string): void {
|
|
448
|
+
if (this.state.verbose) this.stdout.push(`${line}\n`);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async step(step: Step): Promise<void> {
|
|
452
|
+
await this.load();
|
|
453
|
+
switch (step.kind) {
|
|
454
|
+
case "set":
|
|
455
|
+
step.apply(this.state);
|
|
456
|
+
return;
|
|
457
|
+
case "path":
|
|
458
|
+
await this.updateOne(step.path);
|
|
459
|
+
return;
|
|
460
|
+
case "cacheinfo":
|
|
461
|
+
if (!this.addCacheInfo(step.mode, step.id, step.path, 0)) {
|
|
462
|
+
throw new Death(`git update-index: --cacheinfo cannot add ${step.path}`);
|
|
463
|
+
}
|
|
464
|
+
return;
|
|
465
|
+
case "refresh":
|
|
466
|
+
await this.refresh(step.really);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// ------------------------------------------------------------------------------------------
|
|
472
|
+
// The index in memory (read-cache.c)
|
|
473
|
+
|
|
474
|
+
/** `index_name_stage_pos`: the entry's position, or -(insert position)-1. */
|
|
475
|
+
private pos(name: string, stage: number): number {
|
|
476
|
+
let lo = 0;
|
|
477
|
+
let hi = this.entries.length;
|
|
478
|
+
while (lo < hi) {
|
|
479
|
+
const mid = (lo + hi) >>> 1;
|
|
480
|
+
const e = this.entries[mid] as Entry;
|
|
481
|
+
const c = compareNames(name, e.path) || stage - e.stage;
|
|
482
|
+
if (c === 0) return mid;
|
|
483
|
+
if (c < 0) hi = mid;
|
|
484
|
+
else lo = mid + 1;
|
|
485
|
+
}
|
|
486
|
+
return -lo - 1;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** `index_name_pos`: the stage-0 entry's position, or -(insert position)-1. */
|
|
490
|
+
private namePos(name: string): number {
|
|
491
|
+
return this.pos(name, 0);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
private invalidate(path: string): void {
|
|
495
|
+
this.invalidated.add(path);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** `remove_index_entry_at`: a conflict stage removed is kept as resolve-undo. */
|
|
499
|
+
private removeAt(pos: number): void {
|
|
500
|
+
const ce = this.entries[pos] as Entry;
|
|
501
|
+
if (ce.stage > 0) {
|
|
502
|
+
let record = this.resolveUndo.get(ce.path);
|
|
503
|
+
if (!record) {
|
|
504
|
+
record = { path: ce.path, modes: [0, 0, 0], objectIds: [undefined, undefined, undefined] };
|
|
505
|
+
this.resolveUndo.set(ce.path, record);
|
|
506
|
+
}
|
|
507
|
+
record.modes[ce.stage - 1] = ce.mode;
|
|
508
|
+
record.objectIds[ce.stage - 1] = ce.objectId;
|
|
509
|
+
}
|
|
510
|
+
this.entries.splice(pos, 1);
|
|
511
|
+
this.changed = true;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/** `remove_file_from_index`: every stage of `path` removed. */
|
|
515
|
+
private removeFile(path: string): void {
|
|
516
|
+
let pos = this.namePos(path);
|
|
517
|
+
if (pos < 0) pos = -pos - 1;
|
|
518
|
+
this.invalidate(path);
|
|
519
|
+
while (pos < this.entries.length && (this.entries[pos] as Entry).path === path) {
|
|
520
|
+
this.removeAt(pos);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** `add_index_entry` with OK_TO_ADD / OK_TO_REPLACE as the flags say; false: refused. */
|
|
525
|
+
private addEntry(ce: Entry): boolean {
|
|
526
|
+
let okToAdd = this.state.add;
|
|
527
|
+
const okToReplace = this.state.replace;
|
|
528
|
+
let pos = this.pos(ce.path, ce.stage);
|
|
529
|
+
this.invalidate(ce.path);
|
|
530
|
+
if (pos >= 0) {
|
|
531
|
+
this.entries[pos] = ce;
|
|
532
|
+
this.changed = true;
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
pos = -pos - 1;
|
|
536
|
+
if (ce.stage === 0) {
|
|
537
|
+
while (pos < this.entries.length && (this.entries[pos] as Entry).path === ce.path) {
|
|
538
|
+
okToAdd = true;
|
|
539
|
+
this.removeAt(pos);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (!okToAdd) return false;
|
|
543
|
+
if (!isValidWorktreePath(ce.path, ce.mode, this.ctx.pathRules)) {
|
|
544
|
+
this.stderr.push(`error: invalid path '${ce.path}'`);
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
if (this.fileDirectoryConflict(ce, pos, okToReplace)) {
|
|
548
|
+
if (!okToReplace) {
|
|
549
|
+
this.stderr.push(`error: '${ce.path}' appears as both a file and as a directory`);
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
pos = -this.pos(ce.path, ce.stage) - 1;
|
|
553
|
+
}
|
|
554
|
+
this.entries.splice(pos, 0, ce);
|
|
555
|
+
this.changed = true;
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** `check_file_directory_conflict`: `has_file_name`, then `has_dir_name`. */
|
|
560
|
+
private fileDirectoryConflict(ce: Entry, at: number, okToReplace: boolean): boolean {
|
|
561
|
+
let conflict = false;
|
|
562
|
+
// has_file_name: entries below the new path as a directory
|
|
563
|
+
let pos = at;
|
|
564
|
+
const name = ce.path;
|
|
565
|
+
while (pos < this.entries.length) {
|
|
566
|
+
const p = this.entries[pos++] as Entry;
|
|
567
|
+
if (name.length >= p.path.length || !p.path.startsWith(name)) break;
|
|
568
|
+
if (p.stage !== ce.stage) continue;
|
|
569
|
+
if (p.path[name.length] !== "/") continue;
|
|
570
|
+
conflict = true;
|
|
571
|
+
if (!okToReplace) return true;
|
|
572
|
+
this.removeAt(--pos);
|
|
573
|
+
}
|
|
574
|
+
// has_dir_name: a file where one of its leading directories goes
|
|
575
|
+
for (let slash = name.lastIndexOf("/"); slash > 0; slash = name.lastIndexOf("/", slash - 1)) {
|
|
576
|
+
const dir = name.slice(0, slash);
|
|
577
|
+
const found = this.pos(dir, ce.stage);
|
|
578
|
+
if (found >= 0) {
|
|
579
|
+
conflict = true;
|
|
580
|
+
if (!okToReplace) return true;
|
|
581
|
+
this.removeAt(found);
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
// a directory of that name already in the index: the levels above are fine too
|
|
585
|
+
let p = -found - 1;
|
|
586
|
+
let exists = false;
|
|
587
|
+
while (p < this.entries.length) {
|
|
588
|
+
const e = this.entries[p] as Entry;
|
|
589
|
+
if (e.path.length <= dir.length || e.path[dir.length] !== "/" || !e.path.startsWith(dir)) {
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
if (e.stage === ce.stage) {
|
|
593
|
+
exists = true;
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
p++;
|
|
597
|
+
}
|
|
598
|
+
if (exists) break;
|
|
599
|
+
}
|
|
600
|
+
return conflict;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// ------------------------------------------------------------------------------------------
|
|
604
|
+
// update_one and its helpers
|
|
605
|
+
|
|
606
|
+
/** git's `update_one`. */
|
|
607
|
+
async updateOne(path: string): Promise<void> {
|
|
608
|
+
await this.load();
|
|
609
|
+
const s = this.state;
|
|
610
|
+
const markOnly = s.markValid !== undefined || s.markSkipWorktree !== undefined;
|
|
611
|
+
let current: WorktreeEntry | undefined;
|
|
612
|
+
let missing = false;
|
|
613
|
+
let mode = 0;
|
|
614
|
+
if (!markOnly && !s.forceRemove) {
|
|
615
|
+
current = await this.ctx.worktree?.getEntry(path).catch(() => undefined);
|
|
616
|
+
missing = !current;
|
|
617
|
+
if (current) mode = current.isDirectory ? 0o040000 : current.mode;
|
|
618
|
+
}
|
|
619
|
+
if (!isValidWorktreePath(path, mode, this.ctx.pathRules)) {
|
|
620
|
+
this.stderr.push(`Ignoring path ${path}`);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if (s.markValid !== undefined) {
|
|
624
|
+
if (!this.markFlags(path, "assumeValid", s.markValid)) {
|
|
625
|
+
throw new Death(`Unable to mark file ${path}`);
|
|
626
|
+
}
|
|
627
|
+
return this.chmodAfter(path);
|
|
628
|
+
}
|
|
629
|
+
if (s.markSkipWorktree !== undefined) {
|
|
630
|
+
if (!this.markFlags(path, "skipWorktree", s.markSkipWorktree)) {
|
|
631
|
+
throw new Death(`Unable to mark file ${path}`);
|
|
632
|
+
}
|
|
633
|
+
return this.chmodAfter(path);
|
|
634
|
+
}
|
|
635
|
+
if (s.forceRemove) {
|
|
636
|
+
this.removeFile(path);
|
|
637
|
+
this.report(`remove '${path}'`);
|
|
638
|
+
return this.chmodAfter(path);
|
|
639
|
+
}
|
|
640
|
+
if (!(await this.processPath(path, current, missing))) {
|
|
641
|
+
throw new Death(`Unable to process path ${path}`);
|
|
642
|
+
}
|
|
643
|
+
this.report(`add '${path}'`);
|
|
644
|
+
return this.chmodAfter(path);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** The `--chmod` that follows every path (`chmod_path`). */
|
|
648
|
+
private chmodAfter(path: string): void {
|
|
649
|
+
const flip = this.state.chmod;
|
|
650
|
+
if (!flip) return;
|
|
651
|
+
const pos = this.namePos(path);
|
|
652
|
+
const ce = pos >= 0 ? (this.entries[pos] as Entry) : undefined;
|
|
653
|
+
if (!ce || (ce.mode & S_IFMT) !== S_IFREG) {
|
|
654
|
+
throw new Death(`git update-index: cannot chmod ${flip} '${path}'`);
|
|
655
|
+
}
|
|
656
|
+
// chmod_index_entry
|
|
657
|
+
const mode = flip === "+x" ? FileMode.EXECUTABLE_FILE : FileMode.REGULAR_FILE;
|
|
658
|
+
this.entries[pos] = { ...ce, mode };
|
|
659
|
+
this.invalidate(path);
|
|
660
|
+
this.changed = true;
|
|
661
|
+
this.report(`chmod ${flip} '${path}'`);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/** `mark_ce_flags`: false when the path has no stage-0 entry. */
|
|
665
|
+
private markFlags(path: string, flag: "assumeValid" | "skipWorktree", mark: boolean): boolean {
|
|
666
|
+
const pos = this.namePos(path);
|
|
667
|
+
if (pos < 0) return false;
|
|
668
|
+
const ce = this.entries[pos] as Entry;
|
|
669
|
+
this.entries[pos] = { ...ce, [flag]: mark };
|
|
670
|
+
this.invalidate(path);
|
|
671
|
+
this.changed = true;
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/** `remove_one_path`. */
|
|
676
|
+
private removeOnePath(path: string): boolean {
|
|
677
|
+
if (!this.state.remove) {
|
|
678
|
+
this.stderr.push(`error: ${path}: does not exist and --remove not passed`);
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
this.removeFile(path);
|
|
682
|
+
return true;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/** `process_path`: false where git's returns an error. */
|
|
686
|
+
private async processPath(
|
|
687
|
+
path: string,
|
|
688
|
+
current: WorktreeEntry | undefined,
|
|
689
|
+
missing: boolean,
|
|
690
|
+
): Promise<boolean> {
|
|
691
|
+
if (await this.beyondSymlink(path)) {
|
|
692
|
+
this.stderr.push(`error: '${path}' is beyond a symbolic link`);
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
const pos = this.namePos(path);
|
|
696
|
+
const ce = pos >= 0 ? (this.entries[pos] as Entry) : undefined;
|
|
697
|
+
if (ce?.skipWorktree) {
|
|
698
|
+
// the worktree's version is assumed good: only a removal applies
|
|
699
|
+
if (!this.state.ignoreSkipWorktreeEntries && this.state.remove) this.removeFile(path);
|
|
700
|
+
return true;
|
|
701
|
+
}
|
|
702
|
+
if (missing || !current) return this.removeOnePath(path);
|
|
703
|
+
if (current.isDirectory) return this.processDirectory(path, current);
|
|
704
|
+
return this.addOnePath(ce, path, current);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/** `has_symlink_leading_path`. */
|
|
708
|
+
private async beyondSymlink(path: string): Promise<boolean> {
|
|
709
|
+
const worktree = this.ctx.worktree;
|
|
710
|
+
if (!worktree) return false;
|
|
711
|
+
for (let at = path.indexOf("/"); at > 0; at = path.indexOf("/", at + 1)) {
|
|
712
|
+
const dir = await worktree.getEntry(path.slice(0, at)).catch(() => undefined);
|
|
713
|
+
if (!dir) return false;
|
|
714
|
+
if (!dir.isDirectory && (dir.mode & S_IFMT) === FileMode.SYMLINK) return true;
|
|
715
|
+
if (!dir.isDirectory) return false;
|
|
716
|
+
}
|
|
717
|
+
return false;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/** `process_directory`. */
|
|
721
|
+
private async processDirectory(path: string, current: WorktreeEntry): Promise<boolean> {
|
|
722
|
+
const worktree = this.ctx.worktree as Worktree;
|
|
723
|
+
const pos = this.namePos(path);
|
|
724
|
+
if (pos >= 0) {
|
|
725
|
+
const ce = this.entries[pos] as Entry;
|
|
726
|
+
if (ce.mode === FileMode.GITLINK) {
|
|
727
|
+
const head = await worktree.readGitlinkHead?.(path).catch(() => undefined);
|
|
728
|
+
if (!head) return true;
|
|
729
|
+
return this.addGitlink(ce, path, current, head);
|
|
730
|
+
}
|
|
731
|
+
return this.removeOnePath(path);
|
|
732
|
+
}
|
|
733
|
+
// a subdirectory of entries: an error
|
|
734
|
+
for (let p = -pos - 1; p < this.entries.length; p++) {
|
|
735
|
+
const e = this.entries[p] as Entry;
|
|
736
|
+
if (!e.path.startsWith(path)) break;
|
|
737
|
+
const c = e.path.charCodeAt(path.length);
|
|
738
|
+
if (c > 0x2f) break;
|
|
739
|
+
if (c < 0x2f) continue;
|
|
740
|
+
this.stderr.push(`error: ${path}: is a directory - add individual files instead`);
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
const head = await worktree.readGitlinkHead?.(path).catch(() => undefined);
|
|
744
|
+
if (head) return this.addGitlink(undefined, path, current, head);
|
|
745
|
+
this.stderr.push(`error: ${path}: is a directory - add files inside instead`);
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
private addGitlink(
|
|
750
|
+
old: Entry | undefined,
|
|
751
|
+
path: string,
|
|
752
|
+
current: WorktreeEntry,
|
|
753
|
+
head: ObjectId,
|
|
754
|
+
): boolean {
|
|
755
|
+
// ie_match_stat of a gitlink: only the commit checked out counts
|
|
756
|
+
if (old && old.stage === 0 && old.objectId === head) return true;
|
|
757
|
+
const ce: Entry = {
|
|
758
|
+
path,
|
|
759
|
+
mode: FileMode.GITLINK,
|
|
760
|
+
objectId: head,
|
|
761
|
+
stage: 0,
|
|
762
|
+
...entryStatOf(current),
|
|
763
|
+
};
|
|
764
|
+
if (!this.addEntry(ce)) {
|
|
765
|
+
this.stderr.push(`error: ${path}: cannot add to the index - missing --add option?`);
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/** Whether `old` is up to date with the file (`ie_match_stat(old, st, 0)` is 0). */
|
|
772
|
+
private async upToDate(old: Entry, current: WorktreeEntry): Promise<boolean> {
|
|
773
|
+
if (old.assumeValid) return true;
|
|
774
|
+
if (old.intentToAdd) return false;
|
|
775
|
+
const trust = this.ctx.trust;
|
|
776
|
+
if (modeFromWorktree(current.mode, old.mode, trust) !== old.mode) return false;
|
|
777
|
+
if (!basicStatMatches(old, current, trust)) return false;
|
|
778
|
+
const racy =
|
|
779
|
+
this.indexTime === 0 || wholeSeconds(old.mtime, old.mtimeNs) >= wholeSeconds(this.indexTime);
|
|
780
|
+
if (!racy) return true;
|
|
781
|
+
const worktree = this.ctx.worktree as Worktree;
|
|
782
|
+
return (await worktree.computeHash(old.path).catch(() => undefined)) === old.objectId;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/** `add_one_path`. */
|
|
786
|
+
private async addOnePath(
|
|
787
|
+
old: Entry | undefined,
|
|
788
|
+
path: string,
|
|
789
|
+
current: WorktreeEntry,
|
|
790
|
+
): Promise<boolean> {
|
|
791
|
+
if (old && old.stage === 0 && (await this.upToDate(old, current))) return true;
|
|
792
|
+
const worktree = this.ctx.worktree as Worktree;
|
|
793
|
+
let id: ObjectId;
|
|
794
|
+
let stat = current;
|
|
795
|
+
try {
|
|
796
|
+
if (this.state.infoOnly) {
|
|
797
|
+
id = await worktree.computeHash(path);
|
|
798
|
+
} else {
|
|
799
|
+
const stored = await storeWorktreeFile(this.ctx.blobs, worktree, path, current);
|
|
800
|
+
id = stored.id;
|
|
801
|
+
stat = stored.entry;
|
|
802
|
+
}
|
|
803
|
+
} catch (error) {
|
|
804
|
+
this.stderr.push(`error: ${(error as Error).message}`);
|
|
805
|
+
return false;
|
|
806
|
+
}
|
|
807
|
+
const ce: Entry = {
|
|
808
|
+
path,
|
|
809
|
+
mode: modeFromWorktree(stat.mode, old?.mode, this.ctx.trust) as FileModeValue,
|
|
810
|
+
objectId: id,
|
|
811
|
+
stage: 0,
|
|
812
|
+
...entryStatOf(stat),
|
|
813
|
+
};
|
|
814
|
+
if (!this.addEntry(ce)) {
|
|
815
|
+
this.stderr.push(`error: ${path}: cannot add to the index - missing --add option?`);
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
return true;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/** `add_cacheinfo`: false where git returns an error. */
|
|
822
|
+
private addCacheInfo(mode: number, id: string, path: string, stage: number): boolean {
|
|
823
|
+
if (!isValidWorktreePath(path, mode, this.ctx.pathRules)) {
|
|
824
|
+
this.stderr.push(`error: Invalid path '${path}'`);
|
|
825
|
+
return false;
|
|
826
|
+
}
|
|
827
|
+
const ce: Entry = {
|
|
828
|
+
path,
|
|
829
|
+
mode: createCeMode(mode) as FileModeValue,
|
|
830
|
+
objectId: id.toLowerCase(),
|
|
831
|
+
stage: stage as Entry["stage"],
|
|
832
|
+
size: 0,
|
|
833
|
+
mtime: 0,
|
|
834
|
+
// add_cacheinfo's CE_VALID is core.ignoreStat's (assume_unchanged), not the option
|
|
835
|
+
...(this.ctx.ignoreStat ? { assumeValid: true } : {}),
|
|
836
|
+
};
|
|
837
|
+
if (!this.addEntry(ce)) {
|
|
838
|
+
this.stderr.push(`error: ${path}: cannot add to the index - missing --add option?`);
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
this.report(`add '${path}'`);
|
|
842
|
+
return true;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// ------------------------------------------------------------------------------------------
|
|
846
|
+
// --index-info
|
|
847
|
+
|
|
848
|
+
/** `read_index_info`. */
|
|
849
|
+
async readIndexInfo(input: string | Uint8Array, nul: boolean): Promise<void> {
|
|
850
|
+
await this.load();
|
|
851
|
+
const s = this.state;
|
|
852
|
+
s.add = true;
|
|
853
|
+
s.replace = true;
|
|
854
|
+
s.remove = true;
|
|
855
|
+
const hex = this.ctx.hexLength;
|
|
856
|
+
for (const line of inputLines(input, nul)) {
|
|
857
|
+
const bad = (): never => {
|
|
858
|
+
throw new Death(`malformed index info ${line}`);
|
|
859
|
+
};
|
|
860
|
+
const m = /^([0-7]+) /.exec(line);
|
|
861
|
+
if (!m) bad();
|
|
862
|
+
const mode = Number.parseInt((m as RegExpExecArray)[1] as string, 8);
|
|
863
|
+
if (mode > 0xffffffff) bad();
|
|
864
|
+
let tab = line.indexOf("\t");
|
|
865
|
+
if (tab < 0 || tab - (m as RegExpExecArray)[0].length + 1 < hex + 1) bad();
|
|
866
|
+
let stage = 0;
|
|
867
|
+
const pathAt = tab + 1;
|
|
868
|
+
if (
|
|
869
|
+
line[tab - 2] === " " &&
|
|
870
|
+
line[tab - 1] !== undefined &&
|
|
871
|
+
/[0-3]/.test(line[tab - 1] as string)
|
|
872
|
+
) {
|
|
873
|
+
stage = Number(line[tab - 1]);
|
|
874
|
+
tab -= 2;
|
|
875
|
+
}
|
|
876
|
+
const id = line.slice(tab - hex, tab);
|
|
877
|
+
if (!/^[0-9a-fA-F]+$/.test(id) || id.length !== hex || line[tab - hex - 1] !== " ") bad();
|
|
878
|
+
let path = line.slice(pathAt);
|
|
879
|
+
if (!nul && path.startsWith('"')) {
|
|
880
|
+
const unquoted = unquoteLine(path);
|
|
881
|
+
if (unquoted === undefined) throw new Death("git update-index: bad quoting of path name");
|
|
882
|
+
path = unquoted;
|
|
883
|
+
}
|
|
884
|
+
if (!isValidWorktreePath(path, mode, this.ctx.pathRules)) {
|
|
885
|
+
this.stderr.push(`Ignoring path ${path}`);
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
if (mode === 0) {
|
|
889
|
+
this.removeFile(path);
|
|
890
|
+
} else if (!this.addCacheInfo(mode, id, path, stage)) {
|
|
891
|
+
throw new Death(`git update-index: unable to update ${path}`);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// ------------------------------------------------------------------------------------------
|
|
897
|
+
// --refresh / --really-refresh
|
|
898
|
+
|
|
899
|
+
/** `refresh_index` over the entries (read-cache.c), then `has_racy_timestamp`. */
|
|
900
|
+
private async refresh(really: boolean): Promise<void> {
|
|
901
|
+
const s = this.state;
|
|
902
|
+
const worktree = this.ctx.worktree;
|
|
903
|
+
if (!worktree) return;
|
|
904
|
+
const trust = this.ctx.trust;
|
|
905
|
+
for (let i = 0; i < this.entries.length; i++) {
|
|
906
|
+
const ce = this.entries[i] as Entry;
|
|
907
|
+
if (s.ignoreSubmodules && ce.mode === FileMode.GITLINK) continue;
|
|
908
|
+
if (ce.stage !== 0) {
|
|
909
|
+
while (i < this.entries.length && (this.entries[i] as Entry).path === ce.path) i++;
|
|
910
|
+
i--;
|
|
911
|
+
if (s.unmerged) continue;
|
|
912
|
+
this.stdout.push(`${ce.path}: needs merge\n`);
|
|
913
|
+
this.hasErrors = true;
|
|
914
|
+
continue;
|
|
915
|
+
}
|
|
916
|
+
// refresh_cache_ent: what the user promised not to have changed
|
|
917
|
+
if (ce.skipWorktree) continue;
|
|
918
|
+
if (!really && ce.assumeValid) continue;
|
|
919
|
+
const current = await worktree.getEntry(ce.path).catch(() => undefined);
|
|
920
|
+
if (!current && s.ignoreMissing) continue;
|
|
921
|
+
let changed: boolean;
|
|
922
|
+
let fresh: Entry | undefined;
|
|
923
|
+
if (ce.intentToAdd) {
|
|
924
|
+
changed = true;
|
|
925
|
+
} else {
|
|
926
|
+
const compared = await compareWithWorktree(
|
|
927
|
+
worktree,
|
|
928
|
+
ce,
|
|
929
|
+
{ trust, indexTime: this.indexTime },
|
|
930
|
+
current ?? null,
|
|
931
|
+
);
|
|
932
|
+
changed = compared.kind !== undefined;
|
|
933
|
+
const file = compared.worktreeEntry;
|
|
934
|
+
// proved clean by reading it: its fresh stat recorded (refresh_cache_ent's copy)
|
|
935
|
+
if (!changed && compared.hashedId === ce.objectId && file && !file.isDirectory) {
|
|
936
|
+
fresh = { ...ce, ...entryStatOf(file) };
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
if (changed) {
|
|
940
|
+
if (really && ce.assumeValid && current) {
|
|
941
|
+
// the promise broken: the flag goes
|
|
942
|
+
this.entries[i] = { ...ce, assumeValid: false };
|
|
943
|
+
this.changed = true;
|
|
944
|
+
}
|
|
945
|
+
if (s.quiet) continue;
|
|
946
|
+
this.stdout.push(`${ce.path}: needs update\n`);
|
|
947
|
+
this.hasErrors = true;
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
if (fresh && !sameStat(fresh, ce)) {
|
|
951
|
+
this.entries[i] = fresh;
|
|
952
|
+
this.changed = true;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
// has_racy_timestamp: written anyway, so the racy entries stop being racy
|
|
956
|
+
for (const ce of this.entries) {
|
|
957
|
+
if (ce.stage !== 0) continue;
|
|
958
|
+
if (
|
|
959
|
+
this.indexTime === 0 ||
|
|
960
|
+
wholeSeconds(ce.mtime, ce.mtimeNs) >= wholeSeconds(this.indexTime)
|
|
961
|
+
) {
|
|
962
|
+
if (ce.mtime !== 0) {
|
|
963
|
+
this.changed = true;
|
|
964
|
+
break;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// ------------------------------------------------------------------------------------------
|
|
971
|
+
// Writing
|
|
972
|
+
|
|
973
|
+
/** `write_locked_index`: the entries, invalidated cache-tree paths and resolve-undo. */
|
|
974
|
+
async write(): Promise<void> {
|
|
975
|
+
await this.load();
|
|
976
|
+
for (const ce of this.entries) {
|
|
977
|
+
if (ce.objectId === this.ctx.nullId) {
|
|
978
|
+
this.stderr.push(`error: cache entry has null sha1: ${ce.path}`);
|
|
979
|
+
throw new Death("Unable to write new index file");
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
const staging = this.ctx.staging;
|
|
983
|
+
const tree = staging.getCacheTree?.();
|
|
984
|
+
const builder = staging.createBuilder();
|
|
985
|
+
for (const ce of this.entries) builder.add(ce);
|
|
986
|
+
await builder.finish({ upToDate: false });
|
|
987
|
+
if (staging.setCacheTree) {
|
|
988
|
+
if (tree) for (const path of this.invalidated) invalidateCacheTreePath(tree, path);
|
|
989
|
+
staging.setCacheTree(tree);
|
|
990
|
+
}
|
|
991
|
+
if (this.resolveUndo.size > 0) staging.recordResolveUndo?.([...this.resolveUndo.values()]);
|
|
992
|
+
if (this.version !== undefined) this.setVersion?.(this.version);
|
|
993
|
+
await staging.write();
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
function sameStat(a: Entry, b: Entry): boolean {
|
|
998
|
+
return (
|
|
999
|
+
a.size === b.size &&
|
|
1000
|
+
a.mtime === b.mtime &&
|
|
1001
|
+
a.mtimeNs === b.mtimeNs &&
|
|
1002
|
+
a.ctime === b.ctime &&
|
|
1003
|
+
a.ctimeNs === b.ctimeNs &&
|
|
1004
|
+
a.dev === b.dev &&
|
|
1005
|
+
a.ino === b.ino &&
|
|
1006
|
+
a.uid === b.uid &&
|
|
1007
|
+
a.gid === b.gid
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
/** git's `create_ce_mode`. */
|
|
1012
|
+
function createCeMode(mode: number): number {
|
|
1013
|
+
if ((mode & S_IFMT) === FileMode.SYMLINK) return FileMode.SYMLINK;
|
|
1014
|
+
if ((mode & S_IFMT) === 0o040000 || (mode & S_IFMT) === FileMode.GITLINK) return FileMode.GITLINK;
|
|
1015
|
+
return S_IFREG | ((mode & 0o100) !== 0 ? 0o755 : 0o644);
|
|
1016
|
+
}
|