@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,1169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's interactive hunk selection (add-patch.c) as a library: the per-file diff is split
|
|
3
|
+
* into git's hunks, a selector callback answers each prompt as a user would answer git on
|
|
4
|
+
* standard input, and the selected hunks are reassembled into a patch and applied. What git
|
|
5
|
+
* prints (the file headers, hunks, prompts, help and errors) is gathered as text, so a
|
|
6
|
+
* terminal host can show it exactly as git does.
|
|
7
|
+
*
|
|
8
|
+
* The diff and the patch are "binary strings" (one byte per character); the texts given to
|
|
9
|
+
* the selector and gathered in the output are decoded as paths are (`decodeGitPath`).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { compilePosixRegex, PosixRegexError } from "@statewalker/vcs-utils";
|
|
13
|
+
|
|
14
|
+
import { latin1ToBytes, latin1ToPath, pathToLatin1 } from "../apply/index.js";
|
|
15
|
+
import type { PatchApplyArgs, PatchMode, PatchPromptKind } from "./patch-modes.js";
|
|
16
|
+
import { promptIndex } from "./patch-modes.js";
|
|
17
|
+
|
|
18
|
+
/** The git version whose prompts and behaviour are reproduced. */
|
|
19
|
+
export type PatchCompatibility = "2.43" | "2.56";
|
|
20
|
+
|
|
21
|
+
/** One read git makes from standard input (or its editor) while selecting hunks. */
|
|
22
|
+
export type PatchRequest =
|
|
23
|
+
| {
|
|
24
|
+
/** The prompt after a hunk: answered with git's commands (`y`, `n`, `s`, `g3`, `/re`...) */
|
|
25
|
+
type: "hunk";
|
|
26
|
+
mode: PatchMode["name"];
|
|
27
|
+
/** The file's path (the diff's `a/` side) */
|
|
28
|
+
path: string;
|
|
29
|
+
kind: PatchPromptKind;
|
|
30
|
+
/** Index of the hunk in the file (0-based) */
|
|
31
|
+
hunkIndex: number;
|
|
32
|
+
hunkCount: number;
|
|
33
|
+
/** The hunk as git shows it (the header hunk of a file without hunks: empty) */
|
|
34
|
+
hunk: string;
|
|
35
|
+
/** The prompt as git prints it, e.g. `(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,s,e,?]? ` */
|
|
36
|
+
prompt: string;
|
|
37
|
+
/** The commands the prompt offers, in its order (`y`, `n`, `q`, `a`, `d`, ..., `?`) */
|
|
38
|
+
choices: string[];
|
|
39
|
+
/** The earlier decision on this hunk (2.5x shows it as " (was: y)") */
|
|
40
|
+
decision?: "y" | "n";
|
|
41
|
+
/** What git would have printed so far */
|
|
42
|
+
output: string;
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
/** The edit of a hunk (`e`): the buffer git hands its editor; answer the edited buffer */
|
|
46
|
+
type: "edit";
|
|
47
|
+
mode: PatchMode["name"];
|
|
48
|
+
path: string;
|
|
49
|
+
text: string;
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
/** A yes/no question ("Your edited hunk does not apply. Edit again ...", "Apply them to the worktree anyway? ") */
|
|
53
|
+
type: "yesno";
|
|
54
|
+
prompt: string;
|
|
55
|
+
}
|
|
56
|
+
| {
|
|
57
|
+
/** `g` without a number: "go to which hunk? " */
|
|
58
|
+
type: "goto";
|
|
59
|
+
prompt: string;
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
/** `/` without a pattern: "search for regex? " */
|
|
63
|
+
type: "search";
|
|
64
|
+
prompt: string;
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
/**
|
|
68
|
+
* `git add -i`'s menus (add-interactive.c's `list_and_choose`): the main loop's
|
|
69
|
+
* "What now> " (one item), or a selection of files ("Update>> ", "Revert>> ", "Add
|
|
70
|
+
* untracked>> ", "Patch update>> ", "Review diff>> "), answered with numbers, ranges
|
|
71
|
+
* (`1-3`, `3-`), unique prefixes, `*`, `-` to deselect, `?` for help, an empty line to
|
|
72
|
+
* finish
|
|
73
|
+
*/
|
|
74
|
+
type: "choose";
|
|
75
|
+
/** The prompt as git prints it (`What now> `, `Update>> `) */
|
|
76
|
+
prompt: string;
|
|
77
|
+
/** One item is chosen (the main menu), not several */
|
|
78
|
+
singleton: boolean;
|
|
79
|
+
/** The items listed, in their order (numbered from 1) */
|
|
80
|
+
items: string[];
|
|
81
|
+
/** What `git add -i` would have printed so far */
|
|
82
|
+
output: string;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Answers git's reads: the line typed (without its line end), or undefined for the end of
|
|
87
|
+
* input (EOF; for `edit`: the editor failed). An `edit` request is answered with the whole
|
|
88
|
+
* edited buffer.
|
|
89
|
+
*/
|
|
90
|
+
export type PatchSelector = (
|
|
91
|
+
request: PatchRequest,
|
|
92
|
+
) => string | undefined | Promise<string | undefined>;
|
|
93
|
+
|
|
94
|
+
/** What a patch selection printed and did. */
|
|
95
|
+
export interface PatchResult {
|
|
96
|
+
/** Standard output, as git prints it: headers, hunks, prompts, help and messages */
|
|
97
|
+
output: string;
|
|
98
|
+
/** Standard error: git apply's errors and add-patch's `error:` lines (2.43's messages too) */
|
|
99
|
+
errors: string;
|
|
100
|
+
/** Paths whose selected hunks were applied */
|
|
101
|
+
applied: string[];
|
|
102
|
+
/** Whether the selection ended with `q` (or the end of input) */
|
|
103
|
+
quit: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** How the engine reaches the repository. */
|
|
107
|
+
export interface PatchBackend {
|
|
108
|
+
/** The diff to select from (`diff-files -p`, `diff-index -p ...`), as a binary string */
|
|
109
|
+
diff(): Promise<string>;
|
|
110
|
+
/**
|
|
111
|
+
* Runs `git apply` with the patch (a binary string); true when it applied (or, with
|
|
112
|
+
* `check`, would apply). Its standard error goes to `errors`.
|
|
113
|
+
*/
|
|
114
|
+
apply(
|
|
115
|
+
patch: string,
|
|
116
|
+
args: PatchApplyArgs & { check?: boolean },
|
|
117
|
+
): Promise<{ ok: boolean; errors: string }>;
|
|
118
|
+
/**
|
|
119
|
+
* `repo_refresh_and_write_index` of the index the selection works on: refreshed and
|
|
120
|
+
* written, what it prints on standard output (`<path>: needs merge`) handed back. None for
|
|
121
|
+
* an index whose refresh shows nothing (`stash -p`'s temporary one).
|
|
122
|
+
*/
|
|
123
|
+
refresh?(): Promise<string>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Options of {@link runAddPatch}. */
|
|
127
|
+
export interface AddPatchOptions {
|
|
128
|
+
mode: PatchMode;
|
|
129
|
+
backend: PatchBackend;
|
|
130
|
+
selector: PatchSelector;
|
|
131
|
+
/** Default 2.56 */
|
|
132
|
+
compatibility?: PatchCompatibility;
|
|
133
|
+
/** `--no-auto-advance` (2.5x): stay in a file until `q`, apply after the last file */
|
|
134
|
+
autoAdvance?: boolean;
|
|
135
|
+
/** `core.commentChar` / `core.commentString` (default `#`) */
|
|
136
|
+
commentString?: string;
|
|
137
|
+
/** `add -p` run from a command that disallows `e` (ADD_P_DISALLOW_EDIT) */
|
|
138
|
+
disallowEdit?: boolean;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const UNDECIDED = 0;
|
|
142
|
+
const SKIP = 1;
|
|
143
|
+
const USE = 2;
|
|
144
|
+
|
|
145
|
+
interface HunkHeader {
|
|
146
|
+
oldOffset: number;
|
|
147
|
+
oldCount: number;
|
|
148
|
+
newOffset: number;
|
|
149
|
+
newCount: number;
|
|
150
|
+
extraStart: number;
|
|
151
|
+
extraEnd: number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface Hunk {
|
|
155
|
+
start: number;
|
|
156
|
+
end: number;
|
|
157
|
+
splittableInto: number;
|
|
158
|
+
delta: number;
|
|
159
|
+
use: number;
|
|
160
|
+
header: HunkHeader;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
interface FileDiff {
|
|
164
|
+
head: Hunk;
|
|
165
|
+
hunks: Hunk[];
|
|
166
|
+
deleted: boolean;
|
|
167
|
+
added: boolean;
|
|
168
|
+
modeChange: boolean;
|
|
169
|
+
binary: boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const newHunk = (): Hunk => ({
|
|
173
|
+
start: 0,
|
|
174
|
+
end: 0,
|
|
175
|
+
splittableInto: 0,
|
|
176
|
+
delta: 0,
|
|
177
|
+
use: UNDECIDED,
|
|
178
|
+
header: { oldOffset: 0, oldCount: 0, newOffset: 0, newCount: 0, extraStart: 0, extraEnd: 0 },
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const copyHunk = (h: Hunk): Hunk => ({ ...h, header: { ...h.header } });
|
|
182
|
+
|
|
183
|
+
class PatchError extends Error {}
|
|
184
|
+
|
|
185
|
+
const HELP_REMAINDER_256 =
|
|
186
|
+
"j - go to the next undecided hunk, roll over at the bottom\n" +
|
|
187
|
+
"J - go to the next hunk, roll over at the bottom\n" +
|
|
188
|
+
"k - go to the previous undecided hunk, roll over at the top\n" +
|
|
189
|
+
"K - go to the previous hunk, roll over at the top\n" +
|
|
190
|
+
"g - select a hunk to go to\n" +
|
|
191
|
+
"/ - search for a hunk matching the given regex\n" +
|
|
192
|
+
"s - split the current hunk into smaller hunks\n" +
|
|
193
|
+
"e - manually edit the current hunk\n" +
|
|
194
|
+
"p - print the current hunk\n" +
|
|
195
|
+
"P - print the current hunk using the pager\n" +
|
|
196
|
+
"> - go to the next file, roll over at the bottom\n" +
|
|
197
|
+
"< - go to the previous file, roll over at the top\n" +
|
|
198
|
+
"? - print help\n" +
|
|
199
|
+
"HUNKS SUMMARY - Hunks: %d, USE: %d, SKIP: %d\n";
|
|
200
|
+
|
|
201
|
+
const HELP_REMAINDER_243 =
|
|
202
|
+
"j - leave this hunk undecided, see next undecided hunk\n" +
|
|
203
|
+
"J - leave this hunk undecided, see next hunk\n" +
|
|
204
|
+
"k - leave this hunk undecided, see previous undecided hunk\n" +
|
|
205
|
+
"K - leave this hunk undecided, see previous hunk\n" +
|
|
206
|
+
"g - select a hunk to go to\n" +
|
|
207
|
+
"/ - search for a hunk matching the given regex\n" +
|
|
208
|
+
"s - split the current hunk into smaller hunks\n" +
|
|
209
|
+
"e - manually edit the current hunk\n" +
|
|
210
|
+
"? - print help\n";
|
|
211
|
+
|
|
212
|
+
/** `normalize_marker`: an empty context line may omit its leading space. */
|
|
213
|
+
function markerAt(text: string, at: number): string {
|
|
214
|
+
const c = text[at];
|
|
215
|
+
if (c === "\n" || (c === "\r" && text[at + 1] === "\n")) return " ";
|
|
216
|
+
return c ?? "";
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function isOctal(text: string): boolean {
|
|
220
|
+
return text.length > 0 && /^[0-7]+$/.test(text);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** strtoul as parse_range uses it: digits, the end offset; undefined when none. */
|
|
224
|
+
function parseNumber(text: string, at: number): { value: number; end: number } | undefined {
|
|
225
|
+
let end = at;
|
|
226
|
+
while (end < text.length && text[end] >= "0" && text[end] <= "9") end++;
|
|
227
|
+
if (end === at) return undefined;
|
|
228
|
+
return { value: Number(text.slice(at, end)), end };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** One run of git's add-patch.c over a diff. */
|
|
232
|
+
class AddPatchState {
|
|
233
|
+
private plain = "";
|
|
234
|
+
private files: FileDiff[] = [];
|
|
235
|
+
private out = "";
|
|
236
|
+
private errOut = "";
|
|
237
|
+
/** `s->buf`: the scratch buffer (the prompt's choices, the search's rendered hunks) */
|
|
238
|
+
private buf = "";
|
|
239
|
+
private readonly applied: string[] = [];
|
|
240
|
+
private quitAll = false;
|
|
241
|
+
private readonly modern: boolean;
|
|
242
|
+
private readonly comment: string;
|
|
243
|
+
|
|
244
|
+
constructor(private readonly options: AddPatchOptions) {
|
|
245
|
+
this.modern = (options.compatibility ?? "2.56") !== "2.43";
|
|
246
|
+
this.comment = options.commentString ?? "#";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private get mode(): PatchMode {
|
|
250
|
+
return this.options.mode;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
private get autoAdvance(): boolean {
|
|
254
|
+
return !this.modern || this.options.autoAdvance !== false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** add-patch.c's `err()`: 2.5x prints to stdout, 2.43 to stderr */
|
|
258
|
+
private err(message: string): void {
|
|
259
|
+
if (this.modern) this.out += `${message}\n`;
|
|
260
|
+
else this.errOut += `${message}\n`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private error(message: string): void {
|
|
264
|
+
this.errOut += `error: ${message}\n`;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
private text(latin1: string): string {
|
|
268
|
+
return latin1ToPath(latin1);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** repo_refresh_and_write_index through the backend, its lines printed */
|
|
272
|
+
private async refresh(): Promise<void> {
|
|
273
|
+
const refresh = this.options.backend.refresh;
|
|
274
|
+
if (refresh) this.out += pathToLatin1(await refresh.call(this.options.backend));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** The marker of the line at `at`: 2.5x's `normalize_marker`, 2.43's byte as it is */
|
|
278
|
+
private marker(at: number): string {
|
|
279
|
+
return this.modern ? markerAt(this.plain, at) : (this.plain[at] ?? "");
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async run(): Promise<PatchResult> {
|
|
283
|
+
const backend = this.options.backend;
|
|
284
|
+
// run_add_p: every mode but the index-only ones refreshes the index first
|
|
285
|
+
if (!this.mode.indexOnly && backend.refresh) await this.refresh();
|
|
286
|
+
this.plain = await backend.diff();
|
|
287
|
+
if (this.plain.length > 0 && !this.plain.endsWith("\n")) this.plain += "\n";
|
|
288
|
+
this.parseDiff();
|
|
289
|
+
const nr = this.files.length;
|
|
290
|
+
let binaryCount = 0;
|
|
291
|
+
if (this.modern) {
|
|
292
|
+
for (let i = 0; i < nr; ) {
|
|
293
|
+
const file = this.files[i];
|
|
294
|
+
if (file.binary && file.hunks.length === 0) {
|
|
295
|
+
binaryCount++;
|
|
296
|
+
i++;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
i = await this.patchUpdateFile(i);
|
|
300
|
+
if (i === nr) break;
|
|
301
|
+
}
|
|
302
|
+
if (!this.autoAdvance) for (const file of this.files) await this.applyPatch(file);
|
|
303
|
+
} else {
|
|
304
|
+
for (let i = 0; i < nr; i++) {
|
|
305
|
+
const file = this.files[i];
|
|
306
|
+
if (file.binary && file.hunks.length === 0) binaryCount++;
|
|
307
|
+
else if ((await this.patchUpdateFile(i)) === nr) break;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (nr === 0) this.err("No changes.");
|
|
311
|
+
else if (binaryCount === nr) this.err("Only binary files changed.");
|
|
312
|
+
return {
|
|
313
|
+
output: this.text(this.out),
|
|
314
|
+
errors: this.text(this.errOut),
|
|
315
|
+
applied: this.applied,
|
|
316
|
+
quit: this.quitAll,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// --- parsing -------------------------------------------------------------------------
|
|
321
|
+
|
|
322
|
+
private parseHunkHeader(hunk: Hunk): boolean {
|
|
323
|
+
const plain = this.plain;
|
|
324
|
+
const line = hunk.start;
|
|
325
|
+
let eol = plain.indexOf("\n", line);
|
|
326
|
+
if (eol < 0) eol = plain.length;
|
|
327
|
+
const fail = () => {
|
|
328
|
+
this.error(`could not parse hunk header '${plain.slice(line, eol)}'`);
|
|
329
|
+
return false;
|
|
330
|
+
};
|
|
331
|
+
let p = line;
|
|
332
|
+
if (!plain.startsWith("@@ -", p)) return fail();
|
|
333
|
+
p += 4;
|
|
334
|
+
const range = (): [number, number] | undefined => {
|
|
335
|
+
const offset = parseNumber(plain, p);
|
|
336
|
+
if (!offset) return undefined;
|
|
337
|
+
p = offset.end;
|
|
338
|
+
if (plain[p] !== ",") return [offset.value, 1];
|
|
339
|
+
const count = parseNumber(plain, p + 1);
|
|
340
|
+
if (!count) return undefined;
|
|
341
|
+
p = count.end;
|
|
342
|
+
return [offset.value, count.value];
|
|
343
|
+
};
|
|
344
|
+
const old = range();
|
|
345
|
+
if (!old || !plain.startsWith(" +", p)) return fail();
|
|
346
|
+
p += 2;
|
|
347
|
+
const nu = range();
|
|
348
|
+
if (!nu || !plain.startsWith(" @@", p)) return fail();
|
|
349
|
+
p += 3;
|
|
350
|
+
const header = hunk.header;
|
|
351
|
+
[header.oldOffset, header.oldCount] = old;
|
|
352
|
+
[header.newOffset, header.newCount] = nu;
|
|
353
|
+
hunk.start = eol + (plain[eol] === "\n" ? 1 : 0);
|
|
354
|
+
header.extraStart = p;
|
|
355
|
+
header.extraEnd = hunk.start;
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
private parseDiff(): void {
|
|
360
|
+
const plain = this.plain;
|
|
361
|
+
const pend = plain.length;
|
|
362
|
+
let p = 0;
|
|
363
|
+
let marker = "";
|
|
364
|
+
let file: FileDiff | undefined;
|
|
365
|
+
let hunk: Hunk | undefined;
|
|
366
|
+
const completeFile = () => {
|
|
367
|
+
if (hunk && (marker === "-" || marker === "+")) hunk.splittableInto++;
|
|
368
|
+
};
|
|
369
|
+
while (p !== pend) {
|
|
370
|
+
let eol = plain.indexOf("\n", p);
|
|
371
|
+
if (eol < 0) eol = pend;
|
|
372
|
+
const ch = this.marker(p);
|
|
373
|
+
let modeChange = false;
|
|
374
|
+
const atHead = file !== undefined && hunk === file.head;
|
|
375
|
+
if (plain.startsWith("diff ", p) || plain.startsWith("* Unmerged path ", p)) {
|
|
376
|
+
completeFile();
|
|
377
|
+
file = {
|
|
378
|
+
head: newHunk(),
|
|
379
|
+
hunks: [],
|
|
380
|
+
deleted: false,
|
|
381
|
+
added: false,
|
|
382
|
+
modeChange: false,
|
|
383
|
+
binary: false,
|
|
384
|
+
};
|
|
385
|
+
this.files.push(file);
|
|
386
|
+
hunk = file.head;
|
|
387
|
+
hunk.start = p;
|
|
388
|
+
marker = "";
|
|
389
|
+
} else if (!file || !hunk) {
|
|
390
|
+
throw new PatchError(`diff starts with unexpected line:\n${plain.slice(p, eol)}\n`);
|
|
391
|
+
} else if (file.deleted) {
|
|
392
|
+
// keep the rest of the file in a single "hunk"
|
|
393
|
+
} else if (plain.startsWith("@@ ", p) || (atHead && plain.startsWith("deleted file", p))) {
|
|
394
|
+
const deleted = !plain.startsWith("@@ ", p);
|
|
395
|
+
if (marker === "-" || marker === "+") hunk.splittableInto++;
|
|
396
|
+
hunk = newHunk();
|
|
397
|
+
file.hunks.push(hunk);
|
|
398
|
+
hunk.start = p;
|
|
399
|
+
if (deleted) file.deleted = true;
|
|
400
|
+
else if (!this.parseHunkHeader(hunk)) throw new PatchError("could not parse diff");
|
|
401
|
+
marker = ch;
|
|
402
|
+
} else if (atHead && plain.startsWith("new file", p)) {
|
|
403
|
+
file.added = true;
|
|
404
|
+
} else if (atHead && plain.startsWith("old mode ", p) && isOctal(plain.slice(p + 9, eol))) {
|
|
405
|
+
modeChange = true;
|
|
406
|
+
file.modeChange = true;
|
|
407
|
+
const pseudo = newHunk();
|
|
408
|
+
pseudo.start = p;
|
|
409
|
+
file.hunks.push(pseudo);
|
|
410
|
+
} else if (atHead && plain.startsWith("new mode ", p) && isOctal(plain.slice(p + 9, eol))) {
|
|
411
|
+
modeChange = true;
|
|
412
|
+
} else if (atHead && plain.startsWith("Binary files ", p)) {
|
|
413
|
+
file.binary = true;
|
|
414
|
+
}
|
|
415
|
+
if ((marker === "-" || marker === "+") && ch === " ") hunk.splittableInto++;
|
|
416
|
+
if (marker && ch !== "\\") marker = ch;
|
|
417
|
+
p = eol === pend ? pend : eol + 1;
|
|
418
|
+
hunk.end = p;
|
|
419
|
+
if (modeChange && file.hunks.length > 0) file.hunks[0].end = hunk.end;
|
|
420
|
+
}
|
|
421
|
+
completeFile();
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// --- rendering -----------------------------------------------------------------------
|
|
425
|
+
|
|
426
|
+
private renderHunk(hunk: Hunk, delta: number): string {
|
|
427
|
+
const header = hunk.header;
|
|
428
|
+
let out = "";
|
|
429
|
+
if (header.oldOffset !== 0 || header.newOffset !== 0) {
|
|
430
|
+
let oldOffset = header.oldOffset;
|
|
431
|
+
let newOffset = header.newOffset;
|
|
432
|
+
if (this.mode.isReverse) oldOffset -= delta;
|
|
433
|
+
else newOffset += delta;
|
|
434
|
+
out += `@@ -${oldOffset}`;
|
|
435
|
+
if (header.oldCount !== 1) out += `,${header.oldCount}`;
|
|
436
|
+
out += ` +${newOffset}`;
|
|
437
|
+
if (header.newCount !== 1) out += `,${header.newCount}`;
|
|
438
|
+
out += " @@";
|
|
439
|
+
const extra = this.plain.slice(header.extraStart, header.extraEnd);
|
|
440
|
+
out += extra.length ? extra : "\n";
|
|
441
|
+
}
|
|
442
|
+
return out + this.plain.slice(hunk.start, hunk.end);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
private renderDiffHeader(file: FileDiff): string {
|
|
446
|
+
const head = file.head;
|
|
447
|
+
const first = file.hunks[0];
|
|
448
|
+
const skipModeChange = file.modeChange && first.use !== USE;
|
|
449
|
+
if (!skipModeChange) return this.renderHunk(head, 0);
|
|
450
|
+
return this.plain.slice(head.start, first.start) + this.plain.slice(first.end, head.end);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
private findNextLine(offset: number): number {
|
|
454
|
+
const eol = this.plain.indexOf("\n", offset);
|
|
455
|
+
return eol < 0 ? this.plain.length : eol + 1;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* merge_hunks: coalesces hunks that were split again; the merged hunk, or undefined when
|
|
460
|
+
* none merged. On an error (git's `return error(...)`, which its caller takes as merged)
|
|
461
|
+
* the hunk merged so far comes back and `index` stays: the next hunk is rendered on its own.
|
|
462
|
+
*/
|
|
463
|
+
private mergeHunks(file: FileDiff, index: { i: number }, useAll: boolean): Hunk | undefined {
|
|
464
|
+
let i = index.i;
|
|
465
|
+
let hunk = file.hunks[i];
|
|
466
|
+
if (!useAll && hunk.use !== USE) return undefined;
|
|
467
|
+
const merged = copyHunk(hunk);
|
|
468
|
+
const header = merged.header;
|
|
469
|
+
for (; i + 1 < file.hunks.length; i++) {
|
|
470
|
+
hunk = file.hunks[i + 1];
|
|
471
|
+
const next = hunk.header;
|
|
472
|
+
if (
|
|
473
|
+
(!useAll && hunk.use !== USE) ||
|
|
474
|
+
header.newOffset >= next.newOffset + merged.delta ||
|
|
475
|
+
header.newOffset + header.newCount < next.newOffset + merged.delta
|
|
476
|
+
) {
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
let delta: number;
|
|
480
|
+
if (merged.start < hunk.start && merged.end > hunk.start) {
|
|
481
|
+
merged.end = hunk.end;
|
|
482
|
+
delta = 0;
|
|
483
|
+
} else {
|
|
484
|
+
const overlappingLineCount =
|
|
485
|
+
header.newOffset + header.newCount - merged.delta - next.newOffset;
|
|
486
|
+
let overlapEnd = hunk.start;
|
|
487
|
+
let overlapStart = overlapEnd;
|
|
488
|
+
for (let j = 0; j < overlappingLineCount; j++) {
|
|
489
|
+
const overlapNext = this.findNextLine(overlapEnd);
|
|
490
|
+
if (overlapNext > hunk.end) {
|
|
491
|
+
throw new PatchError(`failed to find ${overlappingLineCount} context lines`);
|
|
492
|
+
}
|
|
493
|
+
if (this.marker(overlapEnd) !== " ") {
|
|
494
|
+
this.error(
|
|
495
|
+
`expected context line #${j + 1} in\n${this.plain.slice(hunk.start, hunk.end)}`,
|
|
496
|
+
);
|
|
497
|
+
return merged;
|
|
498
|
+
}
|
|
499
|
+
overlapStart = overlapEnd;
|
|
500
|
+
overlapEnd = overlapNext;
|
|
501
|
+
}
|
|
502
|
+
const len = overlapEnd - overlapStart;
|
|
503
|
+
if (
|
|
504
|
+
len > merged.end - merged.start ||
|
|
505
|
+
this.plain.slice(merged.end - len, merged.end) !==
|
|
506
|
+
this.plain.slice(overlapStart, overlapEnd)
|
|
507
|
+
) {
|
|
508
|
+
this.error(
|
|
509
|
+
`hunks do not overlap:\n${this.plain.slice(merged.start, merged.end)}\n\tdoes not end with:\n${this.plain.slice(overlapStart, overlapEnd)}`,
|
|
510
|
+
);
|
|
511
|
+
return merged;
|
|
512
|
+
}
|
|
513
|
+
if (merged.end !== this.plain.length) {
|
|
514
|
+
const start = this.plain.length;
|
|
515
|
+
this.plain += this.plain.slice(merged.start, merged.end);
|
|
516
|
+
merged.start = start;
|
|
517
|
+
merged.end = this.plain.length;
|
|
518
|
+
}
|
|
519
|
+
this.plain += this.plain.slice(overlapEnd, hunk.end);
|
|
520
|
+
merged.end = this.plain.length;
|
|
521
|
+
merged.splittableInto += hunk.splittableInto;
|
|
522
|
+
delta = merged.delta;
|
|
523
|
+
merged.delta += hunk.delta;
|
|
524
|
+
}
|
|
525
|
+
header.oldCount = next.oldOffset + next.oldCount - header.oldOffset;
|
|
526
|
+
header.newCount = next.newOffset + delta + next.newCount - header.newOffset;
|
|
527
|
+
}
|
|
528
|
+
if (i === index.i) return undefined;
|
|
529
|
+
index.i = i;
|
|
530
|
+
return merged;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
private reassemblePatch(file: FileDiff, useAll: boolean): string {
|
|
534
|
+
const saveLen = this.plain.length;
|
|
535
|
+
let out = this.renderDiffHeader(file);
|
|
536
|
+
let delta = 0;
|
|
537
|
+
for (let i = file.modeChange ? 1 : 0; i < file.hunks.length; i++) {
|
|
538
|
+
let hunk = file.hunks[i];
|
|
539
|
+
if (!useAll && hunk.use !== USE) {
|
|
540
|
+
delta += hunk.header.oldCount - hunk.header.newCount;
|
|
541
|
+
} else {
|
|
542
|
+
const index = { i };
|
|
543
|
+
const merged = this.mergeHunks(file, index, useAll);
|
|
544
|
+
i = index.i;
|
|
545
|
+
if (merged) hunk = merged;
|
|
546
|
+
out += this.renderHunk(hunk, delta);
|
|
547
|
+
this.plain = this.plain.slice(0, saveLen);
|
|
548
|
+
delta += hunk.delta;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return out;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/** split_hunk: false when the hunk cannot be split */
|
|
555
|
+
private splitHunk(file: FileDiff, hunkIndex: number): boolean {
|
|
556
|
+
const original = file.hunks[hunkIndex];
|
|
557
|
+
if (original.splittableInto < 2) return false;
|
|
558
|
+
let splittableInto = original.splittableInto;
|
|
559
|
+
const end = original.end;
|
|
560
|
+
const remaining = { ...original.header };
|
|
561
|
+
const parts: Hunk[] = [original];
|
|
562
|
+
for (let k = 1; k < splittableInto; k++) parts.push(newHunk());
|
|
563
|
+
file.hunks.splice(hunkIndex, 1, ...parts);
|
|
564
|
+
let n = 0;
|
|
565
|
+
let hunk = parts[0];
|
|
566
|
+
hunk.splittableInto = 1;
|
|
567
|
+
// 2.43 kept the decision: the first part keeps it, each later one copies its neighbour's
|
|
568
|
+
if (this.modern) hunk.use = UNDECIDED;
|
|
569
|
+
let header = hunk.header;
|
|
570
|
+
header.oldCount = 0;
|
|
571
|
+
header.newCount = 0;
|
|
572
|
+
let current = hunk.start;
|
|
573
|
+
let marker = "";
|
|
574
|
+
let contextLineCount = 0;
|
|
575
|
+
let first = true;
|
|
576
|
+
while (splittableInto > 1) {
|
|
577
|
+
let ch = this.marker(current);
|
|
578
|
+
if (!ch) throw new PatchError("buffer overrun while splitting hunks");
|
|
579
|
+
if ((marker === "-" || marker === "+") && ch === " ") {
|
|
580
|
+
first = false;
|
|
581
|
+
parts[n + 1].start = current;
|
|
582
|
+
contextLineCount = 0;
|
|
583
|
+
}
|
|
584
|
+
let startNew = !(marker !== " " || (ch !== "-" && ch !== "+"));
|
|
585
|
+
if (startNew && first) {
|
|
586
|
+
header.oldCount = contextLineCount;
|
|
587
|
+
header.newCount = contextLineCount;
|
|
588
|
+
contextLineCount = 0;
|
|
589
|
+
first = false;
|
|
590
|
+
startNew = false;
|
|
591
|
+
}
|
|
592
|
+
if (!startNew) {
|
|
593
|
+
if (ch === "\\") ch = marker ? marker : " ";
|
|
594
|
+
if (ch === " ") contextLineCount++;
|
|
595
|
+
else if (ch === "-") header.oldCount++;
|
|
596
|
+
else if (ch === "+") header.newCount++;
|
|
597
|
+
else throw new PatchError(`unhandled diff marker: '${ch}'`);
|
|
598
|
+
marker = ch;
|
|
599
|
+
current = this.findNextLine(current);
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
remaining.oldOffset += header.oldCount;
|
|
603
|
+
remaining.oldCount -= header.oldCount;
|
|
604
|
+
remaining.newOffset += header.newCount;
|
|
605
|
+
remaining.newCount -= header.newCount;
|
|
606
|
+
parts[n + 1].header.oldOffset = header.oldOffset + header.oldCount;
|
|
607
|
+
parts[n + 1].header.newOffset = header.newOffset + header.newCount;
|
|
608
|
+
header.oldCount += contextLineCount;
|
|
609
|
+
header.newCount += contextLineCount;
|
|
610
|
+
hunk.end = current;
|
|
611
|
+
n++;
|
|
612
|
+
hunk = parts[n];
|
|
613
|
+
hunk.splittableInto = 1;
|
|
614
|
+
hunk.use = this.modern ? UNDECIDED : parts[n - 1].use;
|
|
615
|
+
header = hunk.header;
|
|
616
|
+
header.oldCount = contextLineCount;
|
|
617
|
+
header.newCount = contextLineCount;
|
|
618
|
+
contextLineCount = 0;
|
|
619
|
+
splittableInto--;
|
|
620
|
+
marker = ch;
|
|
621
|
+
}
|
|
622
|
+
header.oldCount = remaining.oldCount;
|
|
623
|
+
header.newCount = remaining.newCount;
|
|
624
|
+
hunk.end = end;
|
|
625
|
+
return true;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// --- editing -------------------------------------------------------------------------
|
|
629
|
+
|
|
630
|
+
private commented(text: string): string {
|
|
631
|
+
let out = "";
|
|
632
|
+
const lines = text.split("\n");
|
|
633
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
634
|
+
for (const line of lines) {
|
|
635
|
+
out += this.comment;
|
|
636
|
+
if (line.length > 0 && line[0] !== "\t") out += " ";
|
|
637
|
+
out += `${line}\n`;
|
|
638
|
+
}
|
|
639
|
+
return out;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/** edit_hunk_manually: 1 edited, 0 abandoned, -1 failed */
|
|
643
|
+
private async editHunkManually(file: FileDiff, hunk: Hunk): Promise<number> {
|
|
644
|
+
const comment = this.comment;
|
|
645
|
+
let buffer = this.commented("Manual hunk edit mode -- see bottom for a quick guide.\n");
|
|
646
|
+
buffer += this.renderHunk(hunk, 0);
|
|
647
|
+
buffer += this.commented(
|
|
648
|
+
"---\n" +
|
|
649
|
+
`To remove '${this.mode.isReverse ? "+" : "-"}' lines, make them ' ' lines (context).\n` +
|
|
650
|
+
`To remove '${this.mode.isReverse ? "-" : "+"}' lines, delete them.\n` +
|
|
651
|
+
`Lines starting with ${comment} will be removed.\n`,
|
|
652
|
+
);
|
|
653
|
+
buffer += this.commented(this.mode.editHunkHint);
|
|
654
|
+
buffer += this.commented(
|
|
655
|
+
"If it does not apply cleanly, you will be given an opportunity to\n" +
|
|
656
|
+
"edit again. If all lines of the hunk are removed, then the edit is\n" +
|
|
657
|
+
"aborted and the hunk is left unchanged.\n",
|
|
658
|
+
);
|
|
659
|
+
const answer = await this.options.selector({
|
|
660
|
+
type: "edit",
|
|
661
|
+
mode: this.mode.name,
|
|
662
|
+
path: this.filePath(file),
|
|
663
|
+
text: this.text(buffer),
|
|
664
|
+
});
|
|
665
|
+
if (answer === undefined) {
|
|
666
|
+
this.error("could not edit 'addp-hunk-edit.diff'"); // an editor failure
|
|
667
|
+
return -1;
|
|
668
|
+
}
|
|
669
|
+
const edited = pathToLatin1(answer);
|
|
670
|
+
hunk.start = this.plain.length;
|
|
671
|
+
let i = 0;
|
|
672
|
+
while (i < edited.length) {
|
|
673
|
+
const eol = edited.indexOf("\n", i);
|
|
674
|
+
const next = eol < 0 ? edited.length : eol + 1;
|
|
675
|
+
if (!edited.startsWith(comment, i)) this.plain += edited.slice(i, next);
|
|
676
|
+
i = next;
|
|
677
|
+
}
|
|
678
|
+
hunk.end = this.plain.length;
|
|
679
|
+
if (hunk.end === hunk.start) return 0;
|
|
680
|
+
if (this.plain[hunk.start] === "@" && !this.parseHunkHeader(hunk)) {
|
|
681
|
+
this.error("could not parse hunk header");
|
|
682
|
+
return -1;
|
|
683
|
+
}
|
|
684
|
+
return 1;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
private recountEditedHunk(hunk: Hunk, origOld: number, origNew: number): number {
|
|
688
|
+
const header = hunk.header;
|
|
689
|
+
if (!this.modern) {
|
|
690
|
+
// 2.43: the counts only (splittable_into kept), a bare line end counting as context
|
|
691
|
+
header.oldCount = 0;
|
|
692
|
+
header.newCount = 0;
|
|
693
|
+
for (let i = hunk.start; i < hunk.end; i = this.findNextLine(i)) {
|
|
694
|
+
const ch = this.plain[i];
|
|
695
|
+
if (ch === "-") header.oldCount++;
|
|
696
|
+
else if (ch === "+") header.newCount++;
|
|
697
|
+
else if (ch === " " || ch === "\r" || ch === "\n") {
|
|
698
|
+
header.oldCount++;
|
|
699
|
+
header.newCount++;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return origOld - origNew - header.oldCount + header.newCount;
|
|
703
|
+
}
|
|
704
|
+
hunk.splittableInto = 0;
|
|
705
|
+
header.oldCount = 0;
|
|
706
|
+
header.newCount = 0;
|
|
707
|
+
let marker = " ";
|
|
708
|
+
for (let i = hunk.start; i < hunk.end; i = this.findNextLine(i)) {
|
|
709
|
+
const ch = markerAt(this.plain, i);
|
|
710
|
+
if (ch === "-") {
|
|
711
|
+
header.oldCount++;
|
|
712
|
+
if (marker === " ") hunk.splittableInto++;
|
|
713
|
+
marker = ch;
|
|
714
|
+
} else if (ch === "+") {
|
|
715
|
+
header.newCount++;
|
|
716
|
+
if (marker === " ") hunk.splittableInto++;
|
|
717
|
+
marker = ch;
|
|
718
|
+
} else if (ch === " ") {
|
|
719
|
+
header.oldCount++;
|
|
720
|
+
header.newCount++;
|
|
721
|
+
marker = ch;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return origOld - origNew - header.oldCount + header.newCount;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
private async runApplyCheck(file: FileDiff): Promise<boolean> {
|
|
728
|
+
const patch = this.reassemblePatch(file, true);
|
|
729
|
+
const r = await this.options.backend.apply(patch, {
|
|
730
|
+
...this.mode.applyCheckArgs,
|
|
731
|
+
check: true,
|
|
732
|
+
});
|
|
733
|
+
this.errOut += r.errors;
|
|
734
|
+
if (!r.ok) {
|
|
735
|
+
this.error("'git apply --cached' failed");
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** prompt_yesno: 1 yes, 0 no, -1 end of input */
|
|
742
|
+
private async promptYesNo(prompt: string): Promise<number> {
|
|
743
|
+
for (;;) {
|
|
744
|
+
this.out += prompt;
|
|
745
|
+
const answer = await this.options.selector({ type: "yesno", prompt });
|
|
746
|
+
if (answer === undefined) return -1;
|
|
747
|
+
const c = answer[0]?.toLowerCase();
|
|
748
|
+
if (c === "n") return 0;
|
|
749
|
+
if (c === "y") return 1;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
private async editHunkLoop(file: FileDiff, index: number): Promise<number> {
|
|
754
|
+
const plainLen = this.plain.length;
|
|
755
|
+
const backup = copyHunk(file.hunks[index]);
|
|
756
|
+
for (;;) {
|
|
757
|
+
const hunk = file.hunks[index];
|
|
758
|
+
const res = await this.editHunkManually(file, hunk);
|
|
759
|
+
if (res === 0) {
|
|
760
|
+
file.hunks[index] = backup;
|
|
761
|
+
return -1;
|
|
762
|
+
}
|
|
763
|
+
if (res > 0) {
|
|
764
|
+
hunk.delta += this.recountEditedHunk(hunk, backup.header.oldCount, backup.header.newCount);
|
|
765
|
+
if (await this.runApplyCheck(file)) return 0;
|
|
766
|
+
}
|
|
767
|
+
this.plain = this.plain.slice(0, plainLen);
|
|
768
|
+
file.hunks[index] = copyHunk(backup);
|
|
769
|
+
const yes = await this.promptYesNo(
|
|
770
|
+
'Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]? ',
|
|
771
|
+
);
|
|
772
|
+
if (yes < 1) return -1;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// --- applying ------------------------------------------------------------------------
|
|
777
|
+
|
|
778
|
+
private async applyForCheckout(patch: string, reverse: boolean): Promise<void> {
|
|
779
|
+
const backend = this.options.backend;
|
|
780
|
+
const index = await backend.apply(patch, { cached: true, reverse, check: true });
|
|
781
|
+
const worktree = await backend.apply(patch, { cached: false, reverse, check: true });
|
|
782
|
+
if (index.ok && worktree.ok) {
|
|
783
|
+
this.errOut += (await backend.apply(patch, { cached: true, reverse })).errors;
|
|
784
|
+
this.errOut += (await backend.apply(patch, { cached: false, reverse })).errors;
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
this.errOut += index.errors + worktree.errors;
|
|
788
|
+
if (!index.ok) {
|
|
789
|
+
this.err("The selected hunks do not apply to the index!");
|
|
790
|
+
if ((await this.promptYesNo("Apply them to the worktree anyway? ")) > 0) {
|
|
791
|
+
this.errOut += (await backend.apply(patch, { cached: false, reverse })).errors;
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
this.err("Nothing was applied.\n");
|
|
795
|
+
} else if (this.modern) {
|
|
796
|
+
// as a last resort, the diff is shown (2.43 wrote it to stderr)
|
|
797
|
+
this.out += patch;
|
|
798
|
+
} else {
|
|
799
|
+
this.errOut += patch;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
private async applyPatch(file: FileDiff): Promise<void> {
|
|
804
|
+
const any = file.hunks.some((h) => h.use === USE);
|
|
805
|
+
if (!any && !(file.hunks.length === 0 && file.head.use === USE)) return;
|
|
806
|
+
const patch = this.reassemblePatch(file, false);
|
|
807
|
+
if (this.mode.applyForCheckout) {
|
|
808
|
+
await this.applyForCheckout(patch, this.mode.isReverse);
|
|
809
|
+
} else {
|
|
810
|
+
const r = await this.options.backend.apply(
|
|
811
|
+
patch,
|
|
812
|
+
this.mode.applyArgs ?? {
|
|
813
|
+
cached: false,
|
|
814
|
+
reverse: false,
|
|
815
|
+
},
|
|
816
|
+
);
|
|
817
|
+
this.errOut += r.errors;
|
|
818
|
+
if (!r.ok) this.error("'git apply' failed");
|
|
819
|
+
}
|
|
820
|
+
// the index read back and refreshed after the apply
|
|
821
|
+
await this.refresh();
|
|
822
|
+
this.applied.push(this.filePath(file));
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
private filePath(file: FileDiff): string {
|
|
826
|
+
const line = this.plain.slice(file.head.start, this.plain.indexOf("\n", file.head.start));
|
|
827
|
+
const m = /^diff --git "?[ab]\/(.*?)"? "?[ab]\//.exec(line);
|
|
828
|
+
if (m) return this.text(m[1]);
|
|
829
|
+
const u = /^\* Unmerged path (.*)$/.exec(line);
|
|
830
|
+
return this.text(u ? u[1] : line);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// --- the prompt loop -----------------------------------------------------------------
|
|
834
|
+
|
|
835
|
+
private summarizeHunk(hunk: Hunk): string {
|
|
836
|
+
const h = hunk.header;
|
|
837
|
+
let out = ` -${h.oldOffset},${h.oldCount} +${h.newOffset},${h.newCount} `;
|
|
838
|
+
if (out.length < 20) out += " ".repeat(20 - out.length);
|
|
839
|
+
let i = hunk.start;
|
|
840
|
+
for (; i < hunk.end; i = this.findNextLine(i)) if (this.plain[i] !== " ") break;
|
|
841
|
+
if (i < hunk.end) out += this.plain.slice(i, this.findNextLine(i));
|
|
842
|
+
if (out.length > 80) out = out.slice(0, 80);
|
|
843
|
+
if (!out.endsWith("\n")) out += "\n";
|
|
844
|
+
return out;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
private displayHunks(file: FileDiff, start: number): number {
|
|
848
|
+
const end = Math.min(start + 20, file.hunks.length);
|
|
849
|
+
for (let i = start; i < end; i++) {
|
|
850
|
+
const hunk = file.hunks[i];
|
|
851
|
+
const mark = hunk.use === USE ? "+" : hunk.use === SKIP ? "-" : " ";
|
|
852
|
+
this.out += `${mark}${String(i + 1).padStart(2)}: ${this.summarizeHunk(hunk)}`;
|
|
853
|
+
}
|
|
854
|
+
return end;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
private matches(regex: ReturnType<typeof compilePosixRegex>, text: string): boolean {
|
|
858
|
+
// REG_NEWLINE: each line on its own
|
|
859
|
+
for (const line of text.split("\n")) {
|
|
860
|
+
if (regex.test(latin1ToBytes(line))) return true;
|
|
861
|
+
}
|
|
862
|
+
return false;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/** patch_update_file: the index of the next file (2.43: `files.length` to quit) */
|
|
866
|
+
private async patchUpdateFile(idx: number): Promise<number> {
|
|
867
|
+
const file = this.files[idx];
|
|
868
|
+
const modern = this.modern;
|
|
869
|
+
const nr = this.files.length;
|
|
870
|
+
let resp = idx;
|
|
871
|
+
if (file.hunks.length === 0 && !file.added) return idx + 1;
|
|
872
|
+
this.out += this.renderDiffHeader(file);
|
|
873
|
+
let hunkIndex = 0;
|
|
874
|
+
let renderedHunkIndex = -1;
|
|
875
|
+
let allDecided = false;
|
|
876
|
+
// 2.43 never cleared its permissions between prompts of one file
|
|
877
|
+
const sticky = new Set<string>();
|
|
878
|
+
for (;;) {
|
|
879
|
+
const count = file.hunks.length;
|
|
880
|
+
if (hunkIndex >= count || hunkIndex < 0) hunkIndex = 0;
|
|
881
|
+
const hunk = count ? file.hunks[hunkIndex] : file.head;
|
|
882
|
+
let undecidedPrevious = -1;
|
|
883
|
+
let undecidedNext = -1;
|
|
884
|
+
if (count) {
|
|
885
|
+
if (modern) {
|
|
886
|
+
for (
|
|
887
|
+
let i = (hunkIndex + count - 1) % count;
|
|
888
|
+
i !== hunkIndex;
|
|
889
|
+
i = (i + count - 1) % count
|
|
890
|
+
)
|
|
891
|
+
if (file.hunks[i].use === UNDECIDED) {
|
|
892
|
+
undecidedPrevious = i;
|
|
893
|
+
break;
|
|
894
|
+
}
|
|
895
|
+
for (let i = (hunkIndex + 1) % count; i !== hunkIndex; i = (i + 1) % count)
|
|
896
|
+
if (file.hunks[i].use === UNDECIDED) {
|
|
897
|
+
undecidedNext = i;
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
} else {
|
|
901
|
+
for (let i = hunkIndex - 1; i >= 0; i--)
|
|
902
|
+
if (file.hunks[i].use === UNDECIDED) {
|
|
903
|
+
undecidedPrevious = i;
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
for (let i = hunkIndex + 1; i < count; i++)
|
|
907
|
+
if (file.hunks[i].use === UNDECIDED) {
|
|
908
|
+
undecidedNext = i;
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (undecidedPrevious < 0 && undecidedNext < 0 && hunk.use !== UNDECIDED) {
|
|
914
|
+
if (!this.autoAdvance) allDecided = true;
|
|
915
|
+
else {
|
|
916
|
+
if (modern) resp++;
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
const permitted = modern ? new Set<string>() : sticky;
|
|
921
|
+
let choices = "";
|
|
922
|
+
let rendered = "";
|
|
923
|
+
if (count) {
|
|
924
|
+
if (!modern || renderedHunkIndex !== hunkIndex) {
|
|
925
|
+
rendered = this.renderHunk(hunk, 0);
|
|
926
|
+
this.out += rendered;
|
|
927
|
+
renderedHunkIndex = hunkIndex;
|
|
928
|
+
} else {
|
|
929
|
+
rendered = this.renderHunk(hunk, 0);
|
|
930
|
+
}
|
|
931
|
+
const allow = (key: string, letters: string) => {
|
|
932
|
+
permitted.add(key);
|
|
933
|
+
choices += letters;
|
|
934
|
+
};
|
|
935
|
+
if (undecidedPrevious >= 0) allow("k", ",k");
|
|
936
|
+
if (modern ? count > 1 : hunkIndex > 0) allow("K", ",K");
|
|
937
|
+
if (undecidedNext >= 0) allow("j", ",j");
|
|
938
|
+
if (modern ? count > 1 : hunkIndex + 1 < count) allow("J", ",J");
|
|
939
|
+
if (count > 1) allow("g", ",g,/");
|
|
940
|
+
if (hunk.splittableInto > 1) allow("s", ",s");
|
|
941
|
+
if (
|
|
942
|
+
!this.options.disallowEdit &&
|
|
943
|
+
hunkIndex + 1 > (file.modeChange ? 1 : 0) &&
|
|
944
|
+
!file.deleted
|
|
945
|
+
) {
|
|
946
|
+
allow("e", ",e");
|
|
947
|
+
}
|
|
948
|
+
if (modern && !this.autoAdvance && nr > 1) {
|
|
949
|
+
allow(">", ",>");
|
|
950
|
+
allow("<", ",<");
|
|
951
|
+
}
|
|
952
|
+
if (modern) choices += ",p,P";
|
|
953
|
+
}
|
|
954
|
+
this.buf = choices;
|
|
955
|
+
const kind: PatchPromptKind = file.deleted
|
|
956
|
+
? "deletion"
|
|
957
|
+
: file.added
|
|
958
|
+
? "addition"
|
|
959
|
+
: file.modeChange && hunkIndex === 0
|
|
960
|
+
? "mode-change"
|
|
961
|
+
: "hunk";
|
|
962
|
+
const decision = hunk.use === USE ? "y" : hunk.use === SKIP ? "n" : undefined;
|
|
963
|
+
let template = this.mode.promptMode[promptIndex(kind)];
|
|
964
|
+
if (modern) {
|
|
965
|
+
template = template.replace("%s", decision ? ` (was: ${decision})` : "");
|
|
966
|
+
} else {
|
|
967
|
+
template = template.replace("%s", "");
|
|
968
|
+
}
|
|
969
|
+
const prompt = `(${hunkIndex + 1}/${count || 1}) ${template.replace("%s", choices)}`;
|
|
970
|
+
this.out += prompt;
|
|
971
|
+
const answer = await this.options.selector({
|
|
972
|
+
type: "hunk",
|
|
973
|
+
mode: this.mode.name,
|
|
974
|
+
path: this.filePath(file),
|
|
975
|
+
kind,
|
|
976
|
+
hunkIndex,
|
|
977
|
+
hunkCount: count || 1,
|
|
978
|
+
hunk: this.text(rendered),
|
|
979
|
+
prompt: this.text(prompt),
|
|
980
|
+
choices: ["y", "n", "q", "a", "d", ...choices.split(",").filter(Boolean), "?"],
|
|
981
|
+
...(decision ? { decision } : {}),
|
|
982
|
+
output: this.text(this.out),
|
|
983
|
+
});
|
|
984
|
+
if (answer === undefined) {
|
|
985
|
+
if (modern) {
|
|
986
|
+
resp = nr;
|
|
987
|
+
this.quitAll = true;
|
|
988
|
+
}
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
let line = answer.replace(/\r?\n$/, "");
|
|
992
|
+
if (line.length === 0) continue;
|
|
993
|
+
const ch = line[0].toLowerCase();
|
|
994
|
+
const c0 = line[0];
|
|
995
|
+
if (modern && line.length !== 1 && ch !== "g" && ch !== "/") {
|
|
996
|
+
this.err(`Only one letter is expected, got '${line}'`);
|
|
997
|
+
continue;
|
|
998
|
+
}
|
|
999
|
+
const softIncrement = () => {
|
|
1000
|
+
hunkIndex = undecidedNext < 0 ? count : undecidedNext;
|
|
1001
|
+
};
|
|
1002
|
+
const firstUndecided = () => {
|
|
1003
|
+
const i = file.hunks.findIndex((h) => h.use === UNDECIDED);
|
|
1004
|
+
return modern ? (i < 0 ? 0 : i) : hunkIndex;
|
|
1005
|
+
};
|
|
1006
|
+
if (ch === "y") {
|
|
1007
|
+
hunk.use = USE;
|
|
1008
|
+
softIncrement();
|
|
1009
|
+
} else if (ch === "n") {
|
|
1010
|
+
hunk.use = SKIP;
|
|
1011
|
+
softIncrement();
|
|
1012
|
+
} else if (ch === "a" || ch === "d") {
|
|
1013
|
+
const use = ch === "a" ? USE : SKIP;
|
|
1014
|
+
if (count) {
|
|
1015
|
+
for (; hunkIndex < count; hunkIndex++) {
|
|
1016
|
+
if (file.hunks[hunkIndex].use === UNDECIDED) file.hunks[hunkIndex].use = use;
|
|
1017
|
+
}
|
|
1018
|
+
hunkIndex = firstUndecided();
|
|
1019
|
+
} else if (hunk.use === UNDECIDED) {
|
|
1020
|
+
hunk.use = use;
|
|
1021
|
+
}
|
|
1022
|
+
} else if (ch === "q") {
|
|
1023
|
+
resp = nr;
|
|
1024
|
+
this.quitAll = true;
|
|
1025
|
+
break;
|
|
1026
|
+
} else if (modern && !this.autoAdvance && c0 === ">") {
|
|
1027
|
+
if (permitted.has(">")) {
|
|
1028
|
+
resp = resp === nr - 1 ? 0 : resp + 1;
|
|
1029
|
+
break;
|
|
1030
|
+
}
|
|
1031
|
+
this.err("No next file");
|
|
1032
|
+
} else if (modern && !this.autoAdvance && c0 === "<") {
|
|
1033
|
+
if (permitted.has("<")) {
|
|
1034
|
+
resp = resp === 0 ? nr - 1 : resp - 1;
|
|
1035
|
+
break;
|
|
1036
|
+
}
|
|
1037
|
+
this.err("No previous file");
|
|
1038
|
+
} else if (c0 === "K") {
|
|
1039
|
+
if (permitted.has("K"))
|
|
1040
|
+
hunkIndex = modern ? (hunkIndex + count - 1) % count : hunkIndex - 1;
|
|
1041
|
+
else this.err(modern ? "No other hunk" : "No previous hunk");
|
|
1042
|
+
} else if (c0 === "J") {
|
|
1043
|
+
if (permitted.has("J")) hunkIndex++;
|
|
1044
|
+
else this.err(modern ? "No other hunk" : "No next hunk");
|
|
1045
|
+
} else if (c0 === "k") {
|
|
1046
|
+
if (permitted.has("k")) hunkIndex = undecidedPrevious;
|
|
1047
|
+
else this.err(modern ? "No other undecided hunk" : "No previous hunk");
|
|
1048
|
+
} else if (c0 === "j") {
|
|
1049
|
+
if (permitted.has("j")) hunkIndex = undecidedNext;
|
|
1050
|
+
else this.err(modern ? "No other undecided hunk" : "No next hunk");
|
|
1051
|
+
} else if (c0 === "g") {
|
|
1052
|
+
if (!permitted.has("g")) {
|
|
1053
|
+
this.err("No other hunks to goto");
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1056
|
+
line = line.slice(1).trim();
|
|
1057
|
+
let i = hunkIndex - 10;
|
|
1058
|
+
const first = file.modeChange ? 1 : 0;
|
|
1059
|
+
if (i < first) i = first;
|
|
1060
|
+
while (line.length === 0) {
|
|
1061
|
+
i = this.displayHunks(file, i);
|
|
1062
|
+
const goPrompt =
|
|
1063
|
+
i < count ? "go to which hunk (<ret> to see more)? " : "go to which hunk? ";
|
|
1064
|
+
this.out += goPrompt;
|
|
1065
|
+
const reply = await this.options.selector({ type: "goto", prompt: goPrompt });
|
|
1066
|
+
if (reply === undefined) break;
|
|
1067
|
+
line = reply.replace(/\r?\n$/, "");
|
|
1068
|
+
}
|
|
1069
|
+
line = line.trim();
|
|
1070
|
+
const m = /^([+-]?)(\d+)$/.exec(line);
|
|
1071
|
+
if (!m) this.err(`Invalid number: '${line}'`);
|
|
1072
|
+
else {
|
|
1073
|
+
const response = m[1] === "-" && Number(m[2]) !== 0 ? -1 : Number(m[2]);
|
|
1074
|
+
if (response > 0 && response <= count) hunkIndex = response - 1;
|
|
1075
|
+
else this.err(`Sorry, only ${count} hunk${count === 1 ? "" : "s"} available.`);
|
|
1076
|
+
}
|
|
1077
|
+
} else if (c0 === "/") {
|
|
1078
|
+
if (!permitted.has("g")) {
|
|
1079
|
+
this.err("No other hunks to search");
|
|
1080
|
+
continue;
|
|
1081
|
+
}
|
|
1082
|
+
line = line.slice(1).replace(/\r?\n$/, "");
|
|
1083
|
+
if (line.length === 0) {
|
|
1084
|
+
const searchPrompt = "search for regex? ";
|
|
1085
|
+
this.out += searchPrompt;
|
|
1086
|
+
const reply = await this.options.selector({ type: "search", prompt: searchPrompt });
|
|
1087
|
+
if (reply === undefined) break;
|
|
1088
|
+
line = reply.replace(/\r?\n$/, "");
|
|
1089
|
+
if (line.length === 0) continue;
|
|
1090
|
+
}
|
|
1091
|
+
let regex: ReturnType<typeof compilePosixRegex>;
|
|
1092
|
+
try {
|
|
1093
|
+
regex = compilePosixRegex(latin1ToBytes(pathToLatin1(line)), { extended: true });
|
|
1094
|
+
} catch (error) {
|
|
1095
|
+
if (!(error instanceof PosixRegexError)) throw error;
|
|
1096
|
+
this.err(`Malformed search regexp ${line}: ${error.message}`);
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
let i = hunkIndex;
|
|
1100
|
+
for (;;) {
|
|
1101
|
+
this.buf += this.renderHunk(file.hunks[i], 0);
|
|
1102
|
+
if (this.matches(regex, this.buf)) break;
|
|
1103
|
+
i++;
|
|
1104
|
+
if (i === count) i = 0;
|
|
1105
|
+
if (i !== hunkIndex) continue;
|
|
1106
|
+
this.err("No hunk matches the given pattern");
|
|
1107
|
+
break;
|
|
1108
|
+
}
|
|
1109
|
+
hunkIndex = i;
|
|
1110
|
+
} else if (c0 === "s") {
|
|
1111
|
+
const into = hunk.splittableInto;
|
|
1112
|
+
if (!permitted.has("s")) this.err("Sorry, cannot split this hunk");
|
|
1113
|
+
else {
|
|
1114
|
+
if (into >= 2) this.splitHunk(file, hunkIndex);
|
|
1115
|
+
this.out += `Split into ${into} hunks.\n`;
|
|
1116
|
+
renderedHunkIndex = -1;
|
|
1117
|
+
}
|
|
1118
|
+
} else if (c0 === "e") {
|
|
1119
|
+
if (!permitted.has("e")) this.err("Sorry, cannot edit this hunk");
|
|
1120
|
+
else if ((await this.editHunkLoop(file, hunkIndex)) >= 0) {
|
|
1121
|
+
file.hunks[hunkIndex].use = USE;
|
|
1122
|
+
softIncrement();
|
|
1123
|
+
}
|
|
1124
|
+
} else if (modern && ch === "p") {
|
|
1125
|
+
renderedHunkIndex = -1;
|
|
1126
|
+
} else if (!modern || c0 === "?") {
|
|
1127
|
+
this.out += this.mode.helpPatchText;
|
|
1128
|
+
const remainder = modern ? HELP_REMAINDER_256 : HELP_REMAINDER_243;
|
|
1129
|
+
for (const helpLine of remainder.split("\n")) {
|
|
1130
|
+
if (!helpLine) continue;
|
|
1131
|
+
if (allDecided && helpLine.startsWith("HUNKS SUMMARY")) {
|
|
1132
|
+
const used = file.hunks.filter((h) => h.use === USE).length;
|
|
1133
|
+
const skipped = file.hunks.filter((h) => h.use === SKIP).length;
|
|
1134
|
+
this.out += `${helpLine
|
|
1135
|
+
.replace("%d", String(count))
|
|
1136
|
+
.replace("%d", String(used))
|
|
1137
|
+
.replace("%d", String(skipped))}\n`;
|
|
1138
|
+
}
|
|
1139
|
+
if (helpLine[0] !== "?" && !this.buf.includes(helpLine[0])) continue;
|
|
1140
|
+
this.out += `${helpLine}\n`;
|
|
1141
|
+
}
|
|
1142
|
+
} else {
|
|
1143
|
+
this.err(`Unknown command '${line}' (use '?' for help)`);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
if (this.autoAdvance) await this.applyPatch(file);
|
|
1147
|
+
this.out += "\n";
|
|
1148
|
+
return modern ? resp : this.quitAll ? nr : idx + 1;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Runs git's interactive hunk selection: the backend's diff is split into hunks, each
|
|
1154
|
+
* prompt goes to the selector, and the selected hunks are applied through the backend.
|
|
1155
|
+
*
|
|
1156
|
+
* @example
|
|
1157
|
+
* ```typescript
|
|
1158
|
+
* const answers = ["y", "n", "s", "y", "q"];
|
|
1159
|
+
* const result = await runAddPatch({
|
|
1160
|
+
* mode: PATCH_MODES.stage,
|
|
1161
|
+
* backend,
|
|
1162
|
+
* selector: () => answers.shift(),
|
|
1163
|
+
* });
|
|
1164
|
+
* process.stdout.write(result.output);
|
|
1165
|
+
* ```
|
|
1166
|
+
*/
|
|
1167
|
+
export async function runAddPatch(options: AddPatchOptions): Promise<PatchResult> {
|
|
1168
|
+
return new AddPatchState(options).run();
|
|
1169
|
+
}
|