@statewalker/vcs-commands 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -8
- package/dist/commands/add-command.d.ts +265 -34
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-interactive.d.ts +46 -0
- package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
- package/dist/commands/add-patch/add-patch.d.ts +139 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
- package/dist/commands/add-patch/index.d.ts +6 -0
- package/dist/commands/add-patch/index.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-backend.d.ts +80 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-modes.d.ts +71 -0
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-session.d.ts +49 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
- package/dist/commands/am/am-command.d.ts +175 -0
- package/dist/commands/am/am-command.d.ts.map +1 -0
- package/dist/commands/am/index.d.ts +3 -0
- package/dist/commands/am/index.d.ts.map +1 -0
- package/dist/commands/am/mailinfo.d.ts +58 -0
- package/dist/commands/am/mailinfo.d.ts.map +1 -0
- package/dist/commands/am/patch-format.d.ts +24 -0
- package/dist/commands/am/patch-format.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts +153 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -0
- package/dist/commands/apply/apply-engine.d.ts +195 -0
- package/dist/commands/apply/apply-engine.d.ts.map +1 -0
- package/dist/commands/apply/apply-parse.d.ts +86 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -0
- package/dist/commands/apply/apply-types.d.ts +70 -0
- package/dist/commands/apply/apply-types.d.ts.map +1 -0
- package/dist/commands/apply/index.d.ts +6 -0
- package/dist/commands/apply/index.d.ts.map +1 -0
- package/dist/commands/apply/latin1.d.ts +32 -0
- package/dist/commands/apply/latin1.d.ts.map +1 -0
- package/dist/commands/apply/whitespace.d.ts +58 -0
- package/dist/commands/apply/whitespace.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +26 -0
- package/dist/commands/attributes-source.d.ts.map +1 -0
- package/dist/commands/backfill-command.d.ts +110 -0
- package/dist/commands/backfill-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
- package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-command.d.ts +201 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-engine.d.ts +219 -0
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-graph.d.ts +127 -0
- package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-quote.d.ts +27 -0
- package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
- package/dist/commands/bisect/index.d.ts +5 -0
- package/dist/commands/bisect/index.d.ts.map +1 -0
- package/dist/commands/blame-command.d.ts +122 -131
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +52 -2
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-tracking.d.ts +98 -0
- package/dist/commands/branch-tracking.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +300 -18
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +124 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +50 -42
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +49 -16
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +134 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/comment-char-config.d.ts +35 -0
- package/dist/commands/comment-char-config.d.ts.map +1 -0
- package/dist/commands/commit-command.d.ts +311 -17
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +78 -1
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/date-format.d.ts +58 -0
- package/dist/commands/date-format.d.ts.map +1 -0
- package/dist/commands/default-branch.d.ts +70 -0
- package/dist/commands/default-branch.d.ts.map +1 -0
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +377 -30
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-textconv.d.ts +40 -0
- package/dist/commands/diff-textconv.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +149 -10
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts +164 -0
- package/dist/commands/format-patch-command.d.ts.map +1 -0
- package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts +227 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +71 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts +159 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +140 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +122 -0
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
- package/dist/commands/fsck/index.d.ts +6 -0
- package/dist/commands/fsck/index.d.ts.map +1 -0
- package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +106 -39
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +2 -0
- package/dist/commands/git-date.d.ts.map +1 -0
- package/dist/commands/git-describe.d.ts +67 -0
- package/dist/commands/git-describe.d.ts.map +1 -0
- package/dist/commands/git-hooks.d.ts +424 -0
- package/dist/commands/git-hooks.d.ts.map +1 -0
- package/dist/commands/git-ident.d.ts +128 -0
- package/dist/commands/git-ident.d.ts.map +1 -0
- package/dist/commands/hook-command.d.ts +96 -0
- package/dist/commands/hook-command.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +233 -0
- package/dist/commands/index-adder.d.ts.map +1 -0
- package/dist/commands/index-host.d.ts +86 -0
- package/dist/commands/index-host.d.ts.map +1 -0
- package/dist/commands/index.d.ts +56 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +62 -4
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/legacy-remotes.d.ts +55 -0
- package/dist/commands/legacy-remotes.d.ts.map +1 -0
- package/dist/commands/local-clone.d.ts +60 -0
- package/dist/commands/local-clone.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +117 -0
- package/dist/commands/local-transport.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +216 -24
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +120 -0
- package/dist/commands/log-graph.d.ts.map +1 -0
- package/dist/commands/log-output.d.ts +323 -0
- package/dist/commands/log-output.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +23 -7
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +31 -0
- package/dist/commands/mailmap.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +85 -0
- package/dist/commands/merge-bases.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +221 -74
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +13 -0
- package/dist/commands/merge-config.d.ts.map +1 -0
- package/dist/commands/merge-drivers.d.ts +130 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +260 -0
- package/dist/commands/merge-support.d.ts.map +1 -0
- package/dist/commands/message-cleanup.d.ts +86 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -0
- package/dist/commands/mv-command.d.ts +94 -0
- package/dist/commands/mv-command.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts +256 -0
- package/dist/commands/notes-command.d.ts.map +1 -0
- package/dist/commands/notes-commands.d.ts +41 -0
- package/dist/commands/notes-commands.d.ts.map +1 -0
- package/dist/commands/notes-merge-command.d.ts +105 -0
- package/dist/commands/notes-merge-command.d.ts.map +1 -0
- package/dist/commands/notes-support.d.ts +125 -0
- package/dist/commands/notes-support.d.ts.map +1 -0
- package/dist/commands/notes-tree.d.ts +116 -0
- package/dist/commands/notes-tree.d.ts.map +1 -0
- package/dist/commands/object-id-input.d.ts +20 -0
- package/dist/commands/object-id-input.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +59 -0
- package/dist/commands/octopus-merge.d.ts.map +1 -0
- package/dist/commands/ort-merge.d.ts +126 -0
- package/dist/commands/ort-merge.d.ts.map +1 -0
- package/dist/commands/ort-recursive.d.ts +53 -0
- package/dist/commands/ort-recursive.d.ts.map +1 -0
- package/dist/commands/pack-refs-command.d.ts +20 -0
- package/dist/commands/pack-refs-command.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +44 -0
- package/dist/commands/patch-id.d.ts.map +1 -0
- package/dist/commands/pathspec-attributes.d.ts +64 -0
- package/dist/commands/pathspec-attributes.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +324 -0
- package/dist/commands/pathspec.d.ts.map +1 -0
- package/dist/commands/post-index-change.d.ts +33 -0
- package/dist/commands/post-index-change.d.ts.map +1 -0
- package/dist/commands/pretty-format.d.ts +222 -0
- package/dist/commands/pretty-format.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts +80 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -0
- package/dist/commands/pull-command.d.ts +59 -8
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +24 -8
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +112 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -0
- package/dist/commands/rebase-command.d.ts +507 -75
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/rebase-todo.d.ts +130 -0
- package/dist/commands/rebase-todo.d.ts.map +1 -0
- package/dist/commands/ref-decoration-filter.d.ts +53 -0
- package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
- package/dist/commands/reflog-messages.d.ts +98 -0
- package/dist/commands/reflog-messages.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +31 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +120 -0
- package/dist/commands/remote-transport.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +161 -7
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +103 -0
- package/dist/commands/restore-command.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +78 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -0
- package/dist/commands/rev-parse-command.d.ts +89 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -0
- package/dist/commands/revert-command.d.ts +46 -38
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-filenames.d.ts +95 -0
- package/dist/commands/revision-filenames.d.ts.map +1 -0
- package/dist/commands/revision-range.d.ts +67 -0
- package/dist/commands/revision-range.d.ts.map +1 -0
- package/dist/commands/revision-resolver.d.ts +325 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -0
- package/dist/commands/rm-command.d.ts +69 -7
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +191 -0
- package/dist/commands/sequencer-pick.d.ts.map +1 -0
- package/dist/commands/sequencer-support.d.ts +125 -0
- package/dist/commands/sequencer-support.d.ts.map +1 -0
- package/dist/commands/serve-repository.d.ts +52 -0
- package/dist/commands/serve-repository.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts +190 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-support.d.ts +268 -0
- package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +42 -8
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +156 -2
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +2 -0
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +23 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts +300 -15
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-format.d.ts +155 -0
- package/dist/commands/status-format.d.ts.map +1 -0
- package/dist/commands/status-header.d.ts +64 -0
- package/dist/commands/status-header.d.ts.map +1 -0
- package/dist/commands/strerror.d.ts +7 -0
- package/dist/commands/strerror.d.ts.map +1 -0
- package/dist/commands/submodule-config.d.ts +38 -0
- package/dist/commands/submodule-config.d.ts.map +1 -0
- package/dist/commands/submodule-summary-command.d.ts +80 -0
- package/dist/commands/submodule-summary-command.d.ts.map +1 -0
- package/dist/commands/submodule-summary.d.ts +150 -0
- package/dist/commands/submodule-summary.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +132 -0
- package/dist/commands/switch-command.d.ts.map +1 -0
- package/dist/commands/tag-command.d.ts +23 -2
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tracking-info.d.ts +64 -0
- package/dist/commands/tracking-info.d.ts.map +1 -0
- package/dist/commands/trailers.d.ts +73 -0
- package/dist/commands/trailers.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +85 -1
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +54 -0
- package/dist/commands/untracked-cache-support.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +108 -0
- package/dist/commands/worktree-add-command.d.ts.map +1 -0
- package/dist/commands/worktree-list-command.d.ts +69 -0
- package/dist/commands/worktree-list-command.d.ts.map +1 -0
- package/dist/commands/worktree-lock-command.d.ts +44 -0
- package/dist/commands/worktree-lock-command.d.ts.map +1 -0
- package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/commands/worktree-prune-command.d.ts +48 -0
- package/dist/commands/worktree-prune-command.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +59 -0
- package/dist/commands/worktree-remove-command.d.ts.map +1 -0
- package/dist/commands/worktree-repair-command.d.ts +35 -0
- package/dist/commands/worktree-repair-command.d.ts.map +1 -0
- package/dist/commands/worktree-support.d.ts +64 -0
- package/dist/commands/worktree-support.d.ts.map +1 -0
- package/dist/commands-DIJ91NnD.js +62225 -0
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/errors/add-errors.d.ts +55 -0
- package/dist/errors/add-errors.d.ts.map +1 -1
- package/dist/errors/checkout-errors.d.ts +16 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts +77 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/commit-errors.d.ts +9 -0
- package/dist/errors/commit-errors.d.ts.map +1 -1
- package/dist/errors/git-api-error.d.ts +59 -2
- package/dist/errors/git-api-error.d.ts.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +354 -19
- package/dist/errors/rebase-errors.d.ts +9 -0
- package/dist/errors/rebase-errors.d.ts.map +1 -1
- package/dist/errors/ref-errors.d.ts +32 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/transport-errors.d.ts +12 -2
- package/dist/errors/transport-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +35 -0
- package/dist/errors/worktree-errors.d.ts.map +1 -0
- package/dist/git-command-BGiOJ8Zk.js +7246 -0
- package/dist/git-command.d.ts +428 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +315 -5
- package/dist/git.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/index.d.ts +1 -1
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +167 -6
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +7 -3
- package/dist/remote-config/remote-refs.d.ts.map +1 -1
- package/dist/rename/detect-renames.d.ts +148 -0
- package/dist/rename/detect-renames.d.ts.map +1 -0
- package/dist/rename/git-similarity.d.ts +44 -0
- package/dist/rename/git-similarity.d.ts.map +1 -0
- package/dist/rename/index.d.ts +2 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/binary-patch.d.ts +11 -0
- package/dist/results/binary-patch.d.ts.map +1 -0
- package/dist/results/blame-format.d.ts +55 -0
- package/dist/results/blame-format.d.ts.map +1 -0
- package/dist/results/cherry-pick-result.d.ts +10 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +18 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +77 -0
- package/dist/results/combined-diff.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +32 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +34 -60
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-order.d.ts +25 -0
- package/dist/results/diff-order.d.ts.map +1 -0
- package/dist/results/diff-output.d.ts +249 -0
- package/dist/results/diff-output.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +15 -0
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +5 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -252
- package/dist/results/init-result.d.ts +7 -0
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/merge-result.d.ts +15 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +17 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +47 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/quote-path.d.ts +27 -0
- package/dist/results/quote-path.d.ts.map +1 -0
- package/dist/results/rebase-result.d.ts +28 -1
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +10 -0
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +5 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +60 -6
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-WVlBhVb1.js +2935 -0
- package/dist/transport-command.d.ts +44 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -11
- package/src/commands/add-command.ts +1291 -226
- package/src/commands/add-patch/add-interactive.ts +941 -0
- package/src/commands/add-patch/add-patch.ts +1169 -0
- package/src/commands/add-patch/index.ts +5 -0
- package/src/commands/add-patch/patch-backend.ts +239 -0
- package/src/commands/add-patch/patch-modes.ts +249 -0
- package/src/commands/add-patch/patch-session.ts +159 -0
- package/src/commands/am/am-command.ts +1111 -0
- package/src/commands/am/index.ts +2 -0
- package/src/commands/am/mailinfo.ts +1015 -0
- package/src/commands/am/patch-format.ts +121 -0
- package/src/commands/apply/apply-command.ts +842 -0
- package/src/commands/apply/apply-engine.ts +1602 -0
- package/src/commands/apply/apply-parse.ts +1210 -0
- package/src/commands/apply/apply-types.ts +112 -0
- package/src/commands/apply/index.ts +5 -0
- package/src/commands/apply/latin1.ts +171 -0
- package/src/commands/apply/whitespace.ts +260 -0
- package/src/commands/attributes-source.ts +96 -0
- package/src/commands/backfill-command.ts +694 -0
- package/src/commands/bisect/bisect-checkout.ts +217 -0
- package/src/commands/bisect/bisect-command.ts +788 -0
- package/src/commands/bisect/bisect-engine.ts +1080 -0
- package/src/commands/bisect/bisect-graph.ts +595 -0
- package/src/commands/bisect/bisect-quote.ts +92 -0
- package/src/commands/bisect/index.ts +4 -0
- package/src/commands/blame-command.ts +711 -986
- package/src/commands/branch-command.ts +354 -32
- package/src/commands/branch-tracking.ts +331 -0
- package/src/commands/checkout-command.ts +1290 -243
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +504 -156
- package/src/commands/clone-command.ts +748 -69
- package/src/commands/comment-char-config.ts +160 -0
- package/src/commands/commit-command.ts +1782 -166
- package/src/commands/core-config.ts +166 -6
- package/src/commands/date-format.ts +668 -0
- package/src/commands/default-branch.ts +196 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1916 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +622 -68
- package/src/commands/format-patch-command.ts +974 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3464 -0
- package/src/commands/fsck/fsck-loose.ts +297 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1085 -0
- package/src/commands/fsck/fsck-object-table.ts +373 -0
- package/src/commands/fsck/fsck-pack.ts +634 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +252 -0
- package/src/commands/gc-command.ts +324 -77
- package/src/commands/git-date.ts +9 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1483 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +711 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +84 -0
- package/src/commands/init-command.ts +194 -14
- package/src/commands/legacy-remotes.ts +224 -0
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1930 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +105 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1416 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1219 -0
- package/src/commands/message-cleanup.ts +275 -0
- package/src/commands/mv-command.ts +976 -0
- package/src/commands/notes-command.ts +890 -0
- package/src/commands/notes-commands.ts +87 -0
- package/src/commands/notes-merge-command.ts +777 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +617 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +378 -0
- package/src/commands/ort-merge.ts +1660 -0
- package/src/commands/ort-recursive.ts +160 -0
- package/src/commands/pack-refs-command.ts +39 -22
- package/src/commands/patch-id.ts +204 -0
- package/src/commands/pathspec-attributes.ts +162 -0
- package/src/commands/pathspec.ts +1199 -0
- package/src/commands/post-index-change.ts +62 -0
- package/src/commands/pretty-format.ts +1432 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +326 -33
- package/src/commands/push-command.ts +257 -29
- package/src/commands/read-tree-command.ts +861 -0
- package/src/commands/rebase-command.ts +3820 -372
- package/src/commands/rebase-todo.ts +584 -0
- package/src/commands/ref-decoration-filter.ts +118 -0
- package/src/commands/reflog-messages.ts +177 -0
- package/src/commands/remote-command.ts +124 -23
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +821 -104
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +299 -0
- package/src/commands/revert-command.ts +152 -399
- package/src/commands/revision-filenames.ts +254 -0
- package/src/commands/revision-range.ts +222 -0
- package/src/commands/revision-resolver.ts +1397 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +874 -0
- package/src/commands/sequencer-support.ts +876 -0
- package/src/commands/serve-repository.ts +125 -0
- package/src/commands/sparse-checkout-command.ts +1389 -0
- package/src/commands/sparse-checkout-support.ts +793 -0
- package/src/commands/stash-apply-command.ts +376 -343
- package/src/commands/stash-create-command.ts +625 -42
- package/src/commands/stash-drop-command.ts +15 -2
- package/src/commands/stash-working-tree.ts +168 -24
- package/src/commands/status-command.ts +1326 -105
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +332 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +333 -0
- package/src/commands/submodule-summary.ts +446 -0
- package/src/commands/switch-command.ts +402 -0
- package/src/commands/tag-command.ts +129 -41
- package/src/commands/tracking-info.ts +201 -0
- package/src/commands/trailers.ts +417 -0
- package/src/commands/tree-restore.ts +204 -4
- package/src/commands/untracked-cache-support.ts +198 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +206 -0
- package/src/commands/worktree-lock-command.ts +96 -0
- package/src/commands/worktree-overwrite-checks.ts +452 -26
- package/src/commands/worktree-prune-command.ts +99 -0
- package/src/commands/worktree-remove-command.ts +186 -0
- package/src/commands/worktree-repair-command.ts +59 -0
- package/src/commands/worktree-support.ts +214 -0
- package/src/core-commands/add.command.impl.ts +8 -2
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +26 -2
- package/src/errors/command-errors.ts +101 -1
- package/src/errors/commit-errors.ts +18 -2
- package/src/errors/git-api-error.ts +82 -2
- package/src/errors/index.ts +1 -0
- package/src/errors/merge-errors.ts +2 -2
- package/src/errors/rebase-errors.ts +12 -0
- package/src/errors/ref-errors.ts +56 -2
- package/src/errors/remote-errors.ts +2 -2
- package/src/errors/stash-errors.ts +1 -1
- package/src/errors/transport-errors.ts +20 -4
- package/src/errors/worktree-errors.ts +49 -0
- package/src/git-command.ts +1207 -118
- package/src/git.ts +538 -12
- package/src/index.ts +1 -1
- package/src/remote-config/index.ts +2 -0
- package/src/remote-config/remote-config-store.ts +378 -18
- package/src/remote-config/remote-refs.ts +22 -6
- package/src/rename/detect-renames.ts +715 -0
- package/src/rename/git-similarity.ts +116 -0
- package/src/rename/index.ts +2 -0
- package/src/results/binary-patch.ts +401 -0
- package/src/results/blame-format.ts +239 -0
- package/src/results/cherry-pick-result.ts +10 -0
- package/src/results/clone-result.ts +21 -0
- package/src/results/combined-diff.ts +585 -0
- package/src/results/diff-entry.ts +35 -0
- package/src/results/diff-formatter.ts +152 -288
- package/src/results/diff-order.ts +64 -0
- package/src/results/diff-output.ts +1053 -0
- package/src/results/fetch-result.ts +15 -0
- package/src/results/index.ts +5 -0
- package/src/results/init-result.ts +9 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +17 -3
- package/src/results/push-result.ts +48 -0
- package/src/results/quote-path.ts +103 -0
- package/src/results/rebase-result.ts +37 -0
- package/src/results/revert-result.ts +10 -0
- package/src/results/stash-result.ts +6 -0
- package/src/results/status-result.ts +127 -46
- package/src/transport-command.ts +121 -2
- package/dist/commands-CsLNyvZ1.js +0 -12587
- package/dist/status-result-BpyUK1Sg.js +0 -519
|
@@ -0,0 +1,941 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git add -i` (add-interactive.c's `run_add_i`) as a library: the status listing, the
|
|
3
|
+
* "*** Commands ***" menu and its actions (status, update, revert, add untracked, patch,
|
|
4
|
+
* diff, quit, help), each read git makes from standard input answered by the selector (a
|
|
5
|
+
* `choose` request for the menus, the hunk prompts of patch mode as `add -p` asks them), and
|
|
6
|
+
* what git prints gathered as its standard output and standard error.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { ObjectId } from "@statewalker/vcs-core";
|
|
10
|
+
import type {
|
|
11
|
+
ResolveUndoRecord,
|
|
12
|
+
StagingEntry,
|
|
13
|
+
StagingIndexLock,
|
|
14
|
+
Worktree,
|
|
15
|
+
} from "@statewalker/vcs-working-tree";
|
|
16
|
+
|
|
17
|
+
import { GitApiError } from "../../errors/index.js";
|
|
18
|
+
import { GitCommand } from "../../git-command.js";
|
|
19
|
+
import type { WorkingCopy } from "../../types.js";
|
|
20
|
+
import { worktreeModeTrust } from "../core-config.js";
|
|
21
|
+
import { DiffCommand } from "../diff-command.js";
|
|
22
|
+
import { AddToIndexError, addLeadingDirs, IndexAdder, stageZeroClashes } from "../index-adder.js";
|
|
23
|
+
import { flatTree, rewriteIndex } from "../merge-support.js";
|
|
24
|
+
import { StatusCommand } from "../status-command.js";
|
|
25
|
+
import type { PatchCompatibility, PatchRequest, PatchSelector } from "./add-patch.js";
|
|
26
|
+
import { IndexRefresh } from "./patch-backend.js";
|
|
27
|
+
import { patchModeFor } from "./patch-modes.js";
|
|
28
|
+
import { type PatchOptions, runPatchSelection } from "./patch-session.js";
|
|
29
|
+
|
|
30
|
+
/** What `git add -i` printed and staged. */
|
|
31
|
+
export interface AddInteractiveResult {
|
|
32
|
+
/** Standard output, as git prints it: listings, menus, prompts, help, patch mode's transcript */
|
|
33
|
+
output: string;
|
|
34
|
+
/** Standard error: `Huh (...)?`, `ignoring unmerged: ...`, patch mode's errors */
|
|
35
|
+
errors: string;
|
|
36
|
+
/** Paths staged by update, add untracked and patch, in order */
|
|
37
|
+
added: string[];
|
|
38
|
+
/** Paths reverted to HEAD */
|
|
39
|
+
reverted: string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Options of {@link runAddInteractive}. */
|
|
43
|
+
export interface AddInteractiveOptions extends PatchOptions {
|
|
44
|
+
selector: PatchSelector;
|
|
45
|
+
/** The pathspec `git add -i <pathspec>` was given */
|
|
46
|
+
paths?: string[];
|
|
47
|
+
/** Default 2.56 */
|
|
48
|
+
compatibility?: PatchCompatibility;
|
|
49
|
+
/** The command running the session: hooks of the index writes run in its session */
|
|
50
|
+
hookSource?: GitCommand<unknown>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface AddDel {
|
|
54
|
+
add: number;
|
|
55
|
+
del: number;
|
|
56
|
+
seen: boolean;
|
|
57
|
+
unmerged: boolean;
|
|
58
|
+
binary: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface Item {
|
|
62
|
+
name: string;
|
|
63
|
+
prefixLength: number;
|
|
64
|
+
index: AddDel;
|
|
65
|
+
worktree: AddDel;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const newAddDel = (): AddDel => ({ add: 0, del: 0, seen: false, unmerged: false, binary: false });
|
|
69
|
+
const newItem = (name: string): Item => ({
|
|
70
|
+
name,
|
|
71
|
+
prefixLength: 0,
|
|
72
|
+
index: newAddDel(),
|
|
73
|
+
worktree: newAddDel(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* strcmp's order: the paths' UTF-8 bytes, which sort as their code points (not as UTF-16
|
|
78
|
+
* code units: U+FF5E before U+1F600, whose surrogates come first in UTF-16)
|
|
79
|
+
*/
|
|
80
|
+
function byName(a: string, b: string): number {
|
|
81
|
+
const n = Math.min(a.length, b.length);
|
|
82
|
+
for (let i = 0; i < n; i++) {
|
|
83
|
+
const x = a.charCodeAt(i);
|
|
84
|
+
const y = b.charCodeAt(i);
|
|
85
|
+
if (x === y) continue;
|
|
86
|
+
if (x < 0xd800 && y < 0xd800) return x - y;
|
|
87
|
+
return (a.codePointAt(i) as number) - (b.codePointAt(i) as number);
|
|
88
|
+
}
|
|
89
|
+
return a.length - b.length;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const isAscii = (c: string | undefined) => c !== undefined && c.charCodeAt(0) < 0x80;
|
|
93
|
+
const isDigit = (c: string | undefined) => c !== undefined && c >= "0" && c <= "9";
|
|
94
|
+
const SEPARATORS = " \t\r\n,";
|
|
95
|
+
|
|
96
|
+
/** strcspn(s, " \t\r\n,") from `at` */
|
|
97
|
+
function separatorSpan(s: string, at: number): number {
|
|
98
|
+
let n = 0;
|
|
99
|
+
while (at + n < s.length && !SEPARATORS.includes(s[at + n])) n++;
|
|
100
|
+
return n;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** `find_unique_prefixes`: each item's shortest unique prefix (1 to 4 ASCII characters). */
|
|
104
|
+
function findUniquePrefixes(items: Item[]): Item[] {
|
|
105
|
+
const sorted = [...items].sort((a, b) => byName(a.name, b.name));
|
|
106
|
+
const extend = (item: Item, other: string) => {
|
|
107
|
+
let len = item.prefixLength;
|
|
108
|
+
if (!len || item.name.slice(0, len) !== other.slice(0, len)) return;
|
|
109
|
+
for (;;) {
|
|
110
|
+
const c = item.name[len];
|
|
111
|
+
if (c === undefined || ++len > 4 || !isAscii(c)) {
|
|
112
|
+
len = 0;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (c !== other[len - 1]) break;
|
|
116
|
+
}
|
|
117
|
+
item.prefixLength = len;
|
|
118
|
+
};
|
|
119
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
120
|
+
const item = sorted[i];
|
|
121
|
+
item.prefixLength = 0;
|
|
122
|
+
const c = item.name[0];
|
|
123
|
+
item.prefixLength = c === undefined || !isAscii(c) ? 0 : 1;
|
|
124
|
+
if (i > 0) extend(item, sorted[i - 1].name);
|
|
125
|
+
if (i + 1 < sorted.length) extend(item, sorted[i + 1].name);
|
|
126
|
+
}
|
|
127
|
+
return sorted;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** `find_unique`: the index of the item `s` names (exactly or by a unique prefix), or -1. */
|
|
131
|
+
function findUnique(s: string, items: Item[], sorted: Item[]): number {
|
|
132
|
+
// string_list_find_insert_index
|
|
133
|
+
let lo = 0;
|
|
134
|
+
let hi = sorted.length;
|
|
135
|
+
let exact = false;
|
|
136
|
+
while (lo < hi) {
|
|
137
|
+
const mid = (lo + hi) >> 1;
|
|
138
|
+
const cmp = byName(sorted[mid].name, s);
|
|
139
|
+
if (cmp === 0) {
|
|
140
|
+
lo = mid;
|
|
141
|
+
exact = true;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
if (cmp < 0) lo = mid + 1;
|
|
145
|
+
else hi = mid;
|
|
146
|
+
}
|
|
147
|
+
const index = lo;
|
|
148
|
+
let item: Item;
|
|
149
|
+
if (exact) item = sorted[index];
|
|
150
|
+
else if (index > 0 && sorted[index - 1].name.startsWith(s)) return -1;
|
|
151
|
+
else if (index + 1 < sorted.length && sorted[index + 1].name.startsWith(s)) return -1;
|
|
152
|
+
else if (index < sorted.length && sorted[index].name.startsWith(s)) item = sorted[index];
|
|
153
|
+
else return -1;
|
|
154
|
+
return items.indexOf(item);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** `is_valid_prefix`: a prefix that means nothing else to list_and_choose. */
|
|
158
|
+
function isValidPrefix(name: string, length: number): boolean {
|
|
159
|
+
return (
|
|
160
|
+
length > 0 &&
|
|
161
|
+
separatorSpan(name, 0) >= length &&
|
|
162
|
+
name[0] !== "-" &&
|
|
163
|
+
!isDigit(name[0]) &&
|
|
164
|
+
(length !== 1 || (name[0] !== "*" && name[0] !== "?"))
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** `%12s` */
|
|
169
|
+
const pad12 = (s: string) => s.padStart(12);
|
|
170
|
+
|
|
171
|
+
function renderAddDel(ad: AddDel, noChanges: string): string {
|
|
172
|
+
if (ad.binary) return "binary";
|
|
173
|
+
if (ad.seen) return `+${ad.add}/-${ad.del}`;
|
|
174
|
+
return noChanges;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** strtoul from `at` (digits only: the caller checked the first is one) */
|
|
178
|
+
function parseNumber(s: string, at: number): { value: number; end: number } {
|
|
179
|
+
let end = at;
|
|
180
|
+
while (isDigit(s[end])) end++;
|
|
181
|
+
return { value: Number(s.slice(at, end)), end };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const LIST_AND_CHOOSE_ERROR = -1;
|
|
185
|
+
const LIST_AND_CHOOSE_QUIT = -2;
|
|
186
|
+
|
|
187
|
+
interface ListOptions {
|
|
188
|
+
columns: number;
|
|
189
|
+
header?: string;
|
|
190
|
+
print: (i: number, selected: boolean, item: Item) => string;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface ChooseOptions {
|
|
194
|
+
list: ListOptions;
|
|
195
|
+
prompt: string;
|
|
196
|
+
singleton: boolean;
|
|
197
|
+
immediate: boolean;
|
|
198
|
+
help: () => void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
type Filter = "none" | "worktree-only" | "index-only";
|
|
202
|
+
|
|
203
|
+
/** A `git add -i` session (run_add_i). */
|
|
204
|
+
class AddInteractiveSession extends GitCommand<AddInteractiveResult> {
|
|
205
|
+
private out = "";
|
|
206
|
+
private err = "";
|
|
207
|
+
private readonly added: string[] = [];
|
|
208
|
+
private readonly reverted: string[] = [];
|
|
209
|
+
private files: Item[] = [];
|
|
210
|
+
/** `files.selected` of the last multi-selection */
|
|
211
|
+
private selected: boolean[] = [];
|
|
212
|
+
/** Whether the files' prefixes are computed (`sorted.nr == items.nr`) */
|
|
213
|
+
private filesSorted?: Item[];
|
|
214
|
+
private onlyNames = false;
|
|
215
|
+
private header = "";
|
|
216
|
+
|
|
217
|
+
constructor(
|
|
218
|
+
workingCopy: WorkingCopy,
|
|
219
|
+
private readonly options: AddInteractiveOptions,
|
|
220
|
+
) {
|
|
221
|
+
super(workingCopy);
|
|
222
|
+
if (options.hookSource) this.shareHooksOf(options.hookSource);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private get modern(): boolean {
|
|
226
|
+
return (this.options.compatibility ?? "2.56") !== "2.43";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private sharing<T extends GitCommand<unknown>>(command: T): T {
|
|
230
|
+
const source = this.options.hookSource;
|
|
231
|
+
return source ? command.shareHooksOf(source) : command;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async call(): Promise<AddInteractiveResult> {
|
|
235
|
+
this.checkCallable();
|
|
236
|
+
this.setCallable(false);
|
|
237
|
+
const commands: Item[] = [
|
|
238
|
+
"status",
|
|
239
|
+
"update",
|
|
240
|
+
"revert",
|
|
241
|
+
"add untracked",
|
|
242
|
+
"patch",
|
|
243
|
+
"diff",
|
|
244
|
+
"quit",
|
|
245
|
+
"help",
|
|
246
|
+
].map(newItem);
|
|
247
|
+
const commandsSorted = findUniquePrefixes(commands);
|
|
248
|
+
this.header = ` ${pad12("staged")} ${pad12("unstaged")} path`;
|
|
249
|
+
const mainLoop: ChooseOptions = {
|
|
250
|
+
list: {
|
|
251
|
+
columns: 4,
|
|
252
|
+
header: "*** Commands ***",
|
|
253
|
+
print: (i, _selected, item) => {
|
|
254
|
+
const n = String(i + 1).padStart(2);
|
|
255
|
+
if (!item.prefixLength || !isValidPrefix(item.name, item.prefixLength)) {
|
|
256
|
+
return ` ${n}: ${item.name}`;
|
|
257
|
+
}
|
|
258
|
+
return ` ${n}: [${item.name.slice(0, item.prefixLength)}]${item.name.slice(item.prefixLength)}`;
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
prompt: "What now",
|
|
262
|
+
singleton: true,
|
|
263
|
+
immediate: true,
|
|
264
|
+
help: () => {
|
|
265
|
+
this.out +=
|
|
266
|
+
"Prompt help:\n" +
|
|
267
|
+
"1 - select a numbered item\n" +
|
|
268
|
+
"foo - select item based on unique prefix\n" +
|
|
269
|
+
" - (empty) select nothing\n";
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
// repo_refresh_and_write_index (REFRESH_QUIET, gentle: an index lock another process
|
|
273
|
+
// holds leaves the refresh in memory, unreported): its `needs merge` lines go to stdout
|
|
274
|
+
try {
|
|
275
|
+
this.out += (
|
|
276
|
+
await this.sharing(new IndexRefresh(this.workingCopy)).setGentle().refresh()
|
|
277
|
+
).output;
|
|
278
|
+
} catch {
|
|
279
|
+
this.err += "warning: could not refresh index\n";
|
|
280
|
+
}
|
|
281
|
+
await this.runStatus();
|
|
282
|
+
for (;;) {
|
|
283
|
+
const i = await this.listAndChoose(commands, commandsSorted, mainLoop);
|
|
284
|
+
const name = i >= 0 && i < commands.length ? commands[i].name : undefined;
|
|
285
|
+
if (i === LIST_AND_CHOOSE_QUIT || name === "quit") {
|
|
286
|
+
this.out += "Bye.\n";
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
switch (name) {
|
|
290
|
+
case "status":
|
|
291
|
+
await this.runStatus();
|
|
292
|
+
break;
|
|
293
|
+
case "update":
|
|
294
|
+
await this.runUpdate();
|
|
295
|
+
break;
|
|
296
|
+
case "revert":
|
|
297
|
+
await this.runRevert();
|
|
298
|
+
break;
|
|
299
|
+
case "add untracked":
|
|
300
|
+
await this.runAddUntracked();
|
|
301
|
+
break;
|
|
302
|
+
case "patch":
|
|
303
|
+
await this.runPatch();
|
|
304
|
+
break;
|
|
305
|
+
case "diff":
|
|
306
|
+
await this.runDiff();
|
|
307
|
+
break;
|
|
308
|
+
case "help":
|
|
309
|
+
this.runHelp();
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return { output: this.out, errors: this.err, added: this.added, reverted: this.reverted };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** The options of the file selections (`opts` of run_add_i) */
|
|
317
|
+
private fileChooser(prompt: string, immediate = false): ChooseOptions {
|
|
318
|
+
return {
|
|
319
|
+
list: {
|
|
320
|
+
columns: 0,
|
|
321
|
+
header: this.header,
|
|
322
|
+
print: (i, selected, item) => {
|
|
323
|
+
let name = item.name;
|
|
324
|
+
if (item.prefixLength > 0 && isValidPrefix(item.name, item.prefixLength)) {
|
|
325
|
+
name = `[${item.name.slice(0, item.prefixLength)}]${item.name.slice(item.prefixLength)}`;
|
|
326
|
+
}
|
|
327
|
+
const lead = `${selected ? "*" : " "}${String(i + 1).padStart(2)}: `;
|
|
328
|
+
if (this.onlyNames) return `${lead}${name}`;
|
|
329
|
+
const worktree = renderAddDel(item.worktree, "nothing");
|
|
330
|
+
const index = renderAddDel(item.index, "unchanged");
|
|
331
|
+
return `${lead}${pad12(index)} ${pad12(worktree)} ${name}`;
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
prompt,
|
|
335
|
+
singleton: false,
|
|
336
|
+
immediate,
|
|
337
|
+
help: () => {
|
|
338
|
+
this.out +=
|
|
339
|
+
"Prompt help:\n" +
|
|
340
|
+
"1 - select a single item\n" +
|
|
341
|
+
"3-5 - select a range of items\n" +
|
|
342
|
+
"2-3,6-9 - select multiple ranges\n" +
|
|
343
|
+
"foo - select item based on unique prefix\n" +
|
|
344
|
+
"-... - unselect specified items\n" +
|
|
345
|
+
"* - choose all items\n" +
|
|
346
|
+
" - (empty) finish selecting\n";
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** `list()` */
|
|
352
|
+
private list(items: Item[], selected: boolean[] | undefined, options: ListOptions): void {
|
|
353
|
+
if (items.length === 0) return;
|
|
354
|
+
if (options.header !== undefined) this.out += `${options.header}\n`;
|
|
355
|
+
let lastLf = false;
|
|
356
|
+
for (let i = 0; i < items.length; i++) {
|
|
357
|
+
this.out += options.print(i, selected?.[i] ?? false, items[i]);
|
|
358
|
+
if (options.columns && (i + 1) % options.columns) {
|
|
359
|
+
this.out += "\t";
|
|
360
|
+
lastLf = false;
|
|
361
|
+
} else {
|
|
362
|
+
this.out += "\n";
|
|
363
|
+
lastLf = true;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (!lastLf) this.out += "\n";
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* `list_and_choose`: the selected index for a singleton, else the number of items
|
|
371
|
+
* selected; LIST_AND_CHOOSE_ERROR, or LIST_AND_CHOOSE_QUIT at the end of input (immediate).
|
|
372
|
+
*/
|
|
373
|
+
private async listAndChoose(
|
|
374
|
+
items: Item[],
|
|
375
|
+
sorted: Item[],
|
|
376
|
+
options: ChooseOptions,
|
|
377
|
+
): Promise<number> {
|
|
378
|
+
const { singleton, immediate } = options;
|
|
379
|
+
let res = singleton ? LIST_AND_CHOOSE_ERROR : 0;
|
|
380
|
+
const selected = singleton ? undefined : items.map(() => false);
|
|
381
|
+
if (selected) this.selected = selected;
|
|
382
|
+
for (;;) {
|
|
383
|
+
this.list(items, selected, options.list);
|
|
384
|
+
const prompt = `${options.prompt}${singleton ? "> " : ">> "}`;
|
|
385
|
+
this.out += prompt;
|
|
386
|
+
const request: PatchRequest = {
|
|
387
|
+
type: "choose",
|
|
388
|
+
prompt,
|
|
389
|
+
singleton,
|
|
390
|
+
items: items.map((item) => item.name),
|
|
391
|
+
output: this.out,
|
|
392
|
+
};
|
|
393
|
+
const reply = await this.options.selector(request);
|
|
394
|
+
if (reply === undefined) {
|
|
395
|
+
this.out += "\n";
|
|
396
|
+
if (immediate) res = LIST_AND_CHOOSE_QUIT;
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
// git_read_line_interactively: the line without its line end
|
|
400
|
+
const input = reply.replace(/\r?\n$/, "");
|
|
401
|
+
if (input.length === 0) break;
|
|
402
|
+
if (input === "?") {
|
|
403
|
+
options.help();
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
// the C string the input is once its tokens are cut (each token's end gets a NUL)
|
|
407
|
+
let firstNul = -1;
|
|
408
|
+
let p = 0;
|
|
409
|
+
for (;;) {
|
|
410
|
+
let sep = separatorSpan(input, p);
|
|
411
|
+
let choose = true;
|
|
412
|
+
let from = -1;
|
|
413
|
+
let to = -1;
|
|
414
|
+
if (!sep) {
|
|
415
|
+
if (p >= input.length) break;
|
|
416
|
+
p++;
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (input[p] === "-") {
|
|
420
|
+
choose = false;
|
|
421
|
+
p++;
|
|
422
|
+
sep--;
|
|
423
|
+
}
|
|
424
|
+
if (sep === 1 && input[p] === "*") {
|
|
425
|
+
from = 0;
|
|
426
|
+
to = items.length;
|
|
427
|
+
} else if (isDigit(input[p])) {
|
|
428
|
+
const first = parseNumber(input, p);
|
|
429
|
+
from = first.value - 1;
|
|
430
|
+
let endp = first.end;
|
|
431
|
+
if (endp === p + sep) to = from + 1;
|
|
432
|
+
else if (input[endp] === "-") {
|
|
433
|
+
endp++;
|
|
434
|
+
if (isDigit(input[endp])) {
|
|
435
|
+
const second = parseNumber(input, endp);
|
|
436
|
+
to = second.value;
|
|
437
|
+
endp = second.end;
|
|
438
|
+
} else to = items.length;
|
|
439
|
+
if (endp !== p + sep) from = -1;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
const token = input.slice(p, p + sep);
|
|
443
|
+
if (p + sep < input.length) {
|
|
444
|
+
if (firstNul < 0) firstNul = p + sep;
|
|
445
|
+
sep++;
|
|
446
|
+
}
|
|
447
|
+
if (from < 0) {
|
|
448
|
+
from = findUnique(token, items, sorted);
|
|
449
|
+
if (from >= 0) to = from + 1;
|
|
450
|
+
}
|
|
451
|
+
if (from < 0 || from >= items.length || (singleton && from + 1 !== to)) {
|
|
452
|
+
this.err += `Huh (${token})?\n`;
|
|
453
|
+
break;
|
|
454
|
+
} else if (singleton) {
|
|
455
|
+
res = from;
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
// `to` (signed) against the item count (unsigned): -1 (`5x`) runs to the end
|
|
459
|
+
if (to < 0 || to > items.length) to = items.length;
|
|
460
|
+
for (; from < to; from++) {
|
|
461
|
+
if ((selected as boolean[])[from] !== choose) {
|
|
462
|
+
(selected as boolean[])[from] = choose;
|
|
463
|
+
res += choose ? 1 : -1;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
p += sep;
|
|
467
|
+
}
|
|
468
|
+
const cString = firstNul < 0 ? input : input.slice(0, firstNul);
|
|
469
|
+
if ((immediate && res !== LIST_AND_CHOOSE_ERROR) || cString === "*") break;
|
|
470
|
+
}
|
|
471
|
+
return res;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** The files a multi-selection chose */
|
|
475
|
+
private chosen(): string[] {
|
|
476
|
+
return this.files.filter((_, i) => this.selected[i]).map((item) => item.name);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** The files list's sorted view, computed once per list (find_unique_prefixes) */
|
|
480
|
+
private sortedFiles(): Item[] {
|
|
481
|
+
if (!this.filesSorted) this.filesSorted = findUniquePrefixes(this.files);
|
|
482
|
+
return this.filesSorted;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
private setFiles(files: Item[]): void {
|
|
486
|
+
this.files = files;
|
|
487
|
+
this.filesSorted = undefined;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** HEAD's commit, undefined on an unborn branch */
|
|
491
|
+
private async headId(): Promise<ObjectId | undefined> {
|
|
492
|
+
try {
|
|
493
|
+
return await this.resolveRevision("HEAD");
|
|
494
|
+
} catch {
|
|
495
|
+
return undefined;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** `get_modified_files` */
|
|
500
|
+
private async getModifiedFiles(
|
|
501
|
+
filter: Filter,
|
|
502
|
+
): Promise<{ unmergedCount: number; binaryCount: number }> {
|
|
503
|
+
const head = await this.headId();
|
|
504
|
+
const files: Item[] = [];
|
|
505
|
+
const byPath = new Map<string, Item>();
|
|
506
|
+
let unmergedCount = 0;
|
|
507
|
+
let binaryCount = 0;
|
|
508
|
+
const paths = this.options.paths ?? [];
|
|
509
|
+
for (let i = 0; i < 2; i++) {
|
|
510
|
+
const fromIndex = filter === "index-only" ? i === 0 : i === 1;
|
|
511
|
+
const skipUnseen = filter !== "none" && i === 1;
|
|
512
|
+
const diff = new DiffCommand(this.workingCopy).setRenames(false).setCombineMerges(false);
|
|
513
|
+
if (fromIndex) {
|
|
514
|
+
diff
|
|
515
|
+
.setOldTree(head ?? this.objectFormat.emptyTreeId)
|
|
516
|
+
.setCached(true)
|
|
517
|
+
.setIntentToAddVisible(true);
|
|
518
|
+
} else diff.setIgnoreSubmodules("dirty");
|
|
519
|
+
if (paths.length > 0) diff.setPathspec(paths);
|
|
520
|
+
for (const stat of await diff.callDiffstat()) {
|
|
521
|
+
let item = byPath.get(stat.name);
|
|
522
|
+
if (!item) {
|
|
523
|
+
if (skipUnseen) continue;
|
|
524
|
+
item = newItem(stat.name);
|
|
525
|
+
files.push(item);
|
|
526
|
+
byPath.set(stat.name, item);
|
|
527
|
+
}
|
|
528
|
+
const ad = fromIndex ? item.index : item.worktree;
|
|
529
|
+
const other = fromIndex ? item.worktree : item.index;
|
|
530
|
+
ad.seen = true;
|
|
531
|
+
ad.add = stat.added;
|
|
532
|
+
ad.del = stat.deleted;
|
|
533
|
+
if (stat.isBinary) {
|
|
534
|
+
if (!other.binary) binaryCount++;
|
|
535
|
+
ad.binary = true;
|
|
536
|
+
}
|
|
537
|
+
if (stat.isUnmerged) {
|
|
538
|
+
if (!other.unmerged) unmergedCount++;
|
|
539
|
+
ad.unmerged = true;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
files.sort((a, b) => byName(a.name, b.name));
|
|
544
|
+
this.setFiles(files);
|
|
545
|
+
return { unmergedCount, binaryCount };
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
private async runStatus(): Promise<void> {
|
|
549
|
+
await this.getModifiedFiles("none");
|
|
550
|
+
this.list(this.files, undefined, this.fileChooser("").list);
|
|
551
|
+
this.out += "\n";
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
private async runUpdate(): Promise<void> {
|
|
555
|
+
await this.getModifiedFiles("worktree-only");
|
|
556
|
+
if (this.files.length === 0) {
|
|
557
|
+
this.out += "\n";
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const count = await this.listAndChoose(
|
|
561
|
+
this.files,
|
|
562
|
+
this.sortedFiles(),
|
|
563
|
+
this.fileChooser("Update"),
|
|
564
|
+
);
|
|
565
|
+
if (count <= 0) {
|
|
566
|
+
this.out += "\n";
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const paths = this.chosen();
|
|
570
|
+
if (await this.stage(paths, true)) {
|
|
571
|
+
this.out += `updated ${count} path${count === 1 ? "" : "s"}\n`;
|
|
572
|
+
}
|
|
573
|
+
this.out += "\n";
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* `repo_hold_locked_index(LOCK_REPORT_ON_ERROR)`: the index lock (null for a staging
|
|
578
|
+
* without an index file), or false with git's error printed when another process holds it.
|
|
579
|
+
*/
|
|
580
|
+
private async holdIndex(): Promise<StagingIndexLock | null | false> {
|
|
581
|
+
await this.readCurrentIndex(false);
|
|
582
|
+
const staging = this.staging;
|
|
583
|
+
if (!staging.lockIndex) return null;
|
|
584
|
+
try {
|
|
585
|
+
return await staging.lockIndex();
|
|
586
|
+
} catch (error) {
|
|
587
|
+
if ((error as Error)?.name !== "IndexLockedError") throw error;
|
|
588
|
+
// lockfile.c's unable_to_lock_message, the lock named by its absolute path
|
|
589
|
+
const lockPath = await this.hooks.gitPath("index.lock", true);
|
|
590
|
+
const advice = this.modern
|
|
591
|
+
? "Another git process seems to be running in this repository, or the lock file may be stale\n"
|
|
592
|
+
: "Another git process seems to be running in this repository, e.g.\n" +
|
|
593
|
+
"an editor opened by 'git commit'. Please make sure all processes\n" +
|
|
594
|
+
"are terminated then try again. If it still fails, a git process\n" +
|
|
595
|
+
"may have crashed in this repository earlier:\n" +
|
|
596
|
+
"remove the file manually to continue.\n";
|
|
597
|
+
this.err += `error: Unable to create '${lockPath}': File exists.\n\n${advice}`;
|
|
598
|
+
return false;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** The index written through the lock held (`write_locked_index(COMMIT_LOCK)`). */
|
|
603
|
+
private async commitIndex(lock: StagingIndexLock | null): Promise<void> {
|
|
604
|
+
if (!lock) return this.staging.write();
|
|
605
|
+
await lock.write();
|
|
606
|
+
await lock.commit();
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* run_update's and run_add_untracked's loop under the index lock: `add_file_to_index` of
|
|
611
|
+
* each path (update: `remove_file_from_index` of a file gone), stopping at the first that
|
|
612
|
+
* fails (`could not stage`) with the index left unwritten (the paths before it staged in
|
|
613
|
+
* memory, as git's index keeps them); no pathspec or sparse-checkout check. False on a
|
|
614
|
+
* failure.
|
|
615
|
+
*/
|
|
616
|
+
private async stage(paths: string[], update: boolean): Promise<boolean> {
|
|
617
|
+
const lock = await this.holdIndex();
|
|
618
|
+
if (lock === false) return false;
|
|
619
|
+
let written = false;
|
|
620
|
+
try {
|
|
621
|
+
const worktree = this.workingCopy.worktree;
|
|
622
|
+
if (!worktree) throw new GitApiError("fatal: this operation must be run in a work tree");
|
|
623
|
+
const adder = await IndexAdder.open(
|
|
624
|
+
this.staging,
|
|
625
|
+
this.blobs,
|
|
626
|
+
worktreeModeTrust(this.workingCopy, worktree),
|
|
627
|
+
);
|
|
628
|
+
for (const path of paths) {
|
|
629
|
+
const failure = await this.stageOne(adder, worktree, path, update);
|
|
630
|
+
if (failure) {
|
|
631
|
+
await adder.finish();
|
|
632
|
+
for (const line of failure) this.err += `${line}\n`;
|
|
633
|
+
this.err += `error: could not stage '${path}'\n`;
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
await adder.finish();
|
|
638
|
+
await this.commitIndex(lock);
|
|
639
|
+
written = true;
|
|
640
|
+
this.added.push(...paths);
|
|
641
|
+
return true;
|
|
642
|
+
} finally {
|
|
643
|
+
if (!written) await lock?.rollback();
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** add_file_to_index (or remove_file_from_index) of one path: git's error lines, if any. */
|
|
648
|
+
private async stageOne(
|
|
649
|
+
adder: IndexAdder,
|
|
650
|
+
worktree: Worktree,
|
|
651
|
+
path: string,
|
|
652
|
+
update: boolean,
|
|
653
|
+
): Promise<string[] | undefined> {
|
|
654
|
+
const entry = await worktree.getEntry(path);
|
|
655
|
+
if (!entry) {
|
|
656
|
+
if (await worktree.isSpecialFile?.(path)) {
|
|
657
|
+
return [`error: ${path}: can only add regular files, symbolic links or git-directories`];
|
|
658
|
+
}
|
|
659
|
+
if (update) {
|
|
660
|
+
adder.remove(path);
|
|
661
|
+
return undefined;
|
|
662
|
+
}
|
|
663
|
+
// add_file_to_index's die_errno
|
|
664
|
+
throw new GitApiError(`fatal: unable to stat '${path}': No such file or directory`);
|
|
665
|
+
}
|
|
666
|
+
try {
|
|
667
|
+
await adder.add(worktree, path, entry, {
|
|
668
|
+
onWarning: (message) => {
|
|
669
|
+
this.err += `${message}\n`;
|
|
670
|
+
},
|
|
671
|
+
});
|
|
672
|
+
return undefined;
|
|
673
|
+
} catch (error) {
|
|
674
|
+
if (!(error instanceof AddToIndexError)) throw error;
|
|
675
|
+
// git 2.43's add_to_index has no "unable to index file" line
|
|
676
|
+
return this.modern
|
|
677
|
+
? error.lines
|
|
678
|
+
: error.lines.filter((line) => !line.startsWith("error: unable to index file"));
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
private async runRevert(): Promise<void> {
|
|
683
|
+
await this.getModifiedFiles("index-only");
|
|
684
|
+
if (this.files.length === 0) {
|
|
685
|
+
this.out += "\n";
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
const count = await this.listAndChoose(
|
|
689
|
+
this.files,
|
|
690
|
+
this.sortedFiles(),
|
|
691
|
+
this.fileChooser("Revert"),
|
|
692
|
+
);
|
|
693
|
+
if (count > 0) await this.revertChosen(count);
|
|
694
|
+
this.out += "\n";
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/** run_revert once the paths are chosen: under the index lock, then a gentle refresh. */
|
|
698
|
+
private async revertChosen(count: number): Promise<void> {
|
|
699
|
+
const lock = await this.holdIndex();
|
|
700
|
+
if (lock === false) return;
|
|
701
|
+
const paths = this.chosen();
|
|
702
|
+
let written = false;
|
|
703
|
+
try {
|
|
704
|
+
await this.revertPaths(paths);
|
|
705
|
+
await this.commitIndex(lock);
|
|
706
|
+
written = true;
|
|
707
|
+
} finally {
|
|
708
|
+
if (!written) await lock?.rollback();
|
|
709
|
+
}
|
|
710
|
+
this.reverted.push(...paths);
|
|
711
|
+
// repo_refresh_and_write_index (gentle) after the write: "reverted" only when it found
|
|
712
|
+
// no error (an unmerged entry left) and could write
|
|
713
|
+
let clean = false;
|
|
714
|
+
try {
|
|
715
|
+
const refreshed = await this.sharing(new IndexRefresh(this.workingCopy))
|
|
716
|
+
.setGentle()
|
|
717
|
+
.refresh();
|
|
718
|
+
this.out += refreshed.output;
|
|
719
|
+
clean = !refreshed.hasErrors;
|
|
720
|
+
} catch {
|
|
721
|
+
clean = false;
|
|
722
|
+
}
|
|
723
|
+
if (clean) this.out += `reverted ${count} path${count === 1 ? "" : "s"}\n`;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* `revert_from_diff` over `do_diff_cache` of HEAD's tree (the empty tree when unborn) and
|
|
728
|
+
* the index, limited to the literal paths: a path the tree has takes its entry (stage 0,
|
|
729
|
+
* no stat data, conflict stages replaced), one it lacks leaves the index ("note: <path> is
|
|
730
|
+
* untracked now.").
|
|
731
|
+
*/
|
|
732
|
+
private async revertPaths(paths: string[]): Promise<void> {
|
|
733
|
+
const head = await this.headId();
|
|
734
|
+
const treeId = head ? await this.revisionResolver().peelToType(head, "tree") : undefined;
|
|
735
|
+
const tree = await flatTree(this.trees, treeId);
|
|
736
|
+
const index = new Map<string, StagingEntry[]>();
|
|
737
|
+
for await (const entry of this.staging.entries()) {
|
|
738
|
+
const list = index.get(entry.path);
|
|
739
|
+
if (list) list.push(entry);
|
|
740
|
+
else index.set(entry.path, [entry]);
|
|
741
|
+
}
|
|
742
|
+
const literal = new Set(paths);
|
|
743
|
+
const named = (path: string) => {
|
|
744
|
+
if (literal.has(path)) return true;
|
|
745
|
+
for (let at = path.indexOf("/"); at > 0; at = path.indexOf("/", at + 1)) {
|
|
746
|
+
if (literal.has(path.slice(0, at))) return true;
|
|
747
|
+
}
|
|
748
|
+
return false;
|
|
749
|
+
};
|
|
750
|
+
const all = [...new Set([...index.keys(), ...tree.keys()])].sort(byName).filter(named);
|
|
751
|
+
const changes = new Map<string, StagingEntry[]>();
|
|
752
|
+
const undo: ResolveUndoRecord[] = [];
|
|
753
|
+
const current = (path: string): readonly { stage?: number }[] =>
|
|
754
|
+
changes.get(path) ?? index.get(path) ?? [];
|
|
755
|
+
const hasStageZero = (path: string) => current(path).some((e) => (e.stage ?? 0) === 0);
|
|
756
|
+
const dirs = new Set<string>();
|
|
757
|
+
for (const path of index.keys()) addLeadingDirs(dirs, path);
|
|
758
|
+
const allPaths = [...new Set([...index.keys(), ...tree.keys()])];
|
|
759
|
+
for (const path of all) {
|
|
760
|
+
const entries = index.get(path) ?? [];
|
|
761
|
+
const t = tree.get(path);
|
|
762
|
+
const unmerged = entries.some((e) => e.stage > 0);
|
|
763
|
+
const staged = entries.find((e) => e.stage === 0);
|
|
764
|
+
if (!unmerged) {
|
|
765
|
+
if (staged && t && staged.mode === t.mode && staged.objectId === t.objectId) continue;
|
|
766
|
+
if (!staged && !t) continue;
|
|
767
|
+
} else {
|
|
768
|
+
const record: ResolveUndoRecord = {
|
|
769
|
+
path,
|
|
770
|
+
modes: [0, 0, 0],
|
|
771
|
+
objectIds: [undefined, undefined, undefined],
|
|
772
|
+
};
|
|
773
|
+
for (const e of entries) {
|
|
774
|
+
if (e.stage < 1 || e.stage > 3) continue;
|
|
775
|
+
record.modes[e.stage - 1] = e.mode;
|
|
776
|
+
record.objectIds[e.stage - 1] = e.objectId;
|
|
777
|
+
}
|
|
778
|
+
undo.push(record);
|
|
779
|
+
}
|
|
780
|
+
if (!t) {
|
|
781
|
+
changes.set(path, []);
|
|
782
|
+
this.out += `note: ${path} is untracked now.\n`;
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
for (const other of stageZeroClashes(path, hasStageZero, allPaths, dirs)) {
|
|
786
|
+
changes.set(
|
|
787
|
+
other,
|
|
788
|
+
(current(other) as StagingEntry[]).filter((e) => (e.stage ?? 0) > 0),
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
addLeadingDirs(dirs, path);
|
|
792
|
+
changes.set(path, [
|
|
793
|
+
{
|
|
794
|
+
path,
|
|
795
|
+
mode: t.mode,
|
|
796
|
+
objectId: t.objectId,
|
|
797
|
+
stage: 0,
|
|
798
|
+
size: 0,
|
|
799
|
+
mtime: 0,
|
|
800
|
+
} as StagingEntry,
|
|
801
|
+
]);
|
|
802
|
+
}
|
|
803
|
+
if (undo.length > 0) this.staging.recordResolveUndo?.(undo);
|
|
804
|
+
// written by the caller, through its lock
|
|
805
|
+
if (changes.size > 0) {
|
|
806
|
+
await rewriteIndex(this.staging, changes, { upToDate: false, write: false });
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
private async runAddUntracked(): Promise<void> {
|
|
811
|
+
const status = await this.sharing(new StatusCommand(this.workingCopy))
|
|
812
|
+
.setUntrackedFiles("all")
|
|
813
|
+
.setWriteIndex(false);
|
|
814
|
+
for (const path of this.options.paths ?? []) status.addPath(path);
|
|
815
|
+
const untracked = [...(await status.call()).untracked].sort(byName);
|
|
816
|
+
this.setFiles(untracked.map(newItem));
|
|
817
|
+
if (this.files.length > 0) {
|
|
818
|
+
this.onlyNames = true;
|
|
819
|
+
let count: number;
|
|
820
|
+
try {
|
|
821
|
+
count = await this.listAndChoose(
|
|
822
|
+
this.files,
|
|
823
|
+
this.sortedFiles(),
|
|
824
|
+
this.fileChooser("Add untracked"),
|
|
825
|
+
);
|
|
826
|
+
} finally {
|
|
827
|
+
this.onlyNames = false;
|
|
828
|
+
}
|
|
829
|
+
if (count > 0 && (await this.stage(this.chosen(), false))) {
|
|
830
|
+
this.out += `added ${count} path${count === 1 ? "" : "s"}\n`;
|
|
831
|
+
}
|
|
832
|
+
} else {
|
|
833
|
+
this.out += "No untracked files.\n";
|
|
834
|
+
}
|
|
835
|
+
this.out += "\n";
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
private async runPatch(): Promise<void> {
|
|
839
|
+
const { unmergedCount, binaryCount } = await this.getModifiedFiles("worktree-only");
|
|
840
|
+
if (unmergedCount || binaryCount) {
|
|
841
|
+
const kept: Item[] = [];
|
|
842
|
+
for (const item of this.files) {
|
|
843
|
+
if (item.index.binary || item.worktree.binary) continue;
|
|
844
|
+
if (item.index.unmerged || item.worktree.unmerged) {
|
|
845
|
+
this.err += `ignoring unmerged: ${item.name}\n`;
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
kept.push(item);
|
|
849
|
+
}
|
|
850
|
+
this.setFiles(kept);
|
|
851
|
+
}
|
|
852
|
+
if (this.files.length === 0) {
|
|
853
|
+
this.err += binaryCount ? "Only binary files changed.\n" : "No changes.\n";
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
const count = await this.listAndChoose(
|
|
857
|
+
this.files,
|
|
858
|
+
this.sortedFiles(),
|
|
859
|
+
this.fileChooser("Patch update"),
|
|
860
|
+
);
|
|
861
|
+
if (count <= 0) return;
|
|
862
|
+
const { selector, compatibility, context, interHunkContext, autoAdvance } = this.options;
|
|
863
|
+
const patch = await runPatchSelection(this.workingCopy, {
|
|
864
|
+
mode: patchModeFor("add"),
|
|
865
|
+
selector,
|
|
866
|
+
paths: this.chosen().map((path) => `:(literal)${path}`),
|
|
867
|
+
...(compatibility ? { compatibility } : {}),
|
|
868
|
+
...(this.modern && context !== undefined ? { context } : {}),
|
|
869
|
+
...(this.modern && interHunkContext !== undefined ? { interHunkContext } : {}),
|
|
870
|
+
...(this.modern && autoAdvance !== undefined ? { autoAdvance } : {}),
|
|
871
|
+
...(this.options.hookSource ? { hookSource: this.options.hookSource } : {}),
|
|
872
|
+
});
|
|
873
|
+
this.out += patch.output;
|
|
874
|
+
this.err += patch.errors;
|
|
875
|
+
this.added.push(...patch.applied);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
private async runDiff(): Promise<void> {
|
|
879
|
+
const head = await this.headId();
|
|
880
|
+
await this.getModifiedFiles("index-only");
|
|
881
|
+
if (this.files.length === 0) {
|
|
882
|
+
this.out += "\n";
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
const count = await this.listAndChoose(
|
|
886
|
+
this.files,
|
|
887
|
+
this.sortedFiles(),
|
|
888
|
+
this.fileChooser("Review diff", true),
|
|
889
|
+
);
|
|
890
|
+
if (count > 0) {
|
|
891
|
+
// `git diff -p --cached [--unified=<n>] [--inter-hunk-context=<n>] <HEAD> -- <paths>`
|
|
892
|
+
const { context, interHunkContext } = this.options;
|
|
893
|
+
const diff = new DiffCommand(this.workingCopy)
|
|
894
|
+
.setCached(true)
|
|
895
|
+
.setOldTree(head ?? this.objectFormat.emptyTreeId)
|
|
896
|
+
.setPathspec(this.chosen());
|
|
897
|
+
if (this.modern) {
|
|
898
|
+
diff.setOptions({
|
|
899
|
+
...(context !== undefined ? { context } : {}),
|
|
900
|
+
...(interHunkContext !== undefined ? { interHunkContext } : {}),
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
try {
|
|
904
|
+
this.out += await diff.callText("patch");
|
|
905
|
+
for (const warning of diff.warnings) this.err += `${warning}\n`;
|
|
906
|
+
} catch (error) {
|
|
907
|
+
this.err += `${(error as Error).message}\n`;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
this.out += "\n";
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
private runHelp(): void {
|
|
914
|
+
this.out +=
|
|
915
|
+
"status - show paths with changes\n" +
|
|
916
|
+
"update - add working tree state to the staged set of changes\n" +
|
|
917
|
+
"revert - revert staged set of changes back to the HEAD version\n" +
|
|
918
|
+
"patch - pick hunks and update selectively\n" +
|
|
919
|
+
"diff - view diff between HEAD and index\n" +
|
|
920
|
+
"add untracked - add contents of untracked files to the staged set of changes\n";
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* Runs `git add -i`: the session's menus and file selections go to the selector as `choose`
|
|
926
|
+
* requests (patch mode's prompts as `add -p` asks them), the transcript comes back.
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```typescript
|
|
930
|
+
* const answers = ["2", "1-2", "", "q"];
|
|
931
|
+
* const { interactive } = await git.add().setInteractive(true)
|
|
932
|
+
* .setPatchSelector(() => answers.shift()).call();
|
|
933
|
+
* process.stdout.write(interactive?.output ?? "");
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
936
|
+
export async function runAddInteractive(
|
|
937
|
+
workingCopy: WorkingCopy,
|
|
938
|
+
options: AddInteractiveOptions,
|
|
939
|
+
): Promise<AddInteractiveResult> {
|
|
940
|
+
return new AddInteractiveSession(workingCopy, options).call();
|
|
941
|
+
}
|