@statewalker/vcs-commands 0.5.0 → 0.6.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 +117 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- 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/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 +225 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +68 -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 +148 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +115 -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 +43 -0
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +66 -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 +416 -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 +231 -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 +54 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +12 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- 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 +209 -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 +252 -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 +106 -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 +41 -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 +41 -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 +80 -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 +321 -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 +155 -1
- 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 +53 -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-DnmlfwGV.js +61620 -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-DxvwPrPB.js +7612 -0
- package/dist/git-command.d.ts +413 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +306 -3
- 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/remote-config-store.d.ts +105 -3
- 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 +10 -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/merge-result.d.ts +15 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +12 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +42 -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-BZGa2Z3I.js +2934 -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 +832 -0
- package/src/commands/apply/apply-engine.ts +1603 -0
- package/src/commands/apply/apply-parse.ts +1209 -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 +1079 -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 +634 -67
- package/src/commands/commit-command.ts +1781 -166
- package/src/commands/core-config.ts +161 -6
- package/src/commands/date-format.ts +668 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1898 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +606 -66
- package/src/commands/format-patch-command.ts +969 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3347 -0
- package/src/commands/fsck/fsck-loose.ts +287 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1044 -0
- package/src/commands/fsck/fsck-object-table.ts +363 -0
- package/src/commands/fsck/fsck-pack.ts +604 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +249 -0
- package/src/commands/gc-command.ts +147 -1
- package/src/commands/git-date.ts +895 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1472 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +706 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +82 -0
- package/src/commands/init-command.ts +28 -4
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1915 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +101 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1386 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1198 -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 +768 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +602 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +377 -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 +196 -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 +1431 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +207 -22
- package/src/commands/push-command.ts +236 -23
- package/src/commands/read-tree-command.ts +857 -0
- package/src/commands/rebase-command.ts +3808 -371
- 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 +93 -22
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +827 -103
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +277 -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 +1379 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +869 -0
- package/src/commands/sequencer-support.ts +869 -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 +1328 -105
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +330 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +334 -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 +194 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +208 -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 +7 -1
- 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 +1177 -118
- package/src/git.ts +523 -10
- package/src/index.ts +1 -1
- package/src/remote-config/remote-config-store.ts +242 -8
- package/src/remote-config/remote-refs.ts +22 -6
- package/src/rename/detect-renames.ts +711 -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 +12 -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 +1051 -0
- package/src/results/fetch-result.ts +15 -0
- package/src/results/index.ts +5 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +12 -3
- package/src/results/push-result.ts +43 -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 +123 -45
- 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,869 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's sequencer for `cherry-pick` and `revert`: each commit's change merged into HEAD by
|
|
3
|
+
* merge-ort and written to the index and the worktree, committed or stopped at a conflict
|
|
4
|
+
* with git's state (`CHERRY_PICK_HEAD` / `REVERT_HEAD`, `MERGE_MSG`, `AUTO_MERGE`, and for
|
|
5
|
+
* several commits `sequencer/` with `head`, `todo` and `abort-safety`), so native git can
|
|
6
|
+
* `--continue`, `--skip` or `--abort` what we started and the other way round.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Commit, ObjectId, PersonIdent } from "@statewalker/vcs-core";
|
|
10
|
+
import { compareGitPaths, parseGitBool } from "@statewalker/vcs-utils/encoding";
|
|
11
|
+
import type { Worktree } from "@statewalker/vcs-working-tree";
|
|
12
|
+
import { GitApiError } from "../errors/git-api-error.js";
|
|
13
|
+
import {
|
|
14
|
+
InvalidMainlineParentError,
|
|
15
|
+
MultipleParentsNotAllowedError,
|
|
16
|
+
} from "../errors/merge-errors.js";
|
|
17
|
+
import { NotACommitError, RefNotFoundError } from "../errors/ref-errors.js";
|
|
18
|
+
import type { CommandCommits, CommandRefs, CommandTrees } from "../git-command.js";
|
|
19
|
+
import { coreBool, createIdAbbreviator, type IdAbbreviator } from "./core-config.js";
|
|
20
|
+
import { type HookSession, sequencerPostCommit, sequencerPrepareMessage } from "./git-hooks.js";
|
|
21
|
+
import { authorIdentOf, committerIdentOf } from "./git-ident.js";
|
|
22
|
+
import { UNMERGED_FILES_MESSAGE } from "./merge-command.js";
|
|
23
|
+
import { conflictStyleOf } from "./merge-config.js";
|
|
24
|
+
import { ortConfigOptions } from "./merge-drivers.js";
|
|
25
|
+
import {
|
|
26
|
+
conflictsComment,
|
|
27
|
+
FlatTreeCache,
|
|
28
|
+
indexChangesFromTree,
|
|
29
|
+
type MergeWriteContext,
|
|
30
|
+
type OperationState,
|
|
31
|
+
readIndex,
|
|
32
|
+
storeFlatTreeOver,
|
|
33
|
+
subjectOf,
|
|
34
|
+
switchTrees,
|
|
35
|
+
treeDelta,
|
|
36
|
+
writeIndexAsTree,
|
|
37
|
+
} from "./merge-support.js";
|
|
38
|
+
import { stripspace } from "./message-cleanup.js";
|
|
39
|
+
import { ortResultEntries } from "./ort-merge.js";
|
|
40
|
+
import { mergeStoredTrees, storedBase } from "./ort-recursive.js";
|
|
41
|
+
import { reflogLine, reflogMessages, updateHead } from "./reflog-messages.js";
|
|
42
|
+
import {
|
|
43
|
+
cleanupMessage,
|
|
44
|
+
moveHeadAsReset,
|
|
45
|
+
removeBranchState,
|
|
46
|
+
resetMerge,
|
|
47
|
+
} from "./sequencer-support.js";
|
|
48
|
+
|
|
49
|
+
/** What the sequencer does with each commit. */
|
|
50
|
+
export type PickAction = "pick" | "revert";
|
|
51
|
+
|
|
52
|
+
/** What a cherry-pick or revert is asked to do. */
|
|
53
|
+
export enum SequencerOperation {
|
|
54
|
+
/** Start picking (reverting) the included commits */
|
|
55
|
+
START = "start",
|
|
56
|
+
/** `--continue`: commit the resolved conflict and pick the rest */
|
|
57
|
+
CONTINUE = "continue",
|
|
58
|
+
/** `--skip`: drop the commit that stopped and pick the rest */
|
|
59
|
+
SKIP = "skip",
|
|
60
|
+
/** `--abort`: back to where the operation started */
|
|
61
|
+
ABORT = "abort",
|
|
62
|
+
/** `--quit`: forget the operation, keep everything as it is */
|
|
63
|
+
QUIT = "quit",
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** How one run of the sequencer ended. */
|
|
67
|
+
export interface PickOutcome {
|
|
68
|
+
status: "ok" | "conflicting" | "failed";
|
|
69
|
+
newHead?: ObjectId;
|
|
70
|
+
picked: ObjectId[];
|
|
71
|
+
conflicts?: string[];
|
|
72
|
+
/** git's error (stderr) for a failure or a stop at a conflict */
|
|
73
|
+
message?: string;
|
|
74
|
+
/** merge-ort's lines (stdout) */
|
|
75
|
+
output: string[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** What the sequencer works with. */
|
|
79
|
+
export interface SequencerDeps extends MergeWriteContext {
|
|
80
|
+
commits: CommandCommits;
|
|
81
|
+
refs: CommandRefs;
|
|
82
|
+
trees: CommandTrees;
|
|
83
|
+
worktree?: Worktree;
|
|
84
|
+
state: OperationState;
|
|
85
|
+
resolve: (name: string) => Promise<ObjectId>;
|
|
86
|
+
/** The hooks of the command (prepare-commit-msg and post-commit around each commit) */
|
|
87
|
+
hooks?: HookSession;
|
|
88
|
+
/**
|
|
89
|
+
* A `git commit` run by the sequencer; the commit made, or the error that stopped it (its
|
|
90
|
+
* editor, an empty message, a hook). `pick`: `git commit -n -e` as git's run_git_commit
|
|
91
|
+
* runs it for a pick with `--edit` (EDIT_MSG without VERIFY_MSG): MERGE_MSG as the
|
|
92
|
+
* template of the editor, `reflogAction` as its GIT_REFLOG_ACTION. `continue`:
|
|
93
|
+
* continue_single_pick's `git commit` for a resolved conflict, `--no-edit --cleanup=strip`
|
|
94
|
+
* unless `edit` (its editor): every hook (pre-commit and commit-msg too), its own reflog
|
|
95
|
+
* message, no GIT_REFLOG_ACTION. Needed for {@link PickOptions.edit}; without it a
|
|
96
|
+
* resolved conflict is committed in process.
|
|
97
|
+
*/
|
|
98
|
+
gitCommit?: (mode: PickCommitMode) => Promise<ObjectId>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The `git commit` the sequencer runs (see {@link SequencerDeps.gitCommit}). */
|
|
102
|
+
export type PickCommitMode =
|
|
103
|
+
| { kind: "pick"; reflogAction: string }
|
|
104
|
+
| { kind: "continue"; edit: boolean };
|
|
105
|
+
|
|
106
|
+
/** Options of one sequencer run. */
|
|
107
|
+
export interface PickOptions {
|
|
108
|
+
action: PickAction;
|
|
109
|
+
noCommit?: boolean;
|
|
110
|
+
mainline?: number;
|
|
111
|
+
favor?: "ours" | "theirs" | "union";
|
|
112
|
+
/** The label of HEAD in conflict markers (default `HEAD`) */
|
|
113
|
+
oursLabel?: string;
|
|
114
|
+
/**
|
|
115
|
+
* The committer (default: resolved as git resolves it, `GIT_COMMITTER_*`, `committer.*`,
|
|
116
|
+
* `user.*`); also a revert's author when nobody is configured
|
|
117
|
+
*/
|
|
118
|
+
committer?: PersonIdent;
|
|
119
|
+
/** The action of the picks' reflog lines (default `cherry-pick` / `revert`) */
|
|
120
|
+
reflogAction?: string;
|
|
121
|
+
/**
|
|
122
|
+
* `--edit`: each pick that merges cleanly is committed by `git commit -n -e` (see
|
|
123
|
+
* {@link SequencerDeps.gitCommit}), its message edited, with git commit's hooks; a
|
|
124
|
+
* conflict resolved and continued is committed by `git commit` with its editor. `false`
|
|
125
|
+
* is `--no-edit` given; both are saved in `sequencer/opts` for `--continue` and `--skip`
|
|
126
|
+
* (git's `options.edit`), left out when neither was given.
|
|
127
|
+
*/
|
|
128
|
+
edit?: boolean;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const ACTION_NAME = { pick: "cherry-pick", revert: "revert" } as const;
|
|
132
|
+
const ACTION_ING = { pick: "Cherry-picking", revert: "Reverting" } as const;
|
|
133
|
+
const HEAD_REF = { pick: "CHERRY_PICK_HEAD", revert: "REVERT_HEAD" } as const;
|
|
134
|
+
|
|
135
|
+
interface TodoItem {
|
|
136
|
+
action: PickAction;
|
|
137
|
+
id: ObjectId;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** git's sequencer for `cherry-pick` / `revert`. */
|
|
141
|
+
export class PickSequencer {
|
|
142
|
+
/** The flat trees the picks read (each pick's result is the next one's HEAD) */
|
|
143
|
+
private readonly flats: FlatTreeCache;
|
|
144
|
+
/** The clock of this run's identities and reflog lines, read again for each commit */
|
|
145
|
+
private clock?: number;
|
|
146
|
+
/** git's find_unique_abbrev (`core.abbrev`) for labels, messages and the todo */
|
|
147
|
+
private readonly abbreviator: IdAbbreviator;
|
|
148
|
+
/** `--edit` / `--no-edit` (git's opts->edit, unset: undefined), read back from the opts */
|
|
149
|
+
private edit: boolean | undefined;
|
|
150
|
+
|
|
151
|
+
constructor(
|
|
152
|
+
private readonly deps: SequencerDeps,
|
|
153
|
+
private readonly options: PickOptions,
|
|
154
|
+
) {
|
|
155
|
+
this.flats = new FlatTreeCache(deps.trees);
|
|
156
|
+
this.abbreviator = createIdAbbreviator(deps.workingCopy);
|
|
157
|
+
this.edit = options.edit;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private get name(): string {
|
|
161
|
+
return ACTION_NAME[this.options.action];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private fail(message: string, output: string[] = [], picked: ObjectId[] = []): PickOutcome {
|
|
165
|
+
return { status: "failed", message, output, picked };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** `git cherry-pick <commits>` / `git revert <commits>`. */
|
|
169
|
+
async start(names: string[]): Promise<PickOutcome> {
|
|
170
|
+
const { state } = this.deps;
|
|
171
|
+
const { unmerged } = await readIndex(this.deps.staging);
|
|
172
|
+
if (unmerged.length > 0) {
|
|
173
|
+
return this.fail(
|
|
174
|
+
[
|
|
175
|
+
`error: ${ACTION_ING[this.options.action]} is not possible because you have unmerged files.`,
|
|
176
|
+
"hint: Fix them up in the work tree, and then use 'git add/rm <file>'",
|
|
177
|
+
"hint: as appropriate to mark resolution and make a commit.",
|
|
178
|
+
`fatal: ${this.name} failed`,
|
|
179
|
+
].join("\n"),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
if (await this.sequenced()) {
|
|
183
|
+
return this.fail(
|
|
184
|
+
`error: a cherry-pick or revert is already in progress\nhint: try "git cherry-pick (--continue | --skip | --abort | --quit)"\nfatal: ${this.name} failed`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
const ids: ObjectId[] = [];
|
|
188
|
+
for (const name of names) ids.push(await this.resolvePick(name));
|
|
189
|
+
const todo = ids.map((id) => ({ action: this.options.action, id }));
|
|
190
|
+
const headId = await this.headId();
|
|
191
|
+
if (todo.length > 1) {
|
|
192
|
+
await state.write("sequencer/head", `${headId}\n`);
|
|
193
|
+
await this.writeTodo(todo);
|
|
194
|
+
await state.write("sequencer/abort-safety", `${headId}\n`);
|
|
195
|
+
// save_opts: options.no-commit, then options.edit when given (git config's format)
|
|
196
|
+
const opts: string[] = [];
|
|
197
|
+
if (this.options.noCommit) opts.push("\tno-commit = true\n");
|
|
198
|
+
if (this.edit !== undefined) opts.push(`\tedit = ${this.edit}\n`);
|
|
199
|
+
if (opts.length > 0) await state.write("sequencer/opts", `[options]\n${opts.join("")}`);
|
|
200
|
+
}
|
|
201
|
+
return this.run(todo, todo.length > 1);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The commit a name to pick or revert names; a tree or a blob is git's `error: <name>:
|
|
206
|
+
* can't cherry-pick a tree` (revision walk), a missing object `fatal: bad object <id>`.
|
|
207
|
+
*/
|
|
208
|
+
private async resolvePick(name: string): Promise<ObjectId> {
|
|
209
|
+
try {
|
|
210
|
+
return await this.deps.resolve(name);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
if (!(error instanceof NotACommitError)) throw error;
|
|
213
|
+
const message = error.objectType
|
|
214
|
+
? `error: ${name}: can't cherry-pick a ${error.objectType}\nfatal: ${this.name} failed`
|
|
215
|
+
: `fatal: bad object ${name}`;
|
|
216
|
+
throw new NotACommitError(name, error.objectId, error.objectType, message);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Picks `todo` in order; `sequenced`: a `sequencer/` directory tracks the progress. */
|
|
221
|
+
private async run(todo: TodoItem[], sequenced: boolean): Promise<PickOutcome> {
|
|
222
|
+
const output: string[] = [];
|
|
223
|
+
const picked: ObjectId[] = [];
|
|
224
|
+
let newHead = await this.headId();
|
|
225
|
+
for (let k = 0; k < todo.length; k++) {
|
|
226
|
+
const item = todo[k];
|
|
227
|
+
const outcome = await this.pickOne(item, output);
|
|
228
|
+
if (outcome.status !== "ok") {
|
|
229
|
+
if (sequenced) {
|
|
230
|
+
await this.writeTodo(todo.slice(k));
|
|
231
|
+
await this.deps.state.write("sequencer/abort-safety", `${await this.headId()}\n`);
|
|
232
|
+
}
|
|
233
|
+
return { ...outcome, picked, output };
|
|
234
|
+
}
|
|
235
|
+
picked.push(item.id);
|
|
236
|
+
newHead = outcome.newHead ?? newHead;
|
|
237
|
+
if (sequenced) {
|
|
238
|
+
await this.writeTodo(todo.slice(k + 1));
|
|
239
|
+
await this.deps.state.write("sequencer/abort-safety", `${newHead}\n`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (sequenced) await this.deps.state.remove("sequencer");
|
|
243
|
+
return { status: "ok", newHead, picked, output };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** One commit's change merged into HEAD (do_pick_commit). */
|
|
247
|
+
private async pickOne(item: TodoItem, output: string[]): Promise<PickOutcome> {
|
|
248
|
+
const { deps } = this;
|
|
249
|
+
const action = item.action;
|
|
250
|
+
const commit = await deps.commits.load(item.id);
|
|
251
|
+
if (!commit) throw new RefNotFoundError(item.id, `Cannot find commit: ${item.id}`);
|
|
252
|
+
const headId = await this.headId();
|
|
253
|
+
const headCommit = await deps.commits.load(headId);
|
|
254
|
+
if (!headCommit) throw new RefNotFoundError(headId, "HEAD commit not found");
|
|
255
|
+
// with --no-commit the change is merged into the index as it is (git's
|
|
256
|
+
// write_index_as_tree): each commit's change on top of the previous one's
|
|
257
|
+
const headTreeId = this.options.noCommit
|
|
258
|
+
? await writeIndexAsTree(deps.staging, deps.trees)
|
|
259
|
+
: headCommit.tree;
|
|
260
|
+
// a commit is never made on top of staged changes (error_dirty_index)
|
|
261
|
+
const { index } = await readIndex(deps.staging);
|
|
262
|
+
if (
|
|
263
|
+
!this.options.noCommit &&
|
|
264
|
+
(await indexChangesFromTree(index, deps.trees, headTreeId)).length > 0
|
|
265
|
+
) {
|
|
266
|
+
return this.fail(
|
|
267
|
+
`error: your local changes would be overwritten by ${ACTION_NAME[action]}.\nhint: commit your changes or stash them to proceed.\nfatal: ${ACTION_NAME[action]} failed`,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// the parent the change is taken against
|
|
272
|
+
let parentId: ObjectId | undefined;
|
|
273
|
+
if (commit.parents.length > 1) {
|
|
274
|
+
if (this.options.mainline === undefined) {
|
|
275
|
+
throw new MultipleParentsNotAllowedError(
|
|
276
|
+
`error: commit ${item.id} is a merge but no -m option was given.\nfatal: ${ACTION_NAME[action]} failed`,
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
if (this.options.mainline < 1 || this.options.mainline > commit.parents.length) {
|
|
280
|
+
throw new InvalidMainlineParentError(this.options.mainline, commit.parents.length);
|
|
281
|
+
}
|
|
282
|
+
parentId = commit.parents[this.options.mainline - 1];
|
|
283
|
+
} else {
|
|
284
|
+
parentId = commit.parents[0];
|
|
285
|
+
}
|
|
286
|
+
const parentTreeId = parentId ? await deps.commits.getTree(parentId) : undefined;
|
|
287
|
+
const subject = subjectOf(commit.message);
|
|
288
|
+
// get_message: short_commit_name, repo_find_unique_abbrev with DEFAULT_ABBREV
|
|
289
|
+
const short = await this.abbreviator.abbreviate(item.id);
|
|
290
|
+
const label = `${short} (${subject})`;
|
|
291
|
+
const parentLabel = parentId ? `parent of ${label}` : "(empty tree)";
|
|
292
|
+
const [base, theirs, baseLabel, theirsLabel] =
|
|
293
|
+
action === "pick"
|
|
294
|
+
? [parentTreeId, commit.tree, parentLabel, label]
|
|
295
|
+
: [commit.tree, parentTreeId, label, parentLabel];
|
|
296
|
+
const flats = this.flats;
|
|
297
|
+
const merge = await mergeStoredTrees(
|
|
298
|
+
deps,
|
|
299
|
+
storedBase(base, baseLabel, () => flats.get(base)),
|
|
300
|
+
headTreeId,
|
|
301
|
+
theirs,
|
|
302
|
+
{
|
|
303
|
+
oursLabel: this.options.oursLabel ?? "HEAD",
|
|
304
|
+
theirsLabel,
|
|
305
|
+
baseLabel,
|
|
306
|
+
style: conflictStyleOf(deps.workingCopy),
|
|
307
|
+
favor: this.options.favor,
|
|
308
|
+
ignoreCase: coreBool(deps.workingCopy, "ignorecase", false),
|
|
309
|
+
...ortConfigOptions(deps.workingCopy, deps.worktree),
|
|
310
|
+
},
|
|
311
|
+
(id) => flats.get(id),
|
|
312
|
+
);
|
|
313
|
+
const target = await ortResultEntries(deps.blobs, merge);
|
|
314
|
+
// only the directories the pick changes are stored again
|
|
315
|
+
const treeId = await storeFlatTreeOver(deps.trees, headTreeId, merge.ours, target);
|
|
316
|
+
const conflicts = [...merge.conflicts.values()];
|
|
317
|
+
// only the paths HEAD and the result differ on are switched
|
|
318
|
+
const delta = await treeDelta(deps.trees, headTreeId, treeId);
|
|
319
|
+
const refused = await switchTrees(deps, delta.from, delta.to, {
|
|
320
|
+
action: "merge",
|
|
321
|
+
operation: ACTION_NAME[action],
|
|
322
|
+
conflicts,
|
|
323
|
+
targetTree: treeId,
|
|
324
|
+
});
|
|
325
|
+
if (refused) {
|
|
326
|
+
return this.fail(`${refused.message}\nfatal: ${ACTION_NAME[action]} failed`);
|
|
327
|
+
}
|
|
328
|
+
output.push(...merge.messages);
|
|
329
|
+
await deps.state.setRef("AUTO_MERGE", treeId);
|
|
330
|
+
const message = this.messageFor(action, item.id, commit, parentId);
|
|
331
|
+
|
|
332
|
+
if (conflicts.length > 0 || !merge.clean) {
|
|
333
|
+
const paths = [...new Set(conflicts.map((c) => c.stagePath))].sort(compareGitPaths);
|
|
334
|
+
// git records REVERT_HEAD for a revert -n too (do_pick_commit), never CHERRY_PICK_HEAD
|
|
335
|
+
if (!this.options.noCommit || action === "revert") {
|
|
336
|
+
await deps.state.setRef(HEAD_REF[action], item.id);
|
|
337
|
+
}
|
|
338
|
+
await deps.state.write("MERGE_MSG", `${message}${conflictsComment(paths, true)}`);
|
|
339
|
+
const advice = this.options.noCommit
|
|
340
|
+
? [
|
|
341
|
+
"hint: after resolving the conflicts, mark the corrected paths",
|
|
342
|
+
"hint: with 'git add <paths>' or 'git rm <paths>'",
|
|
343
|
+
]
|
|
344
|
+
: [
|
|
345
|
+
"hint: After resolving the conflicts, mark them with",
|
|
346
|
+
'hint: "git add/rm <pathspec>", then run',
|
|
347
|
+
`hint: "git ${ACTION_NAME[action]} --continue".`,
|
|
348
|
+
`hint: You can instead skip this commit with "git ${ACTION_NAME[action]} --skip".`,
|
|
349
|
+
`hint: To abort and get back to the state before "git ${ACTION_NAME[action]}",`,
|
|
350
|
+
`hint: run "git ${ACTION_NAME[action]} --abort".`,
|
|
351
|
+
];
|
|
352
|
+
return {
|
|
353
|
+
status: "conflicting",
|
|
354
|
+
conflicts: paths,
|
|
355
|
+
picked: [],
|
|
356
|
+
output,
|
|
357
|
+
message: [
|
|
358
|
+
`error: could not ${action === "pick" ? "apply" : "revert"} ${short}... ${subject}`,
|
|
359
|
+
...advice,
|
|
360
|
+
].join("\n"),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
if (this.options.noCommit) {
|
|
364
|
+
await deps.state.write("MERGE_MSG", message);
|
|
365
|
+
if (action === "revert") await deps.state.setRef(HEAD_REF[action], item.id);
|
|
366
|
+
return { status: "ok", newHead: headId, picked: [item.id], output };
|
|
367
|
+
}
|
|
368
|
+
if (treeId === headCommit.tree) {
|
|
369
|
+
// nothing to commit: git stops, the pick in progress, for --allow-empty or --skip
|
|
370
|
+
// (CHERRY_PICK_HEAD only: git records REVERT_HEAD for a revert that conflicts)
|
|
371
|
+
if (action === "pick") await deps.state.setRef(HEAD_REF[action], item.id);
|
|
372
|
+
await deps.state.write("MERGE_MSG", message);
|
|
373
|
+
return {
|
|
374
|
+
status: "conflicting",
|
|
375
|
+
conflicts: [],
|
|
376
|
+
picked: [],
|
|
377
|
+
output,
|
|
378
|
+
message: [
|
|
379
|
+
`The previous ${ACTION_NAME[action]} is now empty, possibly due to conflict resolution.`,
|
|
380
|
+
"If you wish to commit it anyway, use:",
|
|
381
|
+
"",
|
|
382
|
+
" git commit --allow-empty",
|
|
383
|
+
"",
|
|
384
|
+
`Otherwise, please use 'git ${ACTION_NAME[action]} --skip'`,
|
|
385
|
+
].join("\n"),
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
if (this.edit && deps.gitCommit) {
|
|
389
|
+
// do_pick_commit with EDIT_MSG: the message in MERGE_MSG, CHERRY_PICK_HEAD for a pick
|
|
390
|
+
// (git commit then takes its author and says it concludes a cherry-pick), then
|
|
391
|
+
// run_git_commit; git commit cleans up after itself (CHERRY_PICK_HEAD, MERGE_MSG)
|
|
392
|
+
if (action === "pick") await deps.state.setRef(HEAD_REF[action], item.id);
|
|
393
|
+
await deps.state.write("MERGE_MSG", message);
|
|
394
|
+
let newHead: ObjectId;
|
|
395
|
+
try {
|
|
396
|
+
newHead = await deps.gitCommit({
|
|
397
|
+
kind: "pick",
|
|
398
|
+
reflogAction: this.options.reflogAction ?? ACTION_NAME[action],
|
|
399
|
+
});
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (!(error instanceof GitApiError)) throw error;
|
|
402
|
+
// the commit failed (an empty message, its editor): the pick stays in progress
|
|
403
|
+
return { status: "failed", message: error.message, output, picked: [] };
|
|
404
|
+
}
|
|
405
|
+
return { status: "ok", newHead, picked: [item.id], output };
|
|
406
|
+
}
|
|
407
|
+
// do_pick_commit records CHERRY_PICK_HEAD for a clean pick too, and writes MERGE_MSG,
|
|
408
|
+
// before do_commit: a commit that fails (HEAD's lock held) leaves both
|
|
409
|
+
if (action === "pick") await deps.state.setRef(HEAD_REF[action], item.id);
|
|
410
|
+
await deps.state.write("MERGE_MSG", message);
|
|
411
|
+
const committer = this.committer();
|
|
412
|
+
const commitMessage = action === "pick" ? commit.message : message;
|
|
413
|
+
const newHead = await this.commit(
|
|
414
|
+
treeId,
|
|
415
|
+
[headId],
|
|
416
|
+
action === "pick" ? commit.author : this.revertAuthor(committer),
|
|
417
|
+
committer,
|
|
418
|
+
commitMessage,
|
|
419
|
+
// the sequencer's update_head_with_reflog: "cherry-pick: <subject>", "revert: ..."
|
|
420
|
+
reflogMessages.pick(this.options.reflogAction ?? ACTION_NAME[action], commitMessage),
|
|
421
|
+
);
|
|
422
|
+
// do_commit after try_to_commit: CHERRY_PICK_HEAD (deleted whether there or not) and
|
|
423
|
+
// MERGE_MSG go, a stopped empty pick's left over included (REVERT_HEAD and AUTO_MERGE stay)
|
|
424
|
+
await deps.state.deleteRef("CHERRY_PICK_HEAD");
|
|
425
|
+
await deps.state.remove("MERGE_MSG");
|
|
426
|
+
return { status: "ok", newHead, picked: [item.id], output };
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** `--continue`: the resolved conflict committed, then the rest picked. */
|
|
430
|
+
async continue(): Promise<PickOutcome> {
|
|
431
|
+
const { state } = this.deps;
|
|
432
|
+
const sequenced = await this.sequenced();
|
|
433
|
+
const pickHead = await state.ref("CHERRY_PICK_HEAD");
|
|
434
|
+
const revertHead = await state.ref("REVERT_HEAD");
|
|
435
|
+
const stopped = pickHead ?? revertHead;
|
|
436
|
+
if (!stopped && !sequenced) {
|
|
437
|
+
return this.fail(`error: no cherry-pick or revert in progress\nfatal: ${this.name} failed`);
|
|
438
|
+
}
|
|
439
|
+
const { unmerged } = await readIndex(this.deps.staging);
|
|
440
|
+
if (unmerged.length > 0) return this.fail(UNMERGED_FILES_MESSAGE("Committing"));
|
|
441
|
+
await this.readSavedOptions();
|
|
442
|
+
let todo = sequenced ? await this.readTodo() : [];
|
|
443
|
+
let newHead = await this.headId();
|
|
444
|
+
if (stopped) {
|
|
445
|
+
const action: PickAction = pickHead ? "pick" : "revert";
|
|
446
|
+
const commit = await this.deps.commits.load(stopped);
|
|
447
|
+
if (!commit) throw new RefNotFoundError(stopped, "Commit being picked not found");
|
|
448
|
+
const treeId = await this.deps.staging.writeTree(this.deps.trees);
|
|
449
|
+
const headCommit = await this.deps.commits.load(newHead);
|
|
450
|
+
const fallback = this.messageFor(action, stopped, commit, commit.parents[0]);
|
|
451
|
+
const prepared = (await state.read("MERGE_MSG")) ?? fallback;
|
|
452
|
+
// continue_single_pick runs `git commit --no-edit --cleanup=strip` (plain `git commit`
|
|
453
|
+
// under --edit): without the editor its prepare_to_commit writes MERGE_MSG with its
|
|
454
|
+
// whitespace cleaned up (comments kept) to COMMIT_EDITMSG, before a commit with nothing
|
|
455
|
+
// to commit is refused
|
|
456
|
+
if (!this.edit) await state.write("COMMIT_EDITMSG", stripspace(prepared));
|
|
457
|
+
if (headCommit?.tree === treeId) {
|
|
458
|
+
return this.fail(
|
|
459
|
+
`The previous ${ACTION_NAME[action]} is now empty, possibly due to conflict resolution.`,
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
if (this.deps.gitCommit) {
|
|
463
|
+
// git commit itself: its hooks (pre-commit and commit-msg too), its reflog message,
|
|
464
|
+
// and it ends the stopped pick (CHERRY_PICK_HEAD, REVERT_HEAD, MERGE_MSG, AUTO_MERGE)
|
|
465
|
+
try {
|
|
466
|
+
newHead = await this.deps.gitCommit({ kind: "continue", edit: this.edit === true });
|
|
467
|
+
} catch (error) {
|
|
468
|
+
if (!(error instanceof GitApiError)) throw error;
|
|
469
|
+
return this.fail(error.message);
|
|
470
|
+
}
|
|
471
|
+
if (todo[0]?.id === stopped) todo = todo.slice(1);
|
|
472
|
+
if (!sequenced) return { status: "ok", newHead, picked: [stopped], output: [] };
|
|
473
|
+
await this.writeTodo(todo);
|
|
474
|
+
await state.write("sequencer/abort-safety", `${newHead}\n`);
|
|
475
|
+
const outcome = await this.run(todo, true);
|
|
476
|
+
return { ...outcome, picked: [stopped, ...outcome.picked] };
|
|
477
|
+
}
|
|
478
|
+
const committer = this.committer();
|
|
479
|
+
const message = cleanupMessage(prepared);
|
|
480
|
+
newHead = await this.commit(
|
|
481
|
+
treeId,
|
|
482
|
+
[newHead],
|
|
483
|
+
action === "pick" ? commit.author : this.revertAuthor(committer),
|
|
484
|
+
committer,
|
|
485
|
+
message,
|
|
486
|
+
// `--continue` commits as `git commit` does: "commit (cherry-pick): <subject>" (a
|
|
487
|
+
// revert is no whence of git commit: "commit: <subject>")
|
|
488
|
+
reflogMessages.commit(action === "pick" ? "cherry-pick" : undefined, message),
|
|
489
|
+
);
|
|
490
|
+
// the commit ends the stopped pick (git commit's remove_merge_branch_state)
|
|
491
|
+
await state.removeRef("CHERRY_PICK_HEAD", "REVERT_HEAD", "AUTO_MERGE");
|
|
492
|
+
await state.remove("MERGE_MSG");
|
|
493
|
+
if (todo[0]?.id === stopped) todo = todo.slice(1);
|
|
494
|
+
}
|
|
495
|
+
if (!sequenced) return { status: "ok", newHead, picked: stopped ? [stopped] : [], output: [] };
|
|
496
|
+
await this.writeTodo(todo);
|
|
497
|
+
await state.write("sequencer/abort-safety", `${newHead}\n`);
|
|
498
|
+
const outcome = await this.run(todo, true);
|
|
499
|
+
return { ...outcome, picked: [...(stopped ? [stopped] : []), ...outcome.picked] };
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** `--skip`: the stopped commit dropped (`reset --merge HEAD`), the rest picked. */
|
|
503
|
+
async skip(): Promise<PickOutcome> {
|
|
504
|
+
const { state } = this.deps;
|
|
505
|
+
const stopped = (await state.ref("CHERRY_PICK_HEAD")) ?? (await state.ref("REVERT_HEAD"));
|
|
506
|
+
if (!stopped) {
|
|
507
|
+
return this.fail(`error: no cherry-pick or revert in progress\nfatal: ${this.name} failed`);
|
|
508
|
+
}
|
|
509
|
+
await this.readSavedOptions();
|
|
510
|
+
const headId = await this.headId();
|
|
511
|
+
const refused = await resetMerge(this.deps, headId, "HEAD");
|
|
512
|
+
if (refused) return this.fail(refused.message);
|
|
513
|
+
// git reset --merge <HEAD's id> records ORIG_HEAD, and HEAD's reflog line
|
|
514
|
+
const errors = await this.resetRefs(headId, headId);
|
|
515
|
+
await state.remove("MERGE_MSG");
|
|
516
|
+
if (!(await this.sequenced())) {
|
|
517
|
+
return { status: "ok", newHead: headId, picked: [], output: errors };
|
|
518
|
+
}
|
|
519
|
+
const outcome = await this.run((await this.readTodo()).slice(1), true);
|
|
520
|
+
return { ...outcome, output: [...errors, ...outcome.output] };
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** `--abort`: `reset --merge` to where the operation started, its state removed. */
|
|
524
|
+
async abort(): Promise<PickOutcome> {
|
|
525
|
+
const { state } = this.deps;
|
|
526
|
+
const sequenced = await this.sequenced();
|
|
527
|
+
const stopped = (await state.ref("CHERRY_PICK_HEAD")) ?? (await state.ref("REVERT_HEAD"));
|
|
528
|
+
const headId = await this.headId();
|
|
529
|
+
if (!sequenced) {
|
|
530
|
+
if (!stopped) {
|
|
531
|
+
return this.fail(`error: no cherry-pick or revert in progress\nfatal: ${this.name} failed`);
|
|
532
|
+
}
|
|
533
|
+
const refused = await resetMerge(this.deps, headId, "HEAD");
|
|
534
|
+
if (refused) return this.fail(refused.message);
|
|
535
|
+
// git's rollback_single_pick: `reset --merge <HEAD's id>`
|
|
536
|
+
const errors = await this.resetRefs(headId, headId);
|
|
537
|
+
await this.removeState();
|
|
538
|
+
return { status: "ok", newHead: headId, picked: [], output: errors };
|
|
539
|
+
}
|
|
540
|
+
const origHead = (await state.read("sequencer/head"))?.trim();
|
|
541
|
+
const safety = (await state.read("sequencer/abort-safety"))?.trim();
|
|
542
|
+
if (!origHead) {
|
|
543
|
+
await state.remove("sequencer");
|
|
544
|
+
return this.fail(`error: could not read 'sequencer/head'\nfatal: ${this.name} failed`);
|
|
545
|
+
}
|
|
546
|
+
if (safety && safety !== headId) {
|
|
547
|
+
await state.remove("sequencer");
|
|
548
|
+
return this.fail(
|
|
549
|
+
`warning: You seem to have moved HEAD. Not rewinding, check your HEAD!\nfatal: ${this.name} failed`,
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
const refused = await resetMerge(this.deps, origHead, origHead);
|
|
553
|
+
if (refused) return this.fail(refused.message);
|
|
554
|
+
// git's reset_merge(<sequencer/head>): `reset --merge <id>`
|
|
555
|
+
const errors = await this.resetRefs(headId, origHead);
|
|
556
|
+
await this.removeState();
|
|
557
|
+
return { status: "ok", newHead: origHead, picked: [], output: errors };
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** `--quit`: the operation forgotten, index, worktree and HEAD kept. */
|
|
561
|
+
async quit(): Promise<PickOutcome> {
|
|
562
|
+
await this.deps.state.remove("sequencer");
|
|
563
|
+
await this.deps.state.removeRef("CHERRY_PICK_HEAD", "REVERT_HEAD");
|
|
564
|
+
return { status: "ok", newHead: await this.headId(), picked: [], output: [] };
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* The refs of the `git reset --merge <target>` git runs (its index and worktree reset
|
|
569
|
+
* already): ORIG_HEAD and HEAD (update_refs), then remove_branch_state (CHERRY_PICK_HEAD,
|
|
570
|
+
* REVERT_HEAD, AUTO_MERGE and the merge state). Returns its `error:` lines for an ORIG_HEAD
|
|
571
|
+
* it could not write (HEAD moved all the same).
|
|
572
|
+
*/
|
|
573
|
+
private async resetRefs(headId: ObjectId, target: ObjectId): Promise<string[]> {
|
|
574
|
+
this.clock ??= Math.floor(Date.now() / 1000);
|
|
575
|
+
const log = reflogLine(
|
|
576
|
+
this.deps.workingCopy,
|
|
577
|
+
reflogMessages.reset(target),
|
|
578
|
+
this.options.committer,
|
|
579
|
+
this.clock,
|
|
580
|
+
);
|
|
581
|
+
const errors = await moveHeadAsReset(this.deps.refs, this.deps.state, headId, target, log);
|
|
582
|
+
await removeBranchState(this.deps, this.deps.state);
|
|
583
|
+
return errors;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* read_populate_opts: `options.edit` of `sequencer/opts` (git config's syntax, the last
|
|
588
|
+
* value wins), the `--edit` / `--no-edit` the run started with.
|
|
589
|
+
*/
|
|
590
|
+
private async readSavedOptions(): Promise<void> {
|
|
591
|
+
const text = await this.deps.state.read("sequencer/opts");
|
|
592
|
+
if (text === undefined) return;
|
|
593
|
+
let section = "";
|
|
594
|
+
for (const raw of text.split("\n")) {
|
|
595
|
+
const line = raw.trim();
|
|
596
|
+
const header = /^\[\s*([^\]\s]+)\s*\]/.exec(line);
|
|
597
|
+
if (header) {
|
|
598
|
+
section = header[1].toLowerCase();
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
const entry = /^([A-Za-z][A-Za-z0-9-]*)\s*=\s*(.*)$/.exec(line);
|
|
602
|
+
if (section !== "options" || !entry || entry[1].toLowerCase() !== "edit") continue;
|
|
603
|
+
const value = parseGitBool(entry[2].replace(/^"(.*)"$/, "$1"));
|
|
604
|
+
if (value !== undefined) this.edit = value;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
private async removeState(): Promise<void> {
|
|
609
|
+
await this.deps.state.removeRef("CHERRY_PICK_HEAD", "REVERT_HEAD", "AUTO_MERGE");
|
|
610
|
+
await this.deps.state.remove("MERGE_MSG", "sequencer");
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/** git's message for the commit a pick or revert makes. */
|
|
614
|
+
private messageFor(
|
|
615
|
+
action: PickAction,
|
|
616
|
+
id: ObjectId,
|
|
617
|
+
commit: Commit,
|
|
618
|
+
parentId: ObjectId | undefined,
|
|
619
|
+
): string {
|
|
620
|
+
if (action === "pick") {
|
|
621
|
+
return commit.message.endsWith("\n") ? commit.message : `${commit.message}\n`;
|
|
622
|
+
}
|
|
623
|
+
const subject = subjectOf(commit.message);
|
|
624
|
+
const reverting =
|
|
625
|
+
commit.parents.length > 1 && parentId
|
|
626
|
+
? `This reverts commit ${id}, reversing\nchanges made to ${parentId}.`
|
|
627
|
+
: `This reverts commit ${id}.`;
|
|
628
|
+
return `Revert "${subject}"\n\n${reverting}\n`;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* The committer of the commit a pick is about to make: the one given, else resolved as
|
|
633
|
+
* git's `git_committer_info`. The clock is read again first, as git's `try_to_commit`
|
|
634
|
+
* calls `reset_ident_date()` before each commit; the pick's reflog line keeps that time.
|
|
635
|
+
*/
|
|
636
|
+
private committer(): PersonIdent {
|
|
637
|
+
this.clock = Math.floor(Date.now() / 1000);
|
|
638
|
+
return this.options.committer ?? committerIdentOf(this.deps.workingCopy, { now: this.clock });
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* A revert's author: resolved as git's `git_author_info` (`GIT_AUTHOR_*`, `author.*`,
|
|
643
|
+
* `user.*`), the committer's name when nobody is configured. (A pick keeps its author.)
|
|
644
|
+
*/
|
|
645
|
+
private revertAuthor(committer: PersonIdent): PersonIdent {
|
|
646
|
+
this.clock ??= Math.floor(Date.now() / 1000);
|
|
647
|
+
return authorIdentOf(this.deps.workingCopy, { now: this.clock, fallback: committer });
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
private async commit(
|
|
651
|
+
tree: ObjectId,
|
|
652
|
+
parents: ObjectId[],
|
|
653
|
+
author: PersonIdent,
|
|
654
|
+
committer: PersonIdent,
|
|
655
|
+
message: string,
|
|
656
|
+
reflogMessage: string,
|
|
657
|
+
): Promise<ObjectId> {
|
|
658
|
+
// try_to_commit: prepare-commit-msg may rewrite the message; post-commit after
|
|
659
|
+
const hooks = this.deps.hooks;
|
|
660
|
+
const text = hooks ? await sequencerPrepareMessage(hooks, this.deps.state, message) : message;
|
|
661
|
+
const id = await this.deps.commits.store({ tree, parents, author, committer, message: text });
|
|
662
|
+
await this.moveHead(id, reflogMessage);
|
|
663
|
+
if (hooks) await sequencerPostCommit(hooks);
|
|
664
|
+
return id;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/** HEAD (its branch, when attached) moved to `id`, with `message` in the reflogs. */
|
|
668
|
+
private async moveHead(id: ObjectId, message: string): Promise<void> {
|
|
669
|
+
this.clock ??= Math.floor(Date.now() / 1000);
|
|
670
|
+
const log = reflogLine(this.deps.workingCopy, message, this.options.committer, this.clock);
|
|
671
|
+
// update_head_with_reflog: one transaction on HEAD expecting the commit's parent, as the
|
|
672
|
+
// reference-transaction hook sees it
|
|
673
|
+
const current = (await this.deps.refs.resolve("HEAD"))?.objectId;
|
|
674
|
+
const result = await this.deps.refs.batch(
|
|
675
|
+
[{ name: "HEAD", old: current ?? null, new: id }],
|
|
676
|
+
log,
|
|
677
|
+
);
|
|
678
|
+
if (result.ok) return;
|
|
679
|
+
// HEAD moved meanwhile: git's transaction fails on the old value it expects
|
|
680
|
+
if (result.rejected.some((r) => r.reason === "mismatch")) {
|
|
681
|
+
throw new GitApiError(`fatal: cannot lock ref 'HEAD': is at another value`);
|
|
682
|
+
}
|
|
683
|
+
if (result.rejected.some((r) => r.reason === "locked")) throw await this.headLockedError();
|
|
684
|
+
// a store whose batches cannot take HEAD (no transactions there): HEAD set as that store
|
|
685
|
+
// sets it, without the old value checked (git has no such path)
|
|
686
|
+
await updateHead(this.deps.refs, id, log);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* git's failure of a commit whose ref lock another process holds: try_to_commit's
|
|
691
|
+
* `error: cannot lock ref 'HEAD'` with lockfile.c's hint (2.43's longer wording), then in
|
|
692
|
+
* git 2.43 `fatal: <action> failed` (exit 128); 2.5x returns after the error (exit 1).
|
|
693
|
+
*/
|
|
694
|
+
private async headLockedError(): Promise<GitApiError> {
|
|
695
|
+
let name = "HEAD";
|
|
696
|
+
for (let i = 0; i < 5; i++) {
|
|
697
|
+
const ref = await this.deps.refs.get(name).catch(() => undefined);
|
|
698
|
+
if (!ref || !("target" in ref)) break;
|
|
699
|
+
name = ref.target;
|
|
700
|
+
}
|
|
701
|
+
// lockfile.c names the lock by its absolute path: git runs from the top, where
|
|
702
|
+
// absolute_path keeps the logical $PWD (symbolic links not followed)
|
|
703
|
+
const gitDir =
|
|
704
|
+
(await this.deps.hooks?.hostGitDir({ real: false }).catch(() => undefined)) ??
|
|
705
|
+
(this.deps.workingCopy as { config?: { hostGitDir?: string } }).config?.hostGitDir;
|
|
706
|
+
const lockPath = `${gitDir ? gitDir.replace(/\/+$/, "") : ".git"}/${name}.lock`;
|
|
707
|
+
const legacy = this.deps.hooks?.compatibility === "2.43";
|
|
708
|
+
const hint = legacy
|
|
709
|
+
? [
|
|
710
|
+
"Another git process seems to be running in this repository, e.g.",
|
|
711
|
+
"an editor opened by 'git commit'. Please make sure all processes",
|
|
712
|
+
"are terminated then try again. If it still fails, a git process",
|
|
713
|
+
"may have crashed in this repository earlier:",
|
|
714
|
+
"remove the file manually to continue.",
|
|
715
|
+
]
|
|
716
|
+
: [
|
|
717
|
+
"Another git process seems to be running in this repository, or the lock file may be stale",
|
|
718
|
+
];
|
|
719
|
+
return new GitApiError(
|
|
720
|
+
[
|
|
721
|
+
`error: cannot lock ref 'HEAD': Unable to create '${lockPath}': File exists.`,
|
|
722
|
+
"",
|
|
723
|
+
...hint,
|
|
724
|
+
...(legacy ? [`fatal: ${this.name} failed`] : []),
|
|
725
|
+
].join("\n"),
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
private async headId(): Promise<ObjectId> {
|
|
730
|
+
const resolved = await this.deps.refs.resolve("HEAD");
|
|
731
|
+
if (!resolved?.objectId) throw new RefNotFoundError("HEAD", "HEAD cannot be resolved");
|
|
732
|
+
return resolved.objectId;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/** `sequencer/todo`: `pick <abbrev> <subject>` lines. */
|
|
736
|
+
private async writeTodo(todo: TodoItem[]): Promise<void> {
|
|
737
|
+
const lines: string[] = [];
|
|
738
|
+
for (const item of todo) {
|
|
739
|
+
const commit = await this.deps.commits.load(item.id);
|
|
740
|
+
const short = await this.abbreviator.abbreviate(item.id);
|
|
741
|
+
lines.push(`${item.action} ${short} ${subjectOf(commit?.message ?? "")}\n`);
|
|
742
|
+
}
|
|
743
|
+
await this.deps.state.write("sequencer/todo", lines.join(""));
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/** The todo, abbreviated ids expanded. */
|
|
747
|
+
private async readTodo(): Promise<TodoItem[]> {
|
|
748
|
+
const text = (await this.deps.state.read("sequencer/todo")) ?? "";
|
|
749
|
+
const lines: { action: "pick" | "revert"; id: string }[] = [];
|
|
750
|
+
for (const line of text.split("\n")) {
|
|
751
|
+
const match = /^(pick|p|revert)\s+([0-9a-f]+)/.exec(line.trim());
|
|
752
|
+
if (!match) continue;
|
|
753
|
+
lines.push({ action: match[1] === "revert" ? "revert" : "pick", id: match[2] });
|
|
754
|
+
}
|
|
755
|
+
const ids = await expandCommitIds(
|
|
756
|
+
this.deps,
|
|
757
|
+
lines.map((l) => l.id),
|
|
758
|
+
);
|
|
759
|
+
return lines.map((l, k) => ({ action: l.action, id: ids[k] }));
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/** Whether a `sequencer/` directory tracks a run of several commits. */
|
|
763
|
+
private async sequenced(): Promise<boolean> {
|
|
764
|
+
const { state } = this.deps;
|
|
765
|
+
return (
|
|
766
|
+
(await state.read("sequencer/todo")) !== undefined ||
|
|
767
|
+
(await state.read("sequencer/head")) !== undefined ||
|
|
768
|
+
(await state.listDir("sequencer")).length > 0
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* The full id of an abbreviated commit id (as git writes them in todo lists). See
|
|
775
|
+
* {@link expandCommitIds}.
|
|
776
|
+
*/
|
|
777
|
+
export async function expandCommitId(
|
|
778
|
+
deps: { commits: CommandCommits; refs: CommandRefs; state: OperationState },
|
|
779
|
+
id: string,
|
|
780
|
+
): Promise<ObjectId> {
|
|
781
|
+
return (await expandCommitIds(deps, [id]))[0];
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* The full ids of abbreviated commit ids (as git writes them in todo lists): a full id the
|
|
786
|
+
* store holds is taken as it is; the others are looked up by prefix in the object store
|
|
787
|
+
* (one pass over its ids for all of them, as git's `get_oid` with commit disambiguation),
|
|
788
|
+
* and only where that cannot tell (a store that cannot list its ids, an ambiguous prefix)
|
|
789
|
+
* in the commits reachable from the refs, HEAD, ORIG_HEAD and the sequencer's heads.
|
|
790
|
+
*/
|
|
791
|
+
export async function expandCommitIds(
|
|
792
|
+
deps: { commits: CommandCommits; refs: CommandRefs; state: OperationState },
|
|
793
|
+
ids: string[],
|
|
794
|
+
): Promise<ObjectId[]> {
|
|
795
|
+
const out: (ObjectId | undefined)[] = [];
|
|
796
|
+
const pending = new Set<string>();
|
|
797
|
+
for (const id of ids) {
|
|
798
|
+
if (id.length >= 40 && (await deps.commits.has(id))) out.push(id);
|
|
799
|
+
else {
|
|
800
|
+
out.push(undefined);
|
|
801
|
+
pending.add(id);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
if (pending.size === 0) return out as ObjectId[];
|
|
805
|
+
|
|
806
|
+
const resolved = new Map<string, ObjectId>();
|
|
807
|
+
// the object store's ids, every prefix matched in one pass
|
|
808
|
+
const matches = new Map<string, ObjectId[]>();
|
|
809
|
+
const lengths = [...new Set([...pending].map((p) => p.length))];
|
|
810
|
+
try {
|
|
811
|
+
for await (const key of deps.commits.keys()) {
|
|
812
|
+
for (const length of lengths) {
|
|
813
|
+
const prefix = key.slice(0, length);
|
|
814
|
+
if (pending.has(prefix)) {
|
|
815
|
+
const list = matches.get(prefix) ?? [];
|
|
816
|
+
list.push(key);
|
|
817
|
+
matches.set(prefix, list);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
} catch {
|
|
822
|
+
matches.clear();
|
|
823
|
+
}
|
|
824
|
+
for (const [prefix, list] of matches) {
|
|
825
|
+
const commits: ObjectId[] = [];
|
|
826
|
+
for (const key of new Set(list)) {
|
|
827
|
+
if (await deps.commits.has(key).catch(() => false)) commits.push(key);
|
|
828
|
+
}
|
|
829
|
+
if (commits.length === 1) resolved.set(prefix, commits[0]);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
const unresolved = [...pending].filter((p) => !resolved.has(p));
|
|
833
|
+
if (unresolved.length > 0) {
|
|
834
|
+
const starts = new Set<ObjectId>();
|
|
835
|
+
for (const name of ["HEAD", "ORIG_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD", "REBASE_HEAD"]) {
|
|
836
|
+
const ref = await deps.refs.resolve(name).catch(() => undefined);
|
|
837
|
+
if (ref?.objectId) starts.add(ref.objectId);
|
|
838
|
+
}
|
|
839
|
+
for (const file of ["sequencer/head", "rebase-merge/orig-head", "rebase-merge/onto"]) {
|
|
840
|
+
const value = (await deps.state.read(file))?.trim();
|
|
841
|
+
if (value && /^[0-9a-f]{40,64}$/.test(value)) starts.add(value);
|
|
842
|
+
}
|
|
843
|
+
for await (const entry of deps.refs.list()) {
|
|
844
|
+
const ref = await deps.refs.resolve(entry.name).catch(() => undefined);
|
|
845
|
+
if (ref?.objectId) starts.add(ref.objectId);
|
|
846
|
+
}
|
|
847
|
+
const left = new Set(unresolved);
|
|
848
|
+
const seen = new Set<ObjectId>();
|
|
849
|
+
const stack = [...starts];
|
|
850
|
+
while (stack.length > 0 && left.size > 0) {
|
|
851
|
+
const current = stack.pop() as ObjectId;
|
|
852
|
+
if (seen.has(current)) continue;
|
|
853
|
+
seen.add(current);
|
|
854
|
+
for (const prefix of left) {
|
|
855
|
+
if (current.startsWith(prefix)) {
|
|
856
|
+
resolved.set(prefix, current);
|
|
857
|
+
left.delete(prefix);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
const commit = await deps.commits.load(current).catch(() => undefined);
|
|
861
|
+
if (commit) stack.push(...commit.parents);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return ids.map((id, k) => {
|
|
865
|
+
const found = out[k] ?? resolved.get(id);
|
|
866
|
+
if (!found) throw new RefNotFoundError(id, `Cannot resolve commit ${id}`);
|
|
867
|
+
return found;
|
|
868
|
+
});
|
|
869
|
+
}
|