@statewalker/vcs-commands 0.4.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 +299 -34
- 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 +67 -4
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +179 -7
- 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 +93 -0
- package/dist/commands/core-config.d.ts.map +1 -0
- 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 +244 -23
- 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 +55 -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 +146 -6
- 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 +69 -13
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +214 -26
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +10 -2
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-list-command.d.ts +2 -4
- package/dist/commands/stash-list-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +95 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +320 -28
- 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 +137 -6
- 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 +204 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
- 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/core-commands/index.d.ts +0 -3
- package/dist/core-commands/index.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 +29 -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 +371 -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 +422 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +326 -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 -0
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +123 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +41 -0
- package/dist/remote-config/remote-refs.d.ts.map +1 -0
- 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 +16 -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 +24 -1
- 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 +143 -18
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BZGa2Z3I.js +2934 -0
- package/dist/transport-command.d.ts +56 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -10
- package/src/commands/add-command.ts +1291 -224
- 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 +1426 -297
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +532 -85
- package/src/commands/clone-command.ts +826 -55
- package/src/commands/commit-command.ts +1781 -166
- package/src/commands/core-config.ts +196 -0
- 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 +1038 -79
- 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 +83 -0
- package/src/commands/init-command.ts +60 -11
- 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 +500 -19
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +828 -91
- 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 +692 -124
- package/src/commands/stash-create-command.ts +752 -89
- package/src/commands/stash-drop-command.ts +67 -6
- package/src/commands/stash-list-command.ts +10 -4
- package/src/commands/stash-working-tree.ts +387 -0
- package/src/commands/status-command.ts +1426 -97
- 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 +344 -15
- 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 +641 -0
- 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 +9 -5
- package/src/core-commands/index.ts +0 -8
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +46 -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 +1218 -118
- package/src/git.ts +552 -11
- package/src/index.ts +1 -1
- package/src/remote-config/index.ts +1 -0
- package/src/remote-config/remote-config-store.ts +326 -16
- package/src/remote-config/remote-refs.ts +119 -0
- 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 +18 -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 +24 -1
- 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 +288 -27
- package/src/transport-command.ts +139 -2
- package/dist/commands-BpeXZTC3.js +0 -10278
- package/dist/core-commands/checkout.command.d.ts +0 -103
- package/dist/core-commands/checkout.command.d.ts.map +0 -1
- package/dist/core-commands/checkout.command.impl.d.ts +0 -110
- package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
- package/dist/status-result-BapZoQaR.js +0 -411
- package/src/core-commands/checkout.command.impl.ts +0 -564
- package/src/core-commands/checkout.command.ts +0 -125
|
@@ -1,10 +1,66 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Blobs,
|
|
3
|
+
EMPTY_BLOB_ID,
|
|
4
|
+
EMPTY_TREE_ID,
|
|
5
|
+
FileMode,
|
|
6
|
+
type ObjectId,
|
|
7
|
+
type Ref,
|
|
8
|
+
} from "@statewalker/vcs-core";
|
|
9
|
+
import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
|
|
10
|
+
import {
|
|
11
|
+
applyStatUpdate,
|
|
12
|
+
cacheTreeOfTree,
|
|
13
|
+
compareWithWorktree,
|
|
14
|
+
copyCacheTree,
|
|
15
|
+
entryStatOf,
|
|
16
|
+
getWorktreeEntries,
|
|
17
|
+
type IndexEntryOptions,
|
|
18
|
+
type IndexStatUpdate,
|
|
19
|
+
invalidateCacheTreePath,
|
|
20
|
+
type ResolveUndoRecord,
|
|
21
|
+
type Staging,
|
|
22
|
+
type StagingEntry,
|
|
23
|
+
statUpdateOf,
|
|
24
|
+
type WorkingCopy,
|
|
25
|
+
type Worktree,
|
|
26
|
+
withWorktreeEntries,
|
|
27
|
+
} from "@statewalker/vcs-working-tree";
|
|
28
|
+
import {
|
|
29
|
+
IncompatibleOptionsError,
|
|
30
|
+
InvalidArgumentError,
|
|
31
|
+
ResetRefusedError,
|
|
32
|
+
} from "../errors/command-errors.js";
|
|
4
33
|
import { RefNotFoundError } from "../errors/ref-errors.js";
|
|
5
|
-
import { GitCommand } from "../git-command.js";
|
|
34
|
+
import { type CommandTrees, GitCommand } from "../git-command.js";
|
|
6
35
|
import { ResetMode } from "../types.js";
|
|
7
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
type PatchCompatibility,
|
|
38
|
+
type PatchOptions,
|
|
39
|
+
type PatchResult,
|
|
40
|
+
type PatchSelector,
|
|
41
|
+
patchModeFor,
|
|
42
|
+
runPatchSelection,
|
|
43
|
+
} from "./add-patch/index.js";
|
|
44
|
+
import { coreBool, worktreeModeTrust } from "./core-config.js";
|
|
45
|
+
import { hostEnvironmentOf } from "./git-ident.js";
|
|
46
|
+
import { addLeadingDirs, stageZeroClashes } from "./index-adder.js";
|
|
47
|
+
import { configBool } from "./merge-config.js";
|
|
48
|
+
import { flatTree, OperationState, rewriteIndex } from "./merge-support.js";
|
|
49
|
+
import {
|
|
50
|
+
DO_MATCH_DIRECTORY,
|
|
51
|
+
globalPathspecMagic,
|
|
52
|
+
matchPathspec,
|
|
53
|
+
type PathspecItem,
|
|
54
|
+
parsePathspec,
|
|
55
|
+
parsePathspecFile,
|
|
56
|
+
} from "./pathspec.js";
|
|
57
|
+
import { PathspecAttributes } from "./pathspec-attributes.js";
|
|
58
|
+
import { markIndexUpdate } from "./post-index-change.js";
|
|
59
|
+
import { reflogMessages } from "./reflog-messages.js";
|
|
60
|
+
import { moveHeadAsReset, removeBranchState, resetKeep, resetMerge } from "./sequencer-support.js";
|
|
61
|
+
import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
|
|
62
|
+
import { planTreeRestore, restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
|
|
63
|
+
import { flaggedEntryDiffers, pruneEmptyParents } from "./worktree-overwrite-checks.js";
|
|
8
64
|
|
|
9
65
|
/** Names this operation in restore failure messages. */
|
|
10
66
|
const RESET_HARD = "reset --hard";
|
|
@@ -45,6 +101,118 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
45
101
|
private ref?: string;
|
|
46
102
|
private mode = ResetMode.MIXED;
|
|
47
103
|
private paths: string[] = [];
|
|
104
|
+
private pathspecFromFile: string[] = [];
|
|
105
|
+
/** Whether `--pathspec-from-file` was given (an empty file included) */
|
|
106
|
+
private pathspecFileGiven = false;
|
|
107
|
+
private modeSet = false;
|
|
108
|
+
private intentToAdd = false;
|
|
109
|
+
private quiet = false;
|
|
110
|
+
private noRefresh = false;
|
|
111
|
+
private readonly output: string[] = [];
|
|
112
|
+
private patch = false;
|
|
113
|
+
private patchSelector?: PatchSelector;
|
|
114
|
+
private patchOptions: PatchOptions = {};
|
|
115
|
+
private patchResult?: PatchResult;
|
|
116
|
+
private compatibility: PatchCompatibility = "2.56";
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* `-q` / `--quiet`: a mixed reset does not list the files left with unstaged changes
|
|
120
|
+
* (refresh_index with `REFRESH_QUIET`: only unmerged paths, as `<path>: needs merge`), and
|
|
121
|
+
* gives no hint about a slow refresh. (`reset.quiet` is read by neither git 2.43 nor 2.5x.)
|
|
122
|
+
*/
|
|
123
|
+
setQuiet(quiet: boolean): this {
|
|
124
|
+
this.checkCallable();
|
|
125
|
+
this.quiet = quiet;
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* `git reset -p [<tree-ish>] [-- <paths>]`: the differences between the tree-ish (HEAD by
|
|
131
|
+
* default) and the index are offered hunk by hunk, as git's add-patch.c does; the selected
|
|
132
|
+
* hunks are taken out of the index ("Unstage this hunk"), or with another tree-ish applied
|
|
133
|
+
* to it ("Apply this hunk to index"). HEAD and the worktree stay. The prompts are answered
|
|
134
|
+
* by {@link setPatchSelector}; {@link getPatchResult} gives git's transcript. Not with a
|
|
135
|
+
* mode (`--soft`, `--mixed`, `--hard`...).
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const answers = ["y", "n"];
|
|
140
|
+
* const reset = git.reset().setPatch(true).setPatchSelector(() => answers.shift());
|
|
141
|
+
* await reset.call();
|
|
142
|
+
* console.log(reset.getPatchResult()?.output);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
setPatch(patch: boolean): this {
|
|
146
|
+
this.checkCallable();
|
|
147
|
+
this.patch = patch;
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Answers the prompts of {@link setPatch}. */
|
|
152
|
+
setPatchSelector(selector: PatchSelector): this {
|
|
153
|
+
this.checkCallable();
|
|
154
|
+
this.patchSelector = selector;
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** `-U<n>`, `--inter-hunk-context=<n>` and `--no-auto-advance` of {@link setPatch}. */
|
|
159
|
+
setPatchOptions(options: PatchOptions): this {
|
|
160
|
+
this.checkCallable();
|
|
161
|
+
this.patchOptions = { ...options };
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The git version whose prompts {@link setPatch} reproduces (default 2.56). */
|
|
166
|
+
setCompatibility(version: PatchCompatibility): this {
|
|
167
|
+
this.checkCallable();
|
|
168
|
+
this.compatibility = version;
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** What {@link setPatch}'s selection printed and applied; read after {@link call}. */
|
|
173
|
+
getPatchResult(): PatchResult | undefined {
|
|
174
|
+
return this.patchResult;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** `git reset -p`: run_add_p(ADD_P_RESET, rev). */
|
|
178
|
+
private async callPatch(): Promise<Ref> {
|
|
179
|
+
if (this.modeSet) {
|
|
180
|
+
throw new IncompatibleOptionsError(
|
|
181
|
+
["--patch", "--{hard,mixed,soft}"],
|
|
182
|
+
"fatal: options '--patch' and '--{hard,mixed,soft}' cannot be used together",
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const rev = this.ref === undefined || this.ref === "@" ? "HEAD" : this.ref;
|
|
186
|
+
const head = await this.refsStore.resolve("HEAD");
|
|
187
|
+
const diffRevision = rev === "HEAD" && !head?.objectId ? EMPTY_TREE_ID : rev;
|
|
188
|
+
if (diffRevision !== EMPTY_TREE_ID) await this.resolveRef(rev);
|
|
189
|
+
this.patchResult = await runPatchSelection(this.workingCopy, {
|
|
190
|
+
hookSource: this,
|
|
191
|
+
...this.patchOptions,
|
|
192
|
+
mode: patchModeFor("reset", rev),
|
|
193
|
+
selector: this.patchSelector,
|
|
194
|
+
diffRevision,
|
|
195
|
+
paths: [...this.pathspecFromFile, ...this.paths],
|
|
196
|
+
compatibility: this.compatibility,
|
|
197
|
+
});
|
|
198
|
+
return (await this.refsStore.resolve("HEAD")) as Ref;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** `--no-refresh`: a mixed reset leaves the index's stat data as the reset wrote it. */
|
|
202
|
+
setNoRefresh(noRefresh: boolean): this {
|
|
203
|
+
this.checkCallable();
|
|
204
|
+
this.noRefresh = noRefresh;
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* What the reset printed on stdout, line by line: after a mixed reset (with paths too),
|
|
210
|
+
* git's "Unstaged changes after reset:" and a `M\t<path>` (`D`, `T`, `A`, `U`) line per
|
|
211
|
+
* file whose content differs from its entry. Read after {@link call}.
|
|
212
|
+
*/
|
|
213
|
+
getOutput(): string[] {
|
|
214
|
+
return [...this.output];
|
|
215
|
+
}
|
|
48
216
|
|
|
49
217
|
/**
|
|
50
218
|
* Set the ref to reset to.
|
|
@@ -68,15 +236,40 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
68
236
|
* - HARD: Move HEAD, reset staging, and reset working tree. DESTRUCTIVE -
|
|
69
237
|
* uncommitted changes to tracked files are discarded and tracked files
|
|
70
238
|
* absent from the target commit are deleted from the working tree.
|
|
239
|
+
* - MERGE: as git's `reset --merge`: index entries that differ from the target take
|
|
240
|
+
* its version, worktree files with them; refused (ResetRefusedError) where a file
|
|
241
|
+
* with unstaged changes or an untracked file would be lost. Unmerged entries are reset.
|
|
242
|
+
* - KEEP: as git's `reset --keep`: files that differ between HEAD and the target are
|
|
243
|
+
* switched, local changes elsewhere kept; refused where a switched file has local
|
|
244
|
+
* changes, and in the middle of a merge.
|
|
245
|
+
*
|
|
246
|
+
* Every mode records the old HEAD in ORIG_HEAD and, as git's reset, forgets a merge,
|
|
247
|
+
* cherry-pick or revert in progress (MERGE_HEAD, CHERRY_PICK_HEAD, ...).
|
|
71
248
|
*
|
|
72
249
|
* @param mode Reset mode
|
|
73
250
|
*/
|
|
74
251
|
setMode(mode: ResetMode): this {
|
|
75
252
|
this.checkCallable();
|
|
76
253
|
this.mode = mode;
|
|
254
|
+
this.modeSet = true;
|
|
77
255
|
return this;
|
|
78
256
|
}
|
|
79
257
|
|
|
258
|
+
/**
|
|
259
|
+
* What the reset printed on stderr while applying the sparse checkout's patterns, line by
|
|
260
|
+
* line: the patterns' warnings, and git's `error: Path '<p>' not uptodate; will not remove
|
|
261
|
+
* from working tree.` for a changed file left outside them (`--merge`, `--keep`), and
|
|
262
|
+
* "Autostash exists; creating a new stash entry." with its lines when a stopped merge's
|
|
263
|
+
* autostash is kept on `refs/stash`, and git's `error: update_ref failed for ref
|
|
264
|
+
* 'ORIG_HEAD': ...` when ORIG_HEAD cannot be written (HEAD moves all the same). Read after
|
|
265
|
+
* {@link call}.
|
|
266
|
+
*/
|
|
267
|
+
getWarnings(): string[] {
|
|
268
|
+
return [...this.warnings];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private readonly warnings: string[] = [];
|
|
272
|
+
|
|
80
273
|
/**
|
|
81
274
|
* Add a path to reset.
|
|
82
275
|
*
|
|
@@ -91,6 +284,35 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
91
284
|
return this;
|
|
92
285
|
}
|
|
93
286
|
|
|
287
|
+
/**
|
|
288
|
+
* `-N` / `--intent-to-add` (mixed resets only): a path the tree lacks stays in the index as
|
|
289
|
+
* an intent-to-add entry instead of leaving it.
|
|
290
|
+
*/
|
|
291
|
+
setIntentToAdd(intentToAdd: boolean): this {
|
|
292
|
+
this.checkCallable();
|
|
293
|
+
this.intentToAdd = intentToAdd;
|
|
294
|
+
return this;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* `--pathspec-from-file` (and `--pathspec-file-nul` with `nul`): the pathspec elements of
|
|
299
|
+
* `content`, one per line.
|
|
300
|
+
*/
|
|
301
|
+
setPathspecFromFile(content: string | Uint8Array, nul = false): this {
|
|
302
|
+
this.checkCallable();
|
|
303
|
+
this.pathspecFileGiven = true;
|
|
304
|
+
try {
|
|
305
|
+
this.pathspecFromFile = parsePathspecFile(content, nul);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
throw new InvalidArgumentError(
|
|
308
|
+
"pathspecFromFile",
|
|
309
|
+
content,
|
|
310
|
+
`fatal: ${(error as Error).message}`,
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
return this;
|
|
314
|
+
}
|
|
315
|
+
|
|
94
316
|
/**
|
|
95
317
|
* Execute the reset.
|
|
96
318
|
*
|
|
@@ -98,11 +320,46 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
98
320
|
* @throws RefNotFoundError if ref cannot be resolved
|
|
99
321
|
*/
|
|
100
322
|
async call(): Promise<Ref> {
|
|
323
|
+
// git writes the index once: one post-index-change run, after the worktree is updated
|
|
324
|
+
// a whole-tree reset writes the index and then the stat of the files it wrote: held back
|
|
325
|
+
// and written once, as git's one write (the patch and path modes read the index back)
|
|
326
|
+
const wholeTree = !this.patch && this.paths.length === 0 && !this.pathspecFileGiven;
|
|
327
|
+
// one worktree operation: the files refreshed or written convert with attributes read
|
|
328
|
+
// once, not once per file
|
|
329
|
+
return this.withOneIndexWrite("last", () => this.inOneOperation(() => this.resetOnce()), {
|
|
330
|
+
holdWrites: wholeTree,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
private async resetOnce(): Promise<Ref> {
|
|
101
335
|
this.checkCallable();
|
|
102
336
|
this.setCallable(false);
|
|
337
|
+
// the index as it is now, before the worktree or a ref is touched: one another writer
|
|
338
|
+
// replaced is read again (git reads the index at its start), unless this instance holds
|
|
339
|
+
// unwritten edits (refused)
|
|
340
|
+
await this.readCurrentIndex();
|
|
103
341
|
|
|
342
|
+
if (this.pathspecFileGiven && this.patch)
|
|
343
|
+
throw new IncompatibleOptionsError(
|
|
344
|
+
["--pathspec-from-file", "--patch"],
|
|
345
|
+
"fatal: options '--pathspec-from-file' and '--patch' cannot be used together",
|
|
346
|
+
);
|
|
347
|
+
if (this.paths.length > 0 && this.pathspecFromFile.length > 0) {
|
|
348
|
+
throw new InvalidArgumentError(
|
|
349
|
+
"pathspecFromFile",
|
|
350
|
+
this.pathspecFromFile,
|
|
351
|
+
"fatal: '--pathspec-from-file' and pathspec arguments cannot be used together",
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
if (this.intentToAdd && this.mode !== ResetMode.MIXED) {
|
|
355
|
+
throw new IncompatibleOptionsError(
|
|
356
|
+
["-N", "--mixed"],
|
|
357
|
+
"fatal: the option '-N' requires '--mixed'",
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
if (this.patch) return this.callPatch();
|
|
104
361
|
// If paths are specified, do path reset
|
|
105
|
-
if (this.paths.length > 0) {
|
|
362
|
+
if (this.paths.length > 0 || this.pathspecFromFile.length > 0) {
|
|
106
363
|
return this.resetPaths();
|
|
107
364
|
}
|
|
108
365
|
|
|
@@ -116,86 +373,376 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
116
373
|
const trackedBefore =
|
|
117
374
|
this.mode === ResetMode.HARD ? await this.collectTrackedPaths() : undefined;
|
|
118
375
|
|
|
119
|
-
|
|
120
|
-
await this.
|
|
376
|
+
const state = new OperationState(this.workingCopy.checkout, this.refsStore);
|
|
377
|
+
const headId = (await this.refsStore.resolve("HEAD"))?.objectId;
|
|
378
|
+
// git refuses a soft or keep reset in the middle of a merge (die_if_unmerged_cache)
|
|
379
|
+
if (this.mode === ResetMode.SOFT || this.mode === ResetMode.KEEP) {
|
|
380
|
+
let unmerged = false;
|
|
381
|
+
for await (const entry of this.staging.entries()) if (entry.stage > 0) unmerged = true;
|
|
382
|
+
if (unmerged || (await state.exists("MERGE_HEAD"))) {
|
|
383
|
+
throw new ResetRefusedError(
|
|
384
|
+
`fatal: Cannot do a ${this.mode} reset in the middle of a merge.`,
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
// --merge and --keep: the index and worktree first, refused before anything changes
|
|
389
|
+
if (this.mode === ResetMode.MERGE || this.mode === ResetMode.KEEP) {
|
|
390
|
+
const ctx = {
|
|
391
|
+
workingCopy: this.workingCopy,
|
|
392
|
+
worktree: this.worktreeAccess,
|
|
393
|
+
staging: this.staging,
|
|
394
|
+
blobs: this.blobs,
|
|
395
|
+
trees: this.trees,
|
|
396
|
+
commits: this.commits,
|
|
397
|
+
refs: this.refsStore,
|
|
398
|
+
sparseWarnings: this.warnings,
|
|
399
|
+
};
|
|
400
|
+
const refused =
|
|
401
|
+
this.mode === ResetMode.MERGE
|
|
402
|
+
? await resetMerge(ctx, targetId, targetRef)
|
|
403
|
+
: await resetKeep(ctx, headId ?? targetId, targetId, targetRef);
|
|
404
|
+
if (refused) throw new ResetRefusedError(refused.message, refused.paths);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// a hard reset in a sparse checkout: unpack-trees with its patterns (what stays outside
|
|
408
|
+
// is neither checked nor touched)
|
|
409
|
+
const sparse =
|
|
410
|
+
this.mode === ResetMode.HARD
|
|
411
|
+
? await SparseUnpack.start({
|
|
412
|
+
workingCopy: this.workingCopy,
|
|
413
|
+
worktree: this.worktreeAccess,
|
|
414
|
+
staging: this.staging,
|
|
415
|
+
})
|
|
416
|
+
: undefined;
|
|
417
|
+
|
|
418
|
+
// --hard: unpack-trees' one-way merge checks the entries whose flags cheat (assume-unchanged,
|
|
419
|
+
// skip-worktree) before anything changes; a file kept outside the worktree stays so
|
|
420
|
+
let flagged: FlaggedEntries | undefined;
|
|
421
|
+
if (this.mode === ResetMode.HARD) {
|
|
422
|
+
const commit = await this.commits.load(targetId);
|
|
423
|
+
if (commit) {
|
|
424
|
+
flagged = await checkFlaggedEntries(
|
|
425
|
+
{
|
|
426
|
+
trees: this.trees,
|
|
427
|
+
staging: this.staging,
|
|
428
|
+
workingCopy: this.workingCopy,
|
|
429
|
+
worktree: this.worktreeAccess,
|
|
430
|
+
},
|
|
431
|
+
commit.tree,
|
|
432
|
+
sparse,
|
|
433
|
+
);
|
|
434
|
+
if (flagged.refused !== undefined) {
|
|
435
|
+
throw new ResetRefusedError(
|
|
436
|
+
`error: Entry '${flagged.refused}' not uptodate. Cannot merge.\n` +
|
|
437
|
+
`fatal: Could not reset index file to revision '${targetRef}'.`,
|
|
438
|
+
[flagged.refused],
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// git's set_reflog_message: "reset: moving to <rev>", or "<action>: updating HEAD"
|
|
445
|
+
const message = this.hasReflogAction()
|
|
446
|
+
? `${this.reflogAction("reset")}: updating HEAD`
|
|
447
|
+
: reflogMessages.reset(targetRef);
|
|
448
|
+
// Move HEAD/branch, the old HEAD kept in ORIG_HEAD (git's update_refs)
|
|
449
|
+
// (an ORIG_HEAD it cannot write reported on stderr, HEAD moved all the same)
|
|
450
|
+
this.warnings.push(
|
|
451
|
+
...(await moveHeadAsReset(
|
|
452
|
+
this.refsStore,
|
|
453
|
+
state,
|
|
454
|
+
headId,
|
|
455
|
+
targetId,
|
|
456
|
+
this.reflogLine(message),
|
|
457
|
+
`${this.hasReflogAction() ? this.reflogAction("reset") : "reset"}: updating ORIG_HEAD`,
|
|
458
|
+
)),
|
|
459
|
+
);
|
|
121
460
|
|
|
122
461
|
// Reset staging area (for MIXED and HARD)
|
|
123
462
|
if (this.mode === ResetMode.MIXED || this.mode === ResetMode.HARD) {
|
|
463
|
+
// post-index-change: unpack-trees updated the worktree (hard), or read_from_tree may
|
|
464
|
+
// have changed skip-worktree bits (mixed)
|
|
465
|
+
markIndexUpdate(
|
|
466
|
+
this.staging,
|
|
467
|
+
this.mode === ResetMode.HARD ? { workdir: true } : { skipWorktree: true },
|
|
468
|
+
);
|
|
124
469
|
await this.resetStaging(targetId);
|
|
125
470
|
}
|
|
471
|
+
// a mixed reset refreshes the index and lists what is left unstaged
|
|
472
|
+
if (this.mode === ResetMode.MIXED && (await this.refreshAfterReset())) {
|
|
473
|
+
await this.staging.write();
|
|
474
|
+
}
|
|
126
475
|
|
|
127
476
|
// Reset working tree (for HARD) - this DESTROYS uncommitted changes
|
|
128
477
|
if (this.mode === ResetMode.HARD) {
|
|
129
|
-
await this.resetWorkingTree(
|
|
478
|
+
const written = await this.resetWorkingTree(
|
|
479
|
+
targetId,
|
|
480
|
+
trackedBefore ?? new Set(),
|
|
481
|
+
flagged?.keptOut,
|
|
482
|
+
sparse,
|
|
483
|
+
);
|
|
484
|
+
// check_updates: the entries written carry the stat of their new files
|
|
485
|
+
if (this.worktreeAccess && written.size > 0) {
|
|
486
|
+
await recordWrittenStat(this.staging, this.worktreeAccess, written);
|
|
487
|
+
await this.staging.write();
|
|
488
|
+
}
|
|
489
|
+
if (sparse) {
|
|
490
|
+
// UNPACK_RESET_OVERWRITE_UNTRACKED: an entry coming back is written over anything
|
|
491
|
+
const outcome = await sparse.finish(
|
|
492
|
+
{
|
|
493
|
+
workingCopy: this.workingCopy,
|
|
494
|
+
worktree: this.worktreeAccess,
|
|
495
|
+
staging: this.staging,
|
|
496
|
+
blobs: this.blobs,
|
|
497
|
+
},
|
|
498
|
+
{ written, overwrite: true },
|
|
499
|
+
);
|
|
500
|
+
pushSparseWarnings(this.warnings, sparse, outcome, false);
|
|
501
|
+
}
|
|
130
502
|
}
|
|
131
503
|
|
|
504
|
+
// git's remove_branch_state: a merge, cherry-pick or revert in progress is forgotten
|
|
505
|
+
// (a merge's autostash kept on refs/stash, git's lines printed)
|
|
506
|
+
this.warnings.push(
|
|
507
|
+
...(await removeBranchState({ commits: this.commits, refs: this.refsStore }, state)),
|
|
508
|
+
);
|
|
509
|
+
|
|
132
510
|
// Return the updated HEAD ref
|
|
133
511
|
const headRef = await this.refsStore.resolve("HEAD");
|
|
134
512
|
return headRef as Ref;
|
|
135
513
|
}
|
|
136
514
|
|
|
137
515
|
/**
|
|
138
|
-
*
|
|
516
|
+
* `git reset [<tree-ish>] [--] <pathspec>...` (builtin/reset.c): the index entries the
|
|
517
|
+
* pathspec names are set to the tree's (`read_from_tree`); HEAD and the worktree stay.
|
|
139
518
|
*/
|
|
140
519
|
private async resetPaths(): Promise<Ref> {
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// Load target commit's tree
|
|
146
|
-
const targetCommit = await this.commits.load(targetId);
|
|
147
|
-
if (!targetCommit) {
|
|
148
|
-
throw new RefNotFoundError(targetId, "Target commit not found");
|
|
520
|
+
// cmd_reset: only a mixed reset takes paths (an explicit --mixed is deprecated)
|
|
521
|
+
if (this.modeSet && this.mode !== ResetMode.MIXED) {
|
|
522
|
+
throw new ResetRefusedError(`fatal: Cannot do ${this.mode} reset with paths.`);
|
|
149
523
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
524
|
+
if (this.modeSet) {
|
|
525
|
+
this.warnings.push(
|
|
526
|
+
"warning: --mixed with paths is deprecated; use 'git reset -- <paths>' instead.",
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
let items: PathspecItem[];
|
|
530
|
+
try {
|
|
531
|
+
const global = globalPathspecMagic(hostEnvironmentOf(this.workingCopy)?.pathspecs);
|
|
532
|
+
items = parsePathspec([...this.pathspecFromFile, ...this.paths], { attr: true, global });
|
|
533
|
+
} catch (error) {
|
|
534
|
+
throw new InvalidArgumentError("path", this.paths, `fatal: ${(error as Error).message}`);
|
|
535
|
+
}
|
|
536
|
+
const treeId = await this.resetTree(true);
|
|
537
|
+
await this.readFromTree(treeId, items);
|
|
538
|
+
await this.refreshAfterReset();
|
|
539
|
+
markIndexUpdate(this.staging, { skipWorktree: true });
|
|
540
|
+
await this.staging.write();
|
|
541
|
+
const headRef = await this.refsStore.resolve("HEAD");
|
|
542
|
+
return headRef as Ref;
|
|
543
|
+
}
|
|
154
544
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
545
|
+
/**
|
|
546
|
+
* cmd_reset's refresh after a mixed reset (`refresh_index` with `REFRESH_IN_PORCELAIN`, or
|
|
547
|
+
* `REFRESH_QUIET` with `--quiet`): every stage-0 entry compared with its file, those still
|
|
548
|
+
* holding their content given the file's stat; the others listed under "Unstaged changes
|
|
549
|
+
* after reset:" (unmerged paths whatever the flag). Skip-worktree and assume-unchanged
|
|
550
|
+
* entries are taken as up to date. With git's hint when it took over two seconds
|
|
551
|
+
* (`advice.resetNoRefresh`). Whether any entry's stat changed (the index is to be written).
|
|
552
|
+
*/
|
|
553
|
+
private async refreshAfterReset(): Promise<boolean> {
|
|
554
|
+
const worktree = this.worktreeAccess;
|
|
555
|
+
if (this.noRefresh || !worktree) return false;
|
|
556
|
+
const started = Date.now();
|
|
557
|
+
let first = true;
|
|
558
|
+
const show = (line: string) => {
|
|
559
|
+
if (!this.quiet && first) this.output.push("Unstaged changes after reset:");
|
|
560
|
+
first = false;
|
|
561
|
+
this.output.push(line);
|
|
562
|
+
};
|
|
563
|
+
const trust = worktreeModeTrust(this.workingCopy, worktree);
|
|
564
|
+
const indexTime = this.staging.getUpdateTime();
|
|
565
|
+
const entries: StagingEntry[] = [];
|
|
566
|
+
for await (const entry of this.staging.entryList?.() ?? this.staging.entries()) {
|
|
567
|
+
entries.push(entry);
|
|
568
|
+
}
|
|
569
|
+
const stated = (entry: StagingEntry) =>
|
|
570
|
+
entry.stage === 0 && !entry.skipWorktree && !entry.assumeValid;
|
|
571
|
+
const updates: IndexStatUpdate[] = [];
|
|
572
|
+
let lastUnmerged: string | undefined;
|
|
573
|
+
for await (const { item: entry, current } of withWorktreeEntries(worktree, entries, stated)) {
|
|
574
|
+
if (entry.stage !== 0) {
|
|
575
|
+
if (entry.path === lastUnmerged) continue;
|
|
576
|
+
lastUnmerged = entry.path;
|
|
577
|
+
show(this.quiet ? `${entry.path}: needs merge` : `U\t${entry.path}`);
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
if (entry.skipWorktree || entry.assumeValid) continue;
|
|
581
|
+
const compared = await compareWithWorktree(worktree, entry, { trust, indexTime }, current);
|
|
582
|
+
if (!compared.kind && !entry.intentToAdd) {
|
|
583
|
+
const update = statUpdateOf(entry, compared);
|
|
584
|
+
if (update && !update.smudge) updates.push(update);
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
if (this.quiet) continue;
|
|
588
|
+
const code =
|
|
589
|
+
compared.kind === "deleted"
|
|
590
|
+
? "D"
|
|
591
|
+
: entry.intentToAdd
|
|
592
|
+
? "A"
|
|
593
|
+
: compared.kind === "typechange"
|
|
594
|
+
? "T"
|
|
595
|
+
: "M";
|
|
596
|
+
show(`${code}\t${entry.path}`);
|
|
597
|
+
}
|
|
598
|
+
if (updates.length > 0) {
|
|
599
|
+
const now = Date.now();
|
|
600
|
+
const editor = this.staging.createEditor();
|
|
601
|
+
for (const update of updates) {
|
|
172
602
|
editor.add({
|
|
173
|
-
path,
|
|
174
|
-
apply: () =>
|
|
603
|
+
path: update.path,
|
|
604
|
+
apply: (existing) => applyStatUpdate(existing, update, now) ?? existing,
|
|
175
605
|
});
|
|
176
606
|
}
|
|
607
|
+
await editor.finish();
|
|
177
608
|
}
|
|
609
|
+
const elapsed = Date.now() - started;
|
|
610
|
+
if (
|
|
611
|
+
!this.quiet &&
|
|
612
|
+
elapsed > 2000 &&
|
|
613
|
+
configBool(this.workingCopy, "advice.resetNoRefresh", true)
|
|
614
|
+
) {
|
|
615
|
+
this.warnings.push(
|
|
616
|
+
`hint: It took ${(elapsed / 1000).toFixed(2)} seconds to refresh the index after reset. You can use\n` +
|
|
617
|
+
"hint: '--no-refresh' to avoid this.",
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
return updates.length > 0;
|
|
621
|
+
}
|
|
178
622
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
623
|
+
/**
|
|
624
|
+
* The tree a path reset (or a `-N` reset) reads: the empty tree on an unborn HEAD, else the
|
|
625
|
+
* tree-ish's tree (git's "Failed to resolve '<rev>' as a valid tree.").
|
|
626
|
+
*/
|
|
627
|
+
private async resetTree(paths: boolean): Promise<ObjectId | undefined> {
|
|
628
|
+
const targetRef = this.ref ?? "HEAD";
|
|
629
|
+
let id: ObjectId;
|
|
630
|
+
try {
|
|
631
|
+
id = await this.resolveRevision(targetRef);
|
|
632
|
+
} catch (error) {
|
|
633
|
+
if (targetRef === "HEAD" && error instanceof RefNotFoundError) return undefined;
|
|
634
|
+
if (error instanceof RefNotFoundError) {
|
|
635
|
+
throw new RefNotFoundError(
|
|
636
|
+
targetRef,
|
|
637
|
+
paths
|
|
638
|
+
? `fatal: Failed to resolve '${targetRef}' as a valid tree.`
|
|
639
|
+
: `fatal: Failed to resolve '${targetRef}' as a valid revision.`,
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
throw error;
|
|
643
|
+
}
|
|
644
|
+
const treeId = await this.revisionResolver().peelToType(id, "tree");
|
|
645
|
+
if (treeId === undefined) {
|
|
646
|
+
throw new RefNotFoundError(targetRef, `fatal: Could not parse object '${targetRef}'.`);
|
|
647
|
+
}
|
|
648
|
+
return treeId;
|
|
184
649
|
}
|
|
185
650
|
|
|
186
651
|
/**
|
|
187
|
-
*
|
|
652
|
+
* git's `read_from_tree` (`do_diff_cache` of the tree and the index, then
|
|
653
|
+
* `update_index_from_diff`): each path the pathspec names (every path without one) where
|
|
654
|
+
* the index differs from the tree (mode or blob; an unmerged path always) takes the
|
|
655
|
+
* tree's entry, stage 0, or leaves the index when the tree lacks it (with `-N` it stays as
|
|
656
|
+
* an intent-to-add entry). A new entry keeps a skip-worktree bit, or gets one outside the
|
|
657
|
+
* sparse checkout; the conflict stages it replaces are recorded for resolve-undo.
|
|
188
658
|
*/
|
|
189
|
-
private async
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// Detached HEAD - update HEAD directly
|
|
197
|
-
await this.refsStore.set("HEAD", targetId);
|
|
659
|
+
private async readFromTree(treeId: ObjectId | undefined, items: PathspecItem[]): Promise<void> {
|
|
660
|
+
const tree = await flatTree(this.trees, treeId);
|
|
661
|
+
const index = new Map<string, StagingEntry[]>();
|
|
662
|
+
for await (const entry of this.staging.entries()) {
|
|
663
|
+
const list = index.get(entry.path);
|
|
664
|
+
if (list) list.push(entry);
|
|
665
|
+
else index.set(entry.path, [entry]);
|
|
198
666
|
}
|
|
667
|
+
const attributes = PathspecAttributes.forWorktree(items, this.worktreeAccess);
|
|
668
|
+
if (attributes) await attributes.load([...index.keys(), ...tree.keys()]);
|
|
669
|
+
const named = (path: string, mode: number) =>
|
|
670
|
+
items.length === 0 ||
|
|
671
|
+
matchPathspec(items, path, mode === FileMode.GITLINK ? DO_MATCH_DIRECTORY : 0) > 0;
|
|
672
|
+
const patterns = await this.sparseCheckoutPatterns();
|
|
673
|
+
const changes = new Map<string, IndexEntryOptions[]>();
|
|
674
|
+
const undo: ResolveUndoRecord[] = [];
|
|
675
|
+
// the index as edited so far, for add_index_entry's file/directory clashes
|
|
676
|
+
const current = (path: string): readonly IndexEntryOptions[] =>
|
|
677
|
+
changes.get(path) ?? index.get(path) ?? [];
|
|
678
|
+
const hasStageZero = (path: string) => current(path).some((e) => (e.stage ?? 0) === 0);
|
|
679
|
+
const dirs = new Set<string>();
|
|
680
|
+
for (const path of index.keys()) addLeadingDirs(dirs, path);
|
|
681
|
+
// update_index_from_diff works through the diff queue in the index's order
|
|
682
|
+
const paths = [...new Set([...index.keys(), ...tree.keys()])].sort(compareGitPaths);
|
|
683
|
+
let intentToAddCreated = false;
|
|
684
|
+
for (const path of paths) {
|
|
685
|
+
const entries = index.get(path) ?? [];
|
|
686
|
+
const t = tree.get(path);
|
|
687
|
+
// diff-lib's oneway_diff matches the index entry, else the tree's
|
|
688
|
+
const first = entries[0];
|
|
689
|
+
if (!named(path, first ? first.mode : (t?.mode ?? 0))) continue;
|
|
690
|
+
const unmerged = entries.some((e) => e.stage > 0);
|
|
691
|
+
const staged = entries.find((e) => e.stage === 0);
|
|
692
|
+
if (!unmerged) {
|
|
693
|
+
// the same mode and blob: no change (an intent-to-add entry included)
|
|
694
|
+
if (staged && t && staged.mode === t.mode && staged.objectId === t.objectId) continue;
|
|
695
|
+
if (!staged && !t) continue;
|
|
696
|
+
}
|
|
697
|
+
if (unmerged) {
|
|
698
|
+
const record: ResolveUndoRecord = {
|
|
699
|
+
path,
|
|
700
|
+
modes: [0, 0, 0],
|
|
701
|
+
objectIds: [undefined, undefined, undefined],
|
|
702
|
+
};
|
|
703
|
+
for (const e of entries) {
|
|
704
|
+
if (e.stage < 1 || e.stage > 3) continue;
|
|
705
|
+
record.modes[e.stage - 1] = e.mode;
|
|
706
|
+
record.objectIds[e.stage - 1] = e.objectId;
|
|
707
|
+
}
|
|
708
|
+
undo.push(record);
|
|
709
|
+
}
|
|
710
|
+
if (!t && !this.intentToAdd) {
|
|
711
|
+
changes.set(path, []);
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
const skipWorktree = staged
|
|
715
|
+
? staged.skipWorktree === true
|
|
716
|
+
: patterns !== undefined && !patterns.includes(path);
|
|
717
|
+
// add_index_entry: the new stage-0 entry replaces the stage-0 entries it clashes with
|
|
718
|
+
// as a file or a directory (has_dir_name / has_file_name; conflict stages stay)
|
|
719
|
+
for (const other of stageZeroClashes(path, hasStageZero, paths, dirs)) {
|
|
720
|
+
changes.set(
|
|
721
|
+
other,
|
|
722
|
+
current(other).filter((e) => (e.stage ?? 0) > 0),
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
addLeadingDirs(dirs, path);
|
|
726
|
+
if (!t) intentToAddCreated = true;
|
|
727
|
+
changes.set(path, [
|
|
728
|
+
{
|
|
729
|
+
path,
|
|
730
|
+
// make_cache_entry of a path the tree lacks: create_ce_mode(0), a regular file
|
|
731
|
+
mode: t ? t.mode : FileMode.REGULAR_FILE,
|
|
732
|
+
objectId: t ? t.objectId : EMPTY_BLOB_ID,
|
|
733
|
+
stage: 0,
|
|
734
|
+
size: 0,
|
|
735
|
+
mtime: 0,
|
|
736
|
+
...(skipWorktree ? { skipWorktree: true } : {}),
|
|
737
|
+
...(t ? {} : { intentToAdd: true }),
|
|
738
|
+
},
|
|
739
|
+
]);
|
|
740
|
+
}
|
|
741
|
+
// set_object_name_for_intent_to_add_entry: the empty blob an intent-to-add entry names
|
|
742
|
+
// is written, so the index never names a missing object
|
|
743
|
+
if (intentToAddCreated) await this.blobs.store([new Uint8Array(0)], 0);
|
|
744
|
+
if (undo.length > 0) this.staging.recordResolveUndo?.(undo);
|
|
745
|
+
if (changes.size > 0) await rewriteIndex(this.staging, changes);
|
|
199
746
|
}
|
|
200
747
|
|
|
201
748
|
/**
|
|
@@ -224,29 +771,29 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
224
771
|
* @param targetId Commit to reset the working tree to
|
|
225
772
|
* @param trackedBefore Paths tracked before staging was reset
|
|
226
773
|
*/
|
|
227
|
-
private async resetWorkingTree(
|
|
774
|
+
private async resetWorkingTree(
|
|
775
|
+
targetId: ObjectId,
|
|
776
|
+
trackedBefore: Set<string>,
|
|
777
|
+
keptOut?: ReadonlySet<string>,
|
|
778
|
+
sparse?: SparseUnpack,
|
|
779
|
+
): Promise<Set<string>> {
|
|
228
780
|
const worktree = this.worktreeAccess;
|
|
229
781
|
if (!worktree) {
|
|
230
782
|
// Bare repository: there is no working tree to reset.
|
|
231
|
-
return;
|
|
783
|
+
return new Set();
|
|
232
784
|
}
|
|
233
785
|
|
|
234
786
|
const commit = await this.commits.load(targetId);
|
|
235
787
|
if (!commit) {
|
|
236
788
|
throw new RefNotFoundError(targetId, "Target commit not found");
|
|
237
789
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// Delete files that were tracked but are not in the target tree.
|
|
246
|
-
for (const path of trackedBefore) {
|
|
247
|
-
if (plan.paths.has(path)) continue;
|
|
248
|
-
await worktree.remove(path);
|
|
249
|
-
}
|
|
790
|
+
return restoreWorktreeHard(
|
|
791
|
+
{ trees: this.trees, blobs: this.blobs, workingCopy: this.workingCopy, worktree },
|
|
792
|
+
commit.tree,
|
|
793
|
+
trackedBefore,
|
|
794
|
+
keptOut,
|
|
795
|
+
sparse,
|
|
796
|
+
);
|
|
250
797
|
}
|
|
251
798
|
|
|
252
799
|
/**
|
|
@@ -255,38 +802,228 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
255
802
|
private async resetStaging(commitId: ObjectId): Promise<void> {
|
|
256
803
|
const commit = await this.commits.load(commitId);
|
|
257
804
|
if (commit) {
|
|
258
|
-
|
|
805
|
+
if (this.mode !== ResetMode.MIXED) {
|
|
806
|
+
// oneway_merge: an unchanged entry keeps its flags, a changed one its skip-worktree
|
|
807
|
+
// bit (the stat data goes: every file is written again)
|
|
808
|
+
await this.staging.readTree(this.trees, commit.tree, { keepMatching: "flags" });
|
|
809
|
+
await this.primeCacheTree(commit.tree);
|
|
810
|
+
await this.staging.write();
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
if (this.intentToAdd) {
|
|
814
|
+
// -N: the paths the commit lacks stay as intent-to-add entries
|
|
815
|
+
await this.readFromTree(commit.tree, []);
|
|
816
|
+
await this.staging.write();
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
// git's reset --mixed edits the index in place (read_from_tree): the resolve-undo
|
|
820
|
+
// records stay, and the conflict stages it removes are recorded as well
|
|
821
|
+
const unmerged = new Map<string, ResolveUndoRecord>();
|
|
822
|
+
// read_from_tree edits the index entry by entry: the cache-tree keeps its nodes, those
|
|
823
|
+
// of the paths it changes invalid (not primed, as a hard reset's is)
|
|
824
|
+
const cached = this.staging.getCacheTree?.();
|
|
825
|
+
const before = new Map<string, string>();
|
|
826
|
+
for await (const entry of this.staging.entries()) {
|
|
827
|
+
before.set(
|
|
828
|
+
entry.path,
|
|
829
|
+
`${before.has(entry.path) ? "u" : ""}${entry.mode} ${entry.objectId}`,
|
|
830
|
+
);
|
|
831
|
+
if (entry.stage < 1 || entry.stage > 3) continue;
|
|
832
|
+
let record = unmerged.get(entry.path);
|
|
833
|
+
if (!record) {
|
|
834
|
+
record = {
|
|
835
|
+
path: entry.path,
|
|
836
|
+
modes: [0, 0, 0],
|
|
837
|
+
objectIds: [undefined, undefined, undefined],
|
|
838
|
+
};
|
|
839
|
+
unmerged.set(entry.path, record);
|
|
840
|
+
}
|
|
841
|
+
record.modes[entry.stage - 1] = entry.mode;
|
|
842
|
+
record.objectIds[entry.stage - 1] = entry.objectId;
|
|
843
|
+
}
|
|
844
|
+
// read_from_tree leaves the entries it does not change alone (their flags and stat), and
|
|
845
|
+
// a changed entry keeps its skip-worktree bit (update_index_from_diff)
|
|
846
|
+
await this.staging.readTree(this.trees, commit.tree, {
|
|
847
|
+
keepResolveUndo: true,
|
|
848
|
+
keepMatching: true,
|
|
849
|
+
});
|
|
850
|
+
if (unmerged.size > 0) this.staging.recordResolveUndo?.([...unmerged.values()]);
|
|
851
|
+
if (cached && this.staging.setCacheTree) {
|
|
852
|
+
const tree = copyCacheTree(cached);
|
|
853
|
+
for await (const entry of this.staging.entries()) {
|
|
854
|
+
if (before.get(entry.path) !== `${entry.mode} ${entry.objectId}`) {
|
|
855
|
+
invalidateCacheTreePath(tree, entry.path);
|
|
856
|
+
}
|
|
857
|
+
before.delete(entry.path);
|
|
858
|
+
}
|
|
859
|
+
for (const path of before.keys()) invalidateCacheTreePath(tree, path);
|
|
860
|
+
this.staging.setCacheTree(tree);
|
|
861
|
+
}
|
|
259
862
|
await this.staging.write();
|
|
260
863
|
}
|
|
261
864
|
}
|
|
262
865
|
|
|
263
866
|
/**
|
|
264
|
-
*
|
|
867
|
+
* git's `prime_cache_tree` after a hard reset: the index's cache-tree is the
|
|
868
|
+
* target tree's, every directory valid with the tree stored there (a tree holding 100664
|
|
869
|
+
* modes is kept, so a write-tree of the unchanged index gives it back).
|
|
265
870
|
*/
|
|
266
|
-
private async
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
let currentTreeId = treeId;
|
|
871
|
+
private async primeCacheTree(treeId: ObjectId): Promise<void> {
|
|
872
|
+
if (!this.staging.setCacheTree) return;
|
|
873
|
+
this.staging.setCacheTree(await cacheTreeOfTree(this.trees, treeId));
|
|
874
|
+
}
|
|
875
|
+
}
|
|
272
876
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
877
|
+
/**
|
|
878
|
+
* The working tree half of `git reset --hard` (unpack-trees `oneway_merge` with `update`):
|
|
879
|
+
* `treeId` written over the worktree, the paths of `trackedBefore` it lacks deleted first.
|
|
880
|
+
* Untracked files in the way are overwritten, as git's reset does. The restore is planned
|
|
881
|
+
* in full before any file is touched. In a sparse checkout (`sparse`) only the paths in its
|
|
882
|
+
* patterns are written, nothing that stays outside is removed, and the files leaving the
|
|
883
|
+
* checkout are unlinked first. Returns the paths written.
|
|
884
|
+
*/
|
|
885
|
+
export async function restoreWorktreeHard(
|
|
886
|
+
deps: { trees: CommandTrees; blobs: Blobs; workingCopy: WorkingCopy; worktree: Worktree },
|
|
887
|
+
treeId: ObjectId,
|
|
888
|
+
trackedBefore: Set<string>,
|
|
889
|
+
keptOut?: ReadonlySet<string>,
|
|
890
|
+
sparse?: SparseUnpack,
|
|
891
|
+
): Promise<Set<string>> {
|
|
892
|
+
const { trees, blobs, workingCopy, worktree } = deps;
|
|
893
|
+
// Plan the whole restore first. Anything unrestorable then fails while the
|
|
894
|
+
// working tree is still untouched, instead of half-way through rewriting it.
|
|
895
|
+
const fullPlan = await planTreeRestore(trees, blobs, treeId, RESET_HARD, {
|
|
896
|
+
symlinks: true,
|
|
897
|
+
...(await restoreCaseOptions(worktree, coreBool(workingCopy, "ignorecase", false))),
|
|
898
|
+
windows: worktree.capabilities?.windowsPaths === true,
|
|
899
|
+
reservedNames: worktree.capabilities?.reservedNames,
|
|
900
|
+
});
|
|
901
|
+
// a skip-worktree entry the tree keeps is not checked out (oneway_merge skips it); in a
|
|
902
|
+
// sparse checkout, nothing outside its patterns is (apply_sparse_checkout), and an entry
|
|
903
|
+
// coming back into them is written
|
|
904
|
+
const skip = sparse
|
|
905
|
+
? (path: string) => !sparse.writes(path)
|
|
906
|
+
: keptOut && keptOut.size > 0
|
|
907
|
+
? (path: string) => keptOut.has(path)
|
|
908
|
+
: undefined;
|
|
909
|
+
const plan = skip
|
|
910
|
+
? {
|
|
911
|
+
...fullPlan,
|
|
912
|
+
entries: fullPlan.entries.filter((e) => !skip(e.path)),
|
|
913
|
+
gitlinks: fullPlan.gitlinks.filter((e) => !skip(e.path)),
|
|
914
|
+
}
|
|
915
|
+
: fullPlan;
|
|
276
916
|
|
|
277
|
-
|
|
917
|
+
if (sparse) {
|
|
918
|
+
// apply_sparse_checkout before check_updates: the files leaving the checkout
|
|
919
|
+
const result = new Map<string, { objectId: ObjectId; mode: number }>();
|
|
920
|
+
for (const e of fullPlan.entries) result.set(e.path, e);
|
|
921
|
+
for (const e of fullPlan.gitlinks) result.set(e.path, e);
|
|
922
|
+
const unlink = await sparse.leaving(worktree, (p) => result.get(p), {
|
|
923
|
+
reset: true,
|
|
924
|
+
trust: worktreeModeTrust(workingCopy, worktree),
|
|
925
|
+
});
|
|
926
|
+
await sparse.unlink(worktree, unlink);
|
|
927
|
+
}
|
|
278
928
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
929
|
+
// Delete the files that were tracked but are not in the target tree first, as git's
|
|
930
|
+
// unpack-trees does: a tracked file or symlink `d` then makes way for `d/x`, and is
|
|
931
|
+
// never written beneath or through; the directories left empty go too (unlink_entry's
|
|
932
|
+
// schedule_dir_for_removal). A skip-worktree entry staying outside a sparse checkout
|
|
933
|
+
// keeps its file.
|
|
934
|
+
for (const path of trackedBefore) {
|
|
935
|
+
if (plan.paths.has(path) || sparse?.leavesAlone(path)) continue;
|
|
936
|
+
await worktree.remove(path);
|
|
937
|
+
await pruneEmptyParents(worktree, path);
|
|
938
|
+
}
|
|
282
939
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
940
|
+
// a forced checkout: a file or link where a directory must go is unlinked, never
|
|
941
|
+
// written through; links are written as links where the worktree has them
|
|
942
|
+
await writeTreeRestorePlan(worktree, blobs, plan, RESET_HARD, {
|
|
943
|
+
symlinks: worktreeModeTrust(workingCopy, worktree).symlinks,
|
|
944
|
+
replaceInTheWay: true,
|
|
945
|
+
// git's reset --hard overwrites untracked files (UNPACK_RESET_OVERWRITE_UNTRACKED)
|
|
946
|
+
discardUntracked: true,
|
|
947
|
+
});
|
|
948
|
+
return new Set([...plan.entries, ...plan.gitlinks].map((e) => e.path));
|
|
949
|
+
}
|
|
286
950
|
|
|
287
|
-
|
|
288
|
-
|
|
951
|
+
/**
|
|
952
|
+
* Records in the index the stat of the files a one-way reset just wrote (`paths`): git's
|
|
953
|
+
* `checkout_entry` fills each written entry's stat data in `check_updates`, so a following
|
|
954
|
+
* `diff-files` or sparse update finds them clean. Only stage-0 entries are touched, and the
|
|
955
|
+
* staging's own racy-git smudging still applies when the index is written. Not written here.
|
|
956
|
+
*/
|
|
957
|
+
export async function recordWrittenStat(
|
|
958
|
+
staging: Staging,
|
|
959
|
+
worktree: Worktree,
|
|
960
|
+
paths: Iterable<string>,
|
|
961
|
+
): Promise<void> {
|
|
962
|
+
const list = [...paths];
|
|
963
|
+
if (list.length === 0) return;
|
|
964
|
+
const found = await getWorktreeEntries(worktree, list);
|
|
965
|
+
const editor = staging.createEditor();
|
|
966
|
+
let edits = 0;
|
|
967
|
+
for (let i = 0; i < list.length; i++) {
|
|
968
|
+
const stat = found[i];
|
|
969
|
+
if (!stat || stat.isDirectory) continue;
|
|
970
|
+
edits++;
|
|
971
|
+
editor.add({
|
|
972
|
+
path: list[i] as string,
|
|
973
|
+
apply: (existing) =>
|
|
974
|
+
existing && existing.stage === 0 ? { ...existing, ...entryStatOf(stat) } : existing,
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
if (edits > 0) await editor.finish();
|
|
978
|
+
}
|
|
289
979
|
|
|
290
|
-
|
|
980
|
+
/** What {@link checkFlaggedEntries} found. */
|
|
981
|
+
export interface FlaggedEntries {
|
|
982
|
+
/** The first path whose flagged entry the tree changes or deletes over a changed file. */
|
|
983
|
+
refused?: string;
|
|
984
|
+
/** The skip-worktree entries the tree keeps: their files are left alone. */
|
|
985
|
+
keptOut: Set<string>;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* The index entries whose flags cheat (assume-unchanged, skip-worktree) before a one-way
|
|
990
|
+
* reset onto `treeId` (`reset --hard`, `checkout -f`): unpack-trees checks them even when it
|
|
991
|
+
* resets (`verify_uptodate_1`: "CE_VALID and CE_SKIP_WORKTREE cheat"), so one the tree
|
|
992
|
+
* changes or deletes is refused while its file differs from it (by stat, as
|
|
993
|
+
* `ie_match_stat`; a missing file is fine). A skip-worktree entry the tree keeps is not
|
|
994
|
+
* checked out (`oneway_merge`).
|
|
995
|
+
*/
|
|
996
|
+
export async function checkFlaggedEntries(
|
|
997
|
+
deps: {
|
|
998
|
+
trees: CommandTrees;
|
|
999
|
+
staging: Staging;
|
|
1000
|
+
workingCopy: WorkingCopy;
|
|
1001
|
+
worktree?: Worktree;
|
|
1002
|
+
},
|
|
1003
|
+
treeId: ObjectId,
|
|
1004
|
+
/** A sparse checkout's run: an entry that stays outside it is not checked (verify_uptodate) */
|
|
1005
|
+
sparse?: SparseUnpack,
|
|
1006
|
+
): Promise<FlaggedEntries> {
|
|
1007
|
+
const flagged: StagingEntry[] = [];
|
|
1008
|
+
for await (const entry of deps.staging.entries()) {
|
|
1009
|
+
if (entry.stage === 0 && (entry.assumeValid || entry.skipWorktree)) flagged.push(entry);
|
|
1010
|
+
}
|
|
1011
|
+
const keptOut = new Set<string>();
|
|
1012
|
+
if (flagged.length === 0) return { keptOut };
|
|
1013
|
+
const target = await flatTree(deps.trees, treeId);
|
|
1014
|
+
const worktree = deps.worktree;
|
|
1015
|
+
const trust = worktree ? worktreeModeTrust(deps.workingCopy, worktree) : undefined;
|
|
1016
|
+
const indexTime = deps.staging.getUpdateTime();
|
|
1017
|
+
for (const entry of flagged) {
|
|
1018
|
+
if (sparse?.leavesAlone(entry.path)) continue;
|
|
1019
|
+
const t = target.get(entry.path);
|
|
1020
|
+
if (t && t.mode === entry.mode && t.objectId === entry.objectId) {
|
|
1021
|
+
if (entry.skipWorktree) keptOut.add(entry.path);
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
if (worktree && (await flaggedEntryDiffers(worktree, entry.path, entry, trust, indexTime))) {
|
|
1025
|
+
return { refused: entry.path, keptOut };
|
|
1026
|
+
}
|
|
291
1027
|
}
|
|
1028
|
+
return { keptOut };
|
|
292
1029
|
}
|