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