@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
|
@@ -0,0 +1,1397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's revision syntax (`object-name.c` `get_oid_with_context`, `remote.c`
|
|
3
|
+
* `branch_get_upstream` / `branch_get_push`, `refs.c` `read_ref_at`), checked against git
|
|
4
|
+
* 2.43 and 2.56. Every command that takes a revision resolves it here (through
|
|
5
|
+
* `GitCommand.resolveRevision` and `resolveRef`).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const resolver = new RevisionResolver(sources);
|
|
10
|
+
* await resolver.resolve("main@{u}"); // what refs/remotes/origin/main holds
|
|
11
|
+
* await resolver.resolve("HEAD@{2}"); // HEAD two moves ago (its reflog)
|
|
12
|
+
* await resolver.resolve("main@{yesterday}"); // main as it was a day ago
|
|
13
|
+
* await resolver.resolve(":/fix typo"); // the youngest commit whose message matches
|
|
14
|
+
* await resolver.resolve("v1.0^{tree}"); // the tree of the tagged commit
|
|
15
|
+
* await resolver.resolve("HEAD:src/a.ts"); // a blob of HEAD's tree
|
|
16
|
+
* await resolver.resolve(":2:a.ts"); // "ours" of a conflicted path in the index
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Supported: full object ids; ref names by git's dwim rules (`<name>`, `refs/<name>`,
|
|
20
|
+
* `refs/tags/`, `refs/heads/`, `refs/remotes/`, `refs/remotes/<name>/HEAD`); `@` (HEAD);
|
|
21
|
+
* `@{-N}`; `[<branch>]@{upstream}` / `@{u}`; `[<branch>]@{push}`; `[<ref>]@{<n>}` and
|
|
22
|
+
* `[<ref>]@{<date>}` (git's approxidate); `<rev>~<n>`, `<rev>^<n>`; `<rev>^{<type>}`,
|
|
23
|
+
* `<rev>^{}`, `<rev>^{/<regex>}`; `:/<regex>` (with git's `!-` and `!!`); `<rev>:<path>`;
|
|
24
|
+
* `:<path>` and `:<n>:<path>` (`./` and `../` paths relative to {@link cwdPrefix}); abbreviated
|
|
25
|
+
* object ids (`get_short_oid`: at least 4 hex digits, disambiguated by the type the context
|
|
26
|
+
* needs or `core.disambiguate`, with git's `error: short object ID ... is ambiguous` and its
|
|
27
|
+
* candidate list); `git describe` names (`<tag>-<n>-g<abbrev>`, the abbreviation read as a
|
|
28
|
+
* commit). Regexes are POSIX extended ones run as glibc runs them (`compilePosixRegex`).
|
|
29
|
+
*
|
|
30
|
+
* Revision ranges and sets (`a..b`, `a...b`, `^a`, `a^@`, `a^!`, `a^-<n>`) are read by
|
|
31
|
+
* `parseRevisionArgs` (`revision-range.ts`) on top of this resolver.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import type { Commit, GitObjects, ObjectId, PersonIdent, Refs } from "@statewalker/vcs-core";
|
|
35
|
+
import {
|
|
36
|
+
isSymbolicRef,
|
|
37
|
+
isValidRefName,
|
|
38
|
+
listObjectsWithPrefix,
|
|
39
|
+
MINIMUM_ABBREV_LENGTH,
|
|
40
|
+
objectFormatOf,
|
|
41
|
+
} from "@statewalker/vcs-core";
|
|
42
|
+
import { compilePosixRegex, isNullObjectId, parseGitBool } from "@statewalker/vcs-utils";
|
|
43
|
+
import type { Staging, WorkingCopy } from "@statewalker/vcs-working-tree";
|
|
44
|
+
|
|
45
|
+
import { RevisionError } from "../errors/index.js";
|
|
46
|
+
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
47
|
+
import { applyRefspecs } from "./branch-tracking.js";
|
|
48
|
+
import { configLoadError } from "./core-config.js";
|
|
49
|
+
import { approxidateCareful, formatRfc2822Date } from "./git-date.js";
|
|
50
|
+
import { loadLegacyRemote } from "./legacy-remotes.js";
|
|
51
|
+
|
|
52
|
+
/** The stores a revision is read from. */
|
|
53
|
+
export interface RevisionSources {
|
|
54
|
+
refs: Refs;
|
|
55
|
+
commits: {
|
|
56
|
+
load(id: ObjectId): Promise<Commit | undefined>;
|
|
57
|
+
has(id: ObjectId): Promise<boolean>;
|
|
58
|
+
};
|
|
59
|
+
trees: {
|
|
60
|
+
has(id: ObjectId): Promise<boolean>;
|
|
61
|
+
getEntry(treeId: ObjectId, name: string): Promise<{ id: ObjectId; mode: number } | undefined>;
|
|
62
|
+
};
|
|
63
|
+
blobs: { has(id: ObjectId): Promise<boolean> };
|
|
64
|
+
tags?: {
|
|
65
|
+
has(id: ObjectId): Promise<boolean>;
|
|
66
|
+
load(
|
|
67
|
+
id: ObjectId,
|
|
68
|
+
): Promise<{ object: ObjectId; tag?: string; tagger?: PersonIdent } | undefined>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The object store, for abbreviated ids (its `listPrefix`, else `list`); without it the
|
|
72
|
+
* typed stores' `keys()` are listed
|
|
73
|
+
*/
|
|
74
|
+
objects?: Pick<GitObjects, "list" | "listPrefix" | "objectFormat">;
|
|
75
|
+
/**
|
|
76
|
+
* The lengths git abbreviates ids to (`repo_find_unique_abbrev` with `core.abbrev`), for
|
|
77
|
+
* the candidates of an ambiguous short id; 7 digits without it
|
|
78
|
+
*/
|
|
79
|
+
abbreviate?: (ids: ObjectId[]) => Promise<Map<ObjectId, number>>;
|
|
80
|
+
/** The index, for `:<path>` (undefined where there is none) */
|
|
81
|
+
staging?: () => Staging | undefined;
|
|
82
|
+
/** The configuration (`branch.*`, `remote.*`, `push.default`) */
|
|
83
|
+
workingCopy: WorkingCopy;
|
|
84
|
+
/**
|
|
85
|
+
* Whether something is at `path` (from the top of the worktree) in the worktree, as git's
|
|
86
|
+
* `lstat` finds it; for git's diagnostics of a misspelt `<rev>:<path>` and `:<path>`
|
|
87
|
+
* (`exists on disk, but not in ...`) and `check_filename`. Absent: nothing is
|
|
88
|
+
*/
|
|
89
|
+
fileExists?: (path: string) => Promise<boolean>;
|
|
90
|
+
/** The top of the worktree as the host names it, for `'x' is outside repository at '<dir>'` */
|
|
91
|
+
worktreeHostPath?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
type ObjectType = "commit" | "tree" | "blob" | "tag";
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The type a context needs of an abbreviated id (git's `GET_OID_COMMIT`, `GET_OID_COMMITTISH`,
|
|
98
|
+
* `GET_OID_TREE`, `GET_OID_TREEISH`, `GET_OID_BLOB`; `core.disambiguate`'s values but "none"):
|
|
99
|
+
* of several objects sharing the prefix, the one that is (or peels to) such an object wins.
|
|
100
|
+
*/
|
|
101
|
+
export type DisambiguateHint = "commit" | "committish" | "tree" | "treeish" | "blob";
|
|
102
|
+
|
|
103
|
+
/** How {@link RevisionResolver.resolve} reads a revision. */
|
|
104
|
+
export interface ResolveOptions {
|
|
105
|
+
/** The type the caller needs (`git log` and `A..B` want committishes); default none */
|
|
106
|
+
hint?: DisambiguateHint;
|
|
107
|
+
/** git's `GET_OID_QUIETLY`: no `error:` lines for an ambiguous short id */
|
|
108
|
+
quiet?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* git's `GET_OID_ONLY_TO_DIE` (`maybe_die_on_misspelt_object_name`): a `<rev>:<path>` or
|
|
111
|
+
* `:<path>` that names nothing dies with git's diagnosis (`path 'x' does not exist in
|
|
112
|
+
* 'HEAD'`, `path 'x' exists on disk, but not in the index`, ...); `:/<text>` is not
|
|
113
|
+
* searched
|
|
114
|
+
*/
|
|
115
|
+
onlyToDie?: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** git's `get_short_oid` result. */
|
|
119
|
+
type ShortOid =
|
|
120
|
+
| { status: "found"; id: ObjectId }
|
|
121
|
+
| { status: "missing" }
|
|
122
|
+
| { status: "ambiguous" }
|
|
123
|
+
| { status: "invalid" };
|
|
124
|
+
|
|
125
|
+
const HEX_DIGIT = /^[0-9a-fA-F]$/;
|
|
126
|
+
const isHexDigit = (c: string | undefined) => c !== undefined && HEX_DIGIT.test(c);
|
|
127
|
+
|
|
128
|
+
const HEX_DIGITS = /^[0-9a-fA-F]+$/;
|
|
129
|
+
|
|
130
|
+
/** git's `object_name_msg` advice after a 40-hex name that is also a ref. */
|
|
131
|
+
const OBJECT_NAME_ADVICE = [
|
|
132
|
+
"Git normally never creates a ref that ends with 40 hex characters",
|
|
133
|
+
"because it will be ignored when you just specify 40-hex. These refs",
|
|
134
|
+
"may be created by mistake. For example,",
|
|
135
|
+
"",
|
|
136
|
+
" git switch -c $br $(git rev-parse ...)",
|
|
137
|
+
"",
|
|
138
|
+
'where "$br" is somehow empty and a 40-hex ref is created. Please',
|
|
139
|
+
"examine these refs and maybe delete them. Turn this message off by",
|
|
140
|
+
'running "git config set advice.objectNameWarning false"',
|
|
141
|
+
].join("\n");
|
|
142
|
+
|
|
143
|
+
/** git's `ref_rev_parse_rules`. */
|
|
144
|
+
const REV_PARSE_RULES = [
|
|
145
|
+
(n: string) => n,
|
|
146
|
+
(n: string) => `refs/${n}`,
|
|
147
|
+
(n: string) => `refs/tags/${n}`,
|
|
148
|
+
(n: string) => `refs/heads/${n}`,
|
|
149
|
+
(n: string) => `refs/remotes/${n}`,
|
|
150
|
+
(n: string) => `refs/remotes/${n}/HEAD`,
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
/** git's `at_mark`: the length of the suffix `s` starts with (case-insensitive), or 0. */
|
|
154
|
+
function atMark(s: string, suffixes: string[]): number {
|
|
155
|
+
const lower = s.toLowerCase();
|
|
156
|
+
for (const suffix of suffixes) if (lower.startsWith(suffix)) return suffix.length;
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
const upstreamMark = (s: string) => atMark(s, ["@{upstream}", "@{u}"]);
|
|
160
|
+
const pushMark = (s: string) => atMark(s, ["@{push}"]);
|
|
161
|
+
|
|
162
|
+
/** git's `ambiguous_path`: a path with an empty, `.` or `..` component. */
|
|
163
|
+
function ambiguousPath(path: string): boolean {
|
|
164
|
+
for (const part of path.split("/")) {
|
|
165
|
+
if (part === "" || part === "." || part === "..") return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Characters consumed of a name and what they stand for (git's interpret_branch_name). */
|
|
171
|
+
interface Interpreted {
|
|
172
|
+
used: number;
|
|
173
|
+
value: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Resolves revisions as git's `get_oid` does. Warnings git prints while resolving
|
|
178
|
+
* (`warning: log for 'main' only goes back to ...`) collect in {@link warnings}; where git
|
|
179
|
+
* dies a {@link RevisionError} is thrown with its message.
|
|
180
|
+
*/
|
|
181
|
+
export class RevisionResolver {
|
|
182
|
+
/** What git prints while resolving: `warning: ...` and `error: ...` lines */
|
|
183
|
+
readonly warnings: string[] = [];
|
|
184
|
+
/**
|
|
185
|
+
* The current directory below the top of the worktree (git's `prefix`, `d/sub/` or ""),
|
|
186
|
+
* against which `<rev>:./<path>`, `<rev>:../<path>` and `:./<path>` are read
|
|
187
|
+
*/
|
|
188
|
+
cwdPrefix = "";
|
|
189
|
+
private config?: RemoteConfigStore;
|
|
190
|
+
private disambiguateChecked = false;
|
|
191
|
+
/** Refs read while resolving one revision (`HEAD~3` reads HEAD once) */
|
|
192
|
+
private readonly refCache = new Map<string, Promise<{ id: ObjectId; ref: string } | undefined>>();
|
|
193
|
+
|
|
194
|
+
constructor(
|
|
195
|
+
private readonly sources: RevisionSources,
|
|
196
|
+
private readonly now: () => number = () => Math.floor(Date.now() / 1000),
|
|
197
|
+
) {
|
|
198
|
+
this.hexLength = objectFormatOf(sources.objects).hexLength;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The repository's full hex id length: 40, or 64 in a SHA-256 repository (git's hexsz) */
|
|
202
|
+
private readonly hexLength: number;
|
|
203
|
+
|
|
204
|
+
/** Whether `str` is a full hex object id of the repository's format, in any case */
|
|
205
|
+
private isFullHex(str: string): boolean {
|
|
206
|
+
return str.length === this.hexLength && HEX_DIGITS.test(str);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The object `name` names, or undefined when it names none (git's `unknown revision`).
|
|
211
|
+
*
|
|
212
|
+
* @throws RevisionError where git dies (an `@{u}` without upstream, a reflog too short)
|
|
213
|
+
*/
|
|
214
|
+
async resolve(name: string, options: ResolveOptions = {}): Promise<ObjectId | undefined> {
|
|
215
|
+
this.checkDisambiguateConfig(name);
|
|
216
|
+
const direct = await this.oid1(name, options);
|
|
217
|
+
if (direct !== undefined) return direct;
|
|
218
|
+
if (name.startsWith(":")) {
|
|
219
|
+
if (!options.onlyToDie && name.length > 2 && name[1] === "/") {
|
|
220
|
+
return this.oneline(name.slice(2), await this.allRefCommits());
|
|
221
|
+
}
|
|
222
|
+
let stage = 0;
|
|
223
|
+
let path = name.slice(1);
|
|
224
|
+
if (name.length >= 3 && name[2] === ":" && name[1] >= "0" && name[1] <= "3") {
|
|
225
|
+
stage = Number(name[1]);
|
|
226
|
+
path = name.slice(3);
|
|
227
|
+
}
|
|
228
|
+
const resolved = this.relativePath(path, name);
|
|
229
|
+
const found = await this.indexEntry(resolved, stage);
|
|
230
|
+
if (found === undefined && options.onlyToDie && name.length > 1 && name[1] !== "/") {
|
|
231
|
+
await this.diagnoseIndexPath(name, stage, resolved);
|
|
232
|
+
}
|
|
233
|
+
return found;
|
|
234
|
+
}
|
|
235
|
+
// <tree-ish>:<path>, the first `:` outside `@{...}` / `^{...}`
|
|
236
|
+
let depth = 0;
|
|
237
|
+
for (let i = 0; i < name.length; i++) {
|
|
238
|
+
const c = name[i];
|
|
239
|
+
if ((c === "@" || c === "^") && name[i + 1] === "{") {
|
|
240
|
+
i++;
|
|
241
|
+
depth++;
|
|
242
|
+
} else if (depth > 0 && c === "}") {
|
|
243
|
+
depth--;
|
|
244
|
+
} else if (depth === 0 && c === ":") {
|
|
245
|
+
const objectName = name.slice(0, i);
|
|
246
|
+
const treeish = await this.oid1(objectName, { ...options, hint: "treeish" });
|
|
247
|
+
if (treeish === undefined) {
|
|
248
|
+
if (options.onlyToDie) this.die(name, `fatal: invalid object name '${objectName}'.`);
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
const filename = this.relativePath(name.slice(i + 1), name);
|
|
252
|
+
const tree = await this.peelToType(treeish, "tree");
|
|
253
|
+
const found = tree === undefined ? undefined : await this.treeEntry(tree, filename);
|
|
254
|
+
if (found === undefined && options.onlyToDie) {
|
|
255
|
+
await this.diagnoseTreePath(name, objectName, tree, filename);
|
|
256
|
+
}
|
|
257
|
+
return found;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* The branch name `name` stands for, as git's `interpret_branch_name` gives it (`@{-1}`
|
|
265
|
+
* is the branch left before, `@{u}` the upstream's short name, `@` HEAD), or undefined
|
|
266
|
+
* when it stands for nothing else.
|
|
267
|
+
*/
|
|
268
|
+
async interpretBranchName(name: string): Promise<string | undefined> {
|
|
269
|
+
const interpreted = await this.interpret(name);
|
|
270
|
+
return typeof interpreted === "object" && interpreted.used === name.length
|
|
271
|
+
? interpreted.value
|
|
272
|
+
: undefined;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* The ref `@{upstream}` of `branch` names (git's `branch_get_upstream`); the current
|
|
277
|
+
* branch when undefined.
|
|
278
|
+
*
|
|
279
|
+
* @throws RevisionError with git's message when there is none
|
|
280
|
+
*/
|
|
281
|
+
async upstreamOf(branch: string | undefined, revision = "@{upstream}"): Promise<string> {
|
|
282
|
+
const name = branch ?? (await this.currentBranch());
|
|
283
|
+
if (name === undefined) throw this.fatal(revision, "HEAD does not point to a branch");
|
|
284
|
+
const config = this.remoteConfig();
|
|
285
|
+
const remote = config.value(`branch.${name}.remote`);
|
|
286
|
+
const merges = config.values(`branch.${name}.merge`);
|
|
287
|
+
if (!remote || merges.length === 0) {
|
|
288
|
+
if (!(await this.sources.refs.has(`refs/heads/${name}`))) {
|
|
289
|
+
throw this.fatal(revision, `no such branch: '${name}'`);
|
|
290
|
+
}
|
|
291
|
+
throw this.fatal(revision, `no upstream configured for branch '${name}'`);
|
|
292
|
+
}
|
|
293
|
+
const src = merges[0] ?? "";
|
|
294
|
+
// set_merge: remote_get reads a legacy remote (.git/remotes/, .git/branches/: git 2.x)
|
|
295
|
+
await loadLegacyRemote(this.sources.workingCopy, remote);
|
|
296
|
+
let dst = applyRefspecs(config.configuredFetchRefspecs(remote), src);
|
|
297
|
+
if (dst === undefined && remote === ".") {
|
|
298
|
+
const found = await this.dwimRefAll(src, false);
|
|
299
|
+
dst = found.length === 1 ? found[0]?.ref : src;
|
|
300
|
+
}
|
|
301
|
+
if (dst === undefined) {
|
|
302
|
+
throw this.fatal(revision, `upstream branch '${src}' not stored as a remote-tracking branch`);
|
|
303
|
+
}
|
|
304
|
+
return dst;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The remote `git push` pushes `branch` to (git's `pushremote_for_branch`):
|
|
309
|
+
* `branch.<name>.pushRemote`, `remote.pushDefault`, `branch.<name>.remote`, the one
|
|
310
|
+
* configured remote, else `origin`.
|
|
311
|
+
*/
|
|
312
|
+
pushRemoteOf(branch: string): string {
|
|
313
|
+
const config = this.remoteConfig();
|
|
314
|
+
return (
|
|
315
|
+
config.value(`branch.${branch}.pushRemote`) ??
|
|
316
|
+
config.value("remote.pushDefault") ??
|
|
317
|
+
config.value(`branch.${branch}.remote`) ??
|
|
318
|
+
(config.configuredNames().length === 1 ? config.configuredNames()[0] : "origin") ??
|
|
319
|
+
"origin"
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The ref `@{push}` of `branch` names (git's `branch_get_push`): where `git push` would
|
|
325
|
+
* push it, as the remote-tracking ref that follows it; the current branch when undefined.
|
|
326
|
+
*
|
|
327
|
+
* @throws RevisionError with git's message when there is none
|
|
328
|
+
*/
|
|
329
|
+
async pushOf(branch: string | undefined, revision = "@{push}"): Promise<string> {
|
|
330
|
+
const name = branch ?? (await this.currentBranch());
|
|
331
|
+
if (name === undefined) throw this.fatal(revision, "HEAD does not point to a branch");
|
|
332
|
+
const config = this.remoteConfig();
|
|
333
|
+
const refname = `refs/heads/${name}`;
|
|
334
|
+
const remote = this.pushRemoteOf(name);
|
|
335
|
+
await loadLegacyRemote(this.sources.workingCopy, remote);
|
|
336
|
+
const trackingFor = (dst: string) => {
|
|
337
|
+
const tracking = applyRefspecs(config.configuredFetchRefspecs(remote), dst);
|
|
338
|
+
if (tracking === undefined) {
|
|
339
|
+
throw this.fatal(
|
|
340
|
+
revision,
|
|
341
|
+
`push destination '${dst}' on remote '${remote}' has no local tracking branch`,
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
return tracking;
|
|
345
|
+
};
|
|
346
|
+
const pushSpecs = config.pushRefspecs(remote);
|
|
347
|
+
if (pushSpecs.length > 0) {
|
|
348
|
+
const dst = applyRefspecs(pushSpecs, refname);
|
|
349
|
+
if (dst === undefined) {
|
|
350
|
+
throw this.fatal(revision, `push refspecs for '${remote}' do not include '${name}'`);
|
|
351
|
+
}
|
|
352
|
+
return trackingFor(dst);
|
|
353
|
+
}
|
|
354
|
+
const mirror = config.value(`remote.${remote}.mirror`);
|
|
355
|
+
if (mirror !== undefined && ["true", "yes", "on", "1", ""].includes(mirror.toLowerCase())) {
|
|
356
|
+
return trackingFor(refname);
|
|
357
|
+
}
|
|
358
|
+
const mode = config.value("push.default") ?? "simple";
|
|
359
|
+
switch (mode) {
|
|
360
|
+
case "nothing":
|
|
361
|
+
throw this.fatal(revision, "push has no destination (push.default is 'nothing')");
|
|
362
|
+
case "matching":
|
|
363
|
+
case "current":
|
|
364
|
+
return trackingFor(refname);
|
|
365
|
+
case "upstream":
|
|
366
|
+
case "tracking":
|
|
367
|
+
return this.upstreamOf(name, revision);
|
|
368
|
+
default: {
|
|
369
|
+
const up = await this.upstreamOf(name, revision);
|
|
370
|
+
const cur = trackingFor(refname);
|
|
371
|
+
if (cur !== up) {
|
|
372
|
+
throw this.fatal(revision, "cannot resolve 'simple' push to a single destination");
|
|
373
|
+
}
|
|
374
|
+
return cur;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ------------------------------------------------------------------ get_oid_1
|
|
380
|
+
|
|
381
|
+
/** git's `get_oid_1`: `~<n>` / `^<n>`, then `^{...}`, then a ref or an object id. */
|
|
382
|
+
private async oid1(name: string, flags: ResolveOptions = {}): Promise<ObjectId | undefined> {
|
|
383
|
+
let cp = name.length - 1;
|
|
384
|
+
while (cp >= 0 && (name[cp] ?? "") >= "0" && (name[cp] ?? "") <= "9") cp--;
|
|
385
|
+
const suffix = cp >= 0 ? name[cp] : undefined;
|
|
386
|
+
if (suffix === "~" || suffix === "^") {
|
|
387
|
+
const digits = name.slice(cp + 1);
|
|
388
|
+
let num = digits === "" ? 0 : Number(digits);
|
|
389
|
+
if (!Number.isSafeInteger(num) || num > 2147483647) return undefined;
|
|
390
|
+
if (num === 0 && cp === name.length - 1) num = 1;
|
|
391
|
+
const base = name.slice(0, cp);
|
|
392
|
+
return suffix === "^"
|
|
393
|
+
? this.parent(base, num, flags.quiet)
|
|
394
|
+
: this.nthAncestor(base, num, flags.quiet);
|
|
395
|
+
}
|
|
396
|
+
const peeled = await this.peelOnion(name, flags);
|
|
397
|
+
if (peeled !== undefined) return peeled;
|
|
398
|
+
const basic = await this.basic(name, flags);
|
|
399
|
+
if (basic !== undefined) return basic;
|
|
400
|
+
// describe output, "SOMETHING-gXXXX"
|
|
401
|
+
const described = await this.describeName(name);
|
|
402
|
+
if (described !== undefined) return described;
|
|
403
|
+
const short = await this.shortOid(name, flags);
|
|
404
|
+
return short.status === "found" ? short.id : undefined;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** git's `get_parent`: `<rev>^<n>` (`^0` the commit itself). */
|
|
408
|
+
private async parent(name: string, idx: number, quiet?: boolean): Promise<ObjectId | undefined> {
|
|
409
|
+
const id = await this.oid1(name, { hint: "committish", quiet });
|
|
410
|
+
if (id === undefined) return undefined;
|
|
411
|
+
const commitId = await this.commitReference(id);
|
|
412
|
+
if (commitId === undefined) return undefined;
|
|
413
|
+
if (idx === 0) return commitId;
|
|
414
|
+
const commit = await this.sources.commits.load(commitId);
|
|
415
|
+
return commit?.parents[idx - 1];
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** git's `get_nth_ancestor`: `<rev>~<n>`, first parents. */
|
|
419
|
+
private async nthAncestor(
|
|
420
|
+
name: string,
|
|
421
|
+
generation: number,
|
|
422
|
+
quiet?: boolean,
|
|
423
|
+
): Promise<ObjectId | undefined> {
|
|
424
|
+
const id = await this.oid1(name, { hint: "committish", quiet });
|
|
425
|
+
if (id === undefined) return undefined;
|
|
426
|
+
let commitId = await this.commitReference(id);
|
|
427
|
+
for (let i = 0; commitId !== undefined && i < generation; i++) {
|
|
428
|
+
const commit = await this.sources.commits.load(commitId);
|
|
429
|
+
commitId = commit?.parents[0];
|
|
430
|
+
}
|
|
431
|
+
return commitId;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** git's `peel_onion`: `<rev>^{<type>}`, `<rev>^{}`, `<rev>^{/<regex>}`. */
|
|
435
|
+
private async peelOnion(name: string, flags: ResolveOptions): Promise<ObjectId | undefined> {
|
|
436
|
+
if (name.length < 4 || !name.endsWith("}")) return undefined;
|
|
437
|
+
let sp = name.length - 1;
|
|
438
|
+
for (; sp >= 0; sp--) if (name[sp] === "{" && sp > 0 && name[sp - 1] === "^") break;
|
|
439
|
+
if (sp <= 0) return undefined;
|
|
440
|
+
const spec = name.slice(sp + 1);
|
|
441
|
+
let expected: ObjectType | "any" | "none";
|
|
442
|
+
if (spec.startsWith("commit}")) expected = "commit";
|
|
443
|
+
else if (spec.startsWith("tag}")) expected = "tag";
|
|
444
|
+
else if (spec.startsWith("tree}")) expected = "tree";
|
|
445
|
+
else if (spec.startsWith("blob}")) expected = "blob";
|
|
446
|
+
else if (spec.startsWith("object}")) expected = "any";
|
|
447
|
+
else if (spec.startsWith("}")) expected = "none";
|
|
448
|
+
else if (spec.startsWith("/")) expected = "commit";
|
|
449
|
+
else return undefined;
|
|
450
|
+
// the type wanted decides an abbreviation; other peels fall back to core.disambiguate
|
|
451
|
+
const hint: DisambiguateHint | undefined =
|
|
452
|
+
expected === "commit" ? "committish" : expected === "tree" ? "treeish" : undefined;
|
|
453
|
+
const outer = await this.oid1(name.slice(0, sp - 1), { quiet: flags.quiet, hint });
|
|
454
|
+
if (outer === undefined) return undefined;
|
|
455
|
+
if (expected === "none") return this.derefTags(outer);
|
|
456
|
+
const id = expected === "any" ? outer : await this.peelToType(outer, expected, name);
|
|
457
|
+
if (id === undefined) return undefined;
|
|
458
|
+
if (spec.startsWith("/")) {
|
|
459
|
+
const pattern = name.slice(sp + 2, name.length - 1);
|
|
460
|
+
if (pattern === "") return id;
|
|
461
|
+
return this.oneline(pattern, [id]);
|
|
462
|
+
}
|
|
463
|
+
return id;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// ------------------------------------------------------------------ get_oid_basic
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* git's `get_oid_basic`: an object id (taken as it is, whether the repository has the
|
|
470
|
+
* object or not), a ref, `<ref>@{<n>|<date>}`, `@{-N}`.
|
|
471
|
+
*/
|
|
472
|
+
private async basic(str: string, flags: ResolveOptions = {}): Promise<ObjectId | undefined> {
|
|
473
|
+
if (this.isFullHex(str)) {
|
|
474
|
+
// warn_on_object_refname_ambiguity: a ref spelled as the 40-hex
|
|
475
|
+
if (this.warnAmbiguousRefs() && (await this.dwimRefAll(str)).length > 0) {
|
|
476
|
+
this.warnings.push(`warning: refname '${str}' is ambiguous.`);
|
|
477
|
+
const advice = parseGitBool(this.remoteConfig().value("advice.objectNameWarning"));
|
|
478
|
+
if (advice !== false) this.warnings.push(OBJECT_NAME_ADVICE);
|
|
479
|
+
}
|
|
480
|
+
return str.toLowerCase();
|
|
481
|
+
}
|
|
482
|
+
let len = str.length;
|
|
483
|
+
let at = 0;
|
|
484
|
+
let reflogLen = 0;
|
|
485
|
+
let nthPrior = false;
|
|
486
|
+
if (len > 0 && str[len - 1] === "}") {
|
|
487
|
+
for (at = len - 4; at >= 0; at--) {
|
|
488
|
+
if (str[at] === "@" && str[at + 1] === "{") {
|
|
489
|
+
if (str[at + 2] === "-") {
|
|
490
|
+
// @{-N} not at the start
|
|
491
|
+
if (at !== 0) return undefined;
|
|
492
|
+
nthPrior = true;
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
const rest = str.slice(at);
|
|
496
|
+
if (!upstreamMark(rest) && !pushMark(rest)) {
|
|
497
|
+
reflogLen = len - 1 - (at + 2);
|
|
498
|
+
len = at;
|
|
499
|
+
}
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
const base = str.slice(0, len);
|
|
505
|
+
if (len > 0 && ambiguousPath(base)) return undefined;
|
|
506
|
+
|
|
507
|
+
if (nthPrior) {
|
|
508
|
+
const prior = await this.nthPriorCheckout(base);
|
|
509
|
+
if (typeof prior === "object" && this.isFullHex(prior.value)) {
|
|
510
|
+
return (await this.objectType(prior.value.toLowerCase()))
|
|
511
|
+
? prior.value.toLowerCase()
|
|
512
|
+
: undefined;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
let all: { id: ObjectId; ref: string }[];
|
|
517
|
+
if (len === 0 && reflogLen > 0) all = await this.dwimRefAll("HEAD");
|
|
518
|
+
else if (reflogLen > 0) all = await this.dwimLog(base);
|
|
519
|
+
else all = await this.dwimRefAll(base);
|
|
520
|
+
const found = all[0];
|
|
521
|
+
if (!found) return undefined;
|
|
522
|
+
// warn_ambiguous_refs: more than one rule found a ref (or a log), or the name is also an
|
|
523
|
+
// abbreviated object id
|
|
524
|
+
if (
|
|
525
|
+
this.warnAmbiguousRefs() &&
|
|
526
|
+
!flags.quiet &&
|
|
527
|
+
(all.length > 1 || (await this.shortOid(base, { quiet: true })).status === "found")
|
|
528
|
+
)
|
|
529
|
+
this.warnings.push(`warning: refname '${base}' is ambiguous.`);
|
|
530
|
+
if (reflogLen === 0) return found.id;
|
|
531
|
+
|
|
532
|
+
const spec = str.slice(at + 2, at + 2 + reflogLen);
|
|
533
|
+
let nth = /^[0-9]+$/.test(spec) ? Number(spec) : -1;
|
|
534
|
+
let atTime: number;
|
|
535
|
+
if (nth >= 100000000) {
|
|
536
|
+
atTime = nth;
|
|
537
|
+
nth = -1;
|
|
538
|
+
} else if (nth >= 0) {
|
|
539
|
+
atTime = 0;
|
|
540
|
+
} else {
|
|
541
|
+
const parsed = approxidateCareful(spec, this.now());
|
|
542
|
+
if (parsed.error) return undefined;
|
|
543
|
+
atTime = parsed.timestamp;
|
|
544
|
+
}
|
|
545
|
+
const read = await this.readRefAt(found.ref, atTime, nth, found.id);
|
|
546
|
+
if (read.missing) {
|
|
547
|
+
let shown = base;
|
|
548
|
+
if (len === 0) shown = found.ref.startsWith("refs/heads/") ? found.ref.slice(11) : "HEAD";
|
|
549
|
+
if (atTime) {
|
|
550
|
+
// GET_OID_QUIETLY keeps this one to itself
|
|
551
|
+
if (!flags.quiet) {
|
|
552
|
+
this.warnings.push(
|
|
553
|
+
`warning: log for '${shown}' only goes back to ${formatRfc2822Date(read.cutoffTime, read.cutoffTz)}`,
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
} else if (!(nth === read.cutoffCount && !isNullObjectId(read.id))) {
|
|
557
|
+
throw this.fatal(str, `log for '${shown}' only has ${read.cutoffCount} entries`);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return read.id;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* git's `read_ref_at`: the value `ref` had at `atTime` (seconds), or `nth` moves ago;
|
|
565
|
+
* `missing` when the reflog does not reach that far (the oldest value given instead).
|
|
566
|
+
*/
|
|
567
|
+
private async readRefAt(
|
|
568
|
+
ref: string,
|
|
569
|
+
atTime: number,
|
|
570
|
+
nth: number,
|
|
571
|
+
current: ObjectId,
|
|
572
|
+
): Promise<{
|
|
573
|
+
id: ObjectId;
|
|
574
|
+
missing: boolean;
|
|
575
|
+
cutoffTime: number;
|
|
576
|
+
cutoffTz: string;
|
|
577
|
+
cutoffCount: number;
|
|
578
|
+
}> {
|
|
579
|
+
const log = await this.sources.refs.getReflog?.(ref);
|
|
580
|
+
const entries = log ? await log.getReverseEntries() : [];
|
|
581
|
+
let cnt = nth;
|
|
582
|
+
let ooid: ObjectId | undefined;
|
|
583
|
+
let reccnt = 0;
|
|
584
|
+
let id = current;
|
|
585
|
+
for (const entry of entries) {
|
|
586
|
+
const timestamp = entry.who.timestamp;
|
|
587
|
+
if (timestamp <= atTime || cnt === 0) {
|
|
588
|
+
const date = formatRfc2822Date(timestamp, entry.who.tzOffset);
|
|
589
|
+
if (ooid !== undefined && !isNullObjectId(ooid)) {
|
|
590
|
+
id = entry.newId;
|
|
591
|
+
if (ooid !== entry.newId) {
|
|
592
|
+
this.warnings.push(`warning: log for ref ${ref} has gap after ${date}`);
|
|
593
|
+
}
|
|
594
|
+
} else if (timestamp === atTime) {
|
|
595
|
+
id = entry.newId;
|
|
596
|
+
} else if (entry.newId !== id) {
|
|
597
|
+
this.warnings.push(`warning: log for ref ${ref} unexpectedly ended on ${date}`);
|
|
598
|
+
}
|
|
599
|
+
return {
|
|
600
|
+
id,
|
|
601
|
+
missing: false,
|
|
602
|
+
cutoffTime: timestamp,
|
|
603
|
+
cutoffTz: entry.who.tzOffset,
|
|
604
|
+
cutoffCount: reccnt,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
reccnt++;
|
|
608
|
+
ooid = entry.oldId;
|
|
609
|
+
if (cnt > 0) cnt--;
|
|
610
|
+
}
|
|
611
|
+
if (reccnt === 0) {
|
|
612
|
+
if (nth === 0) {
|
|
613
|
+
return { id, missing: true, cutoffTime: 0, cutoffTz: "+0000", cutoffCount: 0 };
|
|
614
|
+
}
|
|
615
|
+
throw this.fatal(ref, `log for ${ref} is empty`);
|
|
616
|
+
}
|
|
617
|
+
const oldest = entries[entries.length - 1];
|
|
618
|
+
if (!oldest) throw this.fatal(ref, `log for ${ref} is empty`);
|
|
619
|
+
id = oldest.oldId;
|
|
620
|
+
if (atTime && isNullObjectId(id)) id = oldest.newId;
|
|
621
|
+
return {
|
|
622
|
+
id,
|
|
623
|
+
missing: true,
|
|
624
|
+
cutoffTime: oldest.who.timestamp,
|
|
625
|
+
cutoffTz: oldest.who.tzOffset,
|
|
626
|
+
cutoffCount: reccnt,
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* git's `repo_dwim_ref` with `nonfatal_dangling_mark`: every ref the rules find for `name`
|
|
632
|
+
* (one, unless `core.warnAmbiguousRefs` makes it try them all), its value and full name;
|
|
633
|
+
* no warnings.
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```typescript
|
|
637
|
+
* await resolver.dwimRef("v1.0"); // [{ id: "1a2b...", ref: "refs/tags/v1.0" }]
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
async dwimRef(name: string): Promise<{ id: ObjectId; ref: string }[]> {
|
|
641
|
+
return this.dwimRefAll(name, false);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* git's `repo_dwim_ref` (`expand_ref`): every ref the rules find for `name` (its branch
|
|
646
|
+
* syntax read), git's `warn_ambiguous_refs` making it try them all. A name the rules
|
|
647
|
+
* make into no valid ref name (`check_refname_format`: `HEAD:a.txt`, `a..b`) is never
|
|
648
|
+
* looked up; a symref that points nowhere is `warning: ignoring dangling symref <ref>`.
|
|
649
|
+
*/
|
|
650
|
+
private async dwimRefAll(name: string, warn = true): Promise<{ id: ObjectId; ref: string }[]> {
|
|
651
|
+
const substituted = (await this.substituteBranchName(name)) ?? name;
|
|
652
|
+
const found: { id: ObjectId; ref: string }[] = [];
|
|
653
|
+
const all = this.warnAmbiguousRefs();
|
|
654
|
+
for (const full of candidateRefs(substituted)) {
|
|
655
|
+
const resolved = await this.resolveRef(full);
|
|
656
|
+
if (resolved) {
|
|
657
|
+
found.push(resolved);
|
|
658
|
+
if (!all) break;
|
|
659
|
+
} else if (warn && full !== "HEAD" && (await this.danglingSymref(full))) {
|
|
660
|
+
this.warnings.push(`warning: ignoring dangling symref ${full}`);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return found;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* git's `repo_dwim_log`: every ref the rules find for `name` that has a reflog (its own,
|
|
668
|
+
* or that of the ref it points to), the first one's value and log first.
|
|
669
|
+
*/
|
|
670
|
+
private async dwimLog(name: string): Promise<{ id: ObjectId; ref: string }[]> {
|
|
671
|
+
const substituted = (await this.substituteBranchName(name)) ?? name;
|
|
672
|
+
const found: { id: ObjectId; ref: string }[] = [];
|
|
673
|
+
for (const full of candidateRefs(substituted)) {
|
|
674
|
+
const resolved = await this.resolveRef(full);
|
|
675
|
+
if (!resolved) continue;
|
|
676
|
+
if (await this.hasReflog(full)) found.push({ id: resolved.id, ref: full });
|
|
677
|
+
else if (resolved.ref !== full && (await this.hasReflog(resolved.ref))) found.push(resolved);
|
|
678
|
+
else continue;
|
|
679
|
+
if (!this.warnAmbiguousRefs()) break;
|
|
680
|
+
}
|
|
681
|
+
return found;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/** Whether `name` is a symbolic ref (a chain of them) that ends at no ref. */
|
|
685
|
+
private async danglingSymref(name: string): Promise<boolean> {
|
|
686
|
+
const value = await safe(() => this.sources.refs.get(name));
|
|
687
|
+
return value !== undefined && isSymbolicRef(value);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
private async hasReflog(ref: string): Promise<boolean> {
|
|
691
|
+
return (await this.sources.refs.getReflog?.(ref)) !== undefined;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/** A ref and the ref its symbolic chain ends at, resolved (`refs_resolve_ref_unsafe`). */
|
|
695
|
+
private async resolveRef(name: string): Promise<{ id: ObjectId; ref: string } | undefined> {
|
|
696
|
+
const cached = this.refCache.get(name);
|
|
697
|
+
if (cached) return cached;
|
|
698
|
+
const promise = this.lookupRef(name);
|
|
699
|
+
this.refCache.set(name, promise);
|
|
700
|
+
return promise;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
private async lookupRef(name: string): Promise<{ id: ObjectId; ref: string } | undefined> {
|
|
704
|
+
const first = await safe(() => this.sources.refs.get(name));
|
|
705
|
+
if (!first) return undefined;
|
|
706
|
+
if (!isSymbolicRef(first)) {
|
|
707
|
+
return first.objectId ? { id: first.objectId, ref: name } : undefined;
|
|
708
|
+
}
|
|
709
|
+
const resolved = await safe(() => this.sources.refs.resolve(name));
|
|
710
|
+
if (!resolved?.objectId) return undefined;
|
|
711
|
+
let ref = first.target;
|
|
712
|
+
for (let i = 0; i < 10; i++) {
|
|
713
|
+
const value = await safe(() => this.sources.refs.get(ref));
|
|
714
|
+
if (!value || !isSymbolicRef(value)) break;
|
|
715
|
+
ref = value.target;
|
|
716
|
+
}
|
|
717
|
+
return { id: resolved.objectId, ref };
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// ------------------------------------------------------------------ branch syntax
|
|
721
|
+
|
|
722
|
+
/** git's `substitute_branch_name`: the name `name` stands for when all of it is read. */
|
|
723
|
+
private async substituteBranchName(name: string): Promise<string | undefined> {
|
|
724
|
+
const interpreted = await this.interpret(name);
|
|
725
|
+
if (typeof interpreted === "object" && interpreted.used === name.length) {
|
|
726
|
+
return interpreted.value;
|
|
727
|
+
}
|
|
728
|
+
return undefined;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/** git's `repo_interpret_branch_name`: 0 for `@{-N}` beyond the reflog, -1 for nothing. */
|
|
732
|
+
private async interpret(name: string): Promise<Interpreted | number> {
|
|
733
|
+
const prior = await this.nthPriorCheckout(name);
|
|
734
|
+
if (prior === 0) return 0;
|
|
735
|
+
if (typeof prior === "object") {
|
|
736
|
+
if (prior.used === name.length) return prior;
|
|
737
|
+
return this.reinterpret(name, prior);
|
|
738
|
+
}
|
|
739
|
+
for (let at = name.indexOf("@"); at >= 0; at = name.indexOf("@", at + 1)) {
|
|
740
|
+
if (interpretEmptyAt(name, at)) return this.reinterpret(name, { used: 1, value: "HEAD" });
|
|
741
|
+
const upstream = await this.branchMark(name, at, upstreamMark, (b, rev) =>
|
|
742
|
+
this.upstreamOf(b, rev),
|
|
743
|
+
);
|
|
744
|
+
if (upstream) return upstream;
|
|
745
|
+
const push = await this.branchMark(name, at, pushMark, (b, rev) => this.pushOf(b, rev));
|
|
746
|
+
if (push) return push;
|
|
747
|
+
}
|
|
748
|
+
return -1;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/** git's `reinterpret`: what follows an expanded prefix, read again. */
|
|
752
|
+
private async reinterpret(name: string, prefix: Interpreted): Promise<Interpreted> {
|
|
753
|
+
const combined = prefix.value + name.slice(prefix.used);
|
|
754
|
+
const again = await this.interpret(combined);
|
|
755
|
+
if (typeof again !== "object") return prefix;
|
|
756
|
+
return { used: again.used - prefix.value.length + prefix.used, value: again.value };
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/** git's `interpret_branch_mark`: `[<branch>]@{u}` or `@{push}` at `at`. */
|
|
760
|
+
private async branchMark(
|
|
761
|
+
name: string,
|
|
762
|
+
at: number,
|
|
763
|
+
mark: (s: string) => number,
|
|
764
|
+
data: (branch: string | undefined, revision: string) => Promise<string>,
|
|
765
|
+
): Promise<Interpreted | undefined> {
|
|
766
|
+
const len = mark(name.slice(at));
|
|
767
|
+
if (!len) return undefined;
|
|
768
|
+
const prefix = name.slice(0, at);
|
|
769
|
+
if (prefix.includes(":")) return undefined;
|
|
770
|
+
const branch = prefix === "" || prefix === "HEAD" ? undefined : prefix;
|
|
771
|
+
const value = await data(branch, name);
|
|
772
|
+
return { used: len + at, value };
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/** git's `interpret_nth_prior_checkout`: `@{-N}` at the start of `name`. */
|
|
776
|
+
private async nthPriorCheckout(name: string): Promise<Interpreted | number> {
|
|
777
|
+
if (name.length < 4 || !name.startsWith("@{-")) return -1;
|
|
778
|
+
const brace = name.indexOf("}");
|
|
779
|
+
if (brace < 0) return -1;
|
|
780
|
+
const digits = name.slice(3, brace);
|
|
781
|
+
if (!/^[0-9]+$/.test(digits)) return -1;
|
|
782
|
+
const nth = Number(digits);
|
|
783
|
+
if (!(nth > 0)) return -1;
|
|
784
|
+
const log = await this.sources.refs.getReflog?.("HEAD");
|
|
785
|
+
let remaining = nth;
|
|
786
|
+
for (const entry of log ? await log.getReverseEntries() : []) {
|
|
787
|
+
const prefix = "checkout: moving from ";
|
|
788
|
+
if (!entry.comment.startsWith(prefix)) continue;
|
|
789
|
+
const rest = entry.comment.slice(prefix.length);
|
|
790
|
+
const to = rest.indexOf(" to ");
|
|
791
|
+
if (to < 0) continue;
|
|
792
|
+
if (--remaining === 0) return { used: brace + 1, value: rest.slice(0, to) };
|
|
793
|
+
}
|
|
794
|
+
return 0;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
private async currentBranch(): Promise<string | undefined> {
|
|
798
|
+
const head = await this.sources.refs.get("HEAD");
|
|
799
|
+
if (head && isSymbolicRef(head) && head.target.startsWith("refs/heads/")) {
|
|
800
|
+
return head.target.slice("refs/heads/".length);
|
|
801
|
+
}
|
|
802
|
+
return undefined;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// ------------------------------------------------------------------ objects
|
|
806
|
+
|
|
807
|
+
/** The type of an object, undefined when the repository does not have it. */
|
|
808
|
+
async objectType(id: ObjectId): Promise<ObjectType | undefined> {
|
|
809
|
+
const { commits, tags, trees, blobs } = this.sources;
|
|
810
|
+
if (await safe(() => commits.has(id))) return "commit";
|
|
811
|
+
if (tags && (await safe(() => tags.has(id)))) return "tag";
|
|
812
|
+
if (await safe(() => trees.has(id))) return "tree";
|
|
813
|
+
if (await safe(() => blobs.has(id))) return "blob";
|
|
814
|
+
return undefined;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/** git's `peel_to_type`: tags followed, a commit's tree taken, until `type`. */
|
|
818
|
+
async peelToType(id: ObjectId, type: ObjectType, name?: string): Promise<ObjectId | undefined> {
|
|
819
|
+
let current: ObjectId | undefined = id;
|
|
820
|
+
for (let i = 0; current !== undefined && i < 64; i++) {
|
|
821
|
+
const actual = await this.objectType(current);
|
|
822
|
+
if (actual === undefined) return undefined;
|
|
823
|
+
if (actual === type) return current;
|
|
824
|
+
if (actual === "tag") current = (await this.sources.tags?.load(current))?.object;
|
|
825
|
+
else if (actual === "commit") current = (await this.sources.commits.load(current))?.tree;
|
|
826
|
+
else {
|
|
827
|
+
if (name !== undefined) {
|
|
828
|
+
this.warnings.push(
|
|
829
|
+
`error: ${name}: expected ${type} type, but the object dereferences to ${actual} type`,
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
return undefined;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
return undefined;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* git's `deref_tag` as `lookup_commit_reference` uses it: tags followed; the object
|
|
840
|
+
* they end at and its type (undefined when the repository lacks it).
|
|
841
|
+
*/
|
|
842
|
+
async peelTags(id: ObjectId): Promise<{ id: ObjectId; type: ObjectType | undefined }> {
|
|
843
|
+
let current = id;
|
|
844
|
+
for (let i = 0; i < 64; i++) {
|
|
845
|
+
const type = await this.objectType(current);
|
|
846
|
+
if (type !== "tag") return { id: current, type };
|
|
847
|
+
const next = (await this.sources.tags?.load(current))?.object;
|
|
848
|
+
if (next === undefined) return { id: current, type };
|
|
849
|
+
current = next;
|
|
850
|
+
}
|
|
851
|
+
return { id: current, type: "tag" };
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* git's `lookup_commit_reference`: the commit `id` is or its tags end at; for another
|
|
856
|
+
* object git's `error: object <id> is a <type>, not a commit` (printed whether the caller
|
|
857
|
+
* is quiet or not, as git prints it) and undefined; undefined, silently, for an object
|
|
858
|
+
* the repository lacks.
|
|
859
|
+
*/
|
|
860
|
+
async commitReference(id: ObjectId): Promise<ObjectId | undefined> {
|
|
861
|
+
const peeled = await this.peelTags(id);
|
|
862
|
+
if (peeled.type === "commit") return peeled.id;
|
|
863
|
+
if (peeled.type !== undefined) {
|
|
864
|
+
this.warnings.push(`error: object ${peeled.id} is a ${peeled.type}, not a commit`);
|
|
865
|
+
}
|
|
866
|
+
return undefined;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** The parents of a commit, undefined when it cannot be read. */
|
|
870
|
+
async parentsOf(id: ObjectId): Promise<ObjectId[] | undefined> {
|
|
871
|
+
return (await safe(() => this.sources.commits.load(id)))?.parents;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/** git's `deref_tag`: tags followed to what they point at. */
|
|
875
|
+
private async derefTags(id: ObjectId): Promise<ObjectId | undefined> {
|
|
876
|
+
let current: ObjectId | undefined = id;
|
|
877
|
+
for (let i = 0; current !== undefined && i < 64; i++) {
|
|
878
|
+
const actual = await this.objectType(current);
|
|
879
|
+
if (actual === undefined) return undefined;
|
|
880
|
+
if (actual !== "tag") return current;
|
|
881
|
+
current = (await this.sources.tags?.load(current))?.object;
|
|
882
|
+
}
|
|
883
|
+
return undefined;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* git's `get_tree_entry` / `find_tree_entry`: the object at `path` in a tree (the tree
|
|
888
|
+
* itself for ""). Components are matched exactly: an empty one (`/a`, `d//b`) names
|
|
889
|
+
* nothing, and a trailing `/` only follows a directory (`d/` is d, `a.txt/` nothing).
|
|
890
|
+
*/
|
|
891
|
+
private async treeEntry(tree: ObjectId, path: string): Promise<ObjectId | undefined> {
|
|
892
|
+
if (path === "") return tree;
|
|
893
|
+
let current = tree;
|
|
894
|
+
let rest = path;
|
|
895
|
+
for (;;) {
|
|
896
|
+
const slash = rest.indexOf("/");
|
|
897
|
+
const name = slash < 0 ? rest : rest.slice(0, slash);
|
|
898
|
+
if (name === "") return undefined;
|
|
899
|
+
const entry = await safe(() => this.sources.trees.getEntry(current, name));
|
|
900
|
+
if (!entry) return undefined;
|
|
901
|
+
if (slash < 0) return entry.id;
|
|
902
|
+
if ((entry.mode & 0o170000) !== 0o040000) return undefined;
|
|
903
|
+
rest = rest.slice(slash + 1);
|
|
904
|
+
if (rest === "") return entry.id;
|
|
905
|
+
current = entry.id;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/** `:<n>:<path>`: the index entry of `path` at `stage`. */
|
|
910
|
+
private indexEntry(path: string, stage: number): Promise<ObjectId | undefined> {
|
|
911
|
+
return this.indexEntryAt(path, stage);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
private async indexEntryAt(path: string, stage: number): Promise<ObjectId | undefined> {
|
|
915
|
+
let staging: Staging | undefined;
|
|
916
|
+
try {
|
|
917
|
+
staging = this.sources.staging?.();
|
|
918
|
+
} catch {
|
|
919
|
+
return undefined;
|
|
920
|
+
}
|
|
921
|
+
if (!staging) return undefined;
|
|
922
|
+
const entry = await staging.getEntry(path, stage as 0 | 1 | 2 | 3);
|
|
923
|
+
return entry?.objectId;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/** The commits every ref (then HEAD) points at, as `:/` searches from them. */
|
|
927
|
+
private async allRefCommits(): Promise<ObjectId[]> {
|
|
928
|
+
const names: string[] = [];
|
|
929
|
+
for await (const entry of this.sources.refs.list("refs/")) names.push(entry.name);
|
|
930
|
+
names.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
931
|
+
names.push("HEAD");
|
|
932
|
+
const out: ObjectId[] = [];
|
|
933
|
+
for (const name of names) {
|
|
934
|
+
const resolved = await this.sources.refs.resolve(name);
|
|
935
|
+
if (!resolved?.objectId) continue;
|
|
936
|
+
const commit = await this.peelTagsToCommit(resolved.objectId);
|
|
937
|
+
if (commit !== undefined) out.push(commit);
|
|
938
|
+
}
|
|
939
|
+
// commit_list_insert prepends: the queue takes them last ref first
|
|
940
|
+
return out.reverse();
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
private async peelTagsToCommit(id: ObjectId): Promise<ObjectId | undefined> {
|
|
944
|
+
const target = await this.derefTags(id);
|
|
945
|
+
if (target === undefined) return undefined;
|
|
946
|
+
return (await this.objectType(target)) === "commit" ? target : undefined;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* git's `get_oid_oneline`: from `starts`, youngest commit first (commit date, ties in
|
|
951
|
+
* the order queued), the first whose message matches the POSIX extended regex `prefix`
|
|
952
|
+
* (`!-<re>`: the first that does not match; `!!` a literal `!`).
|
|
953
|
+
*/
|
|
954
|
+
private async oneline(prefix: string, starts: ObjectId[]): Promise<ObjectId | undefined> {
|
|
955
|
+
let pattern = prefix;
|
|
956
|
+
let negative = false;
|
|
957
|
+
if (pattern.startsWith("!")) {
|
|
958
|
+
pattern = pattern.slice(1);
|
|
959
|
+
if (pattern.startsWith("-")) {
|
|
960
|
+
pattern = pattern.slice(1);
|
|
961
|
+
negative = true;
|
|
962
|
+
} else if (!pattern.startsWith("!")) {
|
|
963
|
+
return undefined;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
let regex: ReturnType<typeof compilePosixRegex>;
|
|
967
|
+
try {
|
|
968
|
+
regex = compilePosixRegex(pattern, { extended: true });
|
|
969
|
+
} catch {
|
|
970
|
+
return undefined;
|
|
971
|
+
}
|
|
972
|
+
const queue: { id: ObjectId; date: number; ctr: number }[] = [];
|
|
973
|
+
let ctr = 0;
|
|
974
|
+
const seen = new Set<ObjectId>();
|
|
975
|
+
const cache = new Map<ObjectId, Commit | undefined>();
|
|
976
|
+
const load = async (id: ObjectId) => {
|
|
977
|
+
if (!cache.has(id)) cache.set(id, await safe(() => this.sources.commits.load(id)));
|
|
978
|
+
return cache.get(id);
|
|
979
|
+
};
|
|
980
|
+
const put = async (id: ObjectId) => {
|
|
981
|
+
const commit = await load(id);
|
|
982
|
+
queue.push({ id, date: commit?.committer.timestamp ?? 0, ctr: ctr++ });
|
|
983
|
+
};
|
|
984
|
+
for (const id of starts) {
|
|
985
|
+
seen.add(id);
|
|
986
|
+
await put(id);
|
|
987
|
+
}
|
|
988
|
+
const encoder = new TextEncoder();
|
|
989
|
+
while (queue.length > 0) {
|
|
990
|
+
let best = 0;
|
|
991
|
+
for (let i = 1; i < queue.length; i++) {
|
|
992
|
+
const a = queue[i];
|
|
993
|
+
const b = queue[best];
|
|
994
|
+
if (!a || !b) continue;
|
|
995
|
+
if (a.date > b.date || (a.date === b.date && a.ctr < b.ctr)) best = i;
|
|
996
|
+
}
|
|
997
|
+
const [next] = queue.splice(best, 1);
|
|
998
|
+
if (!next) break;
|
|
999
|
+
const commit = await load(next.id);
|
|
1000
|
+
if (!commit) continue;
|
|
1001
|
+
for (const parent of commit.parents) {
|
|
1002
|
+
if (seen.has(parent)) continue;
|
|
1003
|
+
seen.add(parent);
|
|
1004
|
+
await put(parent);
|
|
1005
|
+
}
|
|
1006
|
+
const matches = negative !== regex.test(encoder.encode(commit.message));
|
|
1007
|
+
if (matches) return next.id;
|
|
1008
|
+
}
|
|
1009
|
+
return undefined;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// ------------------------------------------------------------------ short ids
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* git's `get_short_oid`: the one stored object whose id starts with `name` (4 to 40 hex, 64 in a SHA-256 repository,
|
|
1016
|
+
* digits, any case). Of several, the one the hint (`flags.hint`, else `core.disambiguate`)
|
|
1017
|
+
* accepts, when it accepts exactly one. An ambiguity is reported, unless quiet, as git
|
|
1018
|
+
* reports it: `error: short object ID <prefix> is ambiguous` and `hint:` lines listing the
|
|
1019
|
+
* candidates (tags, commits, trees, blobs; by id within a type), only those the hint accepts
|
|
1020
|
+
* when it accepts several.
|
|
1021
|
+
*/
|
|
1022
|
+
private async shortOid(name: string, flags: ResolveOptions = {}): Promise<ShortOid> {
|
|
1023
|
+
if (
|
|
1024
|
+
name.length < MINIMUM_ABBREV_LENGTH ||
|
|
1025
|
+
name.length > this.hexLength ||
|
|
1026
|
+
!HEX_DIGITS.test(name)
|
|
1027
|
+
) {
|
|
1028
|
+
return { status: "invalid" };
|
|
1029
|
+
}
|
|
1030
|
+
const prefix = name.toLowerCase();
|
|
1031
|
+
const candidates = await this.objectsWithPrefix(prefix);
|
|
1032
|
+
if (candidates.length === 0) return { status: "missing" };
|
|
1033
|
+
const hint = flags.hint ?? this.defaultHint();
|
|
1034
|
+
let status: ShortOid;
|
|
1035
|
+
let listedHint = hint;
|
|
1036
|
+
if (candidates.length === 1) {
|
|
1037
|
+
status = { status: "found", id: candidates[0] as ObjectId };
|
|
1038
|
+
} else if (hint === undefined) {
|
|
1039
|
+
status = { status: "ambiguous" };
|
|
1040
|
+
} else {
|
|
1041
|
+
const accepted: ObjectId[] = [];
|
|
1042
|
+
for (const id of candidates) if (await this.satisfies(id, hint)) accepted.push(id);
|
|
1043
|
+
if (accepted.length === 1) status = { status: "found", id: accepted[0] as ObjectId };
|
|
1044
|
+
else {
|
|
1045
|
+
status = { status: "ambiguous" };
|
|
1046
|
+
// none accepted: git lists them all (it drops the hint)
|
|
1047
|
+
if (accepted.length === 0) listedHint = undefined;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
if (status.status === "ambiguous" && !flags.quiet) {
|
|
1051
|
+
await this.reportAmbiguous(prefix, candidates, listedHint);
|
|
1052
|
+
}
|
|
1053
|
+
return status;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/** git's `show_ambiguous_object` for each candidate, sorted as `sort_ambiguous` sorts them. */
|
|
1057
|
+
private async reportAmbiguous(
|
|
1058
|
+
prefix: string,
|
|
1059
|
+
candidates: ObjectId[],
|
|
1060
|
+
hint: DisambiguateHint | undefined,
|
|
1061
|
+
): Promise<void> {
|
|
1062
|
+
const typed: { id: ObjectId; type: ObjectType | undefined }[] = [];
|
|
1063
|
+
for (const id of candidates) typed.push({ id, type: await this.objectType(id) });
|
|
1064
|
+
// tags, commits, trees, blobs (git's type % 4); by id within a type
|
|
1065
|
+
const rank = (t: ObjectType | undefined) =>
|
|
1066
|
+
t === "tag" ? 0 : t === "commit" ? 1 : t === "tree" ? 2 : t === "blob" ? 3 : -1;
|
|
1067
|
+
typed.sort((a, b) =>
|
|
1068
|
+
rank(a.type) !== rank(b.type) ? rank(a.type) - rank(b.type) : a.id < b.id ? -1 : 1,
|
|
1069
|
+
);
|
|
1070
|
+
const shown: typeof typed = [];
|
|
1071
|
+
for (const c of typed)
|
|
1072
|
+
if (hint === undefined || (await this.satisfies(c.id, hint))) shown.push(c);
|
|
1073
|
+
const lengths =
|
|
1074
|
+
(await safe(async () => this.sources.abbreviate?.(shown.map((c) => c.id)))) ?? undefined;
|
|
1075
|
+
const lines = [`error: short object ID ${prefix} is ambiguous`, "hint: The candidates are:"];
|
|
1076
|
+
for (const { id, type } of shown) {
|
|
1077
|
+
const hash = id.slice(0, lengths?.get(id) ?? 7);
|
|
1078
|
+
let line: string;
|
|
1079
|
+
if (type === "commit") {
|
|
1080
|
+
const commit = await safe(() => this.sources.commits.load(id));
|
|
1081
|
+
line = commit
|
|
1082
|
+
? `${hash} commit ${shortDate(commit.author.timestamp, commit.author.tzOffset)} - ${formatSubject(commit.message)}`
|
|
1083
|
+
: `${hash} commit - `;
|
|
1084
|
+
} else if (type === "tag") {
|
|
1085
|
+
const tag = await safe(async () => this.sources.tags?.load(id));
|
|
1086
|
+
line =
|
|
1087
|
+
tag?.tag !== undefined
|
|
1088
|
+
? `${hash} tag ${shortDate(tag.tagger?.timestamp ?? 0, "+0000")} - ${tag.tag}`
|
|
1089
|
+
: `${hash} [bad tag, could not parse it]`;
|
|
1090
|
+
} else if (type === "tree" || type === "blob") {
|
|
1091
|
+
line = `${hash} ${type}`;
|
|
1092
|
+
} else {
|
|
1093
|
+
line = `${hash} [bad object]`;
|
|
1094
|
+
}
|
|
1095
|
+
lines.push(`hint: ${line}`);
|
|
1096
|
+
}
|
|
1097
|
+
this.warnings.push(lines.join("\n"));
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/** The stored ids that start with `prefix` (git's `repo_for_each_abbrev`), sorted. */
|
|
1101
|
+
private async objectsWithPrefix(prefix: string): Promise<ObjectId[]> {
|
|
1102
|
+
const found = new Set<ObjectId>();
|
|
1103
|
+
const { objects } = this.sources;
|
|
1104
|
+
if (objects) {
|
|
1105
|
+
for await (const id of listObjectsWithPrefix(objects, prefix)) found.add(id);
|
|
1106
|
+
} else {
|
|
1107
|
+
const { commits, trees, blobs, tags } = this.sources;
|
|
1108
|
+
for (const store of [commits, trees, blobs, tags] as { keys?(): AsyncIterable<ObjectId> }[]) {
|
|
1109
|
+
if (!store?.keys) continue;
|
|
1110
|
+
for await (const id of store.keys()) if (id.startsWith(prefix)) found.add(id);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
return [...found].sort();
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* git's `set_disambiguate_hint_config` as its config loading runs it, before any revision
|
|
1118
|
+
* is read (see {@link configLoadError}). Commands check it when they start, as every git
|
|
1119
|
+
* command does; checked here too, once per resolver, for a resolver used on its own.
|
|
1120
|
+
*/
|
|
1121
|
+
private checkDisambiguateConfig(name: string): void {
|
|
1122
|
+
if (this.disambiguateChecked) return;
|
|
1123
|
+
this.disambiguateChecked = true;
|
|
1124
|
+
const failure = configLoadError(this.sources.workingCopy);
|
|
1125
|
+
if (failure) throw new RevisionError(name, [...this.warnings, failure.message].join("\n"));
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/** `core.disambiguate` (git's `default_disambiguate_hint`); "none" and unset are no hint. */
|
|
1129
|
+
private defaultHint(): DisambiguateHint | undefined {
|
|
1130
|
+
const value = this.remoteConfig().value("core.disambiguate")?.toLowerCase();
|
|
1131
|
+
switch (value) {
|
|
1132
|
+
case "commit":
|
|
1133
|
+
case "committish":
|
|
1134
|
+
case "tree":
|
|
1135
|
+
case "treeish":
|
|
1136
|
+
case "blob":
|
|
1137
|
+
return value;
|
|
1138
|
+
default:
|
|
1139
|
+
return undefined;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
/** git's `disambiguate_<hint>_only`: whether the object is, or peels to, what `hint` wants. */
|
|
1144
|
+
private async satisfies(id: ObjectId, hint: DisambiguateHint): Promise<boolean> {
|
|
1145
|
+
const type = await this.objectType(id);
|
|
1146
|
+
switch (hint) {
|
|
1147
|
+
case "commit":
|
|
1148
|
+
return type === "commit";
|
|
1149
|
+
case "tree":
|
|
1150
|
+
return type === "tree";
|
|
1151
|
+
case "blob":
|
|
1152
|
+
return type === "blob";
|
|
1153
|
+
case "committish":
|
|
1154
|
+
case "treeish": {
|
|
1155
|
+
const wanted = (t: ObjectType | undefined) =>
|
|
1156
|
+
t === "commit" || (hint === "treeish" && t === "tree");
|
|
1157
|
+
if (wanted(type)) return true;
|
|
1158
|
+
if (type !== "tag") return false;
|
|
1159
|
+
return wanted((await this.peelTags(id)).type);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
/**
|
|
1165
|
+
* git's `get_describe_name`: `<ref>-<count>-g<abbrev>`, the abbreviation read quietly as a
|
|
1166
|
+
* commit, when what precedes `-g` is a valid ref name, a dash and (hex) digits.
|
|
1167
|
+
*/
|
|
1168
|
+
private async describeName(name: string): Promise<ObjectId | undefined> {
|
|
1169
|
+
for (let cp = name.length - 1; cp >= 2; cp--) {
|
|
1170
|
+
const ch = name[cp];
|
|
1171
|
+
if (isHexDigit(ch)) continue;
|
|
1172
|
+
if (ch === "g" && name[cp - 1] === "-" && refAndCountPartsValid(name, cp - 1)) {
|
|
1173
|
+
const short = await this.shortOid(name.slice(cp + 1), { hint: "commit", quiet: true });
|
|
1174
|
+
return short.status === "found" ? short.id : undefined;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
return undefined;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* git's `resolve_relative_path`: a path starting with `./` or `../` read against
|
|
1182
|
+
* {@link cwdPrefix} and normalized; other paths as given.
|
|
1183
|
+
*
|
|
1184
|
+
* @throws RevisionError with git's message for a path outside the worktree
|
|
1185
|
+
*/
|
|
1186
|
+
private relativePath(path: string, revision: string): string {
|
|
1187
|
+
if (!path.startsWith("./") && !path.startsWith("../")) return path;
|
|
1188
|
+
const normalized = normalizePath(this.cwdPrefix + path);
|
|
1189
|
+
if (normalized === undefined) {
|
|
1190
|
+
// prefix_path's die: the worktree named as the host names it
|
|
1191
|
+
const top = this.sources.worktreeHostPath;
|
|
1192
|
+
const at = top === undefined ? "" : ` at '${top}'`;
|
|
1193
|
+
const error = new RevisionError(revision, `fatal: '${path}' is outside repository${at}`);
|
|
1194
|
+
this.diagnoses.add(error);
|
|
1195
|
+
throw error;
|
|
1196
|
+
}
|
|
1197
|
+
return normalized;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* git's `maybe_die_on_misspelt_object_name`: `name` read again quietly with
|
|
1202
|
+
* `GET_OID_ONLY_TO_DIE`, for its better diagnosis of a `<rev>:<path>` or `:<path>` that
|
|
1203
|
+
* names nothing (thrown); where git's read just fails (or dies of something it would not
|
|
1204
|
+
* print quietly) this returns, for the caller's general message.
|
|
1205
|
+
*
|
|
1206
|
+
* @throws RevisionError with git's diagnosis (`fatal: path 'x' does not exist in 'HEAD'`,
|
|
1207
|
+
* `fatal: '../x' is outside repository at '/repo'`, ...)
|
|
1208
|
+
*/
|
|
1209
|
+
async dieOnMisspeltObjectName(name: string): Promise<void> {
|
|
1210
|
+
try {
|
|
1211
|
+
await this.resolve(name, { quiet: true, onlyToDie: true });
|
|
1212
|
+
} catch (error) {
|
|
1213
|
+
if (error instanceof RevisionError && this.diagnoses.has(error)) throw error;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
/** The errors {@link dieOnMisspeltObjectName} passes on. */
|
|
1218
|
+
private readonly diagnoses = new WeakSet<RevisionError>();
|
|
1219
|
+
|
|
1220
|
+
private die(revision: string, message: string): never {
|
|
1221
|
+
const error = new RevisionError(revision, [...this.warnings, message].join("\n"));
|
|
1222
|
+
this.diagnoses.add(error);
|
|
1223
|
+
throw error;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
/**
|
|
1227
|
+
* Whether something is at `path` on disk, from the top of the worktree: git's `file_exists`
|
|
1228
|
+
* runs after setup moved to the top, whatever the current directory was.
|
|
1229
|
+
*/
|
|
1230
|
+
private async onDisk(path: string): Promise<boolean> {
|
|
1231
|
+
const exists = this.sources.fileExists;
|
|
1232
|
+
// git's file_exists: lstat of the path as written (`a.txt/` is no file)
|
|
1233
|
+
return exists ? exists(path) : false;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
/** git's `diagnose_invalid_oid_path`: `<objectName>:<filename>` named nothing. */
|
|
1237
|
+
private async diagnoseTreePath(
|
|
1238
|
+
name: string,
|
|
1239
|
+
objectName: string,
|
|
1240
|
+
tree: ObjectId | undefined,
|
|
1241
|
+
filename: string,
|
|
1242
|
+
): Promise<never> {
|
|
1243
|
+
if (await this.onDisk(filename)) {
|
|
1244
|
+
this.die(name, `fatal: path '${filename}' exists on disk, but not in '${objectName}'`);
|
|
1245
|
+
}
|
|
1246
|
+
const fullname = `${this.cwdPrefix}${filename}`;
|
|
1247
|
+
if (tree !== undefined && (await this.treeEntry(tree, fullname)) !== undefined) {
|
|
1248
|
+
this.die(
|
|
1249
|
+
name,
|
|
1250
|
+
`fatal: path '${fullname}' exists, but not '${filename}'\n` +
|
|
1251
|
+
`hint: Did you mean '${objectName}:${fullname}' aka '${objectName}:./${filename}'?`,
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1254
|
+
this.die(name, `fatal: path '${filename}' does not exist in '${objectName}'`);
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
/** git's `diagnose_invalid_index_path`: `:<stage>:<filename>` named nothing. */
|
|
1258
|
+
private async diagnoseIndexPath(name: string, stage: number, filename: string): Promise<never> {
|
|
1259
|
+
const stageOf = async (path: string): Promise<number | undefined> => {
|
|
1260
|
+
for (const n of [0, 1, 2, 3] as const) {
|
|
1261
|
+
if ((await this.indexEntryAt(path, n)) !== undefined) return n;
|
|
1262
|
+
}
|
|
1263
|
+
return undefined;
|
|
1264
|
+
};
|
|
1265
|
+
const atStage = await stageOf(filename);
|
|
1266
|
+
if (atStage !== undefined) {
|
|
1267
|
+
this.die(
|
|
1268
|
+
name,
|
|
1269
|
+
`fatal: path '${filename}' is in the index, but not at stage ${stage}\n` +
|
|
1270
|
+
`hint: Did you mean ':${atStage}:${filename}'?`,
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
const fullname = `${this.cwdPrefix}${filename}`;
|
|
1274
|
+
const fullStage = await stageOf(fullname);
|
|
1275
|
+
if (fullStage !== undefined) {
|
|
1276
|
+
this.die(
|
|
1277
|
+
name,
|
|
1278
|
+
`fatal: path '${fullname}' is in the index, but not '${filename}'\n` +
|
|
1279
|
+
`hint: Did you mean ':${fullStage}:${fullname}' aka ':${fullStage}:./${filename}'?`,
|
|
1280
|
+
);
|
|
1281
|
+
}
|
|
1282
|
+
if (await this.onDisk(filename)) {
|
|
1283
|
+
this.die(name, `fatal: path '${filename}' exists on disk, but not in the index`);
|
|
1284
|
+
}
|
|
1285
|
+
this.die(name, `fatal: path '${filename}' does not exist (neither on disk nor in the index)`);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// ------------------------------------------------------------------ helpers
|
|
1289
|
+
|
|
1290
|
+
private remoteConfig(): RemoteConfigStore {
|
|
1291
|
+
this.config ??= RemoteConfigStore.from(this.sources.workingCopy);
|
|
1292
|
+
return this.config;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
/** `core.warnAmbiguousRefs` (default true): every dwim rule tried, ambiguity warned. */
|
|
1296
|
+
private warnAmbiguousRefs(): boolean {
|
|
1297
|
+
return parseGitBool(this.remoteConfig().value("core.warnAmbiguousRefs")) ?? true;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
private fatal(revision: string, message: string): RevisionError {
|
|
1301
|
+
return new RevisionError(revision, `fatal: ${message}`);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
/** git's `interpret_empty_at`: `@` alone, or followed by `@{...}`, is HEAD. */
|
|
1306
|
+
function interpretEmptyAt(name: string, at: number): boolean {
|
|
1307
|
+
if (at !== 0 || name[1] === "{") return false;
|
|
1308
|
+
const next = name.indexOf("@", 1);
|
|
1309
|
+
if (next >= 0 && name[next + 1] !== "{") return false;
|
|
1310
|
+
return (next < 0 ? name.length : next) === 1;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
/**
|
|
1314
|
+
* The full names git's `ref_rev_parse_rules` make of `name`, those its ref lookup would
|
|
1315
|
+
* read: valid ref names (`check_refname_format`, one level allowed) that are `refs/...` or
|
|
1316
|
+
* a root ref like `HEAD`.
|
|
1317
|
+
*/
|
|
1318
|
+
function candidateRefs(name: string): string[] {
|
|
1319
|
+
const out: string[] = [];
|
|
1320
|
+
for (const rule of REV_PARSE_RULES) {
|
|
1321
|
+
const full = rule(name);
|
|
1322
|
+
if (isRefLike(full) && isValidRefName(full, { allowOneLevel: true })) out.push(full);
|
|
1323
|
+
}
|
|
1324
|
+
return out;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
/** Whether git's ref lookup takes `name` as a ref (`refs/...` or a root ref like `HEAD`). */
|
|
1328
|
+
function isRefLike(name: string): boolean {
|
|
1329
|
+
return name.startsWith("refs/") || /^[A-Z_]+$/.test(name);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
/**
|
|
1333
|
+
* git's `normalize_path_copy`: `//` collapsed, `.` components dropped, `..` taking the
|
|
1334
|
+
* component before it away; undefined when it climbs above the top. A trailing `/` stays.
|
|
1335
|
+
*/
|
|
1336
|
+
function normalizePath(path: string): string | undefined {
|
|
1337
|
+
const out: string[] = [];
|
|
1338
|
+
const parts = path.split("/");
|
|
1339
|
+
const trailing = parts.length > 1 && parts[parts.length - 1] === "";
|
|
1340
|
+
for (const part of parts) {
|
|
1341
|
+
if (part === "" || part === ".") continue;
|
|
1342
|
+
if (part === "..") {
|
|
1343
|
+
if (out.length === 0) return undefined;
|
|
1344
|
+
out.pop();
|
|
1345
|
+
continue;
|
|
1346
|
+
}
|
|
1347
|
+
out.push(part);
|
|
1348
|
+
}
|
|
1349
|
+
const joined = out.join("/");
|
|
1350
|
+
return trailing && joined !== "" ? `${joined}/` : joined;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* git's `ref_and_count_parts_valid`: `name[len]` is the `-` before `g`; before it come hex
|
|
1355
|
+
* digits (at least one), a `-`, and a valid ref name (one level allowed).
|
|
1356
|
+
*/
|
|
1357
|
+
function refAndCountPartsValid(name: string, len: number): boolean {
|
|
1358
|
+
if (!isHexDigit(name[len - 1])) return false;
|
|
1359
|
+
let cp = len - 2;
|
|
1360
|
+
for (; cp > 0; cp--) {
|
|
1361
|
+
if (name[cp] === "-") break;
|
|
1362
|
+
if (!isHexDigit(name[cp])) return false;
|
|
1363
|
+
}
|
|
1364
|
+
if (cp < 0 || name[cp] !== "-") return false;
|
|
1365
|
+
return isValidRefName(name.slice(0, cp), { allowOneLevel: true });
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
/** git's `DATE_SHORT`: the day `timestamp` falls on in the zone `tz` (`+HHMM`). */
|
|
1369
|
+
function shortDate(timestamp: number, tz: string): string {
|
|
1370
|
+
const m = /^([+-])(\d\d)(\d\d)$/.exec(tz);
|
|
1371
|
+
const offset = m ? (m[1] === "-" ? -1 : 1) * (Number(m[2]) * 60 + Number(m[3])) * 60 : 0;
|
|
1372
|
+
const d = new Date((timestamp + offset) * 1000);
|
|
1373
|
+
const pad = (n: number) => String(n).padStart(2, "0");
|
|
1374
|
+
return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
/** git's `format_subject` (`%s`): the first paragraph, its lines joined with a space. */
|
|
1378
|
+
function formatSubject(message: string): string {
|
|
1379
|
+
const lines = message.split("\n");
|
|
1380
|
+
let i = 0;
|
|
1381
|
+
while (i < lines.length && (lines[i] ?? "").trim() === "") i++;
|
|
1382
|
+
const out: string[] = [];
|
|
1383
|
+
for (; i < lines.length; i++) {
|
|
1384
|
+
const line = lines[i] ?? "";
|
|
1385
|
+
if (line.trim() === "") break;
|
|
1386
|
+
out.push(line.replace(/\s+$/, ""));
|
|
1387
|
+
}
|
|
1388
|
+
return out.join(" ");
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
async function safe<T>(fn: () => Promise<T>): Promise<T | undefined> {
|
|
1392
|
+
try {
|
|
1393
|
+
return await fn();
|
|
1394
|
+
} catch {
|
|
1395
|
+
return undefined;
|
|
1396
|
+
}
|
|
1397
|
+
}
|