@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
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's `checkout_paths` (builtin/checkout.c), shared by `git checkout [<tree-ish>] --
|
|
3
|
+
* <pathspec>` and `git restore`: the index entries a pathspec names are checked out to the
|
|
4
|
+
* worktree, from the index or from a tree (`read_tree_some` puts the tree's entries into the
|
|
5
|
+
* index first), in overlay mode or not, with `--ours`/`--theirs`/`--merge` for unmerged
|
|
6
|
+
* paths and skip-worktree entries passed over unless `--ignore-skip-worktree-bits`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { type Blobs, FileMode, type ObjectId, PromisorFetchError } from "@statewalker/vcs-core";
|
|
10
|
+
import { type ConflictStyle, compareGitPaths } from "@statewalker/vcs-utils";
|
|
11
|
+
import { collect } from "@statewalker/vcs-utils/streams";
|
|
12
|
+
import {
|
|
13
|
+
entryStatOf,
|
|
14
|
+
type IndexEntryOptions,
|
|
15
|
+
type ResolveUndoRecord,
|
|
16
|
+
type Staging,
|
|
17
|
+
type StagingEntry,
|
|
18
|
+
type WorkingCopy,
|
|
19
|
+
type Worktree,
|
|
20
|
+
} from "@statewalker/vcs-working-tree";
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
IncompatibleOptionsError,
|
|
24
|
+
InvalidArgumentError,
|
|
25
|
+
RefNotFoundError,
|
|
26
|
+
} from "../errors/index.js";
|
|
27
|
+
import type { CommandTrees } from "../git-command.js";
|
|
28
|
+
import { worktreeModeTrust } from "./core-config.js";
|
|
29
|
+
import { addLeadingDirs, stageZeroClashes } from "./index-adder.js";
|
|
30
|
+
import { conflictStyleOf } from "./merge-config.js";
|
|
31
|
+
import { lowLevelMerge, ortConfigOptions } from "./merge-drivers.js";
|
|
32
|
+
import { flatTree, rewriteIndex } from "./merge-support.js";
|
|
33
|
+
import {
|
|
34
|
+
DO_MATCH_DIRECTORY,
|
|
35
|
+
type GlobalPathspecMagic,
|
|
36
|
+
matchPathspec,
|
|
37
|
+
matchPathspecSeen,
|
|
38
|
+
type PathspecItem,
|
|
39
|
+
parsePathspec,
|
|
40
|
+
pathspecErrors,
|
|
41
|
+
} from "./pathspec.js";
|
|
42
|
+
import { PathspecAttributes } from "./pathspec-attributes.js";
|
|
43
|
+
import {
|
|
44
|
+
pruneEmptyParents,
|
|
45
|
+
removeDirectoryIfEmpty,
|
|
46
|
+
worktreeDiffers,
|
|
47
|
+
} from "./worktree-overwrite-checks.js";
|
|
48
|
+
|
|
49
|
+
/** What {@link checkoutPaths} reads and writes. */
|
|
50
|
+
export interface CheckoutPathsContext {
|
|
51
|
+
workingCopy: WorkingCopy;
|
|
52
|
+
staging: Staging;
|
|
53
|
+
trees: CommandTrees;
|
|
54
|
+
blobs: Blobs;
|
|
55
|
+
worktree: Worktree | undefined;
|
|
56
|
+
/** An object id abbreviated as git prints it (`repo_find_unique_abbrev`) */
|
|
57
|
+
abbreviate(id: ObjectId): Promise<string>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The `checkout_opts` that `checkout_paths` reads. */
|
|
61
|
+
export interface CheckoutPathsOptions {
|
|
62
|
+
/** The parsed pathspec */
|
|
63
|
+
items: PathspecItem[];
|
|
64
|
+
/** The elements as given, for `report_path_error` */
|
|
65
|
+
originals: readonly string[];
|
|
66
|
+
/** Report elements that matched nothing (off for a whole-index checkout) */
|
|
67
|
+
reportUnmatched?: boolean;
|
|
68
|
+
/** The tree checked out of (`opts->source_tree`); none: the index */
|
|
69
|
+
sourceTree?: ObjectId;
|
|
70
|
+
/** Update the index (`checkout_index`) */
|
|
71
|
+
checkoutIndex: boolean;
|
|
72
|
+
/** Update the worktree (`checkout_worktree`) */
|
|
73
|
+
checkoutWorktree: boolean;
|
|
74
|
+
/** Overlay mode: entries the tree lacks are kept (checkout's default) */
|
|
75
|
+
overlay: boolean;
|
|
76
|
+
/** `--ignore-skip-worktree-bits` */
|
|
77
|
+
ignoreSkipWorktree?: boolean;
|
|
78
|
+
/** `--ours` (2) / `--theirs` (3) */
|
|
79
|
+
writeoutStage?: number;
|
|
80
|
+
/** `-m` / `--merge` / `--conflict`: unmerged paths re-created */
|
|
81
|
+
merge?: boolean;
|
|
82
|
+
/** `--conflict=<style>`; default `merge.conflictStyle` */
|
|
83
|
+
conflictStyle?: ConflictStyle;
|
|
84
|
+
/** `--ignore-unmerged` (`restore`), or `checkout -f` */
|
|
85
|
+
ignoreUnmerged?: boolean;
|
|
86
|
+
/** `-q`: no "path is unmerged" warning, no counts */
|
|
87
|
+
quiet?: boolean;
|
|
88
|
+
/** `count_checkout_paths`: "Updated N paths from ..." (checkout without `--`) */
|
|
89
|
+
countCheckoutPaths?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** What {@link checkoutPaths} did. */
|
|
93
|
+
export interface CheckoutPathsOutcome {
|
|
94
|
+
/** false where git returns 1 (an error was reported) */
|
|
95
|
+
ok: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* git's exit status where it is neither 0 nor 1: 255 once `checkout_worktree` reported an
|
|
98
|
+
* error (an entry it could not write: its `error()` returns -1)
|
|
99
|
+
*/
|
|
100
|
+
exitCode?: number;
|
|
101
|
+
/** git's `error: ...` lines */
|
|
102
|
+
errors: string[];
|
|
103
|
+
/** The other stderr lines: warnings and the counts */
|
|
104
|
+
warnings: string[];
|
|
105
|
+
/** The paths written to the worktree */
|
|
106
|
+
updated: string[];
|
|
107
|
+
/** The paths unlinked from the worktree */
|
|
108
|
+
removed: string[];
|
|
109
|
+
/** The elements that matched nothing, or the paths an error named */
|
|
110
|
+
conflicts: string[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** A path checkout as `checkout` or `restore` was asked for it (`checkout_opts`). */
|
|
114
|
+
export interface PathCheckoutRequest {
|
|
115
|
+
/** Which command: its option checks and messages differ */
|
|
116
|
+
command: "checkout" | "restore";
|
|
117
|
+
/** The pathspec elements as given */
|
|
118
|
+
paths: readonly string[];
|
|
119
|
+
/** The whole index (or tree), whatever the paths: nothing is reported unmatched */
|
|
120
|
+
allPaths?: boolean;
|
|
121
|
+
/** The tree-ish checked out of (`checkout <tree-ish> --`, `restore --source`) */
|
|
122
|
+
source?: string;
|
|
123
|
+
/** `restore --staged` (checkout: always) */
|
|
124
|
+
staged?: boolean;
|
|
125
|
+
/** `restore --worktree` (checkout: always; restore's default without `--staged`) */
|
|
126
|
+
worktree?: boolean;
|
|
127
|
+
/** `--overlay` / `--no-overlay`; default: on for checkout, off for restore */
|
|
128
|
+
overlay?: boolean;
|
|
129
|
+
ignoreSkipWorktree?: boolean;
|
|
130
|
+
/** `--ours` (2) / `--theirs` (3) */
|
|
131
|
+
stage?: number;
|
|
132
|
+
merge?: boolean;
|
|
133
|
+
conflictStyle?: ConflictStyle;
|
|
134
|
+
/** `checkout -f`: unmerged entries are passed over with a warning */
|
|
135
|
+
force?: boolean;
|
|
136
|
+
/** `restore --ignore-unmerged` */
|
|
137
|
+
ignoreUnmerged?: boolean;
|
|
138
|
+
quiet?: boolean;
|
|
139
|
+
countCheckoutPaths?: boolean;
|
|
140
|
+
/** The global pathspec magic (`GIT_LITERAL_PATHSPECS`, ...) */
|
|
141
|
+
globalMagic?: GlobalPathspecMagic;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* `checkout_main`'s and `checkout_paths`' option checks (git's `die()`s, thrown), the
|
|
146
|
+
* pathspec parsed, the source resolved, then {@link checkoutPaths}.
|
|
147
|
+
*
|
|
148
|
+
* @param resolveTree The object a revision names and its tree (`parse_tree_indirect`), the
|
|
149
|
+
* tree undefined when the object is no tree-ish; throws {@link RefNotFoundError} when it
|
|
150
|
+
* names nothing
|
|
151
|
+
*/
|
|
152
|
+
export async function runPathCheckout(
|
|
153
|
+
ctx: CheckoutPathsContext & {
|
|
154
|
+
resolveTree(rev: string): Promise<{ id: ObjectId; tree: ObjectId | undefined }>;
|
|
155
|
+
},
|
|
156
|
+
req: PathCheckoutRequest,
|
|
157
|
+
): Promise<CheckoutPathsOutcome> {
|
|
158
|
+
const isRestore = req.command === "restore";
|
|
159
|
+
// checkout writes both; restore the worktree unless only --staged is given
|
|
160
|
+
let checkoutIndex: boolean;
|
|
161
|
+
let checkoutWorktree: boolean;
|
|
162
|
+
if (!isRestore) {
|
|
163
|
+
checkoutIndex = true;
|
|
164
|
+
checkoutWorktree = true;
|
|
165
|
+
} else if (req.staged !== undefined || req.worktree !== undefined) {
|
|
166
|
+
checkoutIndex = req.staged === true;
|
|
167
|
+
checkoutWorktree = req.worktree === true;
|
|
168
|
+
} else {
|
|
169
|
+
checkoutIndex = false;
|
|
170
|
+
checkoutWorktree = true;
|
|
171
|
+
}
|
|
172
|
+
let from = req.source;
|
|
173
|
+
if (isRestore && from === undefined && checkoutIndex) from = "HEAD";
|
|
174
|
+
const ignoreUnmerged = isRestore ? req.ignoreUnmerged === true : req.force === true;
|
|
175
|
+
const fail = (options: string[], message: string) =>
|
|
176
|
+
new IncompatibleOptionsError(options, message);
|
|
177
|
+
|
|
178
|
+
// the pathspec (`parse_pathspec(&opts->pathspec, 0, 0, prefix, argv)`): attr allowed
|
|
179
|
+
let items: PathspecItem[] = [];
|
|
180
|
+
const originals = req.allPaths && req.paths.length === 0 ? ["."] : [...req.paths];
|
|
181
|
+
try {
|
|
182
|
+
items = parsePathspec(originals, { attr: true, global: req.globalMagic });
|
|
183
|
+
} catch (error) {
|
|
184
|
+
throw new InvalidArgumentError("path", req.paths, `fatal: ${(error as Error).message}`);
|
|
185
|
+
}
|
|
186
|
+
if (items.length === 0 && !req.allPaths) {
|
|
187
|
+
throw new InvalidArgumentError("path", req.paths, "fatal: you must specify path(s) to restore");
|
|
188
|
+
}
|
|
189
|
+
if (1 < Number(!!req.stage) + Number(!isRestore && !!req.force) + Number(!!req.merge)) {
|
|
190
|
+
throw fail(
|
|
191
|
+
["--ours/--theirs", "--force", "--merge"],
|
|
192
|
+
"fatal: git checkout: --ours/--theirs, --force and --merge are incompatible when\nchecking out of the index.",
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
// the source tree, resolved before checkout_paths runs
|
|
196
|
+
let sourceTree: ObjectId | undefined;
|
|
197
|
+
if (from !== undefined) {
|
|
198
|
+
let resolved: { id: ObjectId; tree: ObjectId | undefined };
|
|
199
|
+
try {
|
|
200
|
+
resolved = await ctx.resolveTree(from);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (error instanceof RefNotFoundError) {
|
|
203
|
+
throw new RefNotFoundError(
|
|
204
|
+
from,
|
|
205
|
+
isRestore ? `fatal: could not resolve '${from}'` : `fatal: invalid reference: ${from}`,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
// git 2.5x's parse_tree_indirect dies on an object that is no tree-ish (2.43 went on
|
|
211
|
+
// to "fatal: reference is not a tree: <rev>")
|
|
212
|
+
if (!resolved.tree) {
|
|
213
|
+
throw new RefNotFoundError(from, `fatal: unable to read tree (${resolved.id})`);
|
|
214
|
+
}
|
|
215
|
+
sourceTree = resolved.tree;
|
|
216
|
+
}
|
|
217
|
+
if (ignoreUnmerged && req.merge) {
|
|
218
|
+
throw fail(
|
|
219
|
+
[isRestore ? "--ignore-unmerged" : "--force", "-m"],
|
|
220
|
+
`fatal: options '${isRestore ? "--ignore-unmerged" : "--force"}' and '-m' cannot be used together`,
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
if (!checkoutWorktree && !checkoutIndex) {
|
|
224
|
+
throw fail(
|
|
225
|
+
["--staged", "--worktree"],
|
|
226
|
+
"fatal: neither '--staged' or '--worktree' is specified",
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (!checkoutWorktree && from === undefined) {
|
|
230
|
+
throw fail(
|
|
231
|
+
["--worktree", "--source"],
|
|
232
|
+
"fatal: '--worktree' must be used when '--source' is not specified",
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (isRestore && checkoutIndex) {
|
|
236
|
+
if (req.stage) {
|
|
237
|
+
throw fail(
|
|
238
|
+
["--ours", "--theirs", "--staged"],
|
|
239
|
+
"fatal: '--ours' or '--theirs' cannot be used with --staged",
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
if (req.merge) {
|
|
243
|
+
throw fail(
|
|
244
|
+
["--merge", "--conflict", "--staged"],
|
|
245
|
+
"fatal: '--merge' or '--conflict' cannot be used with --staged",
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if ((req.merge || req.stage) && sourceTree) {
|
|
250
|
+
throw fail(
|
|
251
|
+
["--merge", "--ours", "--theirs"],
|
|
252
|
+
"fatal: '--merge', '--ours', or '--theirs' cannot be used when checking out of a tree",
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
return checkoutPaths(ctx, {
|
|
256
|
+
items,
|
|
257
|
+
originals,
|
|
258
|
+
reportUnmatched: !req.allPaths,
|
|
259
|
+
...(sourceTree ? { sourceTree } : {}),
|
|
260
|
+
checkoutIndex,
|
|
261
|
+
checkoutWorktree,
|
|
262
|
+
overlay: req.overlay ?? !isRestore,
|
|
263
|
+
ignoreSkipWorktree: req.ignoreSkipWorktree === true,
|
|
264
|
+
...(req.stage ? { writeoutStage: req.stage } : {}),
|
|
265
|
+
merge: req.merge === true || req.conflictStyle !== undefined,
|
|
266
|
+
...(req.conflictStyle ? { conflictStyle: req.conflictStyle } : {}),
|
|
267
|
+
ignoreUnmerged,
|
|
268
|
+
quiet: req.quiet === true,
|
|
269
|
+
countCheckoutPaths: req.countCheckoutPaths === true,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** An index entry while `checkout_paths` works on it, with its `ce_flags`. */
|
|
274
|
+
interface Rec {
|
|
275
|
+
entry: IndexEntryOptions;
|
|
276
|
+
/** CE_UPDATE: from the tree (or the same as it) */
|
|
277
|
+
update: boolean;
|
|
278
|
+
/** Fresh from the tree: no stat recorded yet */
|
|
279
|
+
fresh: boolean;
|
|
280
|
+
matched: boolean;
|
|
281
|
+
remove: boolean;
|
|
282
|
+
wtRemove: boolean;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const stageOf = (e: IndexEntryOptions) => e.stage ?? 0;
|
|
286
|
+
const isGitlink = (mode: number) => mode === FileMode.GITLINK;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Runs git's `checkout_paths` past its option checks: `read_tree_some`, `unmerge_index`,
|
|
290
|
+
* the marking (`mark_ce_for_checkout_overlay` / `_no_overlay`), `report_path_error`, the
|
|
291
|
+
* unmerged-path checks, `checkout_worktree` and the index write.
|
|
292
|
+
*/
|
|
293
|
+
export async function checkoutPaths(
|
|
294
|
+
ctx: CheckoutPathsContext,
|
|
295
|
+
o: CheckoutPathsOptions,
|
|
296
|
+
): Promise<CheckoutPathsOutcome> {
|
|
297
|
+
const { staging, worktree } = ctx;
|
|
298
|
+
const errors: string[] = [];
|
|
299
|
+
const warnings: string[] = [];
|
|
300
|
+
const out: CheckoutPathsOutcome = {
|
|
301
|
+
ok: true,
|
|
302
|
+
errors,
|
|
303
|
+
warnings,
|
|
304
|
+
updated: [],
|
|
305
|
+
removed: [],
|
|
306
|
+
conflicts: [],
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// the index, by path (stages in order); paths whose entries change
|
|
310
|
+
const byPath = new Map<string, Rec[]>();
|
|
311
|
+
for await (const entry of staging.entries()) {
|
|
312
|
+
const rec: Rec = {
|
|
313
|
+
entry: { ...entry },
|
|
314
|
+
update: false,
|
|
315
|
+
fresh: false,
|
|
316
|
+
matched: false,
|
|
317
|
+
remove: false,
|
|
318
|
+
wtRemove: false,
|
|
319
|
+
};
|
|
320
|
+
const list = byPath.get(entry.path);
|
|
321
|
+
if (list) list.push(rec);
|
|
322
|
+
else byPath.set(entry.path, [rec]);
|
|
323
|
+
}
|
|
324
|
+
const changed = new Set<string>();
|
|
325
|
+
const resolveUndo: ResolveUndoRecord[] = [];
|
|
326
|
+
// the resolve-undo records unmerge_index used up (dropped with the index write)
|
|
327
|
+
const undone = new Set<string>();
|
|
328
|
+
const recordUndo = (path: string, recs: Rec[]) => {
|
|
329
|
+
const record: ResolveUndoRecord = {
|
|
330
|
+
path,
|
|
331
|
+
modes: [0, 0, 0],
|
|
332
|
+
objectIds: [undefined, undefined, undefined],
|
|
333
|
+
};
|
|
334
|
+
let any = false;
|
|
335
|
+
for (const r of recs) {
|
|
336
|
+
const stage = stageOf(r.entry);
|
|
337
|
+
if (stage < 1 || stage > 3) continue;
|
|
338
|
+
record.modes[stage - 1] = r.entry.mode;
|
|
339
|
+
record.objectIds[stage - 1] = r.entry.objectId;
|
|
340
|
+
any = true;
|
|
341
|
+
}
|
|
342
|
+
if (any) resolveUndo.push(record);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// `:(attr:...)`: the attributes of the index's and the tree's paths
|
|
346
|
+
const tree = o.sourceTree ? await flatTree(ctx.trees, o.sourceTree) : undefined;
|
|
347
|
+
const attributes = PathspecAttributes.forWorktree(o.items, worktree);
|
|
348
|
+
if (attributes) await attributes.load([...byPath.keys(), ...(tree?.keys() ?? [])]);
|
|
349
|
+
const flagsOf = (mode: number) => (isGitlink(mode) ? DO_MATCH_DIRECTORY : 0);
|
|
350
|
+
|
|
351
|
+
// read_tree_some: each tree entry the pathspec names goes into the index (update_some)
|
|
352
|
+
if (tree) {
|
|
353
|
+
const hasStageZero = (path: string) =>
|
|
354
|
+
byPath.get(path)?.some((r) => stageOf(r.entry) === 0) === true;
|
|
355
|
+
const dirs = new Set<string>();
|
|
356
|
+
for (const path of byPath.keys()) addLeadingDirs(dirs, path);
|
|
357
|
+
for (const [path, t] of tree) {
|
|
358
|
+
if (matchPathspec(o.items, path, flagsOf(t.mode)) <= 0) continue;
|
|
359
|
+
const list = byPath.get(path);
|
|
360
|
+
const old = list?.find((r) => stageOf(r.entry) === 0);
|
|
361
|
+
if (
|
|
362
|
+
old &&
|
|
363
|
+
old.entry.mode === t.mode &&
|
|
364
|
+
!old.entry.intentToAdd &&
|
|
365
|
+
old.entry.objectId === t.objectId
|
|
366
|
+
) {
|
|
367
|
+
old.update = true;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
// add_index_entry(ADD_CACHE_OK_TO_REPLACE): a stage-0 entry replaces every stage of
|
|
371
|
+
// its path (recorded for resolve-undo) and the stage-0 entries it clashes with as a
|
|
372
|
+
// file or a directory (their conflict stages stay)
|
|
373
|
+
if (list) recordUndo(path, list);
|
|
374
|
+
for (const other of stageZeroClashes(path, hasStageZero, byPath.keys(), dirs)) {
|
|
375
|
+
const kept = (byPath.get(other) ?? []).filter((r) => stageOf(r.entry) > 0);
|
|
376
|
+
if (kept.length > 0) byPath.set(other, kept);
|
|
377
|
+
else byPath.delete(other);
|
|
378
|
+
changed.add(other);
|
|
379
|
+
}
|
|
380
|
+
addLeadingDirs(dirs, path);
|
|
381
|
+
byPath.set(path, [
|
|
382
|
+
{
|
|
383
|
+
entry: { path, mode: t.mode, objectId: t.objectId, stage: 0, size: 0, mtime: 0 },
|
|
384
|
+
update: true,
|
|
385
|
+
fresh: true,
|
|
386
|
+
matched: false,
|
|
387
|
+
remove: false,
|
|
388
|
+
wtRemove: false,
|
|
389
|
+
},
|
|
390
|
+
]);
|
|
391
|
+
changed.add(path);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// unmerge_index: the conflicts the resolve-undo records keep come back
|
|
396
|
+
if (o.merge) {
|
|
397
|
+
for (const record of staging.getResolveUndo?.() ?? []) {
|
|
398
|
+
if (matchPathspec(o.items, record.path, 0) <= 0) continue;
|
|
399
|
+
undone.add(record.path);
|
|
400
|
+
const list = byPath.get(record.path);
|
|
401
|
+
// already unmerged: left as it is
|
|
402
|
+
if (list?.some((r) => stageOf(r.entry) > 0)) continue;
|
|
403
|
+
const recs: Rec[] = [];
|
|
404
|
+
for (let k = 0; k < 3; k++) {
|
|
405
|
+
const mode = record.modes[k];
|
|
406
|
+
const objectId = record.objectIds[k];
|
|
407
|
+
if (!mode || !objectId) continue;
|
|
408
|
+
recs.push({
|
|
409
|
+
entry: {
|
|
410
|
+
path: record.path,
|
|
411
|
+
mode,
|
|
412
|
+
objectId,
|
|
413
|
+
stage: (k + 1) as 1 | 2 | 3,
|
|
414
|
+
size: 0,
|
|
415
|
+
mtime: 0,
|
|
416
|
+
},
|
|
417
|
+
update: false,
|
|
418
|
+
fresh: true,
|
|
419
|
+
matched: false,
|
|
420
|
+
remove: false,
|
|
421
|
+
wtRemove: false,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
if (recs.length > 0) byPath.set(record.path, recs);
|
|
425
|
+
else byPath.delete(record.path);
|
|
426
|
+
changed.add(record.path);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// the index in its order (by path bytes, then stage)
|
|
431
|
+
const paths = [...byPath.keys()].sort(compareGitPaths);
|
|
432
|
+
const ordered: Rec[] = [];
|
|
433
|
+
for (const path of paths) {
|
|
434
|
+
const list = (byPath.get(path) ?? []).sort((a, b) => stageOf(a.entry) - stageOf(b.entry));
|
|
435
|
+
ordered.push(...list);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// mark_ce_for_checkout_*: which entries are checked out, which the pathspec matched
|
|
439
|
+
const seen = o.items.map(() => 0);
|
|
440
|
+
for (const rec of ordered) {
|
|
441
|
+
rec.matched = false;
|
|
442
|
+
const e = rec.entry;
|
|
443
|
+
if (!o.ignoreSkipWorktree && e.skipWorktree) continue;
|
|
444
|
+
if (o.overlay) {
|
|
445
|
+
if (o.sourceTree && !rec.update) continue;
|
|
446
|
+
if (matchPathspecSeen(o.items, e.path, flagsOf(e.mode), seen)) rec.matched = true;
|
|
447
|
+
} else if (matchPathspecSeen(o.items, e.path, flagsOf(e.mode), seen)) {
|
|
448
|
+
rec.matched = true;
|
|
449
|
+
// not in the tree-ish: removed from the index and the worktree
|
|
450
|
+
if (o.sourceTree && !rec.update) {
|
|
451
|
+
rec.remove = true;
|
|
452
|
+
rec.wtRemove = true;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (o.reportUnmatched !== false) {
|
|
458
|
+
const unmatched = pathspecErrors(o.originals, seen);
|
|
459
|
+
if (unmatched.length > 0) {
|
|
460
|
+
errors.push(...unmatched);
|
|
461
|
+
out.ok = false;
|
|
462
|
+
out.conflicts = o.originals.filter((_, i) => !seen[i]);
|
|
463
|
+
return out;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// any unmerged paths?
|
|
468
|
+
let errs = false;
|
|
469
|
+
forEachMatchedPath(ordered, (rec, stages) => {
|
|
470
|
+
if (stageOf(rec.entry) === 0) return;
|
|
471
|
+
const path = rec.entry.path;
|
|
472
|
+
if (o.ignoreUnmerged) {
|
|
473
|
+
if (!o.quiet) warnings.push(`warning: path '${path}' is unmerged`);
|
|
474
|
+
} else if (o.writeoutStage) {
|
|
475
|
+
if (!stages.some((r) => stageOf(r.entry) === o.writeoutStage) && o.overlay) {
|
|
476
|
+
errors.push(stageMissing(path, o.writeoutStage));
|
|
477
|
+
out.conflicts.push(path);
|
|
478
|
+
errs = true;
|
|
479
|
+
}
|
|
480
|
+
} else if (o.merge) {
|
|
481
|
+
const have = new Set(stages.map((r) => stageOf(r.entry)));
|
|
482
|
+
if (!have.has(2) || !have.has(3)) {
|
|
483
|
+
errors.push(`error: path '${path}' does not have all necessary versions`);
|
|
484
|
+
out.conflicts.push(path);
|
|
485
|
+
errs = true;
|
|
486
|
+
}
|
|
487
|
+
} else {
|
|
488
|
+
errors.push(`error: path '${path}' is unmerged`);
|
|
489
|
+
out.conflicts.push(path);
|
|
490
|
+
errs = true;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
if (errs) {
|
|
494
|
+
out.ok = false;
|
|
495
|
+
return out;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// now committed to check them out
|
|
499
|
+
if (o.checkoutWorktree) {
|
|
500
|
+
const ok = await checkoutWorktree(ctx, o, ordered, out, changed);
|
|
501
|
+
if (!ok) {
|
|
502
|
+
out.ok = false;
|
|
503
|
+
out.exitCode = 255;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
// remove_marked_cache_entries
|
|
507
|
+
for (const rec of ordered) {
|
|
508
|
+
if (rec.remove) {
|
|
509
|
+
const list = byPath.get(rec.entry.path);
|
|
510
|
+
if (list) {
|
|
511
|
+
const kept = list.filter((r) => r !== rec);
|
|
512
|
+
if (kept.length > 0) byPath.set(rec.entry.path, kept);
|
|
513
|
+
else byPath.delete(rec.entry.path);
|
|
514
|
+
}
|
|
515
|
+
changed.add(rec.entry.path);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// the index is written when it is checked out to, or to save the stat of files checked
|
|
520
|
+
// out of it
|
|
521
|
+
const checkoutIndex =
|
|
522
|
+
o.checkoutWorktree && !o.checkoutIndex && !o.sourceTree ? true : o.checkoutIndex;
|
|
523
|
+
if (checkoutIndex) {
|
|
524
|
+
if (undone.size > 0) staging.dropResolveUndo?.(undone);
|
|
525
|
+
if (resolveUndo.length > 0) staging.recordResolveUndo?.(resolveUndo);
|
|
526
|
+
const changes = new Map<string, IndexEntryOptions[]>();
|
|
527
|
+
for (const path of changed) {
|
|
528
|
+
changes.set(
|
|
529
|
+
path,
|
|
530
|
+
(byPath.get(path) ?? []).map((r) => r.entry),
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
await rewriteIndex(staging, changes);
|
|
534
|
+
}
|
|
535
|
+
return out;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** Calls `fn` once per matched path (its first matched entry, all its entries). */
|
|
539
|
+
function forEachMatchedPath(ordered: Rec[], fn: (rec: Rec, stages: Rec[]) => void): void {
|
|
540
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
541
|
+
const rec = ordered[i];
|
|
542
|
+
if (!rec.matched) continue;
|
|
543
|
+
let j = i + 1;
|
|
544
|
+
while (j < ordered.length && ordered[j].entry.path === rec.entry.path) j++;
|
|
545
|
+
const stages = ordered.slice(i, j);
|
|
546
|
+
if (stageOf(rec.entry) === 0) {
|
|
547
|
+
fn(rec, stages);
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
fn(rec, stages);
|
|
551
|
+
i = j - 1;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/** What `checkout_entry` did with an entry. */
|
|
556
|
+
type CheckedOut = "written" | "unchanged" | "failed";
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* git's `check_leading_path` returning -1: every leading component of `path` is there as a
|
|
560
|
+
* directory (none missing, none a symbolic link or a file).
|
|
561
|
+
*/
|
|
562
|
+
async function leadingDirectoriesExist(worktree: Worktree, path: string): Promise<boolean> {
|
|
563
|
+
for (let k = path.indexOf("/"); k > 0; k = path.indexOf("/", k + 1)) {
|
|
564
|
+
const entry = await worktree.getEntry(path.slice(0, k)).catch(() => undefined);
|
|
565
|
+
if (!entry?.isDirectory || entry.mode === FileMode.SYMLINK) return false;
|
|
566
|
+
}
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const stageMissing = (path: string, stage: number) =>
|
|
571
|
+
stage === 2
|
|
572
|
+
? `error: path '${path}' does not have our version`
|
|
573
|
+
: `error: path '${path}' does not have their version`;
|
|
574
|
+
|
|
575
|
+
/** git's `checkout_worktree`: false when an error was reported. */
|
|
576
|
+
async function checkoutWorktree(
|
|
577
|
+
ctx: CheckoutPathsContext,
|
|
578
|
+
o: CheckoutPathsOptions,
|
|
579
|
+
ordered: Rec[],
|
|
580
|
+
out: CheckoutPathsOutcome,
|
|
581
|
+
changed: Set<string>,
|
|
582
|
+
): Promise<boolean> {
|
|
583
|
+
const worktree = ctx.worktree;
|
|
584
|
+
let nrCheckouts = 0;
|
|
585
|
+
let nrUnmerged = 0;
|
|
586
|
+
let ok = true;
|
|
587
|
+
if (worktree) {
|
|
588
|
+
const trust = worktreeModeTrust(ctx.workingCopy, worktree);
|
|
589
|
+
const indexTime = ctx.staging.getUpdateTime();
|
|
590
|
+
const symlinks = trust.symlinks;
|
|
591
|
+
// git's unlink_entry: nothing beneath a missing leading directory or a symbolic link
|
|
592
|
+
// (check_leading_path); a file already gone counts as removed (unlink_or_warn takes
|
|
593
|
+
// ENOENT as success), so its emptied directories are pruned all the same
|
|
594
|
+
// (schedule_dir_for_removal); a removal that fails is a warning
|
|
595
|
+
const unlink = async (rec: Rec) => {
|
|
596
|
+
const path = rec.entry.path;
|
|
597
|
+
if (!(await leadingDirectoriesExist(worktree, path))) return;
|
|
598
|
+
const current = await worktree.getEntry(path).catch(() => undefined);
|
|
599
|
+
if (isGitlink(rec.entry.mode)) {
|
|
600
|
+
// rmdir_or_warn
|
|
601
|
+
if (current) {
|
|
602
|
+
if (!current.isDirectory) {
|
|
603
|
+
out.warnings.push(`warning: unable to rmdir '${path}': Not a directory`);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (!(await removeDirectoryIfEmpty(worktree, path))) {
|
|
607
|
+
out.warnings.push(`warning: unable to rmdir '${path}': Directory not empty`);
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
out.removed.push(path);
|
|
611
|
+
}
|
|
612
|
+
} else if (current) {
|
|
613
|
+
// unlink_or_warn
|
|
614
|
+
if (current.isDirectory) {
|
|
615
|
+
out.warnings.push(`warning: unable to unlink '${path}': Is a directory`);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
await worktree.remove(path);
|
|
619
|
+
out.removed.push(path);
|
|
620
|
+
}
|
|
621
|
+
await pruneEmptyParents(worktree, path);
|
|
622
|
+
};
|
|
623
|
+
// write_entry; false where the blob cannot be read ("unable to read sha1 file of"), after
|
|
624
|
+
// checkout_entry has unlinked what stood there and made the leading directories
|
|
625
|
+
const write = async (path: string, objectId: ObjectId, mode: number): Promise<boolean> => {
|
|
626
|
+
if (isGitlink(mode)) {
|
|
627
|
+
await worktree.mkdir(path, { recursive: true });
|
|
628
|
+
return true;
|
|
629
|
+
}
|
|
630
|
+
// a partial clone's absent blob is fetched by the read (git's lazy fetch)
|
|
631
|
+
const content = await ctx.blobs.load(objectId).catch((error: unknown) => {
|
|
632
|
+
if (error instanceof PromisorFetchError) throw error;
|
|
633
|
+
return undefined;
|
|
634
|
+
});
|
|
635
|
+
if (!content) {
|
|
636
|
+
const current = await worktree.getEntry(path).catch(() => undefined);
|
|
637
|
+
if (current) await worktree.remove(path, { recursive: current.isDirectory });
|
|
638
|
+
const at = path.lastIndexOf("/");
|
|
639
|
+
if (at > 0) await worktree.mkdir(path.slice(0, at), { recursive: true }).catch(() => {});
|
|
640
|
+
out.errors.push(`error: unable to read sha1 file of ${path} (${objectId})`);
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
const written = mode === FileMode.SYMLINK && !symlinks ? FileMode.REGULAR_FILE : mode;
|
|
644
|
+
await worktree.writeContent(path, content, {
|
|
645
|
+
mode: written,
|
|
646
|
+
...(written !== mode ? { raw: true } : {}),
|
|
647
|
+
createParents: true,
|
|
648
|
+
replaceInTheWay: true,
|
|
649
|
+
discardUntracked: true,
|
|
650
|
+
});
|
|
651
|
+
return true;
|
|
652
|
+
};
|
|
653
|
+
// checkout_entry with state.force: an up-to-date file is left alone (not counted), a
|
|
654
|
+
// gitlink whose directory is there too; "written" counts, "failed" is an error
|
|
655
|
+
const checkoutEntry = async (rec: Rec, stat: boolean): Promise<CheckedOut> => {
|
|
656
|
+
const e = rec.entry;
|
|
657
|
+
if (rec.wtRemove) {
|
|
658
|
+
await unlink(rec);
|
|
659
|
+
return "unchanged";
|
|
660
|
+
}
|
|
661
|
+
const current = await worktree.getEntry(e.path).catch(() => undefined);
|
|
662
|
+
if (current) {
|
|
663
|
+
if (isGitlink(e.mode)) return "unchanged";
|
|
664
|
+
const differs =
|
|
665
|
+
rec.fresh ||
|
|
666
|
+
(await worktreeDiffers(worktree, e.path, e as StagingEntry, trust, indexTime));
|
|
667
|
+
if (!differs) return "unchanged";
|
|
668
|
+
}
|
|
669
|
+
if (!(await write(e.path, e.objectId, e.mode))) {
|
|
670
|
+
out.conflicts.push(e.path);
|
|
671
|
+
return "failed";
|
|
672
|
+
}
|
|
673
|
+
out.updated.push(e.path);
|
|
674
|
+
if (stat && !isGitlink(e.mode)) {
|
|
675
|
+
const stats = await worktree.getEntry(e.path);
|
|
676
|
+
if (stats) {
|
|
677
|
+
rec.entry = { ...e, ...entryStatOf(stats) };
|
|
678
|
+
changed.add(e.path);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return "written";
|
|
682
|
+
};
|
|
683
|
+
// checkout_worktree goes on past an entry it cannot write (errs |= ...)
|
|
684
|
+
const count = (outcome: CheckedOut) => {
|
|
685
|
+
if (outcome === "written") nrCheckouts++;
|
|
686
|
+
else if (outcome === "failed") ok = false;
|
|
687
|
+
};
|
|
688
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
689
|
+
const rec = ordered[i];
|
|
690
|
+
if (!rec.matched) continue;
|
|
691
|
+
if (stageOf(rec.entry) === 0) {
|
|
692
|
+
count(await checkoutEntry(rec, true));
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
let j = i + 1;
|
|
696
|
+
while (j < ordered.length && ordered[j].entry.path === rec.entry.path) j++;
|
|
697
|
+
const stages = ordered.slice(i, j);
|
|
698
|
+
i = j - 1;
|
|
699
|
+
if (o.writeoutStage) {
|
|
700
|
+
const chosen = stages.find((r) => stageOf(r.entry) === o.writeoutStage);
|
|
701
|
+
if (chosen) {
|
|
702
|
+
count(await checkoutEntry({ ...chosen, fresh: true }, false));
|
|
703
|
+
} else if (!o.overlay) {
|
|
704
|
+
await unlink(rec);
|
|
705
|
+
} else {
|
|
706
|
+
out.errors.push(stageMissing(rec.entry.path, o.writeoutStage));
|
|
707
|
+
ok = false;
|
|
708
|
+
}
|
|
709
|
+
} else if (o.merge) {
|
|
710
|
+
const merged = await checkoutMerged(ctx, o, stages, out);
|
|
711
|
+
if (merged === undefined) ok = false;
|
|
712
|
+
else if (await write(rec.entry.path, merged.objectId, merged.mode)) {
|
|
713
|
+
out.updated.push(rec.entry.path);
|
|
714
|
+
nrUnmerged++;
|
|
715
|
+
} else ok = false;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if (o.countCheckoutPaths && !o.quiet) {
|
|
720
|
+
if (nrUnmerged) {
|
|
721
|
+
out.warnings.push(`Recreated ${nrUnmerged} merge conflict${nrUnmerged === 1 ? "" : "s"}`);
|
|
722
|
+
}
|
|
723
|
+
const paths = `${nrCheckouts} path${nrCheckouts === 1 ? "" : "s"}`;
|
|
724
|
+
if (o.sourceTree) {
|
|
725
|
+
out.warnings.push(`Updated ${paths} from ${await ctx.abbreviate(o.sourceTree)}`);
|
|
726
|
+
} else if (!nrUnmerged || nrCheckouts) {
|
|
727
|
+
out.warnings.push(`Updated ${paths} from the index`);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
return ok;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* git's `checkout_merged`: the path's stages merged again (`ll_merge`, labels `ours`,
|
|
735
|
+
* `theirs`, `base`), the result stored as a blob and checked out with stage #2's mode.
|
|
736
|
+
*/
|
|
737
|
+
async function checkoutMerged(
|
|
738
|
+
ctx: CheckoutPathsContext,
|
|
739
|
+
o: CheckoutPathsOptions,
|
|
740
|
+
stages: Rec[],
|
|
741
|
+
out: CheckoutPathsOutcome,
|
|
742
|
+
): Promise<{ objectId: ObjectId; mode: number } | undefined> {
|
|
743
|
+
const path = stages[0].entry.path;
|
|
744
|
+
const ids: (ObjectId | undefined)[] = [undefined, undefined, undefined];
|
|
745
|
+
let mode = 0;
|
|
746
|
+
for (const r of stages) {
|
|
747
|
+
const stage = stageOf(r.entry);
|
|
748
|
+
if (stage < 1 || stage > 3) continue;
|
|
749
|
+
ids[stage - 1] = r.entry.objectId;
|
|
750
|
+
if (stage === 2) mode = r.entry.mode;
|
|
751
|
+
}
|
|
752
|
+
if (!ids[1] || !ids[2]) {
|
|
753
|
+
out.errors.push(`error: path '${path}' does not have necessary versions`);
|
|
754
|
+
return undefined;
|
|
755
|
+
}
|
|
756
|
+
const load = async (id: ObjectId | undefined) => {
|
|
757
|
+
if (!id) return new Uint8Array(0);
|
|
758
|
+
const content = await ctx.blobs.load(id);
|
|
759
|
+
return content ? collect(content) : new Uint8Array(0);
|
|
760
|
+
};
|
|
761
|
+
const [base, ours, theirs] = await Promise.all(ids.map(load));
|
|
762
|
+
// ll_merge with the path's `merge` and `conflict-marker-size` attributes and the merge
|
|
763
|
+
// drivers, as the merges read them (myers: checkout_merged's ll_merge_options)
|
|
764
|
+
const config = ortConfigOptions(ctx.workingCopy, ctx.worktree, { indexAttributes: true });
|
|
765
|
+
const merged = await lowLevelMerge(
|
|
766
|
+
{ path, base, ours, theirs, baseLabel: "base", oursLabel: "ours", theirsLabel: "theirs" },
|
|
767
|
+
{
|
|
768
|
+
attributes: (await config.attributes?.(path)) ?? {},
|
|
769
|
+
...(config.drivers ? { drivers: config.drivers } : {}),
|
|
770
|
+
...(config.defaultDriver ? { defaultDriver: config.defaultDriver } : {}),
|
|
771
|
+
style: o.conflictStyle ?? conflictStyleOf(ctx.workingCopy),
|
|
772
|
+
...(config.bigFileThreshold !== undefined
|
|
773
|
+
? { bigFileThreshold: config.bigFileThreshold }
|
|
774
|
+
: {}),
|
|
775
|
+
algorithm: "myers",
|
|
776
|
+
},
|
|
777
|
+
);
|
|
778
|
+
if (merged.status === "binary") {
|
|
779
|
+
out.warnings.push(`warning: Cannot merge binary files: ${path} (ours vs. theirs)`);
|
|
780
|
+
}
|
|
781
|
+
const content = merged.content;
|
|
782
|
+
const objectId = await ctx.blobs.store([content]);
|
|
783
|
+
return { objectId, mode };
|
|
784
|
+
}
|