@statewalker/vcs-commands 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -8
- package/dist/commands/add-command.d.ts +265 -34
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-interactive.d.ts +46 -0
- package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
- package/dist/commands/add-patch/add-patch.d.ts +139 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
- package/dist/commands/add-patch/index.d.ts +6 -0
- package/dist/commands/add-patch/index.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-backend.d.ts +80 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-modes.d.ts +71 -0
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-session.d.ts +49 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
- package/dist/commands/am/am-command.d.ts +175 -0
- package/dist/commands/am/am-command.d.ts.map +1 -0
- package/dist/commands/am/index.d.ts +3 -0
- package/dist/commands/am/index.d.ts.map +1 -0
- package/dist/commands/am/mailinfo.d.ts +58 -0
- package/dist/commands/am/mailinfo.d.ts.map +1 -0
- package/dist/commands/am/patch-format.d.ts +24 -0
- package/dist/commands/am/patch-format.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts +153 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -0
- package/dist/commands/apply/apply-engine.d.ts +195 -0
- package/dist/commands/apply/apply-engine.d.ts.map +1 -0
- package/dist/commands/apply/apply-parse.d.ts +86 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -0
- package/dist/commands/apply/apply-types.d.ts +70 -0
- package/dist/commands/apply/apply-types.d.ts.map +1 -0
- package/dist/commands/apply/index.d.ts +6 -0
- package/dist/commands/apply/index.d.ts.map +1 -0
- package/dist/commands/apply/latin1.d.ts +32 -0
- package/dist/commands/apply/latin1.d.ts.map +1 -0
- package/dist/commands/apply/whitespace.d.ts +58 -0
- package/dist/commands/apply/whitespace.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +26 -0
- package/dist/commands/attributes-source.d.ts.map +1 -0
- package/dist/commands/backfill-command.d.ts +110 -0
- package/dist/commands/backfill-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
- package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-command.d.ts +201 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-engine.d.ts +219 -0
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-graph.d.ts +127 -0
- package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-quote.d.ts +27 -0
- package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
- package/dist/commands/bisect/index.d.ts +5 -0
- package/dist/commands/bisect/index.d.ts.map +1 -0
- package/dist/commands/blame-command.d.ts +122 -131
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +52 -2
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-tracking.d.ts +98 -0
- package/dist/commands/branch-tracking.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +300 -18
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +124 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +50 -42
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +49 -16
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +134 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/comment-char-config.d.ts +35 -0
- package/dist/commands/comment-char-config.d.ts.map +1 -0
- package/dist/commands/commit-command.d.ts +311 -17
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +78 -1
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/date-format.d.ts +58 -0
- package/dist/commands/date-format.d.ts.map +1 -0
- package/dist/commands/default-branch.d.ts +70 -0
- package/dist/commands/default-branch.d.ts.map +1 -0
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +377 -30
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-textconv.d.ts +40 -0
- package/dist/commands/diff-textconv.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +149 -10
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts +164 -0
- package/dist/commands/format-patch-command.d.ts.map +1 -0
- package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts +227 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +71 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts +159 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +140 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +122 -0
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
- package/dist/commands/fsck/index.d.ts +6 -0
- package/dist/commands/fsck/index.d.ts.map +1 -0
- package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +106 -39
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +2 -0
- package/dist/commands/git-date.d.ts.map +1 -0
- package/dist/commands/git-describe.d.ts +67 -0
- package/dist/commands/git-describe.d.ts.map +1 -0
- package/dist/commands/git-hooks.d.ts +424 -0
- package/dist/commands/git-hooks.d.ts.map +1 -0
- package/dist/commands/git-ident.d.ts +128 -0
- package/dist/commands/git-ident.d.ts.map +1 -0
- package/dist/commands/hook-command.d.ts +96 -0
- package/dist/commands/hook-command.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +233 -0
- package/dist/commands/index-adder.d.ts.map +1 -0
- package/dist/commands/index-host.d.ts +86 -0
- package/dist/commands/index-host.d.ts.map +1 -0
- package/dist/commands/index.d.ts +56 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +62 -4
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/legacy-remotes.d.ts +55 -0
- package/dist/commands/legacy-remotes.d.ts.map +1 -0
- package/dist/commands/local-clone.d.ts +60 -0
- package/dist/commands/local-clone.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +117 -0
- package/dist/commands/local-transport.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +216 -24
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +120 -0
- package/dist/commands/log-graph.d.ts.map +1 -0
- package/dist/commands/log-output.d.ts +323 -0
- package/dist/commands/log-output.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +23 -7
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +31 -0
- package/dist/commands/mailmap.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +85 -0
- package/dist/commands/merge-bases.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +221 -74
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +13 -0
- package/dist/commands/merge-config.d.ts.map +1 -0
- package/dist/commands/merge-drivers.d.ts +130 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +260 -0
- package/dist/commands/merge-support.d.ts.map +1 -0
- package/dist/commands/message-cleanup.d.ts +86 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -0
- package/dist/commands/mv-command.d.ts +94 -0
- package/dist/commands/mv-command.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts +256 -0
- package/dist/commands/notes-command.d.ts.map +1 -0
- package/dist/commands/notes-commands.d.ts +41 -0
- package/dist/commands/notes-commands.d.ts.map +1 -0
- package/dist/commands/notes-merge-command.d.ts +105 -0
- package/dist/commands/notes-merge-command.d.ts.map +1 -0
- package/dist/commands/notes-support.d.ts +125 -0
- package/dist/commands/notes-support.d.ts.map +1 -0
- package/dist/commands/notes-tree.d.ts +116 -0
- package/dist/commands/notes-tree.d.ts.map +1 -0
- package/dist/commands/object-id-input.d.ts +20 -0
- package/dist/commands/object-id-input.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +59 -0
- package/dist/commands/octopus-merge.d.ts.map +1 -0
- package/dist/commands/ort-merge.d.ts +126 -0
- package/dist/commands/ort-merge.d.ts.map +1 -0
- package/dist/commands/ort-recursive.d.ts +53 -0
- package/dist/commands/ort-recursive.d.ts.map +1 -0
- package/dist/commands/pack-refs-command.d.ts +20 -0
- package/dist/commands/pack-refs-command.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +44 -0
- package/dist/commands/patch-id.d.ts.map +1 -0
- package/dist/commands/pathspec-attributes.d.ts +64 -0
- package/dist/commands/pathspec-attributes.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +324 -0
- package/dist/commands/pathspec.d.ts.map +1 -0
- package/dist/commands/post-index-change.d.ts +33 -0
- package/dist/commands/post-index-change.d.ts.map +1 -0
- package/dist/commands/pretty-format.d.ts +222 -0
- package/dist/commands/pretty-format.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts +80 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -0
- package/dist/commands/pull-command.d.ts +59 -8
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +24 -8
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +112 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -0
- package/dist/commands/rebase-command.d.ts +507 -75
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/rebase-todo.d.ts +130 -0
- package/dist/commands/rebase-todo.d.ts.map +1 -0
- package/dist/commands/ref-decoration-filter.d.ts +53 -0
- package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
- package/dist/commands/reflog-messages.d.ts +98 -0
- package/dist/commands/reflog-messages.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +31 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +120 -0
- package/dist/commands/remote-transport.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +161 -7
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +103 -0
- package/dist/commands/restore-command.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +78 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -0
- package/dist/commands/rev-parse-command.d.ts +89 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -0
- package/dist/commands/revert-command.d.ts +46 -38
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-filenames.d.ts +95 -0
- package/dist/commands/revision-filenames.d.ts.map +1 -0
- package/dist/commands/revision-range.d.ts +67 -0
- package/dist/commands/revision-range.d.ts.map +1 -0
- package/dist/commands/revision-resolver.d.ts +325 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -0
- package/dist/commands/rm-command.d.ts +69 -7
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +191 -0
- package/dist/commands/sequencer-pick.d.ts.map +1 -0
- package/dist/commands/sequencer-support.d.ts +125 -0
- package/dist/commands/sequencer-support.d.ts.map +1 -0
- package/dist/commands/serve-repository.d.ts +52 -0
- package/dist/commands/serve-repository.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts +190 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-support.d.ts +268 -0
- package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +42 -8
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +156 -2
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +2 -0
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +23 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts +300 -15
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-format.d.ts +155 -0
- package/dist/commands/status-format.d.ts.map +1 -0
- package/dist/commands/status-header.d.ts +64 -0
- package/dist/commands/status-header.d.ts.map +1 -0
- package/dist/commands/strerror.d.ts +7 -0
- package/dist/commands/strerror.d.ts.map +1 -0
- package/dist/commands/submodule-config.d.ts +38 -0
- package/dist/commands/submodule-config.d.ts.map +1 -0
- package/dist/commands/submodule-summary-command.d.ts +80 -0
- package/dist/commands/submodule-summary-command.d.ts.map +1 -0
- package/dist/commands/submodule-summary.d.ts +150 -0
- package/dist/commands/submodule-summary.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +132 -0
- package/dist/commands/switch-command.d.ts.map +1 -0
- package/dist/commands/tag-command.d.ts +23 -2
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tracking-info.d.ts +64 -0
- package/dist/commands/tracking-info.d.ts.map +1 -0
- package/dist/commands/trailers.d.ts +73 -0
- package/dist/commands/trailers.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +85 -1
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +54 -0
- package/dist/commands/untracked-cache-support.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +108 -0
- package/dist/commands/worktree-add-command.d.ts.map +1 -0
- package/dist/commands/worktree-list-command.d.ts +69 -0
- package/dist/commands/worktree-list-command.d.ts.map +1 -0
- package/dist/commands/worktree-lock-command.d.ts +44 -0
- package/dist/commands/worktree-lock-command.d.ts.map +1 -0
- package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/commands/worktree-prune-command.d.ts +48 -0
- package/dist/commands/worktree-prune-command.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +59 -0
- package/dist/commands/worktree-remove-command.d.ts.map +1 -0
- package/dist/commands/worktree-repair-command.d.ts +35 -0
- package/dist/commands/worktree-repair-command.d.ts.map +1 -0
- package/dist/commands/worktree-support.d.ts +64 -0
- package/dist/commands/worktree-support.d.ts.map +1 -0
- package/dist/commands-DIJ91NnD.js +62225 -0
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/errors/add-errors.d.ts +55 -0
- package/dist/errors/add-errors.d.ts.map +1 -1
- package/dist/errors/checkout-errors.d.ts +16 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts +77 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/commit-errors.d.ts +9 -0
- package/dist/errors/commit-errors.d.ts.map +1 -1
- package/dist/errors/git-api-error.d.ts +59 -2
- package/dist/errors/git-api-error.d.ts.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +354 -19
- package/dist/errors/rebase-errors.d.ts +9 -0
- package/dist/errors/rebase-errors.d.ts.map +1 -1
- package/dist/errors/ref-errors.d.ts +32 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/transport-errors.d.ts +12 -2
- package/dist/errors/transport-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +35 -0
- package/dist/errors/worktree-errors.d.ts.map +1 -0
- package/dist/git-command-BGiOJ8Zk.js +7246 -0
- package/dist/git-command.d.ts +428 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +315 -5
- package/dist/git.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/index.d.ts +1 -1
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +167 -6
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +7 -3
- package/dist/remote-config/remote-refs.d.ts.map +1 -1
- package/dist/rename/detect-renames.d.ts +148 -0
- package/dist/rename/detect-renames.d.ts.map +1 -0
- package/dist/rename/git-similarity.d.ts +44 -0
- package/dist/rename/git-similarity.d.ts.map +1 -0
- package/dist/rename/index.d.ts +2 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/binary-patch.d.ts +11 -0
- package/dist/results/binary-patch.d.ts.map +1 -0
- package/dist/results/blame-format.d.ts +55 -0
- package/dist/results/blame-format.d.ts.map +1 -0
- package/dist/results/cherry-pick-result.d.ts +10 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +18 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +77 -0
- package/dist/results/combined-diff.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +32 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +34 -60
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-order.d.ts +25 -0
- package/dist/results/diff-order.d.ts.map +1 -0
- package/dist/results/diff-output.d.ts +249 -0
- package/dist/results/diff-output.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +15 -0
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +5 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -252
- package/dist/results/init-result.d.ts +7 -0
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/merge-result.d.ts +15 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +17 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +47 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/quote-path.d.ts +27 -0
- package/dist/results/quote-path.d.ts.map +1 -0
- package/dist/results/rebase-result.d.ts +28 -1
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +10 -0
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +5 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +60 -6
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-WVlBhVb1.js +2935 -0
- package/dist/transport-command.d.ts +44 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -11
- package/src/commands/add-command.ts +1291 -226
- package/src/commands/add-patch/add-interactive.ts +941 -0
- package/src/commands/add-patch/add-patch.ts +1169 -0
- package/src/commands/add-patch/index.ts +5 -0
- package/src/commands/add-patch/patch-backend.ts +239 -0
- package/src/commands/add-patch/patch-modes.ts +249 -0
- package/src/commands/add-patch/patch-session.ts +159 -0
- package/src/commands/am/am-command.ts +1111 -0
- package/src/commands/am/index.ts +2 -0
- package/src/commands/am/mailinfo.ts +1015 -0
- package/src/commands/am/patch-format.ts +121 -0
- package/src/commands/apply/apply-command.ts +842 -0
- package/src/commands/apply/apply-engine.ts +1602 -0
- package/src/commands/apply/apply-parse.ts +1210 -0
- package/src/commands/apply/apply-types.ts +112 -0
- package/src/commands/apply/index.ts +5 -0
- package/src/commands/apply/latin1.ts +171 -0
- package/src/commands/apply/whitespace.ts +260 -0
- package/src/commands/attributes-source.ts +96 -0
- package/src/commands/backfill-command.ts +694 -0
- package/src/commands/bisect/bisect-checkout.ts +217 -0
- package/src/commands/bisect/bisect-command.ts +788 -0
- package/src/commands/bisect/bisect-engine.ts +1080 -0
- package/src/commands/bisect/bisect-graph.ts +595 -0
- package/src/commands/bisect/bisect-quote.ts +92 -0
- package/src/commands/bisect/index.ts +4 -0
- package/src/commands/blame-command.ts +711 -986
- package/src/commands/branch-command.ts +354 -32
- package/src/commands/branch-tracking.ts +331 -0
- package/src/commands/checkout-command.ts +1290 -243
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +504 -156
- package/src/commands/clone-command.ts +748 -69
- package/src/commands/comment-char-config.ts +160 -0
- package/src/commands/commit-command.ts +1782 -166
- package/src/commands/core-config.ts +166 -6
- package/src/commands/date-format.ts +668 -0
- package/src/commands/default-branch.ts +196 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1916 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +622 -68
- package/src/commands/format-patch-command.ts +974 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3464 -0
- package/src/commands/fsck/fsck-loose.ts +297 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1085 -0
- package/src/commands/fsck/fsck-object-table.ts +373 -0
- package/src/commands/fsck/fsck-pack.ts +634 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +252 -0
- package/src/commands/gc-command.ts +324 -77
- package/src/commands/git-date.ts +9 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1483 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +711 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +84 -0
- package/src/commands/init-command.ts +194 -14
- package/src/commands/legacy-remotes.ts +224 -0
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1930 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +105 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1416 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1219 -0
- package/src/commands/message-cleanup.ts +275 -0
- package/src/commands/mv-command.ts +976 -0
- package/src/commands/notes-command.ts +890 -0
- package/src/commands/notes-commands.ts +87 -0
- package/src/commands/notes-merge-command.ts +777 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +617 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +378 -0
- package/src/commands/ort-merge.ts +1660 -0
- package/src/commands/ort-recursive.ts +160 -0
- package/src/commands/pack-refs-command.ts +39 -22
- package/src/commands/patch-id.ts +204 -0
- package/src/commands/pathspec-attributes.ts +162 -0
- package/src/commands/pathspec.ts +1199 -0
- package/src/commands/post-index-change.ts +62 -0
- package/src/commands/pretty-format.ts +1432 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +326 -33
- package/src/commands/push-command.ts +257 -29
- package/src/commands/read-tree-command.ts +861 -0
- package/src/commands/rebase-command.ts +3820 -372
- package/src/commands/rebase-todo.ts +584 -0
- package/src/commands/ref-decoration-filter.ts +118 -0
- package/src/commands/reflog-messages.ts +177 -0
- package/src/commands/remote-command.ts +124 -23
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +821 -104
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +299 -0
- package/src/commands/revert-command.ts +152 -399
- package/src/commands/revision-filenames.ts +254 -0
- package/src/commands/revision-range.ts +222 -0
- package/src/commands/revision-resolver.ts +1397 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +874 -0
- package/src/commands/sequencer-support.ts +876 -0
- package/src/commands/serve-repository.ts +125 -0
- package/src/commands/sparse-checkout-command.ts +1389 -0
- package/src/commands/sparse-checkout-support.ts +793 -0
- package/src/commands/stash-apply-command.ts +376 -343
- package/src/commands/stash-create-command.ts +625 -42
- package/src/commands/stash-drop-command.ts +15 -2
- package/src/commands/stash-working-tree.ts +168 -24
- package/src/commands/status-command.ts +1326 -105
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +332 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +333 -0
- package/src/commands/submodule-summary.ts +446 -0
- package/src/commands/switch-command.ts +402 -0
- package/src/commands/tag-command.ts +129 -41
- package/src/commands/tracking-info.ts +201 -0
- package/src/commands/trailers.ts +417 -0
- package/src/commands/tree-restore.ts +204 -4
- package/src/commands/untracked-cache-support.ts +198 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +206 -0
- package/src/commands/worktree-lock-command.ts +96 -0
- package/src/commands/worktree-overwrite-checks.ts +452 -26
- package/src/commands/worktree-prune-command.ts +99 -0
- package/src/commands/worktree-remove-command.ts +186 -0
- package/src/commands/worktree-repair-command.ts +59 -0
- package/src/commands/worktree-support.ts +214 -0
- package/src/core-commands/add.command.impl.ts +8 -2
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +26 -2
- package/src/errors/command-errors.ts +101 -1
- package/src/errors/commit-errors.ts +18 -2
- package/src/errors/git-api-error.ts +82 -2
- package/src/errors/index.ts +1 -0
- package/src/errors/merge-errors.ts +2 -2
- package/src/errors/rebase-errors.ts +12 -0
- package/src/errors/ref-errors.ts +56 -2
- package/src/errors/remote-errors.ts +2 -2
- package/src/errors/stash-errors.ts +1 -1
- package/src/errors/transport-errors.ts +20 -4
- package/src/errors/worktree-errors.ts +49 -0
- package/src/git-command.ts +1207 -118
- package/src/git.ts +538 -12
- package/src/index.ts +1 -1
- package/src/remote-config/index.ts +2 -0
- package/src/remote-config/remote-config-store.ts +378 -18
- package/src/remote-config/remote-refs.ts +22 -6
- package/src/rename/detect-renames.ts +715 -0
- package/src/rename/git-similarity.ts +116 -0
- package/src/rename/index.ts +2 -0
- package/src/results/binary-patch.ts +401 -0
- package/src/results/blame-format.ts +239 -0
- package/src/results/cherry-pick-result.ts +10 -0
- package/src/results/clone-result.ts +21 -0
- package/src/results/combined-diff.ts +585 -0
- package/src/results/diff-entry.ts +35 -0
- package/src/results/diff-formatter.ts +152 -288
- package/src/results/diff-order.ts +64 -0
- package/src/results/diff-output.ts +1053 -0
- package/src/results/fetch-result.ts +15 -0
- package/src/results/index.ts +5 -0
- package/src/results/init-result.ts +9 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +17 -3
- package/src/results/push-result.ts +48 -0
- package/src/results/quote-path.ts +103 -0
- package/src/results/rebase-result.ts +37 -0
- package/src/results/revert-result.ts +10 -0
- package/src/results/stash-result.ts +6 -0
- package/src/results/status-result.ts +127 -46
- package/src/transport-command.ts +121 -2
- package/dist/commands-CsLNyvZ1.js +0 -12587
- package/dist/status-result-BpyUK1Sg.js +0 -519
|
@@ -0,0 +1,861 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git read-tree` (builtin/read-tree.c over unpack-trees.c): read trees into the index,
|
|
3
|
+
* merging them with it (`-m`: one-, two- and three-way), optionally updating the worktree.
|
|
4
|
+
*/
|
|
5
|
+
import { FileMode, type ObjectId } from "@statewalker/vcs-core";
|
|
6
|
+
import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
|
|
7
|
+
import {
|
|
8
|
+
attributesIndexOf,
|
|
9
|
+
cacheTreeOfTree,
|
|
10
|
+
entryStatOf,
|
|
11
|
+
type IndexEntryOptions,
|
|
12
|
+
isIndexUnborn,
|
|
13
|
+
repairCacheTree,
|
|
14
|
+
type StagingEntry,
|
|
15
|
+
type Worktree,
|
|
16
|
+
} from "@statewalker/vcs-working-tree";
|
|
17
|
+
|
|
18
|
+
import { ReadTreeFailedError } from "../errors/index.js";
|
|
19
|
+
import { GitCommand } from "../git-command.js";
|
|
20
|
+
import { coreBool, worktreeModeTrust } from "./core-config.js";
|
|
21
|
+
import {
|
|
22
|
+
firstPlainError,
|
|
23
|
+
flatTree,
|
|
24
|
+
type MergeWriteContext,
|
|
25
|
+
plainUnpackError,
|
|
26
|
+
planPathsRestore,
|
|
27
|
+
rewriteIndex,
|
|
28
|
+
switchTrees,
|
|
29
|
+
} from "./merge-support.js";
|
|
30
|
+
import { resetMerge } from "./sequencer-support.js";
|
|
31
|
+
import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
|
|
32
|
+
import { restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
|
|
33
|
+
import {
|
|
34
|
+
type CheckedEntry,
|
|
35
|
+
entryNotUptodate,
|
|
36
|
+
IndexCaseFolding,
|
|
37
|
+
pruneEmptyParents,
|
|
38
|
+
removeCaseVariants,
|
|
39
|
+
untrackedUnder,
|
|
40
|
+
} from "./worktree-overwrite-checks.js";
|
|
41
|
+
|
|
42
|
+
/** unpack-trees' `MAX_UNPACK_TREES`. */
|
|
43
|
+
const MAX_UNPACK_TREES = 8;
|
|
44
|
+
|
|
45
|
+
/** Result of {@link ReadTreeCommand}. */
|
|
46
|
+
export interface ReadTreeResult {
|
|
47
|
+
/**
|
|
48
|
+
* What git prints on stderr without failing: the deprecation warning of a bare
|
|
49
|
+
* `read-tree`, the sparse checkout's warnings
|
|
50
|
+
*/
|
|
51
|
+
warnings: string[];
|
|
52
|
+
/** The paths left unmerged (three-way merge stages 1-3) */
|
|
53
|
+
unmerged: string[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const same = (a: CheckedEntry | undefined, b: CheckedEntry | undefined) =>
|
|
57
|
+
a === undefined || b === undefined ? a === b : a.objectId === b.objectId && a.mode === b.mode;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Read trees into the index (`git read-tree`).
|
|
61
|
+
*
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // the index becomes HEAD's tree (stat data and flags gone)
|
|
64
|
+
* await git.readTree().addTree("HEAD").call();
|
|
65
|
+
*
|
|
66
|
+
* // a fast-forward of the index and the worktree from HEAD to `next`
|
|
67
|
+
* await git.readTree().setMerge(true).setUpdate(true).addTree("HEAD").addTree("next").call();
|
|
68
|
+
*
|
|
69
|
+
* // a three-way merge leaving the conflicts as stages 1-3
|
|
70
|
+
* await git.readTree().setMerge(true).addTree(base).addTree("HEAD").addTree(other).call();
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* A refusal is unpack-trees' plain message for the first path refused (`error: Entry 'x'
|
|
74
|
+
* would be overwritten by merge. Cannot merge.`), thrown as {@link ReadTreeFailedError}
|
|
75
|
+
* before anything changed. One tree read without `--prefix` leaves the index's cache-tree
|
|
76
|
+
* primed with it (`prime_cache_tree`); otherwise each directory is valid where its tree is
|
|
77
|
+
* stored (`cache_tree_update` with `WRITE_TREE_REPAIR`), none while conflicts remain.
|
|
78
|
+
*/
|
|
79
|
+
export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
|
|
80
|
+
private treeishes: string[] = [];
|
|
81
|
+
private merge = false;
|
|
82
|
+
private reset = false;
|
|
83
|
+
private prefix: string | undefined;
|
|
84
|
+
private update = false;
|
|
85
|
+
private indexOnly = false;
|
|
86
|
+
private empty = false;
|
|
87
|
+
private trivial = false;
|
|
88
|
+
private aggressive = false;
|
|
89
|
+
private skipSparseCheckout = false;
|
|
90
|
+
|
|
91
|
+
/** A tree-ish to read (up to eight). */
|
|
92
|
+
addTree(treeish: string): this {
|
|
93
|
+
this.checkCallable();
|
|
94
|
+
this.treeishes.push(treeish);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** `-m`: merge the trees with the index (one-, two- or three-way by their number). */
|
|
99
|
+
setMerge(merge: boolean): this {
|
|
100
|
+
this.checkCallable();
|
|
101
|
+
this.merge = merge;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** `--reset`: as `-m`, unmerged entries discarded and local changes no refusal. */
|
|
106
|
+
setReset(reset: boolean): this {
|
|
107
|
+
this.checkCallable();
|
|
108
|
+
this.reset = reset;
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** `--prefix=<dir>/`: the tree read under `<dir>/` (bound into the index, which keeps the rest). */
|
|
113
|
+
setPrefix(prefix: string | undefined): this {
|
|
114
|
+
this.checkCallable();
|
|
115
|
+
this.prefix = prefix;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** `-u`: the worktree updated with the merge's result. */
|
|
120
|
+
setUpdate(update: boolean): this {
|
|
121
|
+
this.checkCallable();
|
|
122
|
+
this.update = update;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** `-i`: the worktree is not looked at (no up-to-date check). */
|
|
127
|
+
setIndexOnly(indexOnly: boolean): this {
|
|
128
|
+
this.checkCallable();
|
|
129
|
+
this.indexOnly = indexOnly;
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** `--empty`: empty the index. */
|
|
134
|
+
setEmpty(empty: boolean): this {
|
|
135
|
+
this.checkCallable();
|
|
136
|
+
this.empty = empty;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** `--trivial`: a three-way merge only where no path needs a file-level merge. */
|
|
141
|
+
setTrivial(trivial: boolean): this {
|
|
142
|
+
this.checkCallable();
|
|
143
|
+
this.trivial = trivial;
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** `--aggressive`: a three-way merge also resolving deletions and identical additions. */
|
|
148
|
+
setAggressive(aggressive: boolean): this {
|
|
149
|
+
this.checkCallable();
|
|
150
|
+
this.aggressive = aggressive;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* `-v`: accepted for parity. git shows only a delayed progress meter ("Updating files"),
|
|
156
|
+
* which an update shorter than two seconds never prints; nothing is reported here.
|
|
157
|
+
*/
|
|
158
|
+
setVerbose(_verbose: boolean): this {
|
|
159
|
+
this.checkCallable();
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** `--no-sparse-checkout`: the sparse-checkout patterns are not applied. */
|
|
164
|
+
setSkipSparseCheckout(skip: boolean): this {
|
|
165
|
+
this.checkCallable();
|
|
166
|
+
this.skipSparseCheckout = skip;
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async call(): Promise<ReadTreeResult> {
|
|
171
|
+
this.checkCallable();
|
|
172
|
+
this.setCallable(false);
|
|
173
|
+
const fatal = (message: string): never => {
|
|
174
|
+
throw new ReadTreeFailedError(`fatal: ${message}`);
|
|
175
|
+
};
|
|
176
|
+
const result: ReadTreeResult = { warnings: [], unmerged: [] };
|
|
177
|
+
const prefixSet = this.prefix !== undefined;
|
|
178
|
+
if (Number(this.merge) + Number(this.reset) + Number(prefixSet) > 1) {
|
|
179
|
+
fatal("Which one? -m, --reset, or --prefix?");
|
|
180
|
+
}
|
|
181
|
+
if (this.prefix?.startsWith("/")) fatal("Invalid prefix, prefix cannot start with '/'");
|
|
182
|
+
await this.readCurrentIndex();
|
|
183
|
+
|
|
184
|
+
let merge = this.merge;
|
|
185
|
+
let unmergedIndex = false;
|
|
186
|
+
for await (const e of this.staging.entries()) {
|
|
187
|
+
if (e.stage !== 0) {
|
|
188
|
+
unmergedIndex = true;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (this.reset || merge || prefixSet) {
|
|
193
|
+
if (unmergedIndex && (prefixSet || merge)) {
|
|
194
|
+
fatal("You need to resolve your current index first");
|
|
195
|
+
}
|
|
196
|
+
merge = true;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const treeIds: ObjectId[] = [];
|
|
200
|
+
for (const name of this.treeishes) {
|
|
201
|
+
if (treeIds.length >= MAX_UNPACK_TREES) {
|
|
202
|
+
fatal(`I cannot read more than ${MAX_UNPACK_TREES} trees`);
|
|
203
|
+
}
|
|
204
|
+
const id = await this.resolveRevision(name).catch(() => undefined);
|
|
205
|
+
const tree = id ? await this.revisionResolver().peelToType(id, "tree") : undefined;
|
|
206
|
+
if (!id) fatal(`Not a valid object name ${name}`);
|
|
207
|
+
if (!tree) fatal(`failed to unpack tree object ${name}`);
|
|
208
|
+
treeIds.push(tree as ObjectId);
|
|
209
|
+
}
|
|
210
|
+
if (treeIds.length === 0 && !this.empty && !merge) {
|
|
211
|
+
result.warnings.push(
|
|
212
|
+
"warning: read-tree: emptying the index with no arguments is deprecated; use --empty",
|
|
213
|
+
);
|
|
214
|
+
} else if (treeIds.length > 0 && this.empty) {
|
|
215
|
+
fatal("passing trees as arguments contradicts --empty");
|
|
216
|
+
}
|
|
217
|
+
if (this.update && this.indexOnly) fatal("-u and -i at the same time makes no sense");
|
|
218
|
+
if ((this.update || this.indexOnly) && !merge) {
|
|
219
|
+
fatal(`${this.update ? "-u" : "-i"} is meaningless without -m, --reset, or --prefix`);
|
|
220
|
+
}
|
|
221
|
+
if (merge && treeIds.length === 0) fatal("you must specify at least one tree to merge");
|
|
222
|
+
|
|
223
|
+
// the worktree checked (none with -i) and updated (-u)
|
|
224
|
+
const checked = this.indexOnly ? undefined : this.worktreeAccess;
|
|
225
|
+
const sequencerCtx = {
|
|
226
|
+
workingCopy: this.workingCopy,
|
|
227
|
+
worktree: checked,
|
|
228
|
+
staging: this.staging,
|
|
229
|
+
blobs: this.blobs,
|
|
230
|
+
trees: this.trees,
|
|
231
|
+
commits: this.commits,
|
|
232
|
+
refs: this.refsStore,
|
|
233
|
+
sparseWarnings: result.warnings,
|
|
234
|
+
};
|
|
235
|
+
const refused = (message: string | undefined, paths: string[] = []) => {
|
|
236
|
+
if (message) throw new ReadTreeFailedError(message, paths);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
if (!merge) {
|
|
240
|
+
await this.readWithoutMerge(treeIds);
|
|
241
|
+
} else if (prefixSet) {
|
|
242
|
+
const prefix = (this.prefix as string).replace(/\/*$/, "/");
|
|
243
|
+
await this.bindMerge(sequencerCtx, treeIds, prefix === "/" ? "" : prefix, result);
|
|
244
|
+
} else if (treeIds.length === 1) {
|
|
245
|
+
const tree = treeIds[0] as ObjectId;
|
|
246
|
+
const refusal = await resetMerge(sequencerCtx, tree, tree, {
|
|
247
|
+
hard: this.reset,
|
|
248
|
+
update: this.update,
|
|
249
|
+
overwriteUntracked: this.reset,
|
|
250
|
+
skipSparseCheckout: this.skipSparseCheckout,
|
|
251
|
+
targetTree: tree,
|
|
252
|
+
plain: true,
|
|
253
|
+
});
|
|
254
|
+
refused(refusal?.message, refusal?.paths);
|
|
255
|
+
} else if (treeIds.length === 2) {
|
|
256
|
+
const [h, m] = treeIds as [ObjectId, ObjectId];
|
|
257
|
+
const refusal = await switchTrees(
|
|
258
|
+
sequencerCtx,
|
|
259
|
+
await flatTree(this.trees, h),
|
|
260
|
+
await flatTree(this.trees, m),
|
|
261
|
+
{
|
|
262
|
+
action: "merge",
|
|
263
|
+
operation: "read-tree",
|
|
264
|
+
update: this.update,
|
|
265
|
+
skipSparseCheckout: this.skipSparseCheckout,
|
|
266
|
+
plainErrors: true,
|
|
267
|
+
initialCheckout: await isIndexUnborn(this.staging),
|
|
268
|
+
},
|
|
269
|
+
);
|
|
270
|
+
refused(refusal?.message, refusal?.paths);
|
|
271
|
+
} else {
|
|
272
|
+
await this.threewayMerge(sequencerCtx, treeIds, result);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// read-tree starts from no cache-tree and resolve-undo (cache_tree_free,
|
|
276
|
+
// resolve_undo_clear_index); one tree read whole primes it
|
|
277
|
+
this.staging.clearResolveUndo?.();
|
|
278
|
+
if (treeIds.length === 1 && !prefixSet) {
|
|
279
|
+
this.staging.setCacheTree?.(await cacheTreeOfTree(this.trees, treeIds[0] as ObjectId));
|
|
280
|
+
} else {
|
|
281
|
+
this.staging.setCacheTree?.(await this.repairedCacheTree());
|
|
282
|
+
}
|
|
283
|
+
await this.staging.write();
|
|
284
|
+
for await (const e of this.staging.entries()) {
|
|
285
|
+
if (e.stage !== 0 && result.unmerged[result.unmerged.length - 1] !== e.path) {
|
|
286
|
+
result.unmerged.push(e.path);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** `cache_tree_update(WRITE_TREE_SILENT | WRITE_TREE_REPAIR)` of the index as it is. */
|
|
293
|
+
private async repairedCacheTree() {
|
|
294
|
+
const entries = await this.entryList();
|
|
295
|
+
const trees = this.trees;
|
|
296
|
+
return repairCacheTree(
|
|
297
|
+
{
|
|
298
|
+
has: async (id: ObjectId) => id === this.objectFormat.emptyTreeId || (await trees.has(id)),
|
|
299
|
+
},
|
|
300
|
+
entries,
|
|
301
|
+
// the repository's format: an empty index has no id to tell it (read-tree --empty)
|
|
302
|
+
this.objectFormat,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private async entryList(): Promise<readonly StagingEntry[]> {
|
|
307
|
+
const list = this.staging.entryList?.();
|
|
308
|
+
if (list) return list;
|
|
309
|
+
const out: StagingEntry[] = [];
|
|
310
|
+
for await (const e of this.staging.entries()) out.push(e);
|
|
311
|
+
return out;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* unpack-trees without `-m`: the index is the trees' entries, at stage 0, without stat
|
|
316
|
+
* data or flags, added in `traverse_trees` order (at each name the trees' files in their
|
|
317
|
+
* order, then what a directory of that name holds), each with `add_index_entry`'s
|
|
318
|
+
* `OK_TO_REPLACE`: a later tree's entry replaces an earlier one's, a directory's files
|
|
319
|
+
* replace a file of its name, whichever tree holds which.
|
|
320
|
+
*/
|
|
321
|
+
private async readWithoutMerge(treeIds: ObjectId[]): Promise<void> {
|
|
322
|
+
const flat = await Promise.all(treeIds.map((id) => flatTree(this.trees, id)));
|
|
323
|
+
const all = new Set<string>();
|
|
324
|
+
for (const m of flat) for (const p of m.keys()) all.add(p);
|
|
325
|
+
const entries = new Map<string, CheckedEntry>();
|
|
326
|
+
for (const path of traversalOrder(all)) {
|
|
327
|
+
for (const m of flat) {
|
|
328
|
+
const e = m.get(path);
|
|
329
|
+
if (!e) continue;
|
|
330
|
+
// add_index_entry with OK_TO_REPLACE: a file in place of a leading directory goes
|
|
331
|
+
// (nothing beneath the path is added yet: a directory's files come after it)
|
|
332
|
+
for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) {
|
|
333
|
+
entries.delete(path.slice(0, at));
|
|
334
|
+
}
|
|
335
|
+
entries.set(path, e);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
assertNoStageZeroClash(new Set(entries.keys()));
|
|
339
|
+
const builder = this.staging.createBuilder();
|
|
340
|
+
for (const path of [...entries.keys()].sort(compareGitPaths)) {
|
|
341
|
+
const e = entries.get(path) as CheckedEntry;
|
|
342
|
+
builder.add({ path, objectId: e.objectId, mode: e.mode, size: 0, mtime: 0 });
|
|
343
|
+
}
|
|
344
|
+
await builder.finish();
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* `bind_merge` (`--prefix=<dir>/`): the tree's entries under `<dir>/`, every index entry
|
|
349
|
+
* kept; a path both have is refused ("Entry 'x' overlaps with 'x'. Cannot bind."). The
|
|
350
|
+
* entries are added in `traverse_trees` order with `add_index_entry`'s `OK_TO_REPLACE`, so
|
|
351
|
+
* where a file and a directory clash the directory's entries, added after, win: an index
|
|
352
|
+
* file in place of a bound leading directory is dropped, and so is a bound file with index
|
|
353
|
+
* entries beneath it. With `-u` the new files are written: a file in the way is refused
|
|
354
|
+
* first, tracked or not ("Untracked working tree file 'a' would be overwritten by merge.",
|
|
355
|
+
* as `check_ok_to_remove` finds it kept in the result); where a bound file finds a
|
|
356
|
+
* directory, its tracked files must be up to date and go (`verify_clean_subdirectory` marks
|
|
357
|
+
* them removed), and the bound file is written in its place.
|
|
358
|
+
*/
|
|
359
|
+
private async bindMerge(
|
|
360
|
+
ctx: MergeWriteContext,
|
|
361
|
+
treeIds: ObjectId[],
|
|
362
|
+
prefix: string,
|
|
363
|
+
result: ReadTreeResult,
|
|
364
|
+
): Promise<void> {
|
|
365
|
+
if (treeIds.length !== 1) {
|
|
366
|
+
throw new ReadTreeFailedError(`error: Cannot do a bind merge of ${treeIds.length} trees`);
|
|
367
|
+
}
|
|
368
|
+
const tree = await flatTree(this.trees, treeIds[0] as ObjectId);
|
|
369
|
+
const index = new Map<string, StagingEntry>();
|
|
370
|
+
for (const e of await this.entryList()) index.set(e.path, e);
|
|
371
|
+
const target = new Map<string, CheckedEntry>();
|
|
372
|
+
for (const [p, e] of tree) target.set(`${prefix}${p}`, e);
|
|
373
|
+
const targetDirs = directoriesOf(target);
|
|
374
|
+
// an index file at a bound leading directory goes; a bound file with index files
|
|
375
|
+
// beneath it is replaced by them
|
|
376
|
+
const dropped = new Set<string>();
|
|
377
|
+
const beneath = new Map<string, string[]>();
|
|
378
|
+
for (const p of index.keys()) {
|
|
379
|
+
if (targetDirs.has(p)) dropped.add(p);
|
|
380
|
+
for (let at = p.indexOf("/"); at >= 0; at = p.indexOf("/", at + 1)) {
|
|
381
|
+
const dir = p.slice(0, at);
|
|
382
|
+
if (target.has(dir)) {
|
|
383
|
+
const list = beneath.get(dir) ?? [];
|
|
384
|
+
list.push(p);
|
|
385
|
+
beneath.set(dir, list);
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const checking = traversalOrder(target.keys());
|
|
391
|
+
const worktree = this.update ? ctx.worktree : undefined;
|
|
392
|
+
const sparse = worktree && !this.skipSparseCheckout ? await SparseUnpack.start(ctx) : undefined;
|
|
393
|
+
const trust = worktree ? worktreeModeTrust(this.workingCopy, worktree) : undefined;
|
|
394
|
+
const indexTime = this.staging.getUpdateTime();
|
|
395
|
+
const removing: string[] = [];
|
|
396
|
+
// core.ignorecase: verify_absent asks the source index folding case
|
|
397
|
+
const folding = await this.caseFolding(worktree, index);
|
|
398
|
+
const caseVariants: string[] = [];
|
|
399
|
+
for (const path of checking) {
|
|
400
|
+
if (index.has(path)) {
|
|
401
|
+
throw new ReadTreeFailedError(
|
|
402
|
+
`error: Entry '${path}' overlaps with '${path}'. Cannot bind.`,
|
|
403
|
+
[path],
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
if (!worktree || sparse?.leavesAlone(path)) continue;
|
|
407
|
+
const entry = await worktree.getEntry(path).catch(() => undefined);
|
|
408
|
+
if (entry?.isDirectory && entry.mode !== FileMode.GITLINK) {
|
|
409
|
+
const under = beneath.get(path) ?? [];
|
|
410
|
+
for (const old of under) {
|
|
411
|
+
const e = index.get(old) as StagingEntry;
|
|
412
|
+
if (await entryNotUptodate(worktree, old, e, trust, indexTime)) {
|
|
413
|
+
throw new ReadTreeFailedError(plainUnpackError("notUptodate", old), [old]);
|
|
414
|
+
}
|
|
415
|
+
removing.push(old);
|
|
416
|
+
dropped.add(old);
|
|
417
|
+
}
|
|
418
|
+
beneath.delete(path);
|
|
419
|
+
}
|
|
420
|
+
const error = await verifyAbsent(worktree, path, (p) => index.has(p), "untracked", {
|
|
421
|
+
folding,
|
|
422
|
+
caseVariants,
|
|
423
|
+
});
|
|
424
|
+
if (error) throw new ReadTreeFailedError(error, [path]);
|
|
425
|
+
}
|
|
426
|
+
const paths = checking.filter((p) => !beneath.has(p));
|
|
427
|
+
const stage0 = new Set<string>(paths);
|
|
428
|
+
for (const p of index.keys()) if (!dropped.has(p)) stage0.add(p);
|
|
429
|
+
assertNoStageZeroClash(stage0);
|
|
430
|
+
|
|
431
|
+
const writing = new Set(paths.filter((p) => !sparse || sparse.writes(p)));
|
|
432
|
+
if (worktree) {
|
|
433
|
+
if (sparse) {
|
|
434
|
+
// apply_sparse_checkout's unlinks before the files are written (check_updates)
|
|
435
|
+
const unlink = await sparse.leaving(
|
|
436
|
+
worktree,
|
|
437
|
+
(p) =>
|
|
438
|
+
(beneath.has(p) ? undefined : target.get(p)) ??
|
|
439
|
+
(dropped.has(p) ? undefined : index.get(p)),
|
|
440
|
+
{ trust },
|
|
441
|
+
);
|
|
442
|
+
await sparse.unlink(worktree, unlink);
|
|
443
|
+
}
|
|
444
|
+
for (const old of removing) {
|
|
445
|
+
const entry = await worktree.getEntry(old).catch(() => undefined);
|
|
446
|
+
if (entry && !entry.isDirectory) {
|
|
447
|
+
await worktree.remove(old);
|
|
448
|
+
await pruneEmptyParents(worktree, old);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// what verify_clean_subdirectory took as tracked goes with the directory
|
|
452
|
+
await removeCaseVariants(worktree, caseVariants);
|
|
453
|
+
if (writing.size > 0) await this.writeFiles(ctx, worktree, target, writing, index);
|
|
454
|
+
}
|
|
455
|
+
const changes = new Map<string, IndexEntryOptions[]>();
|
|
456
|
+
for (const p of dropped) changes.set(p, []);
|
|
457
|
+
for (const path of paths) {
|
|
458
|
+
const e = target.get(path) as CheckedEntry;
|
|
459
|
+
const stat = worktree && writing.has(path) ? await worktree.getEntry(path) : undefined;
|
|
460
|
+
changes.set(path, [
|
|
461
|
+
{
|
|
462
|
+
path,
|
|
463
|
+
objectId: e.objectId,
|
|
464
|
+
mode: e.mode,
|
|
465
|
+
...entryStatOf(stat && !stat.isDirectory ? stat : {}),
|
|
466
|
+
},
|
|
467
|
+
]);
|
|
468
|
+
}
|
|
469
|
+
await rewriteIndex(this.staging, changes);
|
|
470
|
+
if (sparse && worktree) {
|
|
471
|
+
const outcome = await sparse.finish(ctx, { written: writing });
|
|
472
|
+
pushSparseWarnings(result.warnings, sparse, outcome, false);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** The source index's case-folding lookups under `core.ignorecase` (undefined: off). */
|
|
477
|
+
private async caseFolding(
|
|
478
|
+
worktree: Worktree | undefined,
|
|
479
|
+
index: Map<string, unknown>,
|
|
480
|
+
): Promise<IndexCaseFolding | undefined> {
|
|
481
|
+
if (!worktree || !coreBool(this.workingCopy, "ignorecase", false)) return undefined;
|
|
482
|
+
return new IndexCaseFolding(index, await restoreCaseOptions(worktree, true));
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** The files of `writing` written from `target` (smudged with the result's attributes). */
|
|
486
|
+
private async writeFiles(
|
|
487
|
+
ctx: MergeWriteContext,
|
|
488
|
+
worktree: Worktree,
|
|
489
|
+
target: Map<string, CheckedEntry>,
|
|
490
|
+
writing: Set<string>,
|
|
491
|
+
index: Map<string, CheckedEntry>,
|
|
492
|
+
): Promise<void> {
|
|
493
|
+
const plan = await planPathsRestore(ctx, target, undefined, writing, "read-tree");
|
|
494
|
+
const attributes = new Map<string, ObjectId>();
|
|
495
|
+
for (const [p, e] of index) if (p.endsWith(".gitattributes")) attributes.set(p, e.objectId);
|
|
496
|
+
for (const p of writing) {
|
|
497
|
+
if (p.endsWith(".gitattributes")) attributes.set(p, (target.get(p) as CheckedEntry).objectId);
|
|
498
|
+
}
|
|
499
|
+
await writeTreeRestorePlan(worktree, ctx.blobs, plan, "read-tree", {
|
|
500
|
+
symlinks: worktreeModeTrust(this.workingCopy, worktree).symlinks,
|
|
501
|
+
gitlinks: true,
|
|
502
|
+
replaceInTheWay: true,
|
|
503
|
+
attributes: { direction: "checkout", index: attributesIndexOf(attributes) },
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* `threeway_merge` over `<base>... <head> <remote>`: the trivial cases resolved (the
|
|
509
|
+
* index must hold the head's entry, or the result's where `#14ALT`/`#2ALT` allow it),
|
|
510
|
+
* the rest left as stages 1 (the first base), 2 and 3, the worktree untouched there.
|
|
511
|
+
* `--aggressive` resolves deletions on one side with the other unchanged, deletions on
|
|
512
|
+
* both, and identical additions. `--trivial` fails where a file-level merge is needed.
|
|
513
|
+
*
|
|
514
|
+
* A path that is a file in some trees and a directory in others is unpack-trees'
|
|
515
|
+
* file/directory conflict: the trees holding the directory (or a file in place of one of
|
|
516
|
+
* the path's leading directories) stand as `df_conflict_entry` there, which matches
|
|
517
|
+
* nothing, is no stage, and keeps `#14`/`#2ALT` (a conflicting head) and `#13`/`#3ALT`
|
|
518
|
+
* (a conflicting remote) from resolving. Every check runs before anything is written.
|
|
519
|
+
*/
|
|
520
|
+
private async threewayMerge(
|
|
521
|
+
ctx: MergeWriteContext,
|
|
522
|
+
treeIds: ObjectId[],
|
|
523
|
+
result: ReadTreeResult,
|
|
524
|
+
): Promise<void> {
|
|
525
|
+
const flat = await Promise.all(treeIds.map((id) => flatTree(this.trees, id)));
|
|
526
|
+
const dirs = flat.map(directoriesOf);
|
|
527
|
+
const bases = flat.slice(0, -2);
|
|
528
|
+
const indexEntries = new Map<string, StagingEntry>();
|
|
529
|
+
for (const e of await this.entryList()) if (e.stage === 0) indexEntries.set(e.path, e);
|
|
530
|
+
const checkedWorktree = ctx.worktree;
|
|
531
|
+
const worktree = this.update ? checkedWorktree : undefined;
|
|
532
|
+
const sparse = worktree && !this.skipSparseCheckout ? await SparseUnpack.start(ctx) : undefined;
|
|
533
|
+
const quiet = (p: string) => sparse?.leavesAlone(p) === true;
|
|
534
|
+
const trust = checkedWorktree
|
|
535
|
+
? worktreeModeTrust(this.workingCopy, checkedWorktree)
|
|
536
|
+
: undefined;
|
|
537
|
+
const indexTime = this.staging.getUpdateTime();
|
|
538
|
+
// core.ignorecase: verify_absent asks the source index folding case
|
|
539
|
+
const folding = await this.caseFolding(worktree, indexEntries);
|
|
540
|
+
const caseVariants: string[] = [];
|
|
541
|
+
|
|
542
|
+
const paths = new Set<string>(indexEntries.keys());
|
|
543
|
+
for (const m of flat) for (const p of m.keys()) paths.add(p);
|
|
544
|
+
const sorted = traversalOrder(paths);
|
|
545
|
+
|
|
546
|
+
/** The entry tree `k` stands with at `path` (df_conflict_entry, a file, or none). */
|
|
547
|
+
const stageOf = (k: number, path: string, anyTree: boolean): CheckedEntry | undefined => {
|
|
548
|
+
const m = flat[k] as Map<string, CheckedEntry>;
|
|
549
|
+
const e = m.get(path);
|
|
550
|
+
if (e) return e;
|
|
551
|
+
if (!anyTree) return undefined;
|
|
552
|
+
if ((dirs[k] as Set<string>).has(path)) return DF_CONFLICT;
|
|
553
|
+
for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) {
|
|
554
|
+
if (m.has(path.slice(0, at))) return DF_CONFLICT;
|
|
555
|
+
}
|
|
556
|
+
return undefined;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
const changes = new Map<string, IndexEntryOptions[]>();
|
|
560
|
+
const writes = new Set<string>();
|
|
561
|
+
const removes = new Set<string>();
|
|
562
|
+
const conflicted: string[] = [];
|
|
563
|
+
let nontrivial = false;
|
|
564
|
+
const fail = (message: string, path: string): never => {
|
|
565
|
+
throw new ReadTreeFailedError(message, [path]);
|
|
566
|
+
};
|
|
567
|
+
const verifyUptodate = async (old: StagingEntry) => {
|
|
568
|
+
if (!checkedWorktree || quiet(old.path)) return;
|
|
569
|
+
if (await entryNotUptodate(checkedWorktree, old.path, old, trust, indexTime)) {
|
|
570
|
+
fail(`error: Entry '${old.path}' not uptodate. Cannot merge.`, old.path);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
// check_ok_to_remove: a file in the way is expendable only where this merge already
|
|
574
|
+
// removes its entry (CE_REMOVE in the result)
|
|
575
|
+
const removedHere = (p: string) => removes.has(p);
|
|
576
|
+
const absent = async (path: string, kind: "untracked" | "untrackedRemoved") => {
|
|
577
|
+
if (!worktree || quiet(path)) return;
|
|
578
|
+
const error = await verifyAbsent(worktree, path, (p) => indexEntries.has(p), kind, {
|
|
579
|
+
leadingOk: removedHere,
|
|
580
|
+
folding,
|
|
581
|
+
caseVariants,
|
|
582
|
+
});
|
|
583
|
+
if (error) fail(error, path);
|
|
584
|
+
};
|
|
585
|
+
// verify_absent_if_directory passes over an entry leaving the checkout (CE_SKIP_WORKTREE
|
|
586
|
+
// or CE_NEW_SKIP_WORKTREE): verify_uptodate then speaks for a directory in its place
|
|
587
|
+
const absentIfDirectory = async (path: string, old: StagingEntry) => {
|
|
588
|
+
if (!worktree || quiet(path) || old.skipWorktree || sparse?.outside(path)) return;
|
|
589
|
+
const entry = await worktree.getEntry(path).catch(() => undefined);
|
|
590
|
+
if (!entry?.isDirectory || entry.mode === FileMode.GITLINK) return;
|
|
591
|
+
if (await untrackedUnder(worktree, path, (p) => indexEntries.has(p))) {
|
|
592
|
+
fail(plainUnpackError("lostDir", path), path);
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
const mergedEntry = async (ce: CheckedEntry, old: StagingEntry | undefined, path: string) => {
|
|
596
|
+
if (!old) {
|
|
597
|
+
await absent(path, "untracked");
|
|
598
|
+
changes.set(path, [{ path, objectId: ce.objectId, mode: ce.mode, size: 0, mtime: 0 }]);
|
|
599
|
+
writes.add(path);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
if (same(old, ce)) return; // the old entry kept, stat data and flags with it
|
|
603
|
+
await verifyUptodate(old);
|
|
604
|
+
changes.set(path, [
|
|
605
|
+
{
|
|
606
|
+
path,
|
|
607
|
+
objectId: ce.objectId,
|
|
608
|
+
mode: ce.mode,
|
|
609
|
+
size: 0,
|
|
610
|
+
mtime: 0,
|
|
611
|
+
...(old.skipWorktree ? { skipWorktree: true } : {}),
|
|
612
|
+
},
|
|
613
|
+
]);
|
|
614
|
+
writes.add(path);
|
|
615
|
+
};
|
|
616
|
+
const deletedEntry = async (old: StagingEntry, path: string) => {
|
|
617
|
+
await absentIfDirectory(path, old);
|
|
618
|
+
await verifyUptodate(old);
|
|
619
|
+
changes.set(path, []);
|
|
620
|
+
removes.add(path);
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
for (const path of sorted) {
|
|
624
|
+
const index = indexEntries.get(path);
|
|
625
|
+
const anyTree = flat.some((m) => m.has(path)) || dirs.some((d) => d.has(path));
|
|
626
|
+
const stages = bases.map((_, k) => stageOf(k, path, anyTree));
|
|
627
|
+
let h = stageOf(flat.length - 2, path, anyTree);
|
|
628
|
+
let r = stageOf(flat.length - 1, path, anyTree);
|
|
629
|
+
const anyAncMissing = stages.some((s) => !s || s === DF_CONFLICT);
|
|
630
|
+
const noAncExists = stages.every((s) => !s || s === DF_CONFLICT);
|
|
631
|
+
const dfHead = h === DF_CONFLICT;
|
|
632
|
+
const dfRemote = r === DF_CONFLICT;
|
|
633
|
+
if (dfHead) h = undefined;
|
|
634
|
+
if (dfRemote) r = undefined;
|
|
635
|
+
let headMatch = 0;
|
|
636
|
+
let remoteMatch = 0;
|
|
637
|
+
if (!same(r, h)) {
|
|
638
|
+
stages.forEach((s, k) => {
|
|
639
|
+
if (same(s, h)) headMatch = k + 1;
|
|
640
|
+
if (same(s, r)) remoteMatch = k + 1;
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
// #14, #14ALT, #2ALT
|
|
644
|
+
if (r && !dfHead && headMatch && !remoteMatch) {
|
|
645
|
+
if (index && !same(index, r) && !same(index, h)) {
|
|
646
|
+
fail(`error: Entry '${path}' would be overwritten by merge. Cannot merge.`, path);
|
|
647
|
+
}
|
|
648
|
+
await mergedEntry(r, index, path);
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
if (index && !same(index, h)) {
|
|
652
|
+
fail(`error: Entry '${path}' would be overwritten by merge. Cannot merge.`, path);
|
|
653
|
+
}
|
|
654
|
+
if (h) {
|
|
655
|
+
// #5ALT, #15
|
|
656
|
+
if (same(h, r)) {
|
|
657
|
+
await mergedEntry(h, index, path);
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
// #13, #3ALT
|
|
661
|
+
if (!dfRemote && remoteMatch && !headMatch) {
|
|
662
|
+
await mergedEntry(h, index, path);
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
// #1
|
|
667
|
+
if (!h && !r && anyAncMissing) continue;
|
|
668
|
+
if (this.aggressive) {
|
|
669
|
+
const headDeleted = !h;
|
|
670
|
+
const remoteDeleted = !r;
|
|
671
|
+
const ce = index ?? h ?? r ?? stages.find((s) => s && s !== DF_CONFLICT);
|
|
672
|
+
if (
|
|
673
|
+
(headDeleted && remoteDeleted) ||
|
|
674
|
+
(headDeleted && r && remoteMatch) ||
|
|
675
|
+
(remoteDeleted && h && headMatch)
|
|
676
|
+
) {
|
|
677
|
+
if (index) {
|
|
678
|
+
await deletedEntry(index, path);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (ce && !headDeleted) await absent(path, "untrackedRemoved");
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
if (noAncExists && h && r && same(h, r)) {
|
|
685
|
+
await mergedEntry(h, index, path);
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
// the "no merge" cases: the index must be up to date
|
|
690
|
+
if (index) await verifyUptodate(index);
|
|
691
|
+
nontrivial = true;
|
|
692
|
+
const list: IndexEntryOptions[] = [];
|
|
693
|
+
if (!headMatch || !remoteMatch) {
|
|
694
|
+
const base = stages.find((s) => s !== undefined && s !== DF_CONFLICT);
|
|
695
|
+
if (base) list.push({ path, objectId: base.objectId, mode: base.mode, stage: 1 });
|
|
696
|
+
}
|
|
697
|
+
if (h) list.push({ path, objectId: h.objectId, mode: h.mode, stage: 2 });
|
|
698
|
+
if (r) list.push({ path, objectId: r.objectId, mode: r.mode, stage: 3 });
|
|
699
|
+
for (const e of list) Object.assign(e, { size: 0, mtime: 0 });
|
|
700
|
+
changes.set(path, list);
|
|
701
|
+
conflicted.push(path);
|
|
702
|
+
}
|
|
703
|
+
if (this.trivial && nontrivial) {
|
|
704
|
+
throw new ReadTreeFailedError("error: Merge requires file-level merging");
|
|
705
|
+
}
|
|
706
|
+
// never an index holding a file and a directory of one name at stage 0
|
|
707
|
+
const stage0 = new Set<string>();
|
|
708
|
+
for (const p of indexEntries.keys()) if (!changes.has(p)) stage0.add(p);
|
|
709
|
+
for (const [p, list] of changes) if (list.some((e) => !e.stage)) stage0.add(p);
|
|
710
|
+
assertNoStageZeroClash(stage0);
|
|
711
|
+
|
|
712
|
+
// the worktree: removals first, then the files written
|
|
713
|
+
sparse?.conflict(conflicted);
|
|
714
|
+
const target = new Map<string, CheckedEntry>();
|
|
715
|
+
for (const path of writes) {
|
|
716
|
+
const e = changes.get(path)?.[0];
|
|
717
|
+
if (e) target.set(path, e);
|
|
718
|
+
}
|
|
719
|
+
const writing = new Set([...writes].filter((p) => !sparse || sparse.writes(p)));
|
|
720
|
+
if (worktree) {
|
|
721
|
+
if (sparse) {
|
|
722
|
+
const unlink = await sparse.leaving(
|
|
723
|
+
worktree,
|
|
724
|
+
(p) => (removes.has(p) ? undefined : (target.get(p) ?? indexEntries.get(p))),
|
|
725
|
+
{ trust },
|
|
726
|
+
);
|
|
727
|
+
await sparse.unlink(worktree, unlink);
|
|
728
|
+
}
|
|
729
|
+
for (const path of removes) {
|
|
730
|
+
if (quiet(path)) continue;
|
|
731
|
+
const entry = await worktree.getEntry(path);
|
|
732
|
+
if (entry && !entry.isDirectory) {
|
|
733
|
+
await worktree.remove(path);
|
|
734
|
+
await pruneEmptyParents(worktree, path);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
// what verify_clean_subdirectory took as tracked goes with the directory
|
|
738
|
+
await removeCaseVariants(worktree, caseVariants);
|
|
739
|
+
if (writing.size > 0) await this.writeFiles(ctx, worktree, target, writing, indexEntries);
|
|
740
|
+
for (const path of writing) {
|
|
741
|
+
const stat = await worktree.getEntry(path);
|
|
742
|
+
const e = changes.get(path)?.[0];
|
|
743
|
+
if (e && stat && !stat.isDirectory) Object.assign(e, entryStatOf(stat));
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
await rewriteIndex(this.staging, changes);
|
|
747
|
+
if (sparse && worktree) {
|
|
748
|
+
const outcome = await sparse.finish(ctx, { written: worktree ? writing : new Set() });
|
|
749
|
+
pushSparseWarnings(result.warnings, sparse, outcome, false);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/** unpack-trees' `df_conflict_entry`: mode 0, no id; matches only itself, never a stage. */
|
|
755
|
+
const DF_CONFLICT: CheckedEntry = Object.freeze({ objectId: "" as ObjectId, mode: 0 });
|
|
756
|
+
|
|
757
|
+
/** The directories a flat tree holds (every leading path of its files). */
|
|
758
|
+
function directoriesOf(tree: Map<string, CheckedEntry>): Set<string> {
|
|
759
|
+
const out = new Set<string>();
|
|
760
|
+
for (const p of tree.keys()) {
|
|
761
|
+
for (let at = p.indexOf("/"); at >= 0; at = p.indexOf("/", at + 1)) out.add(p.slice(0, at));
|
|
762
|
+
}
|
|
763
|
+
return out;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* `paths` in `traverse_trees` order: the index's (a directory named as `<name>/`), except
|
|
768
|
+
* that a directory some path also names as a file comes right after that file (unpack-trees
|
|
769
|
+
* looks ahead for it), before the names that sort between the two.
|
|
770
|
+
*/
|
|
771
|
+
function traversalOrder(paths: Iterable<string>): string[] {
|
|
772
|
+
const all = new Set(paths);
|
|
773
|
+
const keys = new Map<string, string[]>();
|
|
774
|
+
const keyOf = (path: string): string[] => {
|
|
775
|
+
let key = keys.get(path);
|
|
776
|
+
if (!key) {
|
|
777
|
+
const parts = path.split("/");
|
|
778
|
+
key = parts.map((part, k) =>
|
|
779
|
+
k < parts.length - 1 && !all.has(parts.slice(0, k + 1).join("/")) ? `${part}/` : part,
|
|
780
|
+
);
|
|
781
|
+
keys.set(path, key);
|
|
782
|
+
}
|
|
783
|
+
return key;
|
|
784
|
+
};
|
|
785
|
+
return [...all].sort((a, b) => {
|
|
786
|
+
const x = keyOf(a);
|
|
787
|
+
const y = keyOf(b);
|
|
788
|
+
for (let k = 0; k < Math.min(x.length, y.length); k++) {
|
|
789
|
+
const c = compareGitPaths(x[k] as string, y[k] as string);
|
|
790
|
+
if (c !== 0) return c;
|
|
791
|
+
}
|
|
792
|
+
return x.length - y.length;
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* The last guard before an index is written: no stage-0 path may also be a leading
|
|
798
|
+
* directory of another (git's `add_index_entry` never leaves one; a tree written from such an
|
|
799
|
+
* index would hold two entries of one name).
|
|
800
|
+
*/
|
|
801
|
+
function assertNoStageZeroClash(paths: Set<string>): void {
|
|
802
|
+
for (const path of paths) {
|
|
803
|
+
for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) {
|
|
804
|
+
const dir = path.slice(0, at);
|
|
805
|
+
if (paths.has(dir)) {
|
|
806
|
+
throw new ReadTreeFailedError(
|
|
807
|
+
`fatal: BUG: the index would hold both '${dir}' and '${path}'`,
|
|
808
|
+
[dir, path],
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* unpack-trees' `verify_absent` of a path the merge adds (or, `untrackedRemoved`, removes)
|
|
817
|
+
* with no index entry there: an untracked file or link in the way (ignored files are
|
|
818
|
+
* expendable: `preserve_ignored` is off with `-u`), or a directory holding untracked files.
|
|
819
|
+
* A file in place of a leading directory is in the way even when tracked, unless the merge
|
|
820
|
+
* removes its entry (`leadingOk`: `check_ok_to_remove` finds it `CE_REMOVE` in the result).
|
|
821
|
+
* Returns git's plain message, or undefined.
|
|
822
|
+
*/
|
|
823
|
+
async function verifyAbsent(
|
|
824
|
+
worktree: Worktree,
|
|
825
|
+
path: string,
|
|
826
|
+
tracked: (path: string) => boolean,
|
|
827
|
+
kind: "untracked" | "untrackedRemoved",
|
|
828
|
+
options: {
|
|
829
|
+
leadingOk?: (path: string) => boolean;
|
|
830
|
+
/** `core.ignorecase`'s folding lookups of the source index (icase_exists, read_directory) */
|
|
831
|
+
folding?: IndexCaseFolding;
|
|
832
|
+
/** Receives the case variants a replaced directory holds (removed before the writes) */
|
|
833
|
+
caseVariants?: string[];
|
|
834
|
+
} = {},
|
|
835
|
+
): Promise<string | undefined> {
|
|
836
|
+
const parts = path.split("/");
|
|
837
|
+
for (let k = 1; k < parts.length; k++) {
|
|
838
|
+
const prefix = parts.slice(0, k).join("/");
|
|
839
|
+
const entry = await worktree.getEntry(prefix).catch(() => undefined);
|
|
840
|
+
if (!entry) return undefined;
|
|
841
|
+
if (entry.isDirectory) continue;
|
|
842
|
+
if (options.leadingOk?.(prefix) || (await worktree.isIgnored(prefix))) return undefined;
|
|
843
|
+
// check_ok_to_remove: a case variant of an index entry's own file (icase_exists)
|
|
844
|
+
if (await options.folding?.exists(worktree, prefix, entry)) return undefined;
|
|
845
|
+
return firstPlainError({ [kind]: [prefix] });
|
|
846
|
+
}
|
|
847
|
+
const entry = await worktree.getEntry(path).catch(() => undefined);
|
|
848
|
+
if (!entry) return undefined;
|
|
849
|
+
if (entry.isDirectory) {
|
|
850
|
+
if (entry.mode === FileMode.GITLINK) return undefined;
|
|
851
|
+
const variants = options.caseVariants ? options.folding?.variants() : undefined;
|
|
852
|
+
if (await untrackedUnder(worktree, path, tracked, false, variants)) {
|
|
853
|
+
return firstPlainError({ lostDir: [path] });
|
|
854
|
+
}
|
|
855
|
+
if (variants) options.caseVariants?.push(...variants.found);
|
|
856
|
+
return undefined;
|
|
857
|
+
}
|
|
858
|
+
if (await worktree.isIgnored(path)) return undefined;
|
|
859
|
+
if (await options.folding?.exists(worktree, path, entry)) return undefined;
|
|
860
|
+
return firstPlainError({ [kind]: [path] });
|
|
861
|
+
}
|