@statewalker/vcs-commands 0.5.0 → 0.7.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 +123 -8
- package/dist/commands/add-command.d.ts +265 -34
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-interactive.d.ts +46 -0
- package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
- package/dist/commands/add-patch/add-patch.d.ts +139 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
- package/dist/commands/add-patch/index.d.ts +6 -0
- package/dist/commands/add-patch/index.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-backend.d.ts +80 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-modes.d.ts +71 -0
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-session.d.ts +49 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
- package/dist/commands/am/am-command.d.ts +175 -0
- package/dist/commands/am/am-command.d.ts.map +1 -0
- package/dist/commands/am/index.d.ts +3 -0
- package/dist/commands/am/index.d.ts.map +1 -0
- package/dist/commands/am/mailinfo.d.ts +58 -0
- package/dist/commands/am/mailinfo.d.ts.map +1 -0
- package/dist/commands/am/patch-format.d.ts +24 -0
- package/dist/commands/am/patch-format.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts +153 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -0
- package/dist/commands/apply/apply-engine.d.ts +195 -0
- package/dist/commands/apply/apply-engine.d.ts.map +1 -0
- package/dist/commands/apply/apply-parse.d.ts +86 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -0
- package/dist/commands/apply/apply-types.d.ts +70 -0
- package/dist/commands/apply/apply-types.d.ts.map +1 -0
- package/dist/commands/apply/index.d.ts +6 -0
- package/dist/commands/apply/index.d.ts.map +1 -0
- package/dist/commands/apply/latin1.d.ts +32 -0
- package/dist/commands/apply/latin1.d.ts.map +1 -0
- package/dist/commands/apply/whitespace.d.ts +58 -0
- package/dist/commands/apply/whitespace.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +26 -0
- package/dist/commands/attributes-source.d.ts.map +1 -0
- package/dist/commands/backfill-command.d.ts +110 -0
- package/dist/commands/backfill-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
- package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-command.d.ts +201 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-engine.d.ts +219 -0
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-graph.d.ts +127 -0
- package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-quote.d.ts +27 -0
- package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
- package/dist/commands/bisect/index.d.ts +5 -0
- package/dist/commands/bisect/index.d.ts.map +1 -0
- package/dist/commands/blame-command.d.ts +122 -131
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +52 -2
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-tracking.d.ts +98 -0
- package/dist/commands/branch-tracking.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +300 -18
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +124 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +50 -42
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +49 -16
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +134 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/comment-char-config.d.ts +35 -0
- package/dist/commands/comment-char-config.d.ts.map +1 -0
- package/dist/commands/commit-command.d.ts +311 -17
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +78 -1
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/date-format.d.ts +58 -0
- package/dist/commands/date-format.d.ts.map +1 -0
- package/dist/commands/default-branch.d.ts +70 -0
- package/dist/commands/default-branch.d.ts.map +1 -0
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +377 -30
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-textconv.d.ts +40 -0
- package/dist/commands/diff-textconv.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +149 -10
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts +164 -0
- package/dist/commands/format-patch-command.d.ts.map +1 -0
- package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts +227 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +71 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts +159 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +140 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +122 -0
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
- package/dist/commands/fsck/index.d.ts +6 -0
- package/dist/commands/fsck/index.d.ts.map +1 -0
- package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +106 -39
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +2 -0
- package/dist/commands/git-date.d.ts.map +1 -0
- package/dist/commands/git-describe.d.ts +67 -0
- package/dist/commands/git-describe.d.ts.map +1 -0
- package/dist/commands/git-hooks.d.ts +424 -0
- package/dist/commands/git-hooks.d.ts.map +1 -0
- package/dist/commands/git-ident.d.ts +128 -0
- package/dist/commands/git-ident.d.ts.map +1 -0
- package/dist/commands/hook-command.d.ts +96 -0
- package/dist/commands/hook-command.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +233 -0
- package/dist/commands/index-adder.d.ts.map +1 -0
- package/dist/commands/index-host.d.ts +86 -0
- package/dist/commands/index-host.d.ts.map +1 -0
- package/dist/commands/index.d.ts +56 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +62 -4
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/legacy-remotes.d.ts +55 -0
- package/dist/commands/legacy-remotes.d.ts.map +1 -0
- package/dist/commands/local-clone.d.ts +60 -0
- package/dist/commands/local-clone.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +117 -0
- package/dist/commands/local-transport.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +216 -24
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +120 -0
- package/dist/commands/log-graph.d.ts.map +1 -0
- package/dist/commands/log-output.d.ts +323 -0
- package/dist/commands/log-output.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +23 -7
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +31 -0
- package/dist/commands/mailmap.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +85 -0
- package/dist/commands/merge-bases.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +221 -74
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +13 -0
- package/dist/commands/merge-config.d.ts.map +1 -0
- package/dist/commands/merge-drivers.d.ts +130 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +260 -0
- package/dist/commands/merge-support.d.ts.map +1 -0
- package/dist/commands/message-cleanup.d.ts +86 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -0
- package/dist/commands/mv-command.d.ts +94 -0
- package/dist/commands/mv-command.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts +256 -0
- package/dist/commands/notes-command.d.ts.map +1 -0
- package/dist/commands/notes-commands.d.ts +41 -0
- package/dist/commands/notes-commands.d.ts.map +1 -0
- package/dist/commands/notes-merge-command.d.ts +105 -0
- package/dist/commands/notes-merge-command.d.ts.map +1 -0
- package/dist/commands/notes-support.d.ts +125 -0
- package/dist/commands/notes-support.d.ts.map +1 -0
- package/dist/commands/notes-tree.d.ts +116 -0
- package/dist/commands/notes-tree.d.ts.map +1 -0
- package/dist/commands/object-id-input.d.ts +20 -0
- package/dist/commands/object-id-input.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +59 -0
- package/dist/commands/octopus-merge.d.ts.map +1 -0
- package/dist/commands/ort-merge.d.ts +126 -0
- package/dist/commands/ort-merge.d.ts.map +1 -0
- package/dist/commands/ort-recursive.d.ts +53 -0
- package/dist/commands/ort-recursive.d.ts.map +1 -0
- package/dist/commands/pack-refs-command.d.ts +20 -0
- package/dist/commands/pack-refs-command.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +44 -0
- package/dist/commands/patch-id.d.ts.map +1 -0
- package/dist/commands/pathspec-attributes.d.ts +64 -0
- package/dist/commands/pathspec-attributes.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +324 -0
- package/dist/commands/pathspec.d.ts.map +1 -0
- package/dist/commands/post-index-change.d.ts +33 -0
- package/dist/commands/post-index-change.d.ts.map +1 -0
- package/dist/commands/pretty-format.d.ts +222 -0
- package/dist/commands/pretty-format.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts +80 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -0
- package/dist/commands/pull-command.d.ts +59 -8
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +24 -8
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +112 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -0
- package/dist/commands/rebase-command.d.ts +507 -75
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/rebase-todo.d.ts +130 -0
- package/dist/commands/rebase-todo.d.ts.map +1 -0
- package/dist/commands/ref-decoration-filter.d.ts +53 -0
- package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
- package/dist/commands/reflog-messages.d.ts +98 -0
- package/dist/commands/reflog-messages.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +31 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +120 -0
- package/dist/commands/remote-transport.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +161 -7
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +103 -0
- package/dist/commands/restore-command.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +78 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -0
- package/dist/commands/rev-parse-command.d.ts +89 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -0
- package/dist/commands/revert-command.d.ts +46 -38
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-filenames.d.ts +95 -0
- package/dist/commands/revision-filenames.d.ts.map +1 -0
- package/dist/commands/revision-range.d.ts +67 -0
- package/dist/commands/revision-range.d.ts.map +1 -0
- package/dist/commands/revision-resolver.d.ts +325 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -0
- package/dist/commands/rm-command.d.ts +69 -7
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +191 -0
- package/dist/commands/sequencer-pick.d.ts.map +1 -0
- package/dist/commands/sequencer-support.d.ts +125 -0
- package/dist/commands/sequencer-support.d.ts.map +1 -0
- package/dist/commands/serve-repository.d.ts +52 -0
- package/dist/commands/serve-repository.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts +190 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-support.d.ts +268 -0
- package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +42 -8
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +156 -2
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +2 -0
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +23 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts +300 -15
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-format.d.ts +155 -0
- package/dist/commands/status-format.d.ts.map +1 -0
- package/dist/commands/status-header.d.ts +64 -0
- package/dist/commands/status-header.d.ts.map +1 -0
- package/dist/commands/strerror.d.ts +7 -0
- package/dist/commands/strerror.d.ts.map +1 -0
- package/dist/commands/submodule-config.d.ts +38 -0
- package/dist/commands/submodule-config.d.ts.map +1 -0
- package/dist/commands/submodule-summary-command.d.ts +80 -0
- package/dist/commands/submodule-summary-command.d.ts.map +1 -0
- package/dist/commands/submodule-summary.d.ts +150 -0
- package/dist/commands/submodule-summary.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +132 -0
- package/dist/commands/switch-command.d.ts.map +1 -0
- package/dist/commands/tag-command.d.ts +23 -2
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tracking-info.d.ts +64 -0
- package/dist/commands/tracking-info.d.ts.map +1 -0
- package/dist/commands/trailers.d.ts +73 -0
- package/dist/commands/trailers.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +85 -1
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +54 -0
- package/dist/commands/untracked-cache-support.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +108 -0
- package/dist/commands/worktree-add-command.d.ts.map +1 -0
- package/dist/commands/worktree-list-command.d.ts +69 -0
- package/dist/commands/worktree-list-command.d.ts.map +1 -0
- package/dist/commands/worktree-lock-command.d.ts +44 -0
- package/dist/commands/worktree-lock-command.d.ts.map +1 -0
- package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/commands/worktree-prune-command.d.ts +48 -0
- package/dist/commands/worktree-prune-command.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +59 -0
- package/dist/commands/worktree-remove-command.d.ts.map +1 -0
- package/dist/commands/worktree-repair-command.d.ts +35 -0
- package/dist/commands/worktree-repair-command.d.ts.map +1 -0
- package/dist/commands/worktree-support.d.ts +64 -0
- package/dist/commands/worktree-support.d.ts.map +1 -0
- package/dist/commands-DIJ91NnD.js +62225 -0
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/errors/add-errors.d.ts +55 -0
- package/dist/errors/add-errors.d.ts.map +1 -1
- package/dist/errors/checkout-errors.d.ts +16 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts +77 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/commit-errors.d.ts +9 -0
- package/dist/errors/commit-errors.d.ts.map +1 -1
- package/dist/errors/git-api-error.d.ts +59 -2
- package/dist/errors/git-api-error.d.ts.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +354 -19
- package/dist/errors/rebase-errors.d.ts +9 -0
- package/dist/errors/rebase-errors.d.ts.map +1 -1
- package/dist/errors/ref-errors.d.ts +32 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/transport-errors.d.ts +12 -2
- package/dist/errors/transport-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +35 -0
- package/dist/errors/worktree-errors.d.ts.map +1 -0
- package/dist/git-command-BGiOJ8Zk.js +7246 -0
- package/dist/git-command.d.ts +428 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +315 -5
- package/dist/git.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/index.d.ts +1 -1
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +167 -6
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +7 -3
- package/dist/remote-config/remote-refs.d.ts.map +1 -1
- package/dist/rename/detect-renames.d.ts +148 -0
- package/dist/rename/detect-renames.d.ts.map +1 -0
- package/dist/rename/git-similarity.d.ts +44 -0
- package/dist/rename/git-similarity.d.ts.map +1 -0
- package/dist/rename/index.d.ts +2 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/binary-patch.d.ts +11 -0
- package/dist/results/binary-patch.d.ts.map +1 -0
- package/dist/results/blame-format.d.ts +55 -0
- package/dist/results/blame-format.d.ts.map +1 -0
- package/dist/results/cherry-pick-result.d.ts +10 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +18 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +77 -0
- package/dist/results/combined-diff.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +32 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +34 -60
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-order.d.ts +25 -0
- package/dist/results/diff-order.d.ts.map +1 -0
- package/dist/results/diff-output.d.ts +249 -0
- package/dist/results/diff-output.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +15 -0
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +5 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -252
- package/dist/results/init-result.d.ts +7 -0
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/merge-result.d.ts +15 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +17 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +47 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/quote-path.d.ts +27 -0
- package/dist/results/quote-path.d.ts.map +1 -0
- package/dist/results/rebase-result.d.ts +28 -1
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +10 -0
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +5 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +60 -6
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-WVlBhVb1.js +2935 -0
- package/dist/transport-command.d.ts +44 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -11
- package/src/commands/add-command.ts +1291 -226
- package/src/commands/add-patch/add-interactive.ts +941 -0
- package/src/commands/add-patch/add-patch.ts +1169 -0
- package/src/commands/add-patch/index.ts +5 -0
- package/src/commands/add-patch/patch-backend.ts +239 -0
- package/src/commands/add-patch/patch-modes.ts +249 -0
- package/src/commands/add-patch/patch-session.ts +159 -0
- package/src/commands/am/am-command.ts +1111 -0
- package/src/commands/am/index.ts +2 -0
- package/src/commands/am/mailinfo.ts +1015 -0
- package/src/commands/am/patch-format.ts +121 -0
- package/src/commands/apply/apply-command.ts +842 -0
- package/src/commands/apply/apply-engine.ts +1602 -0
- package/src/commands/apply/apply-parse.ts +1210 -0
- package/src/commands/apply/apply-types.ts +112 -0
- package/src/commands/apply/index.ts +5 -0
- package/src/commands/apply/latin1.ts +171 -0
- package/src/commands/apply/whitespace.ts +260 -0
- package/src/commands/attributes-source.ts +96 -0
- package/src/commands/backfill-command.ts +694 -0
- package/src/commands/bisect/bisect-checkout.ts +217 -0
- package/src/commands/bisect/bisect-command.ts +788 -0
- package/src/commands/bisect/bisect-engine.ts +1080 -0
- package/src/commands/bisect/bisect-graph.ts +595 -0
- package/src/commands/bisect/bisect-quote.ts +92 -0
- package/src/commands/bisect/index.ts +4 -0
- package/src/commands/blame-command.ts +711 -986
- package/src/commands/branch-command.ts +354 -32
- package/src/commands/branch-tracking.ts +331 -0
- package/src/commands/checkout-command.ts +1290 -243
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +504 -156
- package/src/commands/clone-command.ts +748 -69
- package/src/commands/comment-char-config.ts +160 -0
- package/src/commands/commit-command.ts +1782 -166
- package/src/commands/core-config.ts +166 -6
- package/src/commands/date-format.ts +668 -0
- package/src/commands/default-branch.ts +196 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1916 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +622 -68
- package/src/commands/format-patch-command.ts +974 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3464 -0
- package/src/commands/fsck/fsck-loose.ts +297 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1085 -0
- package/src/commands/fsck/fsck-object-table.ts +373 -0
- package/src/commands/fsck/fsck-pack.ts +634 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +252 -0
- package/src/commands/gc-command.ts +324 -77
- package/src/commands/git-date.ts +9 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1483 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +711 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +84 -0
- package/src/commands/init-command.ts +194 -14
- package/src/commands/legacy-remotes.ts +224 -0
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1930 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +105 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1416 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1219 -0
- package/src/commands/message-cleanup.ts +275 -0
- package/src/commands/mv-command.ts +976 -0
- package/src/commands/notes-command.ts +890 -0
- package/src/commands/notes-commands.ts +87 -0
- package/src/commands/notes-merge-command.ts +777 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +617 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +378 -0
- package/src/commands/ort-merge.ts +1660 -0
- package/src/commands/ort-recursive.ts +160 -0
- package/src/commands/pack-refs-command.ts +39 -22
- package/src/commands/patch-id.ts +204 -0
- package/src/commands/pathspec-attributes.ts +162 -0
- package/src/commands/pathspec.ts +1199 -0
- package/src/commands/post-index-change.ts +62 -0
- package/src/commands/pretty-format.ts +1432 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +326 -33
- package/src/commands/push-command.ts +257 -29
- package/src/commands/read-tree-command.ts +861 -0
- package/src/commands/rebase-command.ts +3820 -372
- package/src/commands/rebase-todo.ts +584 -0
- package/src/commands/ref-decoration-filter.ts +118 -0
- package/src/commands/reflog-messages.ts +177 -0
- package/src/commands/remote-command.ts +124 -23
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +821 -104
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +299 -0
- package/src/commands/revert-command.ts +152 -399
- package/src/commands/revision-filenames.ts +254 -0
- package/src/commands/revision-range.ts +222 -0
- package/src/commands/revision-resolver.ts +1397 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +874 -0
- package/src/commands/sequencer-support.ts +876 -0
- package/src/commands/serve-repository.ts +125 -0
- package/src/commands/sparse-checkout-command.ts +1389 -0
- package/src/commands/sparse-checkout-support.ts +793 -0
- package/src/commands/stash-apply-command.ts +376 -343
- package/src/commands/stash-create-command.ts +625 -42
- package/src/commands/stash-drop-command.ts +15 -2
- package/src/commands/stash-working-tree.ts +168 -24
- package/src/commands/status-command.ts +1326 -105
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +332 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +333 -0
- package/src/commands/submodule-summary.ts +446 -0
- package/src/commands/switch-command.ts +402 -0
- package/src/commands/tag-command.ts +129 -41
- package/src/commands/tracking-info.ts +201 -0
- package/src/commands/trailers.ts +417 -0
- package/src/commands/tree-restore.ts +204 -4
- package/src/commands/untracked-cache-support.ts +198 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +206 -0
- package/src/commands/worktree-lock-command.ts +96 -0
- package/src/commands/worktree-overwrite-checks.ts +452 -26
- package/src/commands/worktree-prune-command.ts +99 -0
- package/src/commands/worktree-remove-command.ts +186 -0
- package/src/commands/worktree-repair-command.ts +59 -0
- package/src/commands/worktree-support.ts +214 -0
- package/src/core-commands/add.command.impl.ts +8 -2
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +26 -2
- package/src/errors/command-errors.ts +101 -1
- package/src/errors/commit-errors.ts +18 -2
- package/src/errors/git-api-error.ts +82 -2
- package/src/errors/index.ts +1 -0
- package/src/errors/merge-errors.ts +2 -2
- package/src/errors/rebase-errors.ts +12 -0
- package/src/errors/ref-errors.ts +56 -2
- package/src/errors/remote-errors.ts +2 -2
- package/src/errors/stash-errors.ts +1 -1
- package/src/errors/transport-errors.ts +20 -4
- package/src/errors/worktree-errors.ts +49 -0
- package/src/git-command.ts +1207 -118
- package/src/git.ts +538 -12
- package/src/index.ts +1 -1
- package/src/remote-config/index.ts +2 -0
- package/src/remote-config/remote-config-store.ts +378 -18
- package/src/remote-config/remote-refs.ts +22 -6
- package/src/rename/detect-renames.ts +715 -0
- package/src/rename/git-similarity.ts +116 -0
- package/src/rename/index.ts +2 -0
- package/src/results/binary-patch.ts +401 -0
- package/src/results/blame-format.ts +239 -0
- package/src/results/cherry-pick-result.ts +10 -0
- package/src/results/clone-result.ts +21 -0
- package/src/results/combined-diff.ts +585 -0
- package/src/results/diff-entry.ts +35 -0
- package/src/results/diff-formatter.ts +152 -288
- package/src/results/diff-order.ts +64 -0
- package/src/results/diff-output.ts +1053 -0
- package/src/results/fetch-result.ts +15 -0
- package/src/results/index.ts +5 -0
- package/src/results/init-result.ts +9 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +17 -3
- package/src/results/push-result.ts +48 -0
- package/src/results/quote-path.ts +103 -0
- package/src/results/rebase-result.ts +37 -0
- package/src/results/revert-result.ts +10 -0
- package/src/results/stash-result.ts +6 -0
- package/src/results/status-result.ts +127 -46
- package/src/transport-command.ts +121 -2
- package/dist/commands-CsLNyvZ1.js +0 -12587
- package/dist/status-result-BpyUK1Sg.js +0 -519
package/src/git-command.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
BlobRead,
|
|
2
3
|
Blobs,
|
|
3
4
|
Commit,
|
|
4
5
|
Commits,
|
|
5
6
|
ObjectId,
|
|
7
|
+
PersonIdent,
|
|
6
8
|
Ref,
|
|
9
|
+
RefLogOptions,
|
|
10
|
+
RefRemoveOptions,
|
|
7
11
|
Refs,
|
|
12
|
+
RefTransactionHook,
|
|
8
13
|
SymbolicRef,
|
|
9
14
|
Tag,
|
|
10
15
|
Tags,
|
|
@@ -12,17 +17,71 @@ import type {
|
|
|
12
17
|
TreeEntry,
|
|
13
18
|
Trees,
|
|
14
19
|
} from "@statewalker/vcs-core";
|
|
15
|
-
import { isSymbolicRef } from "@statewalker/vcs-core";
|
|
16
20
|
import {
|
|
21
|
+
createReplacedBlobs,
|
|
22
|
+
createReplacedCommits,
|
|
23
|
+
createReplacedTags,
|
|
24
|
+
createReplacedTrees,
|
|
25
|
+
type GraftFileBase,
|
|
26
|
+
graftFileBaseDir,
|
|
27
|
+
graftFileReader,
|
|
28
|
+
hasReplacements,
|
|
29
|
+
isSymbolicRef,
|
|
30
|
+
type LoadedObjectReplacements,
|
|
31
|
+
loadObjectReplacements,
|
|
32
|
+
objectFormatOf,
|
|
33
|
+
overlayMethods,
|
|
34
|
+
} from "@statewalker/vcs-core";
|
|
35
|
+
import { type ObjectFormat, OrderedMap, parseGitBool } from "@statewalker/vcs-utils";
|
|
36
|
+
import {
|
|
37
|
+
type AttributesSourceResolver,
|
|
17
38
|
basicStatMatches,
|
|
39
|
+
clearSkipWorktreeFromPresentFiles,
|
|
18
40
|
compareWithWorktree,
|
|
41
|
+
IndexChangedError,
|
|
42
|
+
type OperationOptions,
|
|
43
|
+
type SparseCheckoutPatterns,
|
|
19
44
|
type Staging,
|
|
20
45
|
type WorkingCopy,
|
|
21
46
|
type Worktree,
|
|
22
47
|
} from "@statewalker/vcs-working-tree";
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
import {
|
|
48
|
+
import { attributesSourceResolver } from "./commands/attributes-source.js";
|
|
49
|
+
import { checkAutoCommentChar } from "./commands/comment-char-config.js";
|
|
50
|
+
import {
|
|
51
|
+
configLoadError,
|
|
52
|
+
createIdAbbreviator,
|
|
53
|
+
type IdAbbreviator,
|
|
54
|
+
worktreeModeTrust,
|
|
55
|
+
} from "./commands/core-config.js";
|
|
56
|
+
import { HookSession, refTransactionHookOf } from "./commands/git-hooks.js";
|
|
57
|
+
import {
|
|
58
|
+
authorIdentOf,
|
|
59
|
+
committerIdentOf,
|
|
60
|
+
hostEnvironmentOf,
|
|
61
|
+
type IdentRole,
|
|
62
|
+
resolveIdentDate,
|
|
63
|
+
withoutCrud,
|
|
64
|
+
} from "./commands/git-ident.js";
|
|
65
|
+
import { indexHostOf, indexVersionConfigError } from "./commands/index-host.js";
|
|
66
|
+
import { loadLegacyRemote } from "./commands/legacy-remotes.js";
|
|
67
|
+
import type { NotesContext } from "./commands/notes-support.js";
|
|
68
|
+
import { postIndexChangeHookOf } from "./commands/post-index-change.js";
|
|
69
|
+
import { createPromisorFetcher, promisorOf } from "./commands/promisor-remote.js";
|
|
70
|
+
import { reflogLine } from "./commands/reflog-messages.js";
|
|
71
|
+
import {
|
|
72
|
+
type ArgumentFiles,
|
|
73
|
+
lstatExists,
|
|
74
|
+
type WorktreeLookup,
|
|
75
|
+
} from "./commands/revision-filenames.js";
|
|
76
|
+
import { type ResolveOptions, RevisionResolver } from "./commands/revision-resolver.js";
|
|
77
|
+
import { readSparseCheckoutPatterns } from "./commands/sparse-checkout-support.js";
|
|
78
|
+
import {
|
|
79
|
+
InvalidConfigError,
|
|
80
|
+
NoHeadError,
|
|
81
|
+
NotACommitError,
|
|
82
|
+
RefNotFoundError,
|
|
83
|
+
} from "./errors/index.js";
|
|
84
|
+
import { RemoteConfigStore } from "./remote-config/index.js";
|
|
26
85
|
|
|
27
86
|
/**
|
|
28
87
|
* Extended Trees interface with legacy method names for command compatibility.
|
|
@@ -37,9 +96,24 @@ export interface CommandTrees extends Trees {
|
|
|
37
96
|
/**
|
|
38
97
|
* Extended Refs interface with legacy method names for command compatibility.
|
|
39
98
|
*/
|
|
99
|
+
/** A ref store that runs the reference-transaction hook (the files store). */
|
|
100
|
+
interface TransactionHookStore {
|
|
101
|
+
setTransactionHook?(hook: RefTransactionHook | undefined): void;
|
|
102
|
+
getTransactionHook?(): RefTransactionHook | undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The reference-transaction hooks commands installed: a command without hooks removes one
|
|
107
|
+
* of these left on its store (a command that wrote refs outside its `call`), never a hook
|
|
108
|
+
* someone else set (the receive side of a local push, a library user).
|
|
109
|
+
*/
|
|
110
|
+
const commandTransactionHooks = new WeakSet<RefTransactionHook>();
|
|
111
|
+
/** The post-index-change hooks commands installed (see `installIndexWriteHook`). */
|
|
112
|
+
const commandIndexWriteHooks = new WeakSet<() => Promise<void>>();
|
|
113
|
+
|
|
40
114
|
export interface CommandRefs extends Refs {
|
|
41
115
|
/** Delete a reference - alias for remove() */
|
|
42
|
-
delete(name: string): Promise<boolean>;
|
|
116
|
+
delete(name: string, options?: RefRemoveOptions): Promise<boolean>;
|
|
43
117
|
}
|
|
44
118
|
|
|
45
119
|
/**
|
|
@@ -87,7 +161,7 @@ function wrapTrees(trees: Trees): CommandTrees {
|
|
|
87
161
|
function wrapRefs(refs: Refs): CommandRefs {
|
|
88
162
|
const wrapper = refs as CommandRefs;
|
|
89
163
|
if (!wrapper.delete) {
|
|
90
|
-
wrapper.delete = (name: string) => refs.remove(name);
|
|
164
|
+
wrapper.delete = (name: string, options?: RefRemoveOptions) => refs.remove(name, options);
|
|
91
165
|
}
|
|
92
166
|
return wrapper;
|
|
93
167
|
}
|
|
@@ -144,6 +218,18 @@ function wrapCommits(commits: Commits): CommandCommits {
|
|
|
144
218
|
return wrapper as CommandCommits;
|
|
145
219
|
}
|
|
146
220
|
|
|
221
|
+
/** git's advice when it reads a grafts file (2.5x wording). */
|
|
222
|
+
const GRAFT_FILE_ADVICE = [
|
|
223
|
+
"hint: Support for <GIT_DIR>/info/grafts is deprecated",
|
|
224
|
+
"hint: and will be removed in a future Git version.",
|
|
225
|
+
"hint:",
|
|
226
|
+
'hint: Please use "git replace --convert-graft-file"',
|
|
227
|
+
"hint: to convert the grafts into replace refs.",
|
|
228
|
+
"hint:",
|
|
229
|
+
"hint: Turn this message off by running",
|
|
230
|
+
'hint: "git config set advice.graftFileDeprecated false"',
|
|
231
|
+
];
|
|
232
|
+
|
|
147
233
|
/**
|
|
148
234
|
* Abstract base class for all Git commands.
|
|
149
235
|
*
|
|
@@ -156,56 +242,615 @@ function wrapCommits(commits: Commits): CommandCommits {
|
|
|
156
242
|
*
|
|
157
243
|
* @typeParam T - The return type of the command's call() method
|
|
158
244
|
*/
|
|
245
|
+
/** Trees the commands sharing reads keep (see `GitCommand.shareReadsOf`). */
|
|
246
|
+
const SHARED_TREES = 1024;
|
|
247
|
+
/** Bytes of blob content the commands sharing reads keep, and the largest blob kept */
|
|
248
|
+
export const SHARED_BLOB_BYTES = 64 * 2 ** 20;
|
|
249
|
+
export const SHARED_BLOB_MAX = 2 ** 20;
|
|
250
|
+
|
|
251
|
+
/** Blob contents kept for the commands sharing reads, most recently used last */
|
|
252
|
+
export interface SharedBlobs {
|
|
253
|
+
recent: OrderedMap<ObjectId, Uint8Array>;
|
|
254
|
+
bytes: number;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* `blobs` keeping the small blobs it reads in `shared` until they are read again: `git log -p`
|
|
259
|
+
* reads a file's version as the old side of one commit's diff and again as the new side of
|
|
260
|
+
* the next one down, then no more. The bytes handed out are shared between the readers,
|
|
261
|
+
* never to be changed.
|
|
262
|
+
*/
|
|
263
|
+
export function sharingBlobs(blobs: Blobs, shared: SharedBlobs): Blobs {
|
|
264
|
+
const open = async (id: ObjectId): Promise<BlobRead | undefined> => {
|
|
265
|
+
const known = shared.recent.get(id);
|
|
266
|
+
if (known) {
|
|
267
|
+
// the second read is mostly the last (newest first, a version is read as the old side
|
|
268
|
+
// of the change after it, then as the new side of its own): it leaves the cache, which
|
|
269
|
+
// so holds the versions still to come instead of the ones done with
|
|
270
|
+
shared.recent.delete(id);
|
|
271
|
+
shared.bytes -= known.length;
|
|
272
|
+
return { size: known.length, bytes: known, content: single(known) };
|
|
273
|
+
}
|
|
274
|
+
const blob = await blobs.open?.(id);
|
|
275
|
+
if (blob?.bytes && blob.size <= SHARED_BLOB_MAX) {
|
|
276
|
+
// another open of the same id may have kept it while this one read: hand out that copy
|
|
277
|
+
const kept = shared.recent.get(id);
|
|
278
|
+
if (kept) return { size: kept.length, bytes: kept, content: single(kept) };
|
|
279
|
+
shared.recent.set(id, blob.bytes);
|
|
280
|
+
shared.bytes += blob.bytes.length;
|
|
281
|
+
while (shared.bytes > SHARED_BLOB_BYTES && shared.recent.size > 0) {
|
|
282
|
+
const oldest = shared.recent.oldestKey() as ObjectId;
|
|
283
|
+
shared.bytes -= shared.recent.get(oldest)?.length ?? 0;
|
|
284
|
+
shared.recent.delete(oldest);
|
|
285
|
+
}
|
|
286
|
+
if (shared.recent.size === 0) shared.bytes = 0;
|
|
287
|
+
}
|
|
288
|
+
return blob;
|
|
289
|
+
};
|
|
290
|
+
return overlayMethods(blobs, {
|
|
291
|
+
open,
|
|
292
|
+
load: async (id: ObjectId) => {
|
|
293
|
+
const blob = await open(id);
|
|
294
|
+
if (!blob) return undefined;
|
|
295
|
+
return blob.bytes ? single(blob.bytes) : blob.content;
|
|
296
|
+
},
|
|
297
|
+
size: async (id: ObjectId) => {
|
|
298
|
+
const blob = await open(id);
|
|
299
|
+
if (!blob) return -1;
|
|
300
|
+
if (!blob.bytes) await blob.content[Symbol.asyncIterator]().return?.();
|
|
301
|
+
return blob.size;
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** One chunk as a stream */
|
|
307
|
+
async function* single(bytes: Uint8Array): AsyncGenerator<Uint8Array> {
|
|
308
|
+
yield bytes;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** The entry points (`call`, `callText`, ...) of each command class, found once per class */
|
|
312
|
+
const ENTRY_POINTS = new WeakMap<object, readonly string[]>();
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* The names of the entry points a command's prototype chain defines (`call` and `callX`
|
|
316
|
+
* methods), looked up once per class: `git log -p` makes a command per commit.
|
|
317
|
+
*/
|
|
318
|
+
function entryPointNames(prototype: object): readonly string[] {
|
|
319
|
+
const known = ENTRY_POINTS.get(prototype);
|
|
320
|
+
if (known) return known;
|
|
321
|
+
const names = new Set<string>();
|
|
322
|
+
for (
|
|
323
|
+
let proto = prototype;
|
|
324
|
+
proto && proto !== Object.prototype;
|
|
325
|
+
proto = Object.getPrototypeOf(proto)
|
|
326
|
+
) {
|
|
327
|
+
for (const name of Object.getOwnPropertyNames(proto)) {
|
|
328
|
+
if (!/^call(?:[A-Z]\w*)?$/.test(name)) continue;
|
|
329
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
|
330
|
+
if (typeof descriptor?.value === "function") names.add(name);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const found = [...names];
|
|
334
|
+
ENTRY_POINTS.set(prototype, found);
|
|
335
|
+
return found;
|
|
336
|
+
}
|
|
337
|
+
|
|
159
338
|
export abstract class GitCommand<T> {
|
|
160
339
|
protected readonly _workingCopy: WorkingCopy;
|
|
161
340
|
private callable = true;
|
|
162
341
|
private racyCheckInstalled = false;
|
|
342
|
+
/** `--no-replace-objects` (false) or not given (undefined: config and environment decide) */
|
|
343
|
+
protected useReplaceRefsOverride?: boolean;
|
|
344
|
+
private replacementsLoad?: Promise<LoadedObjectReplacements | undefined>;
|
|
345
|
+
private reflogActionOverride?: string;
|
|
346
|
+
/** The time of this command's reflog lines, read once (git's ident_default_date). */
|
|
347
|
+
private reflogClock?: number;
|
|
348
|
+
/** The hooks this command runs (made when first asked for) */
|
|
349
|
+
private hookSession?: HookSession;
|
|
163
350
|
|
|
164
351
|
constructor(workingCopy: WorkingCopy) {
|
|
165
352
|
this._workingCopy = workingCopy;
|
|
353
|
+
this.installAttributesSource();
|
|
354
|
+
// a partial clone's absent objects come from its promisor remotes (unless the library
|
|
355
|
+
// user installed a fetcher of their own)
|
|
356
|
+
const promisor = promisorOf(workingCopy);
|
|
357
|
+
if (promisor && !promisor.fetcher) promisor.setFetcher(createPromisorFetcher(workingCopy));
|
|
358
|
+
this.releaseHooksAfterCalls();
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Each entry point of the command (`call`, `callText`, ...) puts back the ref store's
|
|
363
|
+
* reference-transaction hook when it ends, whatever the outcome.
|
|
364
|
+
*/
|
|
365
|
+
private releaseHooksAfterCalls(): void {
|
|
366
|
+
const self = this as unknown as Record<string, unknown>;
|
|
367
|
+
for (const name of entryPointNames(Object.getPrototypeOf(this))) {
|
|
368
|
+
const method = self[name];
|
|
369
|
+
if (typeof method !== "function") continue;
|
|
370
|
+
self[name] = (...args: unknown[]) => {
|
|
371
|
+
let result: unknown;
|
|
372
|
+
try {
|
|
373
|
+
result = (method as (...a: unknown[]) => unknown).apply(this, args);
|
|
374
|
+
} catch (error) {
|
|
375
|
+
this.releaseRefTransactionHook();
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
if (result && typeof (result as Promise<unknown>).finally === "function") {
|
|
379
|
+
return (result as Promise<unknown>).finally(() => this.releaseRefTransactionHook());
|
|
380
|
+
}
|
|
381
|
+
this.releaseRefTransactionHook();
|
|
382
|
+
return result;
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Runs `enter` as each entry point of the command (`call`, `callText`, ...) starts; the
|
|
389
|
+
* function it returns runs when that call ends, whatever the outcome (subclasses scope
|
|
390
|
+
* state to their calls with it: a transport command's promisor fetcher).
|
|
391
|
+
*/
|
|
392
|
+
protected aroundEntryPoints(enter: () => (() => void) | undefined): void {
|
|
393
|
+
const self = this as unknown as Record<string, unknown>;
|
|
394
|
+
for (const name of entryPointNames(Object.getPrototypeOf(this))) {
|
|
395
|
+
const method = self[name];
|
|
396
|
+
if (typeof method !== "function") continue;
|
|
397
|
+
self[name] = (...args: unknown[]) => {
|
|
398
|
+
const leave = enter();
|
|
399
|
+
let result: unknown;
|
|
400
|
+
try {
|
|
401
|
+
result = (method as (...a: unknown[]) => unknown).apply(this, args);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
leave?.();
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
if (leave && result && typeof (result as Promise<unknown>).finally === "function") {
|
|
407
|
+
return (result as Promise<unknown>).finally(leave);
|
|
408
|
+
}
|
|
409
|
+
leave?.();
|
|
410
|
+
return result;
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Lets git's content filter resolve an attribute source (`$GIT_ATTR_SOURCE`, `attr.tree`)
|
|
417
|
+
* with git's revision syntax over this repository.
|
|
418
|
+
*/
|
|
419
|
+
private installAttributesSource(): void {
|
|
420
|
+
let worktree: Worktree | undefined;
|
|
421
|
+
try {
|
|
422
|
+
worktree = this._workingCopy.worktree;
|
|
423
|
+
} catch {
|
|
424
|
+
// a bare repository's working copy refuses its worktree
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const filter = worktree?.contentFilter as
|
|
428
|
+
| { setAttributesSourceResolver?: (resolve: AttributesSourceResolver) => void }
|
|
429
|
+
| undefined;
|
|
430
|
+
if (!filter?.setAttributesSourceResolver || !this._workingCopy.history) return;
|
|
431
|
+
filter.setAttributesSourceResolver(attributesSourceResolver(() => this.revisionResolver()));
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The hooks this command runs (git's `run_hooks_opt`), through the host environment's
|
|
436
|
+
* `hookRunner`; with none, no hook runs.
|
|
437
|
+
*/
|
|
438
|
+
protected get hooks(): HookSession {
|
|
439
|
+
if (!this.hookSession) this.hookSession = new HookSession(this._workingCopy);
|
|
440
|
+
return this.hookSession;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Reads the legacy remote `name` (`$GIT_COMMON_DIR/remotes/<name>`, then `branches/<name>`)
|
|
445
|
+
* as git 2.x's `remote_get` does before it looks the remote up, so this working copy's
|
|
446
|
+
* `RemoteConfigStore`s see it (see `loadLegacyRemote`); nothing under git 3.0.
|
|
447
|
+
*
|
|
448
|
+
* @returns what git prints on stderr reading them, for this command's compatibility
|
|
449
|
+
*/
|
|
450
|
+
protected async loadLegacyRemote(name: string): Promise<string[]> {
|
|
451
|
+
return (await loadLegacyRemote(this._workingCopy, name, this.hooks.compatibility)).messages;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Runs this command's hooks in another command's session: a command that runs another
|
|
456
|
+
* (merge committing, rebase picking) gathers the output of both in one place. With `env`,
|
|
457
|
+
* this command's hooks also get those variables, as the hooks of a git command git runs as
|
|
458
|
+
* a child process with them set (a sequencer's `git commit` with GIT_REFLOG_ACTION).
|
|
459
|
+
*/
|
|
460
|
+
shareHooksOf(source: GitCommand<unknown>, env?: Record<string, string>): this {
|
|
461
|
+
this.hookSession = env ? source.hooks.withEnv(env) : source.hooks;
|
|
462
|
+
return this;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* What the hooks this command ran wrote, in order, with git's hints about hooks it ignored
|
|
467
|
+
* (`advice.ignoredHook`): git relays all of it on its stderr (a hook's stdout included,
|
|
468
|
+
* except for the hooks whose stdout git keeps apart). Empty when no hook ran.
|
|
469
|
+
*/
|
|
470
|
+
getHookOutput(): string {
|
|
471
|
+
return this.hookSession?.output ?? "";
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** What the hooks whose stdout git keeps on its own stdout (pre-push) wrote there. */
|
|
475
|
+
getHookStdout(): string {
|
|
476
|
+
return this.hookSession?.stdout ?? "";
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* The action named in the reflog lines this command writes, in place of its own (git's
|
|
481
|
+
* `GIT_REFLOG_ACTION`): `git pull` runs its merge as `pull`, so the line reads
|
|
482
|
+
* `pull: Fast-forward`. Each command uses it where git does: as the whole message of
|
|
483
|
+
* `checkout`, as the prefix of `commit`, `merge`, `fetch`, `rebase`, `cherry-pick`.
|
|
484
|
+
*/
|
|
485
|
+
setReflogAction(action: string): this {
|
|
486
|
+
this.checkCallable();
|
|
487
|
+
this.reflogActionOverride = action;
|
|
488
|
+
return this;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** The reflog action set with {@link setReflogAction}, else `fallback`. */
|
|
492
|
+
protected reflogAction(fallback: string): string {
|
|
493
|
+
return this.reflogActionOverride ?? fallback;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** Whether {@link setReflogAction} named an action. */
|
|
497
|
+
protected hasReflogAction(): boolean {
|
|
498
|
+
return this.reflogActionOverride !== undefined;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* A reflog line's options: `message` with `who` (a commit's committer) as its identity,
|
|
503
|
+
* else git's committer ident from the environment and configuration, at the time this
|
|
504
|
+
* command first asked for a line.
|
|
505
|
+
*/
|
|
506
|
+
protected reflogLine(message: string, who?: PersonIdent): RefLogOptions {
|
|
507
|
+
return reflogLine(this._workingCopy, message, who, this.clock());
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* The clock of this command's identities and reflog lines, in seconds: read once per
|
|
512
|
+
* command (a rebase's finish logs the branch and HEAD at one time, as git's process reads
|
|
513
|
+
* its default date once), and again where git resets it ({@link resetClock}).
|
|
514
|
+
*/
|
|
515
|
+
protected clock(): number {
|
|
516
|
+
this.reflogClock ??= Math.floor(Date.now() / 1000);
|
|
517
|
+
return this.reflogClock;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* git's `reset_ident_date()`: the clock read again, for the commit about to be made and
|
|
522
|
+
* the lines after it (the sequencer does this before each pick).
|
|
523
|
+
*/
|
|
524
|
+
protected resetClock(): number {
|
|
525
|
+
this.reflogClock = Math.floor(Date.now() / 1000);
|
|
526
|
+
return this.reflogClock;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* The committer of a commit (or tagger of a tag) this command makes, as git resolves it
|
|
531
|
+
* (`resolveCommitterIdent`): `GIT_COMMITTER_*`, `committer.*`, `user.*`, the clock;
|
|
532
|
+
* `fallback`'s name and email (an identity given explicitly) where git would guess them;
|
|
533
|
+
* never `fallback`'s date.
|
|
534
|
+
*/
|
|
535
|
+
protected resolveCommitter(fallback?: Pick<PersonIdent, "name" | "email">): PersonIdent {
|
|
536
|
+
return committerIdentOf(this._workingCopy, { now: this.clock(), fallback });
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* The author of a commit this command makes, as git resolves it (`resolveAuthorIdent`):
|
|
541
|
+
* `GIT_AUTHOR_*`, `author.*`, `user.*`, the clock; `fallback`'s name and email where git
|
|
542
|
+
* would guess them.
|
|
543
|
+
*/
|
|
544
|
+
protected resolveAuthor(fallback?: Pick<PersonIdent, "name" | "email">): PersonIdent {
|
|
545
|
+
return authorIdentOf(this._workingCopy, { now: this.clock(), fallback });
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* An identity named explicitly (`--author=<who>`), dated as git dates `role` now; its
|
|
550
|
+
* name and email without crud, as git writes them.
|
|
551
|
+
*/
|
|
552
|
+
protected datedIdent(role: IdentRole, who: { name: string; email: string }): PersonIdent {
|
|
553
|
+
const date = resolveIdentDate(role, hostEnvironmentOf(this._workingCopy), this.clock());
|
|
554
|
+
return { name: withoutCrud(who.name), email: withoutCrud(who.email), ...date };
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** What git's notes code reads and writes through this command (`notes-support.ts`). */
|
|
558
|
+
protected notesContext(): NotesContext {
|
|
559
|
+
const tags = this.tagsStore;
|
|
560
|
+
return {
|
|
561
|
+
workingCopy: this._workingCopy,
|
|
562
|
+
blobs: this.blobs,
|
|
563
|
+
trees: this.trees,
|
|
564
|
+
commits: this.commits,
|
|
565
|
+
refs: this.refsStore,
|
|
566
|
+
...(tags ? { tags } : {}),
|
|
567
|
+
author: () => this.resolveAuthor(),
|
|
568
|
+
committer: () => this.resolveCommitter(),
|
|
569
|
+
reflogLine: (message) => this.reflogLine(message),
|
|
570
|
+
objectFormat: this.objectFormat,
|
|
571
|
+
// a full object id is itself (get_oid_basic); the resolver would also look for refs
|
|
572
|
+
// spelled as it, for an ambiguity warning the notes commands do not print — a ref
|
|
573
|
+
// lookup per line of `git notes copy --stdin` that costs most of its time
|
|
574
|
+
resolve: (name) =>
|
|
575
|
+
name.length === this.objectFormat.hexLength && /^[0-9a-fA-F]+$/.test(name)
|
|
576
|
+
? Promise.resolve(name.toLowerCase())
|
|
577
|
+
: this.revisionResolver()
|
|
578
|
+
.resolve(name)
|
|
579
|
+
.catch(() => undefined),
|
|
580
|
+
};
|
|
166
581
|
}
|
|
167
582
|
|
|
168
583
|
// ============ Store Accessors ============
|
|
169
584
|
|
|
170
585
|
/**
|
|
171
|
-
*
|
|
586
|
+
* The repository's object format (`extensions.objectFormat`): the length of its ids, its
|
|
587
|
+
* null id, empty tree and empty blob. SHA-1 unless the repository is SHA-256.
|
|
172
588
|
*/
|
|
173
|
-
protected get
|
|
589
|
+
protected get objectFormat(): ObjectFormat {
|
|
590
|
+
return objectFormatOf(this._workingCopy.history);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/** Whether `id` is a full lowercase hex id of the repository's format (40, or 64 digits) */
|
|
594
|
+
protected isFullObjectId(id: string): boolean {
|
|
595
|
+
return id.length === this.objectFormat.hexLength && /^[0-9a-f]+$/.test(id);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Whether this command reads objects through replace refs and grafts (see {@link commits}).
|
|
600
|
+
* git applies them to every object read but those of gc, prune, pack-objects, upload-pack,
|
|
601
|
+
* index-pack, fsck and commit-graph; the commands doing those override this to read the
|
|
602
|
+
* objects as stored.
|
|
603
|
+
*/
|
|
604
|
+
protected readsReplacedObjects(): boolean {
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/** The stored objects, as {@link storedCommits} reads commits. */
|
|
609
|
+
private historyOf(): NonNullable<WorkingCopy["history"]> {
|
|
174
610
|
if (!this._workingCopy.history) {
|
|
175
611
|
throw new Error("WorkingCopy.history is required for commands");
|
|
176
612
|
}
|
|
177
|
-
return this._workingCopy.history
|
|
613
|
+
return this._workingCopy.history;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/** Whether an object was read through the replacements (git then read them, and printed) */
|
|
617
|
+
private replacementsRead = false;
|
|
618
|
+
|
|
619
|
+
/** The views of the stored objects through the replacements, made once per command */
|
|
620
|
+
private replacedViews?: {
|
|
621
|
+
blobs: Blobs;
|
|
622
|
+
trees: CommandTrees;
|
|
623
|
+
commits: CommandCommits;
|
|
624
|
+
tags?: CommandTags;
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
private views() {
|
|
628
|
+
if (!this.replacedViews) {
|
|
629
|
+
const history = this.historyOf();
|
|
630
|
+
const load = () => {
|
|
631
|
+
this.replacementsRead = true;
|
|
632
|
+
return this.objectReplacements();
|
|
633
|
+
};
|
|
634
|
+
const storedTrees = wrapTrees(history.trees as unknown as Trees);
|
|
635
|
+
const trees = createReplacedTrees(storedTrees, load);
|
|
636
|
+
const rawTags = history.tags ? wrapTags(history.tags as unknown as Tags) : undefined;
|
|
637
|
+
const tags = rawTags ? createReplacedTags(rawTags, load) : undefined;
|
|
638
|
+
this.replacedViews = {
|
|
639
|
+
blobs: createReplacedBlobs(history.blobs as unknown as Blobs, load),
|
|
640
|
+
// the legacy names read through the view too
|
|
641
|
+
trees: overlayMethods(trees, {
|
|
642
|
+
loadTree: async function* (id: ObjectId): AsyncIterable<TreeEntry> {
|
|
643
|
+
const entries = await trees.load(id);
|
|
644
|
+
if (entries) yield* entries;
|
|
645
|
+
},
|
|
646
|
+
}),
|
|
647
|
+
commits: createReplacedCommits(
|
|
648
|
+
wrapCommits(history.commits as unknown as Commits),
|
|
649
|
+
load,
|
|
650
|
+
) as CommandCommits,
|
|
651
|
+
...(tags
|
|
652
|
+
? { tags: overlayMethods(tags, { loadTag: (id: ObjectId) => tags.load(id) }) }
|
|
653
|
+
: {}),
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
return this.replacedViews;
|
|
178
657
|
}
|
|
179
658
|
|
|
180
659
|
/**
|
|
181
|
-
* Access
|
|
660
|
+
* Access blob storage: a blob replaced by `refs/replace/<id>` reads as its replacement,
|
|
661
|
+
* unless this command reads the objects as stored ({@link readsReplacedObjects}).
|
|
182
662
|
*/
|
|
183
|
-
protected get
|
|
184
|
-
|
|
185
|
-
|
|
663
|
+
protected get blobs(): Blobs {
|
|
664
|
+
const blobs = this.readsReplacedObjects() ? this.views().blobs : this.storedBlobs;
|
|
665
|
+
const shared = this.sharedBlobs;
|
|
666
|
+
if (!shared || !blobs.open) return blobs;
|
|
667
|
+
if (this.sharedBlobsView?.of !== blobs) {
|
|
668
|
+
this.sharedBlobsView = { of: blobs, view: sharingBlobs(blobs, shared) };
|
|
186
669
|
}
|
|
187
|
-
return
|
|
670
|
+
return this.sharedBlobsView.view;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/** Blob contents read lately by the commands sharing reads ({@link shareReadsOf}) */
|
|
674
|
+
private sharedBlobs?: SharedBlobs;
|
|
675
|
+
private sharedBlobsView?: { of: Blobs; view: Blobs };
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Access tree storage: a tree replaced by `refs/replace/<id>` reads as its replacement,
|
|
679
|
+
* unless this command reads the objects as stored ({@link readsReplacedObjects}).
|
|
680
|
+
*/
|
|
681
|
+
protected get trees(): CommandTrees {
|
|
682
|
+
return this.readsReplacedObjects() ? this.views().trees : this.storedTrees;
|
|
188
683
|
}
|
|
189
684
|
|
|
190
685
|
/**
|
|
191
|
-
* Access commit storage
|
|
686
|
+
* Access commit storage, as git reads commits: a commit replaced by `refs/replace/<id>`
|
|
687
|
+
* reads as its replacement (keeping its id), a commit in `info/grafts` with its grafted
|
|
688
|
+
* parents, a shallow commit with none; merge bases, ancestry and walks follow them (see
|
|
689
|
+
* `createReplacedCommits`). Without replace refs or grafts, or in a command that reads the
|
|
690
|
+
* objects as stored ({@link readsReplacedObjects}), it is the store itself.
|
|
192
691
|
*/
|
|
193
692
|
protected get commits(): CommandCommits {
|
|
194
|
-
|
|
195
|
-
|
|
693
|
+
return this.readsReplacedObjects() ? this.views().commits : this.storedCommits;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** The blobs as stored, without replace refs. */
|
|
697
|
+
protected get storedBlobs(): Blobs {
|
|
698
|
+
return this.historyOf().blobs as unknown as Blobs;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/** The trees as stored, without replace refs. */
|
|
702
|
+
protected get storedTrees(): CommandTrees {
|
|
703
|
+
return wrapTrees(this.historyOf().trees as unknown as Trees);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/** The commits as stored, without replace refs or grafts. */
|
|
707
|
+
protected get storedCommits(): CommandCommits {
|
|
708
|
+
return wrapCommits(this.historyOf().commits as unknown as Commits);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Whether replace refs apply to this command's history walks: `false` is git's
|
|
713
|
+
* `--no-replace-objects`. Unset, `core.useReplaceRefs` (default true) decides, and
|
|
714
|
+
* `GIT_NO_REPLACE_OBJECTS` in the host environment turns them off.
|
|
715
|
+
*/
|
|
716
|
+
setUseReplaceRefs(use: boolean): this {
|
|
717
|
+
this.checkCallable();
|
|
718
|
+
this.useReplaceRefsOverride = use;
|
|
719
|
+
return this;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/** Whether replace refs apply (see {@link setUseReplaceRefs}). */
|
|
723
|
+
protected useReplaceRefs(): boolean {
|
|
724
|
+
if (this.useReplaceRefsOverride !== undefined) return this.useReplaceRefsOverride;
|
|
725
|
+
if (hostEnvironmentOf(this._workingCopy)?.noReplaceObjects) return false;
|
|
726
|
+
const value = this._workingCopy.config
|
|
727
|
+
? RemoteConfigStore.from(this._workingCopy).value("core.useReplaceRefs")
|
|
728
|
+
: undefined;
|
|
729
|
+
return parseGitBool(value) ?? true;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Where a relative `GIT_GRAFT_FILE` is read from: the worktree top (the git directory when
|
|
734
|
+
* `core.bare`), as the host names it (the working copy's `hostGitDir`), where git's setup
|
|
735
|
+
* has changed to before opening the file; undefined when the host path is unknown.
|
|
736
|
+
*/
|
|
737
|
+
protected graftFileBase(): GraftFileBase | undefined {
|
|
738
|
+
const gitDir = (this._workingCopy.config as { hostGitDir?: string } | undefined)?.hostGitDir;
|
|
739
|
+
if (gitDir === undefined) return undefined;
|
|
740
|
+
const bare = this._workingCopy.config
|
|
741
|
+
? parseGitBool(RemoteConfigStore.from(this._workingCopy).value("core.bare"))
|
|
742
|
+
: undefined;
|
|
743
|
+
return { dir: graftFileBaseDir(gitDir, bare) };
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* The directory git runs in, as the host names it: the worktree top (the git directory when
|
|
748
|
+
* `core.bare`), where git reads a relative path from the configuration
|
|
749
|
+
* (`fetch.fsck.skipList`); from the working copy's `hostGitDir`, else from the repository's
|
|
750
|
+
* FilesApi root. Undefined when the host path is unknown.
|
|
751
|
+
*/
|
|
752
|
+
protected async hostWorkingDir(): Promise<string | undefined> {
|
|
753
|
+
const known = this.graftFileBase()?.dir;
|
|
754
|
+
if (known !== undefined) return known;
|
|
755
|
+
const gitDir = await this.hooks.hostGitDir({ real: false }).catch(() => undefined);
|
|
756
|
+
if (gitDir === undefined) return undefined;
|
|
757
|
+
const bare = this._workingCopy.config
|
|
758
|
+
? parseGitBool(RemoteConfigStore.from(this._workingCopy).value("core.bare"))
|
|
759
|
+
: undefined;
|
|
760
|
+
return graftFileBaseDir(gitDir, bare);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/** The commits as git's history walks read them: {@link commits}. */
|
|
764
|
+
protected get walkCommits(): CommandCommits {
|
|
765
|
+
return this.commits;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* The replace refs and grafts this command's reads apply, read once; undefined when there
|
|
770
|
+
* are none (or they cannot be read).
|
|
771
|
+
*/
|
|
772
|
+
protected objectReplacements(): Promise<LoadedObjectReplacements | undefined> {
|
|
773
|
+
return this.loadedReplacements().then((r) => (hasReplacements(r) ? r : undefined));
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* The replace refs and grafts as read, with the messages git prints while reading them
|
|
778
|
+
* (`bad graft data`, `bad replace ref name`), read once.
|
|
779
|
+
*/
|
|
780
|
+
protected loadedReplacements(): Promise<LoadedObjectReplacements | undefined> {
|
|
781
|
+
if (!this.replacementsLoad) {
|
|
782
|
+
const environment = hostEnvironmentOf(this._workingCopy);
|
|
783
|
+
const replaceRefBase = environment?.replaceRefBase;
|
|
784
|
+
// GIT_GRAFT_FILE: that file is read in place of info/grafts (an empty one is a grafts
|
|
785
|
+
// file all the same: git gives its deprecation advice)
|
|
786
|
+
const readGraftFile = graftFileReader(environment, this.graftFileBase());
|
|
787
|
+
this.replacementsLoad = loadObjectReplacements({
|
|
788
|
+
refs: this.refsStore,
|
|
789
|
+
useReplaceRefs: this.useReplaceRefs(),
|
|
790
|
+
...(replaceRefBase !== undefined ? { replaceRefBase } : {}),
|
|
791
|
+
...(readGraftFile ? { readGraftFile } : {}),
|
|
792
|
+
}).catch(() => undefined);
|
|
196
793
|
}
|
|
197
|
-
return
|
|
794
|
+
return this.replacementsLoad;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* What git prints on stderr while it reads the replace refs and grafts, once this command
|
|
799
|
+
* has read an object through them (`git log`, `git rev-parse HEAD~1`; not `git rev-parse
|
|
800
|
+
* HEAD`, which reads no object): `warning: bad replace ref name: <name>`, the advice that
|
|
801
|
+
* `info/grafts` is deprecated (unless `advice.graftFileDeprecated` is false), `error: bad
|
|
802
|
+
* graft data: <line>`. The advice is worded as git 2.5x words it.
|
|
803
|
+
*/
|
|
804
|
+
async replacementMessages(): Promise<string[]> {
|
|
805
|
+
if (!this.replacementsRead) return [];
|
|
806
|
+
const loaded = await this.loadedReplacements();
|
|
807
|
+
if (!loaded) return [];
|
|
808
|
+
const advice =
|
|
809
|
+
loaded.graftFile &&
|
|
810
|
+
parseGitBool(
|
|
811
|
+
this._workingCopy.config
|
|
812
|
+
? RemoteConfigStore.from(this._workingCopy).value("advice.graftFileDeprecated")
|
|
813
|
+
: undefined,
|
|
814
|
+
) !== false
|
|
815
|
+
? GRAFT_FILE_ADVICE
|
|
816
|
+
: [];
|
|
817
|
+
return [...loaded.replaceMessages, ...advice, ...loaded.graftMessages];
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* The error lines git prints on stderr when it prepares the object database and reads the
|
|
822
|
+
* repository's alternates (odb.c: `error: object directory <path> does not exist; check
|
|
823
|
+
* .git/objects/info/alternates`, `error: unable to normalize alternate object path: <path>`,
|
|
824
|
+
* `error: <path>: ignoring alternate object stores, nesting too deep`), in git's order; empty
|
|
825
|
+
* when the alternates read cleanly. git prints them once per process, when it first looks up
|
|
826
|
+
* an object (status, log, diff, fsck, gc, fetch, push, commit all do), so a caller printing a
|
|
827
|
+
* command's stderr prints these once, first. Where git runs child git processes it repeats
|
|
828
|
+
* them per child (gc's repack and prune, 2.5x fsck's `refs verify` and index-pack checks,
|
|
829
|
+
* commit), and 2.43's `rev-parse HEAD` reads no object and prints none: ours are read with
|
|
830
|
+
* the repository, once.
|
|
831
|
+
*
|
|
832
|
+
* This is the channel for these lines: commands whose results have no stderr of their own
|
|
833
|
+
* (status, log, diff, commit, fetch, push, clone, ...) leave them here for the caller to print
|
|
834
|
+
* first. Where a result carries git's stderr they are folded in as well, first and once:
|
|
835
|
+
* `FsckResult.errorOutput`/`findings` and `GcResult.errors`.
|
|
836
|
+
*/
|
|
837
|
+
alternatesErrors(): string[] {
|
|
838
|
+
return [...(this._workingCopy.history?.objects?.alternates?.errors ?? [])];
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/** Marks that this command read objects through the replacements (see replacementMessages). */
|
|
842
|
+
protected markReplacementsRead(): void {
|
|
843
|
+
this.replacementsRead = true;
|
|
198
844
|
}
|
|
199
845
|
|
|
200
846
|
/**
|
|
201
|
-
* Access tag storage
|
|
847
|
+
* Access tag storage: an annotated tag replaced by `refs/replace/<id>` reads as its
|
|
848
|
+
* replacement, unless this command reads the objects as stored.
|
|
202
849
|
* Named tagsStore to avoid conflict with command properties.
|
|
203
850
|
*/
|
|
204
851
|
protected get tagsStore(): CommandTags | undefined {
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
const tags = this._workingCopy.history.tags as unknown as Tags | undefined;
|
|
852
|
+
if (this.readsReplacedObjects()) return this.views().tags;
|
|
853
|
+
const tags = this.historyOf().tags as unknown as Tags | undefined;
|
|
209
854
|
return tags ? wrapTags(tags) : undefined;
|
|
210
855
|
}
|
|
211
856
|
|
|
@@ -217,7 +862,223 @@ export abstract class GitCommand<T> {
|
|
|
217
862
|
if (!this._workingCopy.history) {
|
|
218
863
|
throw new Error("WorkingCopy.history is required for commands");
|
|
219
864
|
}
|
|
220
|
-
|
|
865
|
+
const refs = wrapRefs(this._workingCopy.history.refs as unknown as Refs);
|
|
866
|
+
this.installRefTransactionHook(refs);
|
|
867
|
+
return refs;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Deletes `names` whatever their values, as git's `delete_refs` (branch -d, tag -d, remote
|
|
872
|
+
* prune): on a store with `removeAll`, one transaction for them all (git 2.5x), or as git
|
|
873
|
+
* 2.43's files backend when the hooks follow 2.43 (their reference-transaction calls and
|
|
874
|
+
* a failure's outcome differ); else one by one. Returns the names that no longer exist
|
|
875
|
+
* and the failure, if any (git reports it after the others are deleted).
|
|
876
|
+
*/
|
|
877
|
+
protected async removeRefsAsGit(
|
|
878
|
+
names: string[],
|
|
879
|
+
message?: string,
|
|
880
|
+
): Promise<{ removed: string[]; error?: unknown }> {
|
|
881
|
+
const refs = this.refsStore;
|
|
882
|
+
let error: unknown;
|
|
883
|
+
try {
|
|
884
|
+
if (refs.removeAll) {
|
|
885
|
+
await refs.removeAll(names, {
|
|
886
|
+
legacy: this.hooks.compatibility === "2.43",
|
|
887
|
+
...(message !== undefined ? { message } : {}),
|
|
888
|
+
});
|
|
889
|
+
} else {
|
|
890
|
+
for (const name of names) {
|
|
891
|
+
try {
|
|
892
|
+
await refs.delete(name, { deleteRefs: true });
|
|
893
|
+
} catch (e) {
|
|
894
|
+
error ??= e;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
} catch (e) {
|
|
899
|
+
error = e;
|
|
900
|
+
}
|
|
901
|
+
const removed: string[] = [];
|
|
902
|
+
for (const name of names) if (!(await refs.has(name).catch(() => true))) removed.push(name);
|
|
903
|
+
return error === undefined ? { removed } : { removed, error };
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/** The reference-transaction hook this command installs on its ref store (made once). */
|
|
907
|
+
private refTransactionHook?: RefTransactionHook;
|
|
908
|
+
/** The store it is installed on, and the hook that was there before (put back at the end) */
|
|
909
|
+
private refTransactionInstalled?: {
|
|
910
|
+
store: TransactionHookStore;
|
|
911
|
+
previous: RefTransactionHook | undefined;
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* git's reference-transaction hook (see {@link refTransactionHookOf}) on a ref store that
|
|
916
|
+
* supports it (the files store), while this command runs: the hook that was there before
|
|
917
|
+
* is put back when the command's `call` ends ({@link releaseRefTransactionHook}), so a
|
|
918
|
+
* later write never routes its output to this command. A command without hooks (no
|
|
919
|
+
* runner) removes a command's hook left there, and leaves any other hook in place.
|
|
920
|
+
*/
|
|
921
|
+
private installRefTransactionHook(refs: Refs): void {
|
|
922
|
+
const store = refs as TransactionHookStore;
|
|
923
|
+
if (!store.setTransactionHook) return;
|
|
924
|
+
if (!this.hooks.enabled) {
|
|
925
|
+
const current = store.getTransactionHook?.();
|
|
926
|
+
if (current && commandTransactionHooks.has(current)) store.setTransactionHook(undefined);
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
if (!this.refTransactionHook) {
|
|
930
|
+
const env = this.refTransactionHookEnv();
|
|
931
|
+
const plain = refTransactionHookOf(this.hooks, env ? { env } : {});
|
|
932
|
+
// a git child process with variables of its own (withRefTransactionEnv) runs it with them
|
|
933
|
+
this.refTransactionHook = (state, updates, context) => {
|
|
934
|
+
const extra = this.refTransactionExtraEnv;
|
|
935
|
+
if (!extra) return plain(state, updates, context);
|
|
936
|
+
return refTransactionHookOf(this.hooks, { env: { ...(env ?? {}), ...extra } })(
|
|
937
|
+
state,
|
|
938
|
+
updates,
|
|
939
|
+
context,
|
|
940
|
+
);
|
|
941
|
+
};
|
|
942
|
+
commandTransactionHooks.add(this.refTransactionHook);
|
|
943
|
+
}
|
|
944
|
+
if (!this.refTransactionInstalled) {
|
|
945
|
+
this.refTransactionInstalled = { store, previous: store.getTransactionHook?.() };
|
|
946
|
+
}
|
|
947
|
+
store.setTransactionHook(this.refTransactionHook);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/** Variables the reference-transaction hook gets for now (see {@link withRefTransactionEnv}) */
|
|
951
|
+
private refTransactionExtraEnv?: Record<string, string>;
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* Runs `body` with `env` added to the reference-transaction hook's variables: the ref
|
|
955
|
+
* updates of a git command git runs as a child process with variables set (a sequencer's
|
|
956
|
+
* `git commit` with GIT_REFLOG_ACTION).
|
|
957
|
+
*/
|
|
958
|
+
protected async withRefTransactionEnv<T>(
|
|
959
|
+
env: Record<string, string>,
|
|
960
|
+
body: () => Promise<T>,
|
|
961
|
+
): Promise<T> {
|
|
962
|
+
const previous = this.refTransactionExtraEnv;
|
|
963
|
+
this.refTransactionExtraEnv = { ...(previous ?? {}), ...env };
|
|
964
|
+
try {
|
|
965
|
+
return await body();
|
|
966
|
+
} finally {
|
|
967
|
+
this.refTransactionExtraEnv = previous;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Variables git's command exports for every hook it runs, the reference-transaction hook
|
|
973
|
+
* included (merge's GIT_REFLOG_ACTION); none by default.
|
|
974
|
+
*/
|
|
975
|
+
protected refTransactionHookEnv(): Record<string, string> | undefined {
|
|
976
|
+
return undefined;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/** The post-index-change hook this command installs on its staging (made once). */
|
|
980
|
+
private indexWriteHook?: () => Promise<void>;
|
|
981
|
+
/** The staging it is installed on, and the hook that was there before (put back at the end) */
|
|
982
|
+
private indexWriteInstalled?: {
|
|
983
|
+
staging: Staging;
|
|
984
|
+
previous: (() => Promise<void>) | undefined;
|
|
985
|
+
};
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* git's post-index-change hook (see {@link postIndexChangeHookOf}) after each index write
|
|
989
|
+
* of this command's staging (one that supports it), while the command runs: the hook
|
|
990
|
+
* that was there before is put back when its `call` ends. Without a hook runner, a
|
|
991
|
+
* command's hook left there is removed.
|
|
992
|
+
*/
|
|
993
|
+
private installIndexWriteHook(staging: Staging): void {
|
|
994
|
+
if (!staging.setWriteHook) return;
|
|
995
|
+
if (!this.hooks.enabled) {
|
|
996
|
+
const current = staging.getWriteHook?.();
|
|
997
|
+
if (current && commandIndexWriteHooks.has(current)) staging.setWriteHook(undefined);
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (this.indexWriteInstalled?.staging === staging) {
|
|
1001
|
+
if (staging.getWriteHook?.() !== this.indexWriteHook) {
|
|
1002
|
+
staging.setWriteHook(this.indexWriteHook);
|
|
1003
|
+
}
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
if (!this.indexWriteHook) {
|
|
1007
|
+
const run = postIndexChangeHookOf(this.hooks, staging);
|
|
1008
|
+
this.indexWriteRun = run;
|
|
1009
|
+
this.indexWriteHook = async () => {
|
|
1010
|
+
const scope = this.indexWriteScope;
|
|
1011
|
+
if (!scope) return run();
|
|
1012
|
+
// one hook run for the writes of a scope (see withOneIndexWrite)
|
|
1013
|
+
if (scope.written) return;
|
|
1014
|
+
scope.written = true;
|
|
1015
|
+
if (scope.at === "first") await run();
|
|
1016
|
+
};
|
|
1017
|
+
commandIndexWriteHooks.add(this.indexWriteHook);
|
|
1018
|
+
}
|
|
1019
|
+
this.indexWriteInstalled = { staging, previous: staging.getWriteHook?.() };
|
|
1020
|
+
staging.setWriteHook(this.indexWriteHook);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/** What the installed hook runs (post-index-change with the flags marked) */
|
|
1024
|
+
private indexWriteRun?: () => Promise<void>;
|
|
1025
|
+
/** Index writes git makes once (see {@link withOneIndexWrite}) */
|
|
1026
|
+
private indexWriteScope?: { at: "first" | "last"; written: boolean };
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Runs `body` with its index writes counted as git's one write of the index: the
|
|
1030
|
+
* post-index-change hook runs once, at the first write (`first`: `commit -a`, while the
|
|
1031
|
+
* lock is held) or after `body` when it wrote (`last`: a reset that writes the index
|
|
1032
|
+
* again after updating the worktree), with every flag marked meanwhile.
|
|
1033
|
+
*/
|
|
1034
|
+
protected async withOneIndexWrite<T>(
|
|
1035
|
+
at: "first" | "last",
|
|
1036
|
+
body: () => Promise<T>,
|
|
1037
|
+
options: { holdWrites?: boolean } = {},
|
|
1038
|
+
): Promise<T> {
|
|
1039
|
+
if (this.indexWriteScope) return body();
|
|
1040
|
+
const scope = { at, written: false };
|
|
1041
|
+
this.indexWriteScope = scope;
|
|
1042
|
+
// `holdWrites`: the writes before the last one are held back, the index written once at
|
|
1043
|
+
// the end (a body that reads the index back between its writes must not hold them)
|
|
1044
|
+
const release = options.holdWrites ? this.staging.holdWrites?.() : undefined;
|
|
1045
|
+
try {
|
|
1046
|
+
const result = await body();
|
|
1047
|
+
await release?.();
|
|
1048
|
+
return result;
|
|
1049
|
+
} catch (error) {
|
|
1050
|
+
await release?.();
|
|
1051
|
+
throw error;
|
|
1052
|
+
} finally {
|
|
1053
|
+
this.indexWriteScope = undefined;
|
|
1054
|
+
if (at === "last" && scope.written) await this.indexWriteRun?.();
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/** Puts back the post-index-change hook the staging had before this command's. */
|
|
1059
|
+
private releaseIndexWriteHook(): void {
|
|
1060
|
+
const installed = this.indexWriteInstalled;
|
|
1061
|
+
if (!installed) return;
|
|
1062
|
+
this.indexWriteInstalled = undefined;
|
|
1063
|
+
const current = installed.staging.getWriteHook?.();
|
|
1064
|
+
if (current === undefined || current === this.indexWriteHook) {
|
|
1065
|
+
installed.staging.setWriteHook?.(installed.previous);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* Puts back the reference-transaction hook the store had before this command installed
|
|
1071
|
+
* its own (when its own is still the one installed), and the post-index-change hook.
|
|
1072
|
+
*/
|
|
1073
|
+
protected releaseRefTransactionHook(): void {
|
|
1074
|
+
this.releaseIndexWriteHook();
|
|
1075
|
+
const installed = this.refTransactionInstalled;
|
|
1076
|
+
if (!installed) return;
|
|
1077
|
+
this.refTransactionInstalled = undefined;
|
|
1078
|
+
const current = installed.store.getTransactionHook?.();
|
|
1079
|
+
if (current === undefined || current === this.refTransactionHook) {
|
|
1080
|
+
installed.store.setTransactionHook?.(installed.previous);
|
|
1081
|
+
}
|
|
221
1082
|
}
|
|
222
1083
|
|
|
223
1084
|
/**
|
|
@@ -230,9 +1091,73 @@ export abstract class GitCommand<T> {
|
|
|
230
1091
|
this.racyCheckInstalled = true;
|
|
231
1092
|
this.installRacyCheck(staging);
|
|
232
1093
|
}
|
|
1094
|
+
this.installIndexWriteHook(staging);
|
|
1095
|
+
this.installIndexHost(staging);
|
|
233
1096
|
return staging;
|
|
234
1097
|
}
|
|
235
1098
|
|
|
1099
|
+
/**
|
|
1100
|
+
* Gives the staging what its index file reads from the repository (`indexHostOf`: the
|
|
1101
|
+
* split and sparse index settings, the trees), once: a host already there stays (the
|
|
1102
|
+
* sparse-checkout command installs its own while it writes new patterns).
|
|
1103
|
+
*/
|
|
1104
|
+
private installIndexHost(staging: Staging): void {
|
|
1105
|
+
if (!staging.setIndexHost || staging.getIndexHost?.() !== undefined) return;
|
|
1106
|
+
staging.setIndexHost(
|
|
1107
|
+
indexHostOf(this._workingCopy, staging, () => this.historyOf().trees as unknown as Trees),
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* The index as it is on disk at the start of an index-writing command, as git reads the
|
|
1113
|
+
* index at the start of every command (`repo_read_index`): when another writer replaced
|
|
1114
|
+
* the index since this instance read or wrote it, the index is read again, unless this
|
|
1115
|
+
* instance holds edits it has not written (they would be lost), which refuses the
|
|
1116
|
+
* command with `IndexChangedError` before it touches the worktree, the index or a ref.
|
|
1117
|
+
* A staging area that cannot be outdated (no index file) is left as it is.
|
|
1118
|
+
*
|
|
1119
|
+
* @param refuseUnwritten false for a command that writes no index (`clean`): unwritten
|
|
1120
|
+
* edits are then kept and used instead of refusing
|
|
1121
|
+
*/
|
|
1122
|
+
protected async readCurrentIndex(refuseUnwritten = true): Promise<void> {
|
|
1123
|
+
const staging = this.staging;
|
|
1124
|
+
if (await staging.isOutdated()) {
|
|
1125
|
+
if (staging.hasUnwrittenChanges?.() !== false) {
|
|
1126
|
+
if (!refuseUnwritten) return;
|
|
1127
|
+
throw new IndexChangedError("index");
|
|
1128
|
+
}
|
|
1129
|
+
await staging.read();
|
|
1130
|
+
}
|
|
1131
|
+
await this.clearPresentSkipWorktree();
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* git's `clear_skip_worktree_from_present_files`, which `repo_read_index` runs on every
|
|
1136
|
+
* index read: with `core.sparseCheckout` on (and `sparse.expectFilesOutsideOfPatterns`
|
|
1137
|
+
* off), a skip-worktree entry whose path exists in the worktree loses the flag, written
|
|
1138
|
+
* with the index when the command writes it. Nothing is stat'ed outside a sparse checkout.
|
|
1139
|
+
*/
|
|
1140
|
+
protected async clearPresentSkipWorktree(): Promise<void> {
|
|
1141
|
+
// a bare repository's working copy refuses its worktree: asked without touching it
|
|
1142
|
+
if (!("worktree" in this._workingCopy)) return;
|
|
1143
|
+
const worktree = this._workingCopy.worktree;
|
|
1144
|
+
if (!worktree || !this._workingCopy.config) return;
|
|
1145
|
+
const config = RemoteConfigStore.from(this._workingCopy);
|
|
1146
|
+
if (parseGitBool(config.value("core.sparseCheckout")) !== true) return;
|
|
1147
|
+
if (parseGitBool(config.value("sparse.expectFilesOutsideOfPatterns")) === true) return;
|
|
1148
|
+
await clearSkipWorktreeFromPresentFiles(this.staging, worktree);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* The sparse checkout's patterns (`$GIT_DIR/info/sparse-checkout`, cone matching with
|
|
1153
|
+
* `core.sparseCheckoutCone`, case folded with `core.ignoreCase`) for git's
|
|
1154
|
+
* `path_in_sparse_checkout`, or undefined when `core.sparseCheckout` is off (every path
|
|
1155
|
+
* is in the checkout).
|
|
1156
|
+
*/
|
|
1157
|
+
protected async sparseCheckoutPatterns(): Promise<SparseCheckoutPatterns | undefined> {
|
|
1158
|
+
return readSparseCheckoutPatterns(this._workingCopy);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
236
1161
|
/**
|
|
237
1162
|
* Gives the staging git's racy-git smudging for its writes: an entry whose mtime second is
|
|
238
1163
|
* not older than the index file and whose content changed behind a matching stat is
|
|
@@ -278,6 +1203,18 @@ export abstract class GitCommand<T> {
|
|
|
278
1203
|
return this._workingCopy.worktree;
|
|
279
1204
|
}
|
|
280
1205
|
|
|
1206
|
+
/**
|
|
1207
|
+
* Runs `fn` as one worktree operation (`Worktree.batch`, which nests): the configuration,
|
|
1208
|
+
* `info/attributes` and the `.gitattributes` files are read once for every path the
|
|
1209
|
+
* command converts, filters or checks, instead of once per path (each attributes lookup
|
|
1210
|
+
* outside an operation opens one of its own). Without a worktree, `fn` runs as it is.
|
|
1211
|
+
* `options` go to the content filter's operation (`keepAttributes`).
|
|
1212
|
+
*/
|
|
1213
|
+
protected inOneOperation<T>(fn: () => Promise<T>, options?: OperationOptions): Promise<T> {
|
|
1214
|
+
const worktree = "worktree" in this._workingCopy ? this._workingCopy.worktree : undefined;
|
|
1215
|
+
return worktree?.batch ? worktree.batch(fn, options) : fn();
|
|
1216
|
+
}
|
|
1217
|
+
|
|
281
1218
|
/**
|
|
282
1219
|
* Get the WorkingCopy.
|
|
283
1220
|
*/
|
|
@@ -292,22 +1229,42 @@ export abstract class GitCommand<T> {
|
|
|
292
1229
|
abstract call(): Promise<T>;
|
|
293
1230
|
|
|
294
1231
|
/**
|
|
295
|
-
* Verify the command hasn't been called yet
|
|
1232
|
+
* Verify the command hasn't been called yet, and that the configuration loads as git
|
|
1233
|
+
* loads it (see {@link checkConfigOnLoad}). Every `call()` starts here, before it reads or
|
|
1234
|
+
* writes anything, so a command git would refuse to start changes nothing.
|
|
296
1235
|
* @throws Error if command was already executed
|
|
1236
|
+
* @throws InvalidConfigError if git would die loading the configuration
|
|
297
1237
|
*/
|
|
298
1238
|
protected checkCallable(): void {
|
|
299
1239
|
if (!this.callable) {
|
|
300
1240
|
throw new Error(`Command ${this.constructor.name} has already been called`);
|
|
301
1241
|
}
|
|
1242
|
+
this.checkConfigOnLoad();
|
|
302
1243
|
}
|
|
303
1244
|
|
|
304
|
-
/**
|
|
305
|
-
* Mark command as no longer callable.
|
|
306
|
-
*/
|
|
1245
|
+
/** Mark command as no longer callable (or callable again). */
|
|
307
1246
|
protected setCallable(value: boolean): void {
|
|
308
1247
|
this.callable = value;
|
|
309
1248
|
}
|
|
310
1249
|
|
|
1250
|
+
/**
|
|
1251
|
+
* What every git command dies on before it runs, `status` included: configuration git's
|
|
1252
|
+
* `git_default_config` refuses (an unknown `core.disambiguate`, see {@link configLoadError}).
|
|
1253
|
+
* Checked each time, so a setter run before the configuration changed does not excuse
|
|
1254
|
+
* the `call()` after it.
|
|
1255
|
+
*
|
|
1256
|
+
* @throws InvalidConfigError with git's `error:` and `fatal:` lines
|
|
1257
|
+
*/
|
|
1258
|
+
protected checkConfigOnLoad(): void {
|
|
1259
|
+
const failure = configLoadError(this._workingCopy);
|
|
1260
|
+
if (failure) throw new InvalidConfigError(failure.key, failure.message);
|
|
1261
|
+
// repo_read_config's check_deprecated_config: core.commentChar=auto dies in git 3.0
|
|
1262
|
+
checkAutoCommentChar(this._workingCopy);
|
|
1263
|
+
// prepare_repo_settings, which every command but `git config` runs before its work
|
|
1264
|
+
const indexVersion = indexVersionConfigError(this._workingCopy);
|
|
1265
|
+
if (indexVersion) throw indexVersion;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
311
1268
|
/**
|
|
312
1269
|
* Resolve HEAD to its target commit.
|
|
313
1270
|
*
|
|
@@ -336,118 +1293,238 @@ export abstract class GitCommand<T> {
|
|
|
336
1293
|
}
|
|
337
1294
|
|
|
338
1295
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* @param refName Ref name, commit ID, or commit-ish
|
|
342
|
-
* @returns ObjectId of the resolved ref
|
|
343
|
-
* @throws RefNotFoundError if ref cannot be resolved
|
|
1296
|
+
* A resolver for git's revision syntax over this command's stores (see
|
|
1297
|
+
* {@link RevisionResolver}); its `warnings` hold what git would print.
|
|
344
1298
|
*/
|
|
345
|
-
protected
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
1299
|
+
protected revisionResolver(): RevisionResolver {
|
|
1300
|
+
return new RevisionResolver({
|
|
1301
|
+
refs: this.refsStore,
|
|
1302
|
+
commits: this.walkCommits,
|
|
1303
|
+
trees: this.trees,
|
|
1304
|
+
blobs: this.blobs,
|
|
1305
|
+
tags: this.tagsStore,
|
|
1306
|
+
staging: () => this.staging,
|
|
1307
|
+
workingCopy: this._workingCopy,
|
|
1308
|
+
objects: this._workingCopy.history?.objects,
|
|
1309
|
+
abbreviate: (ids) => this.idAbbreviator().lengths(ids),
|
|
1310
|
+
...this.worktreeSources(),
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
350
1313
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
1314
|
+
/**
|
|
1315
|
+
* The worktree as git's checks of revision-or-path arguments see it (`check_filename`),
|
|
1316
|
+
* from the current directory `prefix` below the top.
|
|
1317
|
+
*/
|
|
1318
|
+
protected argumentFiles(prefix = ""): ArgumentFiles {
|
|
1319
|
+
const exists = this.worktreeSources().fileExists;
|
|
1320
|
+
return {
|
|
1321
|
+
inWorktree: exists !== undefined,
|
|
1322
|
+
prefix,
|
|
1323
|
+
exists: exists ?? (async () => false),
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
357
1326
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
1327
|
+
/** What a resolver checks in the worktree (git's `lstat` of an argument). */
|
|
1328
|
+
protected worktreeSources(): {
|
|
1329
|
+
fileExists?: (path: string) => Promise<boolean>;
|
|
1330
|
+
worktreeHostPath?: string;
|
|
1331
|
+
} {
|
|
1332
|
+
let worktree: Worktree | undefined;
|
|
1333
|
+
try {
|
|
1334
|
+
worktree = this._workingCopy.worktree;
|
|
1335
|
+
} catch {
|
|
1336
|
+
// a bare repository's admin copy refuses its worktree (no work tree)
|
|
1337
|
+
return {};
|
|
362
1338
|
}
|
|
1339
|
+
if (!worktree) return {};
|
|
1340
|
+
const host = (worktree as { hostPath?: string }).hostPath;
|
|
1341
|
+
const wt = worktree;
|
|
1342
|
+
const lookup: WorktreeLookup = {
|
|
1343
|
+
kind: async (path) => {
|
|
1344
|
+
const entry = await wt.getEntry(path).catch(() => undefined);
|
|
1345
|
+
if (!entry) return undefined;
|
|
1346
|
+
if ((entry.mode & 0o170000) === 0o120000) return "symlink";
|
|
1347
|
+
return entry.isDirectory ? "directory" : "file";
|
|
1348
|
+
},
|
|
1349
|
+
readlink: async (path) => {
|
|
1350
|
+
try {
|
|
1351
|
+
const chunks: Uint8Array[] = [];
|
|
1352
|
+
for await (const chunk of wt.readContent(path)) chunks.push(chunk);
|
|
1353
|
+
return new TextDecoder().decode(concatBytes(chunks));
|
|
1354
|
+
} catch {
|
|
1355
|
+
return undefined;
|
|
1356
|
+
}
|
|
1357
|
+
},
|
|
1358
|
+
...(host !== undefined ? { hostPath: host } : {}),
|
|
1359
|
+
};
|
|
1360
|
+
return {
|
|
1361
|
+
// git's lstat of the path as written, from the top (links among its parents followed)
|
|
1362
|
+
fileExists: async (path) => {
|
|
1363
|
+
try {
|
|
1364
|
+
return await lstatExists(lookup, path);
|
|
1365
|
+
} catch {
|
|
1366
|
+
return false;
|
|
1367
|
+
}
|
|
1368
|
+
},
|
|
1369
|
+
...(host !== undefined ? { worktreeHostPath: host } : {}),
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
363
1372
|
|
|
364
|
-
|
|
365
|
-
const tagRef = await this.refsStore.resolve(`refs/tags/${refName}`);
|
|
366
|
-
if (tagRef?.objectId) {
|
|
367
|
-
// Peel tag objects to commits
|
|
368
|
-
return this.peelToCommit(tagRef.objectId);
|
|
369
|
-
}
|
|
1373
|
+
private abbreviator?: IdAbbreviator;
|
|
370
1374
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
1375
|
+
/**
|
|
1376
|
+
* This command's id abbreviator: the objects are counted once for git's automatic length,
|
|
1377
|
+
* however many ids the command prints (see {@link createIdAbbreviator}).
|
|
1378
|
+
*/
|
|
1379
|
+
protected idAbbreviator(): IdAbbreviator {
|
|
1380
|
+
this.abbreviator ??= createIdAbbreviator(this._workingCopy, {
|
|
1381
|
+
cacheListings: this.writesNoObjects(),
|
|
1382
|
+
});
|
|
1383
|
+
return this.abbreviator;
|
|
1384
|
+
}
|
|
375
1385
|
|
|
376
|
-
|
|
1386
|
+
/**
|
|
1387
|
+
* Whether this command stores no objects while it abbreviates ids: its abbreviator then
|
|
1388
|
+
* lists each loose fan-out directory once (see `IdAbbreviatorOptions.cacheListings`).
|
|
1389
|
+
*/
|
|
1390
|
+
protected writesNoObjects(): boolean {
|
|
1391
|
+
return false;
|
|
377
1392
|
}
|
|
378
1393
|
|
|
379
1394
|
/**
|
|
380
|
-
*
|
|
1395
|
+
* Read objects through the replace refs and grafts `source` reads, and abbreviate ids with
|
|
1396
|
+
* its object count: git reads both once per process, so a command run for each commit of
|
|
1397
|
+
* another (`git log -p` runs a diff per commit) reads them once.
|
|
381
1398
|
*/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
1399
|
+
shareReadsOf(source: GitCommand<unknown>): this {
|
|
1400
|
+
this.replacementsLoad = source.loadedReplacements();
|
|
1401
|
+
this.abbreviator = source.idAbbreviator();
|
|
1402
|
+
source.sharedTrees ??= new OrderedMap();
|
|
1403
|
+
this.sharedTrees = source.sharedTrees;
|
|
1404
|
+
source.sharedBlobs ??= { recent: new OrderedMap(), bytes: 0 };
|
|
1405
|
+
this.sharedBlobs = source.sharedBlobs;
|
|
1406
|
+
return this;
|
|
1407
|
+
}
|
|
388
1408
|
|
|
389
|
-
|
|
390
|
-
|
|
1409
|
+
/** Trees read lately by the commands sharing reads ({@link shareReadsOf}), newest last */
|
|
1410
|
+
private sharedTrees?: OrderedMap<ObjectId, TreeEntry[]>;
|
|
391
1411
|
|
|
392
|
-
|
|
1412
|
+
/**
|
|
1413
|
+
* A tree's entries through the replacements (`trees.loadTree`), kept a while for the
|
|
1414
|
+
* commands that share reads: one commit's tree is the next one's parent tree.
|
|
1415
|
+
*/
|
|
1416
|
+
protected async treeEntries(id: ObjectId): Promise<readonly TreeEntry[]> {
|
|
1417
|
+
const trees = this.trees;
|
|
1418
|
+
// a store that caches decoded trees hands them out as they are (no copy per read)
|
|
1419
|
+
if (trees.entries) {
|
|
1420
|
+
// a missing tree reads as empty, as `loadTree` yields nothing for it
|
|
1421
|
+
return (await trees.entries(id)) ?? [];
|
|
1422
|
+
}
|
|
1423
|
+
const cache = this.sharedTrees;
|
|
1424
|
+
const known = cache?.get(id);
|
|
1425
|
+
if (known) {
|
|
1426
|
+
cache?.delete(id);
|
|
1427
|
+
cache?.set(id, known);
|
|
1428
|
+
return known;
|
|
1429
|
+
}
|
|
1430
|
+
const entries: TreeEntry[] = [];
|
|
1431
|
+
for await (const e of this.trees.loadTree(id)) entries.push(e);
|
|
1432
|
+
if (cache) {
|
|
1433
|
+
cache.set(id, entries);
|
|
1434
|
+
while (cache.size > SHARED_TREES) cache.delete(cache.oldestKey() as ObjectId);
|
|
1435
|
+
}
|
|
1436
|
+
return entries;
|
|
1437
|
+
}
|
|
393
1438
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const count = m[2] ? parseInt(m[2], 10) : 1;
|
|
1439
|
+
/** `id` abbreviated as git prints it, through {@link idAbbreviator}. */
|
|
1440
|
+
protected abbreviateObjectId(id: ObjectId): Promise<string> {
|
|
1441
|
+
return this.idAbbreviator().abbreviate(id);
|
|
1442
|
+
}
|
|
399
1443
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
const parentIndex = count > 0 ? count - 1 : 0;
|
|
416
|
-
if (commit.parents.length <= parentIndex) {
|
|
417
|
-
throw new RefNotFoundError(ref, `Cannot resolve ${ref}: no parent ${count}`);
|
|
418
|
-
}
|
|
419
|
-
commitId = commit.parents[parentIndex];
|
|
420
|
-
}
|
|
421
|
-
}
|
|
1444
|
+
/**
|
|
1445
|
+
* The object a revision names, as git's `get_oid` finds it: refs by git's rules, object
|
|
1446
|
+
* ids, `@`, `@{-N}`, `@{u}`, `@{push}`, `<ref>@{<n>}`, `<ref>@{<date>}`, `~`, `^`,
|
|
1447
|
+
* `^{<type>}`, `^{/<regex>}`, `:/<regex>`, `<rev>:<path>`, `:<n>:<path>`. An annotated
|
|
1448
|
+
* tag is returned as the tag object.
|
|
1449
|
+
*
|
|
1450
|
+
* @throws RefNotFoundError if it names nothing
|
|
1451
|
+
* @throws RevisionError where git dies (no upstream, reflog too short)
|
|
1452
|
+
*/
|
|
1453
|
+
protected async resolveRevision(name: string, options?: ResolveOptions): Promise<ObjectId> {
|
|
1454
|
+
const id = await this.revisionResolver().resolve(name, options);
|
|
1455
|
+
if (id === undefined) throw new RefNotFoundError(name);
|
|
1456
|
+
return id;
|
|
1457
|
+
}
|
|
422
1458
|
|
|
423
|
-
|
|
1459
|
+
/**
|
|
1460
|
+
* Resolve a revision (see {@link resolveRevision}) to a commit, as git's
|
|
1461
|
+
* `lookup_commit_reference` does: tags are peeled, and a revision that ends at a tree, a
|
|
1462
|
+
* blob or a missing object is refused with git's lines, `error: object <id> is a tree,
|
|
1463
|
+
* not a commit` (not for a missing object) and `fatal` (by default reset's `fatal: Could
|
|
1464
|
+
* not parse object '<name>'.`).
|
|
1465
|
+
*
|
|
1466
|
+
* @param name Ref name, commit ID, or any revision expression
|
|
1467
|
+
* @param fatal The command's last line for a revision that names no commit
|
|
1468
|
+
* @returns ObjectId of the resolved commit
|
|
1469
|
+
* @throws RefNotFoundError if it cannot be resolved
|
|
1470
|
+
* @throws NotACommitError if it names something else
|
|
1471
|
+
* @throws RevisionError where git dies (no upstream, reflog too short)
|
|
1472
|
+
*/
|
|
1473
|
+
protected async resolveRef(
|
|
1474
|
+
name: string,
|
|
1475
|
+
fatal: (name: string) => string = (n) => `fatal: Could not parse object '${n}'.`,
|
|
1476
|
+
): Promise<ObjectId> {
|
|
1477
|
+
// a commit is wanted: an abbreviation is read as a committish (repo_get_oid_committish)
|
|
1478
|
+
const id = await this.resolveRevision(name, { hint: "committish" });
|
|
1479
|
+
const peeled = await this.revisionResolver().peelTags(id);
|
|
1480
|
+
if (peeled.type === "commit") return peeled.id;
|
|
1481
|
+
const lines = peeled.type
|
|
1482
|
+
? [`error: object ${peeled.id} is a ${peeled.type}, not a commit`, fatal(name)]
|
|
1483
|
+
: [fatal(name)];
|
|
1484
|
+
throw new NotACommitError(name, peeled.id, peeled.type, lines.join("\n"));
|
|
424
1485
|
}
|
|
425
1486
|
|
|
426
1487
|
/**
|
|
427
|
-
*
|
|
1488
|
+
* git's `setup_branch_path` (`INTERPRET_BRANCH_LOCAL`): the local branch a name's branch
|
|
1489
|
+
* syntax stands for (`loc@{u}` is `main` when loc tracks main with `remote = .`), else
|
|
1490
|
+
* the name as given.
|
|
1491
|
+
*
|
|
1492
|
+
* @throws RevisionError where git dies reading it (`@{u}` without an upstream)
|
|
428
1493
|
*/
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
1494
|
+
protected async interpretLocalBranch(name: string): Promise<string> {
|
|
1495
|
+
if (!name.includes("@")) return name;
|
|
1496
|
+
const value = await this.revisionResolver().interpretBranchName(name);
|
|
1497
|
+
return value?.startsWith("refs/heads/") ? value.slice("refs/heads/".length) : name;
|
|
1498
|
+
}
|
|
434
1499
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
1500
|
+
/**
|
|
1501
|
+
* git's `interpret_nth_prior_checkout`: the name a leading `@{-N}` stands for, the
|
|
1502
|
+
* branch (or detached commit) the Nth most recent `checkout: moving from <x> to <y>`
|
|
1503
|
+
* line of HEAD's reflog left, followed by the rest of `name` (`@{-1}~2` is `main~2`).
|
|
1504
|
+
* A name without it, or an `@{-N}` the reflog cannot answer, is returned as given.
|
|
1505
|
+
*
|
|
1506
|
+
* @example
|
|
1507
|
+
* ```typescript
|
|
1508
|
+
* await this.expandPriorCheckout("@{-1}"); // "feat" after `checkout feat` + `checkout main`
|
|
1509
|
+
* ```
|
|
1510
|
+
*/
|
|
1511
|
+
protected async expandPriorCheckout(name: string): Promise<string> {
|
|
1512
|
+
const match = /^@\{-(\d+)\}/.exec(name);
|
|
1513
|
+
if (!match) return name;
|
|
1514
|
+
const nth = Number.parseInt(match[1] ?? "0", 10);
|
|
1515
|
+
if (!(nth > 0)) return name;
|
|
1516
|
+
const log = await this.refsStore.getReflog?.("HEAD");
|
|
1517
|
+
if (!log) return name;
|
|
1518
|
+
let remaining = nth;
|
|
1519
|
+
for (const entry of await log.getReverseEntries()) {
|
|
1520
|
+
const prefix = "checkout: moving from ";
|
|
1521
|
+
if (!entry.comment.startsWith(prefix)) continue;
|
|
1522
|
+
const rest = entry.comment.slice(prefix.length);
|
|
1523
|
+
const to = rest.indexOf(" to ");
|
|
1524
|
+
if (to < 0) continue;
|
|
1525
|
+
if (--remaining === 0) return rest.slice(0, to) + name.slice(match[0].length);
|
|
447
1526
|
}
|
|
448
|
-
|
|
449
|
-
// Return as-is (might be a tree or blob in some contexts)
|
|
450
|
-
return objectId;
|
|
1527
|
+
return name;
|
|
451
1528
|
}
|
|
452
1529
|
|
|
453
1530
|
/**
|
|
@@ -460,3 +1537,15 @@ export abstract class GitCommand<T> {
|
|
|
460
1537
|
return this.refsStore.get(refName);
|
|
461
1538
|
}
|
|
462
1539
|
}
|
|
1540
|
+
|
|
1541
|
+
/** `chunks` as one array. */
|
|
1542
|
+
function concatBytes(chunks: Uint8Array[]): Uint8Array {
|
|
1543
|
+
if (chunks.length === 1) return chunks[0];
|
|
1544
|
+
const out = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));
|
|
1545
|
+
let offset = 0;
|
|
1546
|
+
for (const chunk of chunks) {
|
|
1547
|
+
out.set(chunk, offset);
|
|
1548
|
+
offset += chunk.length;
|
|
1549
|
+
}
|
|
1550
|
+
return out;
|
|
1551
|
+
}
|