@statewalker/vcs-commands 0.5.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 +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 +117 -0
- 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 +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/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 +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 +54 -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 +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 +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 +42 -8
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +155 -1
- 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 +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 +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-DnmlfwGV.js +61620 -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-DxvwPrPB.js +7612 -0
- package/dist/git-command.d.ts +413 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +306 -3
- 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/remote-config-store.d.ts +105 -3
- 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 +10 -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/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 +60 -6
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BZGa2Z3I.js +2934 -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 +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 +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 +634 -67
- package/src/commands/commit-command.ts +1781 -166
- package/src/commands/core-config.ts +161 -6
- 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 +606 -66
- 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 +82 -0
- package/src/commands/init-command.ts +28 -4
- 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 +93 -22
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +827 -103
- 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 +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 +1328 -105
- 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 +204 -4
- 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 +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 +7 -1
- 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 +1177 -118
- package/src/git.ts +523 -10
- package/src/index.ts +1 -1
- package/src/remote-config/remote-config-store.ts +242 -8
- package/src/remote-config/remote-refs.ts +22 -6
- 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 +12 -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 +15 -0
- 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 +123 -45
- 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,976 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git mv` (builtin/mv.c): move or rename files, directories and submodules in the worktree
|
|
3
|
+
* and the index together.
|
|
4
|
+
*/
|
|
5
|
+
import { FileMode, type ObjectId } from "@statewalker/vcs-core";
|
|
6
|
+
import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
|
|
7
|
+
import {
|
|
8
|
+
attributesIndexOf,
|
|
9
|
+
compareWithWorktree,
|
|
10
|
+
entryStatOf,
|
|
11
|
+
type IndexEntry,
|
|
12
|
+
type Worktree,
|
|
13
|
+
type WorktreeModeTrust,
|
|
14
|
+
} from "@statewalker/vcs-working-tree";
|
|
15
|
+
|
|
16
|
+
import { MvFailedError } from "../errors/index.js";
|
|
17
|
+
import { GitCommand } from "../git-command.js";
|
|
18
|
+
import { worktreeModeTrust } from "./core-config.js";
|
|
19
|
+
import { IndexAdder } from "./index-adder.js";
|
|
20
|
+
import { configBool } from "./merge-config.js";
|
|
21
|
+
import { sparseCheckoutConfig, sparsePathAdvice } from "./sparse-checkout-support.js";
|
|
22
|
+
import { strerror } from "./strerror.js";
|
|
23
|
+
import { parseGitmodules } from "./submodule-config.js";
|
|
24
|
+
import { planFlatRestore, writeTreeRestorePlan } from "./tree-restore.js";
|
|
25
|
+
import {
|
|
26
|
+
removeDirectoryIfEmpty,
|
|
27
|
+
statFollowingLinks,
|
|
28
|
+
statThroughLeadingLinks,
|
|
29
|
+
} from "./worktree-overwrite-checks.js";
|
|
30
|
+
|
|
31
|
+
/** One move `git mv` made (or, with `-n`, would make). */
|
|
32
|
+
export interface MvRename {
|
|
33
|
+
source: string;
|
|
34
|
+
destination: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Result of {@link MvCommand}. */
|
|
38
|
+
export interface MvResult {
|
|
39
|
+
/** The moves made, in git's order (a directory's entries after the directory) */
|
|
40
|
+
renamed: MvRename[];
|
|
41
|
+
/** What git prints on stdout: `Checking rename of ...` (`-n`), `Renaming ...` (`-n`, `-v`) */
|
|
42
|
+
output: string[];
|
|
43
|
+
/**
|
|
44
|
+
* What git prints on stderr without failing: `warning: overwriting '<dst>'` (`-f -v`), the
|
|
45
|
+
* sparse advice with `-k`, the advice on paths moved out of the cone while dirty, the
|
|
46
|
+
* `.gitmodules` warnings
|
|
47
|
+
*/
|
|
48
|
+
warnings: string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// builtin/mv.c's `enum update_mode`
|
|
52
|
+
const WORKING_DIRECTORY = 1 << 1;
|
|
53
|
+
const INDEX = 1 << 2;
|
|
54
|
+
const SPARSE = 1 << 3;
|
|
55
|
+
const SKIP_WORKTREE_DIR = 1 << 4;
|
|
56
|
+
const MOVE_VIA_PARENT_DIR = 1 << 5;
|
|
57
|
+
|
|
58
|
+
/** `submodule_gitfile_path`'s marker for a submodule holding its own `.git` directory. */
|
|
59
|
+
const SUBMODULE_WITH_GITDIR = Symbol("SUBMODULE_WITH_GITDIR");
|
|
60
|
+
type SubmoduleGitfile = string | typeof SUBMODULE_WITH_GITDIR | undefined;
|
|
61
|
+
|
|
62
|
+
/** `needs_worktree_rename`: whether the move renames anything in the worktree. */
|
|
63
|
+
function needsWorktreeRename(mode: number, dstMode: number): boolean {
|
|
64
|
+
return (
|
|
65
|
+
(mode & (INDEX | SPARSE | SKIP_WORKTREE_DIR)) === 0 &&
|
|
66
|
+
(dstMode & (SKIP_WORKTREE_DIR | SPARSE)) === 0
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** `add_slash`: `path` with a trailing `/` (the empty path stays empty). */
|
|
71
|
+
function addSlash(path: string): string {
|
|
72
|
+
return path.length > 0 && !path.endsWith("/") ? `${path}/` : path;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** POSIX `basename` of a path without trailing slashes. */
|
|
76
|
+
function basename(path: string): string {
|
|
77
|
+
if (path === "") return ".";
|
|
78
|
+
const at = path.lastIndexOf("/");
|
|
79
|
+
return at < 0 ? path : path.slice(at + 1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* git's `prefix_path` with the worktree root as prefix (`normalize_path_copy`): `.` and
|
|
84
|
+
* empty components dropped, `..` climbing one, a trailing `/` kept; undefined when the
|
|
85
|
+
* path leaves the worktree.
|
|
86
|
+
*/
|
|
87
|
+
function normalizePath(path: string): string | undefined {
|
|
88
|
+
const trailing = path.endsWith("/") && path.replace(/\/+$/, "") !== "";
|
|
89
|
+
const out: string[] = [];
|
|
90
|
+
for (const part of path.split("/")) {
|
|
91
|
+
if (part === "" || part === ".") continue;
|
|
92
|
+
if (part === "..") {
|
|
93
|
+
if (out.length === 0) return undefined;
|
|
94
|
+
out.pop();
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
out.push(part);
|
|
98
|
+
}
|
|
99
|
+
const joined = out.join("/");
|
|
100
|
+
return trailing && joined ? `${joined}/` : joined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Move or rename files, directories and submodules (`git mv`).
|
|
105
|
+
*
|
|
106
|
+
* ```typescript
|
|
107
|
+
* // rename one file
|
|
108
|
+
* await git.mv().addSource("old.txt").setDestination("new.txt").call();
|
|
109
|
+
*
|
|
110
|
+
* // move several paths into a directory, skipping the ones that cannot move
|
|
111
|
+
* await git.mv().addSource("a").addSource("b").setDestination("dir").setSkipErrors(true).call();
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* Every check runs first (builtin/mv.c's "Checking" loop): one failing dies with git's
|
|
115
|
+
* `fatal: <reason>, source=<src>, destination=<dst>` before anything moves, unless `-k`
|
|
116
|
+
* passes over it. Then each worktree path is renamed through the worktree (a symbolic link
|
|
117
|
+
* as the link, a directory with everything in it) and its index entries renamed with
|
|
118
|
+
* `rename_index_entry_at`: flags kept, the stat data refreshed only where the file still
|
|
119
|
+
* matches, the cache-tree invalidated at both paths. A submodule's gitfile, `core.worktree`
|
|
120
|
+
* and `.gitmodules` path follow it, `.gitmodules` staged again.
|
|
121
|
+
*/
|
|
122
|
+
export class MvCommand extends GitCommand<MvResult> {
|
|
123
|
+
private sources: string[] = [];
|
|
124
|
+
private destination: string | undefined;
|
|
125
|
+
private force = false;
|
|
126
|
+
private skipErrors = false;
|
|
127
|
+
private dryRun = false;
|
|
128
|
+
private verbose = false;
|
|
129
|
+
private sparse = false;
|
|
130
|
+
private compatibility: "2.43" | "2.56" = "2.56";
|
|
131
|
+
|
|
132
|
+
/** A `<source>` (relative to the worktree root, `/` separated). */
|
|
133
|
+
addSource(source: string): this {
|
|
134
|
+
this.checkCallable();
|
|
135
|
+
this.sources.push(source);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The `<destination>`: a new name for one source, or a directory for several. */
|
|
140
|
+
setDestination(destination: string): this {
|
|
141
|
+
this.checkCallable();
|
|
142
|
+
this.destination = destination;
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** `-f`: a file or link at the destination is overwritten (`warning: overwriting` with `-v`). */
|
|
147
|
+
setForce(force: boolean): this {
|
|
148
|
+
this.checkCallable();
|
|
149
|
+
this.force = force;
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** `-k`: a source whose move would fail is passed over instead of dying. */
|
|
154
|
+
setSkipErrors(skip: boolean): this {
|
|
155
|
+
this.checkCallable();
|
|
156
|
+
this.skipErrors = skip;
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** `-n`: tell what would be moved (`Checking rename of`, `Renaming`), change nothing. */
|
|
161
|
+
setDryRun(dryRun: boolean): this {
|
|
162
|
+
this.checkCallable();
|
|
163
|
+
this.dryRun = dryRun;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** `-v`: tell each move (`Renaming <src> to <dst>`), and each file overwritten with `-f`. */
|
|
168
|
+
setVerbose(verbose: boolean): this {
|
|
169
|
+
this.checkCallable();
|
|
170
|
+
this.verbose = verbose;
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* `--sparse`: entries outside the sparse checkout (skip-worktree, or paths out of the
|
|
176
|
+
* patterns) may be moved; in cone mode an entry moved into the cone is checked out and
|
|
177
|
+
* one moved out of it leaves the worktree (kept there, with git's advice, when dirty).
|
|
178
|
+
*/
|
|
179
|
+
setSparse(sparse: boolean): this {
|
|
180
|
+
this.checkCallable();
|
|
181
|
+
this.sparse = sparse;
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The git version whose behaviour is reproduced where versions differ (default 2.56):
|
|
187
|
+
* 2.43 has no check of the destination's leading directory (the rename fails instead,
|
|
188
|
+
* `renaming '<src>' failed: <reason>`) and gives the advice's older last hint.
|
|
189
|
+
*/
|
|
190
|
+
setCompatibility(version: "2.43" | "2.56"): this {
|
|
191
|
+
this.checkCallable();
|
|
192
|
+
this.compatibility = version;
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async call(): Promise<MvResult> {
|
|
197
|
+
this.checkCallable();
|
|
198
|
+
this.setCallable(false);
|
|
199
|
+
if (this.sources.length === 0 || this.destination === undefined) {
|
|
200
|
+
throw new MvFailedError(
|
|
201
|
+
"usage: git mv [-v] [-f] [-n] [-k] <source> <destination>\n" +
|
|
202
|
+
" or: git mv [-v] [-f] [-n] [-k] <source>... <destination-directory>",
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
await this.readCurrentIndex();
|
|
206
|
+
const worktree = this.worktreeAccess;
|
|
207
|
+
if (!worktree) throw new MvFailedError("fatal: this operation must be run in a work tree");
|
|
208
|
+
|
|
209
|
+
const result: MvResult = { renamed: [], output: [], warnings: [] };
|
|
210
|
+
const die = (message: string): never => {
|
|
211
|
+
throw new MvFailedError([...result.warnings, `fatal: ${message}`].join("\n"), result);
|
|
212
|
+
};
|
|
213
|
+
// git names the worktree's top as the host does (an absolute path)
|
|
214
|
+
const top =
|
|
215
|
+
(worktree as { hostPath?: string }).hostPath?.replace(/(.)\/+$/, "$1") ?? worktree.getRoot();
|
|
216
|
+
const normalized = (path: string) =>
|
|
217
|
+
normalizePath(path) ?? die(`'${path}' is outside repository at '${top}'`);
|
|
218
|
+
const lstat = (path: string) => worktree.getEntry(path).catch(() => undefined);
|
|
219
|
+
// lstat(2) of a path with a trailing slash, or of one beneath a symbolic link, follows
|
|
220
|
+
// the links (`ld/` names the directory `ld` points to)
|
|
221
|
+
const lstatFollowing = async (path: string) => {
|
|
222
|
+
const bare = path.replace(/\/+$/, "");
|
|
223
|
+
if (bare !== path) return statFollowingLinks(worktree, bare);
|
|
224
|
+
const found = await lstat(path);
|
|
225
|
+
if (found) return found;
|
|
226
|
+
const through = await statThroughLeadingLinks(worktree, path);
|
|
227
|
+
return through?.entry;
|
|
228
|
+
};
|
|
229
|
+
// is_directory: stat(2), following links
|
|
230
|
+
const isDirectory = async (path: string) =>
|
|
231
|
+
(await statFollowingLinks(worktree, path.replace(/\/+$/, "")))?.isDirectory === true;
|
|
232
|
+
|
|
233
|
+
const cache = await this.indexEntries();
|
|
234
|
+
const namePos = (name: string) => indexNamePos(cache, name);
|
|
235
|
+
const patterns = await this.sparseCheckoutPatterns();
|
|
236
|
+
const inSparse = (path: string) => !path || !patterns || patterns.includes(path);
|
|
237
|
+
const inCone = (path: string) => !path || !patterns?.cone || inSparse(path);
|
|
238
|
+
const ignoreCase = configBool(this.workingCopy, "core.ignoreCase", false);
|
|
239
|
+
const fold = (p: string) => (ignoreCase ? p.toLowerCase() : p);
|
|
240
|
+
const emptyDirHasSparseContents = (name: string) => {
|
|
241
|
+
const withSlash = addSlash(name);
|
|
242
|
+
let pos = namePos(withSlash);
|
|
243
|
+
if (pos >= 0) return false;
|
|
244
|
+
pos = -pos - 1;
|
|
245
|
+
const ce = cache[pos];
|
|
246
|
+
return ce?.path.startsWith(withSlash) === true && ce.skipWorktree === true;
|
|
247
|
+
};
|
|
248
|
+
const indexRangeOfSameDir = (src: string): [number, number] => {
|
|
249
|
+
const withSlash = addSlash(src);
|
|
250
|
+
let first = namePos(withSlash);
|
|
251
|
+
if (first >= 0) die(`${withSlash} is in index`);
|
|
252
|
+
first = -1 - first;
|
|
253
|
+
let last = first;
|
|
254
|
+
while (last < cache.length && (cache[last] as IndexEntry).path.startsWith(withSlash)) last++;
|
|
255
|
+
return [first, last];
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// internal_prefix_pathspec: sources without trailing slashes; the destination keeps its
|
|
259
|
+
// own unless one directory moves to a name that is no directory
|
|
260
|
+
const argv = this.sources;
|
|
261
|
+
let argc = argv.length;
|
|
262
|
+
const sources = argv.map((a) => normalized(a.replace(/\/+$/, "")));
|
|
263
|
+
const keepSlash = !(
|
|
264
|
+
argc === 1 &&
|
|
265
|
+
(await isDirectory(sources[0] as string)) &&
|
|
266
|
+
!(await isDirectory(normalized(this.destination)))
|
|
267
|
+
);
|
|
268
|
+
const destPath = normalized(
|
|
269
|
+
keepSlash ? this.destination : this.destination.replace(/\/+$/, ""),
|
|
270
|
+
);
|
|
271
|
+
const dstWithSlash = addSlash(destPath);
|
|
272
|
+
const intoDir = (prefix: string) =>
|
|
273
|
+
argv.map((a) => normalized(`${prefix}${basename(a.replace(/\/+$/, ""))}`));
|
|
274
|
+
let destinations: string[];
|
|
275
|
+
let dstMode = 0;
|
|
276
|
+
// git's `struct stat st`, shared by several lstat calls: a failing one leaves it as the
|
|
277
|
+
// last successful one left it (a skip-worktree directory as source relies on it)
|
|
278
|
+
let lastStat: { isDirectory: boolean } | undefined;
|
|
279
|
+
const lstatSt = async (path: string) => {
|
|
280
|
+
const found = await lstatFollowing(path);
|
|
281
|
+
if (found) lastStat = found;
|
|
282
|
+
return found;
|
|
283
|
+
};
|
|
284
|
+
if (destPath === "") destinations = intoDir("");
|
|
285
|
+
else if ((await lstatSt(destPath))?.isDirectory) destinations = intoDir(dstWithSlash);
|
|
286
|
+
else if (!inSparse(dstWithSlash) && emptyDirHasSparseContents(dstWithSlash)) {
|
|
287
|
+
destinations = intoDir(dstWithSlash);
|
|
288
|
+
dstMode = SKIP_WORKTREE_DIR;
|
|
289
|
+
} else if (argc !== 1) {
|
|
290
|
+
return die(`destination '${destPath}' is not a directory`);
|
|
291
|
+
} else {
|
|
292
|
+
destinations = [destPath];
|
|
293
|
+
if (!inCone(destPath)) dstMode = SPARSE;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const modes: number[] = argv.map(() => 0);
|
|
297
|
+
const gitfiles: SubmoduleGitfile[] = argv.map(() => undefined);
|
|
298
|
+
const srcForDst = new Set<string>();
|
|
299
|
+
const onlyMatchSkipWorktree: string[] = [];
|
|
300
|
+
const movedDirs = new Set<string>();
|
|
301
|
+
const srcDirs: string[] = [];
|
|
302
|
+
/** The repository of each submodule with a gitfile, found before anything moves */
|
|
303
|
+
const gitDirs = new Map<string, string>();
|
|
304
|
+
const trust = worktreeModeTrust(this.workingCopy, worktree);
|
|
305
|
+
const indexTime = this.staging.getUpdateTime();
|
|
306
|
+
|
|
307
|
+
for (let i = 0; i < argc; i++) {
|
|
308
|
+
const src = sources[i] as string;
|
|
309
|
+
const dst = destinations[i] as string;
|
|
310
|
+
let bad: string | undefined;
|
|
311
|
+
let skipSparse = false;
|
|
312
|
+
let removeEntry = false;
|
|
313
|
+
if (this.dryRun) result.output.push(`Checking rename of '${src}' to '${dst}'`);
|
|
314
|
+
const st = await lstatSt(src);
|
|
315
|
+
const check = async (): Promise<void> => {
|
|
316
|
+
let srcIsDir = st?.isDirectory === true;
|
|
317
|
+
if (!st) {
|
|
318
|
+
const pos = namePos(src);
|
|
319
|
+
if (pos < 0) {
|
|
320
|
+
if (!inSparse(addSlash(src)) && emptyDirHasSparseContents(src)) {
|
|
321
|
+
modes[i] = (modes[i] as number) | SKIP_WORKTREE_DIR;
|
|
322
|
+
// S_ISDIR(st.st_mode) of whatever lstat filled in last; where none did, git
|
|
323
|
+
// reads a stat nothing filled in, almost always no directory ("not under
|
|
324
|
+
// version control" on 2.43 and 2.5x alike; rarely a directory, moving it)
|
|
325
|
+
srcIsDir = lastStat ? lastStat.isDirectory : false;
|
|
326
|
+
return dirCheck(srcIsDir);
|
|
327
|
+
}
|
|
328
|
+
if (!((modes[i] as number) & SPARSE)) bad = "bad source";
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const ce = cache[pos] as IndexEntry;
|
|
332
|
+
if (!ce.skipWorktree) {
|
|
333
|
+
bad = "bad source";
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (!this.sparse) {
|
|
337
|
+
onlyMatchSkipWorktree.push(src);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (namePos(dst) < 0) {
|
|
341
|
+
modes[i] = (modes[i] as number) | SPARSE;
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (!this.force) {
|
|
345
|
+
bad = "destination exists";
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
modes[i] = (modes[i] as number) | SPARSE;
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (dst.startsWith(src) && (dst.length === src.length || dst[src.length] === "/")) {
|
|
352
|
+
bad = "can not move directory into itself";
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (st.isDirectory && (await lstatFollowing(dst))) {
|
|
356
|
+
bad = "destination already exists";
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
return dirCheck(srcIsDir);
|
|
360
|
+
};
|
|
361
|
+
const dirCheck = async (srcIsDir: boolean): Promise<void> => {
|
|
362
|
+
if (srcIsDir) {
|
|
363
|
+
const first = namePos(src);
|
|
364
|
+
if (first >= 0) {
|
|
365
|
+
const gitfile = await this.submoduleGitfilePath(
|
|
366
|
+
worktree,
|
|
367
|
+
src,
|
|
368
|
+
cache[first] as IndexEntry,
|
|
369
|
+
);
|
|
370
|
+
gitfiles[i] = gitfile;
|
|
371
|
+
if (gitfile && gitfile !== SUBMODULE_WITH_GITDIR && worktree.gitlinkRepository) {
|
|
372
|
+
// connect_work_tree_and_git_dir rewrites the gitfile and the repository's
|
|
373
|
+
// core.worktree after the move: refused now when that repository cannot be
|
|
374
|
+
// reached, rather than leave the submodule broken
|
|
375
|
+
const gitDir = await worktree.gitlinkRepository(src);
|
|
376
|
+
if (gitDir === null) {
|
|
377
|
+
die(
|
|
378
|
+
`cannot update the repository of submodule '${src}' ('${gitfile}'): it lies outside the files this worktree reaches`,
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
if (gitDir) gitDirs.set(src, gitDir);
|
|
382
|
+
}
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const [from, to] = indexRangeOfSameDir(src);
|
|
386
|
+
if (to - from < 1) {
|
|
387
|
+
bad = "source directory is empty";
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
movedDirs.add(fold(src));
|
|
391
|
+
modes[i] = (modes[i] as number) | WORKING_DIRECTORY;
|
|
392
|
+
srcDirs.push(src);
|
|
393
|
+
const dstSlash = addSlash(dst);
|
|
394
|
+
for (let j = from; j < to; j++) {
|
|
395
|
+
const ce = cache[j] as IndexEntry;
|
|
396
|
+
sources.push(ce.path);
|
|
397
|
+
destinations.push(normalized(`${dstSlash}${ce.path.slice(src.length + 1)}`));
|
|
398
|
+
modes.push(MOVE_VIA_PARENT_DIR | (ce.skipWorktree ? SPARSE : INDEX));
|
|
399
|
+
gitfiles.push(undefined);
|
|
400
|
+
}
|
|
401
|
+
argc += to - from;
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const anyStage = cache.find((e) => e.path === src);
|
|
405
|
+
if (!anyStage) {
|
|
406
|
+
bad = "not under version control";
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (anyStage.stage !== 0 && !cache.some((e) => e.path === src && e.stage === 0)) {
|
|
410
|
+
bad = "conflicted";
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const dstStat = await lstatSt(dst);
|
|
414
|
+
if (dstStat && (!ignoreCase || src.toLowerCase() !== dst.toLowerCase())) {
|
|
415
|
+
bad = "destination exists";
|
|
416
|
+
if (this.force) {
|
|
417
|
+
// only files can overwrite each other
|
|
418
|
+
if (!dstStat.isDirectory) {
|
|
419
|
+
if (this.verbose) result.warnings.push(`warning: overwriting '${dst}'`);
|
|
420
|
+
bad = undefined;
|
|
421
|
+
} else bad = "Cannot overwrite";
|
|
422
|
+
}
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (srcForDst.has(dst)) {
|
|
426
|
+
bad = "multiple sources for the same target";
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (dst.endsWith("/")) {
|
|
430
|
+
bad = "destination directory does not exist";
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (this.compatibility !== "2.43" && (await hasSymlinkLeadingPath(worktree, dst))) {
|
|
434
|
+
bad = "destination is beyond a symbolic link";
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (this.compatibility !== "2.43" && needsWorktreeRename(modes[i] as number, dstMode)) {
|
|
438
|
+
const slash = dst.lastIndexOf("/");
|
|
439
|
+
if (slash >= 0) {
|
|
440
|
+
const dir = dst.slice(0, slash);
|
|
441
|
+
const dirStat = await lstat(dir);
|
|
442
|
+
if (!dirStat) {
|
|
443
|
+
// ENOENT or ENOTDIR (a file among the leading components)
|
|
444
|
+
bad = "destination directory does not exist";
|
|
445
|
+
} else if (!dirStat.isDirectory) bad = "destination is not a directory";
|
|
446
|
+
if (bad) return;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if (
|
|
450
|
+
this.sparse &&
|
|
451
|
+
dstMode & (SKIP_WORKTREE_DIR | SPARSE) &&
|
|
452
|
+
cache.some((e) => e.path === dst)
|
|
453
|
+
) {
|
|
454
|
+
bad = "destination exists in the index";
|
|
455
|
+
if (!this.force) return;
|
|
456
|
+
if (this.verbose) result.warnings.push(`warning: overwriting '${dst}'`);
|
|
457
|
+
bad = undefined;
|
|
458
|
+
}
|
|
459
|
+
// the sparse checks last, so the advice can point at --sparse
|
|
460
|
+
if (!this.sparse && !inSparse(src)) {
|
|
461
|
+
onlyMatchSkipWorktree.push(src);
|
|
462
|
+
skipSparse = true;
|
|
463
|
+
}
|
|
464
|
+
if (!this.sparse && !inSparse(dst)) {
|
|
465
|
+
onlyMatchSkipWorktree.push(dst);
|
|
466
|
+
skipSparse = true;
|
|
467
|
+
}
|
|
468
|
+
if (skipSparse) {
|
|
469
|
+
removeEntry = true;
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
srcForDst.add(dst);
|
|
473
|
+
};
|
|
474
|
+
await check();
|
|
475
|
+
if (!removeEntry) {
|
|
476
|
+
if (!bad) continue;
|
|
477
|
+
if (!this.skipErrors) die(`${bad}, source=${src}, destination=${dst}`);
|
|
478
|
+
}
|
|
479
|
+
// remove_entry
|
|
480
|
+
if (--argc > 0) {
|
|
481
|
+
sources.splice(i, 1);
|
|
482
|
+
destinations.splice(i, 1);
|
|
483
|
+
modes.splice(i, 1);
|
|
484
|
+
gitfiles.splice(i, 1);
|
|
485
|
+
i--;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// a path moved together with one of its parent directories (2.5x; 2.43 moves the
|
|
490
|
+
// directory, then fails renaming the path, or aborts on an assertion)
|
|
491
|
+
for (let i = 0; i < argc && this.compatibility !== "2.43"; i++) {
|
|
492
|
+
if ((modes[i] as number) & MOVE_VIA_PARENT_DIR) continue;
|
|
493
|
+
const src = sources[i] as string;
|
|
494
|
+
for (let at = src.lastIndexOf("/"); at > 0; at = src.lastIndexOf("/", at - 1)) {
|
|
495
|
+
const parent = src.slice(0, at);
|
|
496
|
+
if (movedDirs.has(fold(parent))) {
|
|
497
|
+
die(`cannot move both '${src}' and its parent directory '${parent}'`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (onlyMatchSkipWorktree.length > 0) {
|
|
503
|
+
const advice = sparsePathAdvice(
|
|
504
|
+
onlyMatchSkipWorktree,
|
|
505
|
+
configBool(this.workingCopy, "advice.updateSparsePath", true),
|
|
506
|
+
this.compatibility,
|
|
507
|
+
);
|
|
508
|
+
result.warnings.push(...advice);
|
|
509
|
+
if (!this.skipErrors) throw new MvFailedError(result.warnings.join("\n"), result);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// the moves
|
|
513
|
+
const sparseConfig = sparseCheckoutConfig(this.workingCopy);
|
|
514
|
+
const adder = await IndexAdder.open(this.staging, this.blobs, trust);
|
|
515
|
+
const current = new Map<string, IndexEntry>();
|
|
516
|
+
for (const e of cache) if (e.stage === 0) current.set(e.path, e);
|
|
517
|
+
const dirtyPaths: string[] = [];
|
|
518
|
+
let gitmodulesModified = false;
|
|
519
|
+
let changed = false;
|
|
520
|
+
for (let i = 0; i < argc; i++) {
|
|
521
|
+
const src = sources[i] as string;
|
|
522
|
+
const dst = destinations[i] as string;
|
|
523
|
+
const mode = modes[i] as number;
|
|
524
|
+
if (this.dryRun || this.verbose) result.output.push(`Renaming ${src} to ${dst}`);
|
|
525
|
+
if (this.dryRun) continue;
|
|
526
|
+
const gitfile = gitfiles[i];
|
|
527
|
+
const gitDir = gitfile && gitfile !== SUBMODULE_WITH_GITDIR ? gitDirs.get(src) : undefined;
|
|
528
|
+
if (needsWorktreeRename(mode, dstMode)) {
|
|
529
|
+
try {
|
|
530
|
+
await renamePath(worktree, src, dst);
|
|
531
|
+
} catch (error) {
|
|
532
|
+
if (this.skipErrors) continue;
|
|
533
|
+
// die_errno: the index lock is rolled back, the moves made so far stay unrecorded
|
|
534
|
+
die(
|
|
535
|
+
this.compatibility === "2.43"
|
|
536
|
+
? `renaming '${src}' failed: ${strerror(error)}`
|
|
537
|
+
: `renaming '${src}' to '${dst}' failed: ${strerror(error)}`,
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
result.renamed.push({ source: src, destination: dst });
|
|
542
|
+
if (gitfile) {
|
|
543
|
+
if (await this.updatePathInGitmodules(worktree, src, dst, result.warnings)) {
|
|
544
|
+
gitmodulesModified = true;
|
|
545
|
+
}
|
|
546
|
+
if (gitDir !== undefined) await worktree.connectGitlink?.(dst, gitDir);
|
|
547
|
+
}
|
|
548
|
+
if (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR)) continue;
|
|
549
|
+
|
|
550
|
+
const old = current.get(src);
|
|
551
|
+
if (!old) die(`BUG: could not find source in index: '${src}'`);
|
|
552
|
+
const entry = old as IndexEntry;
|
|
553
|
+
let sparseAndDirty = false;
|
|
554
|
+
if (!(mode & SPARSE)) {
|
|
555
|
+
const at = await lstat(src);
|
|
556
|
+
if (at) sparseAndDirty = await entryModified(worktree, entry, trust, indexTime);
|
|
557
|
+
}
|
|
558
|
+
// rename_index_entry_at: flags kept; refresh_cache_entry takes the new file's stat
|
|
559
|
+
// only while the content still matches (a gitlink's never: ie_match_stat compares its
|
|
560
|
+
// type and HEAD alone, so its stat data stays as it was)
|
|
561
|
+
let moved: IndexEntry = { ...entry, path: dst };
|
|
562
|
+
if (
|
|
563
|
+
!entry.skipWorktree &&
|
|
564
|
+
!entry.assumeValid &&
|
|
565
|
+
!entry.intentToAdd &&
|
|
566
|
+
entry.mode !== FileMode.GITLINK
|
|
567
|
+
) {
|
|
568
|
+
const file = await lstat(dst);
|
|
569
|
+
if (file && !(await entryModified(worktree, moved, trust, indexTime, true))) {
|
|
570
|
+
moved = { ...moved, ...entryStatOf(file) };
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
let checkout = false;
|
|
574
|
+
if (this.sparse && sparseConfig.enabled && sparseConfig.cone) {
|
|
575
|
+
if (mode & SPARSE && inSparse(dst)) {
|
|
576
|
+
// from out-of-cone to in-cone: checked out (checkout_entry, forced only with -f:
|
|
577
|
+
// without it a file already there stops the move before the index is written)
|
|
578
|
+
moved = { ...moved, skipWorktree: false };
|
|
579
|
+
if (!this.force && (await lstat(dst))) {
|
|
580
|
+
result.warnings.push(`${dst} already exists, no checkout`);
|
|
581
|
+
die(`cannot checkout ${dst}`);
|
|
582
|
+
}
|
|
583
|
+
checkout = true;
|
|
584
|
+
} else if (dstMode & (SKIP_WORKTREE_DIR | SPARSE) && !(mode & SPARSE) && !inSparse(dst)) {
|
|
585
|
+
// from in-cone to out-of-cone
|
|
586
|
+
if (!sparseAndDirty) {
|
|
587
|
+
moved = { ...moved, skipWorktree: true };
|
|
588
|
+
await worktree.remove(src).catch((error) => {
|
|
589
|
+
result.warnings.push(`warning: unable to unlink '${src}': ${strerror(error)}`);
|
|
590
|
+
});
|
|
591
|
+
} else {
|
|
592
|
+
dirtyPaths.push(dst);
|
|
593
|
+
const slash = dst.lastIndexOf("/");
|
|
594
|
+
if (slash > 0) await worktree.mkdir(dst.slice(0, slash), { recursive: true });
|
|
595
|
+
await renamePath(worktree, src, dst).catch(() => undefined);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
if (moved.skipWorktree === false) {
|
|
600
|
+
const { skipWorktree: _drop, ...rest } = moved;
|
|
601
|
+
moved = rest;
|
|
602
|
+
}
|
|
603
|
+
current.delete(src);
|
|
604
|
+
current.set(dst, moved);
|
|
605
|
+
adder.remove(src);
|
|
606
|
+
adder.put(moved);
|
|
607
|
+
changed = true;
|
|
608
|
+
if (checkout) await this.checkoutEntries(worktree, [moved], current, trust);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// remove_empty_src_dirs
|
|
612
|
+
if (!this.dryRun) {
|
|
613
|
+
for (const dir of srcDirs) {
|
|
614
|
+
const prefix = `${dir}/`;
|
|
615
|
+
let has = false;
|
|
616
|
+
for (const p of current.keys()) {
|
|
617
|
+
if (p.startsWith(prefix)) {
|
|
618
|
+
has = true;
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
if (!has && (await lstat(dir))) await worktree.remove(dir, { recursive: true });
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if (dirtyPaths.length > 0) {
|
|
627
|
+
result.warnings.push(
|
|
628
|
+
"The following paths have been moved outside the",
|
|
629
|
+
"sparse-checkout definition but are not sparse due to local",
|
|
630
|
+
"modifications.",
|
|
631
|
+
...dirtyPaths,
|
|
632
|
+
);
|
|
633
|
+
if (configBool(this.workingCopy, "advice.updateSparsePath", true)) {
|
|
634
|
+
result.warnings.push(
|
|
635
|
+
"hint: To correct the sparsity of these paths, do the following:",
|
|
636
|
+
'hint: * Use "git add --sparse <paths>" to update the index',
|
|
637
|
+
'hint: * Use "git sparse-checkout reapply" to apply the sparsity rules',
|
|
638
|
+
`hint: Disable this message with "${this.compatibility === "2.43" ? "git config" : "git config set"} advice.updateSparsePath false"`,
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if (changed || gitmodulesModified) {
|
|
643
|
+
await this.writeMoves(adder, worktree, gitmodulesModified);
|
|
644
|
+
}
|
|
645
|
+
return result;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/** The index's entries in its order. */
|
|
649
|
+
private async indexEntries(): Promise<IndexEntry[]> {
|
|
650
|
+
const list = this.staging.entryList?.();
|
|
651
|
+
if (list) return [...list];
|
|
652
|
+
const out: IndexEntry[] = [];
|
|
653
|
+
for await (const e of this.staging.entries()) out.push(e);
|
|
654
|
+
return out;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/** `stage_updated_gitmodules` when needed, then the index written. */
|
|
658
|
+
private async writeMoves(
|
|
659
|
+
adder: IndexAdder,
|
|
660
|
+
worktree: Worktree,
|
|
661
|
+
gitmodulesModified: boolean,
|
|
662
|
+
): Promise<void> {
|
|
663
|
+
if (gitmodulesModified) {
|
|
664
|
+
const entry = await worktree.getEntry(".gitmodules");
|
|
665
|
+
if (entry && !entry.isDirectory) await adder.add(worktree, ".gitmodules", entry);
|
|
666
|
+
}
|
|
667
|
+
await adder.finish();
|
|
668
|
+
await this.staging.write();
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/** `checkout_entry` (forced) of the entries moved into the sparse cone. */
|
|
672
|
+
private async checkoutEntries(
|
|
673
|
+
worktree: Worktree,
|
|
674
|
+
entries: IndexEntry[],
|
|
675
|
+
index: Map<string, IndexEntry>,
|
|
676
|
+
trust: WorktreeModeTrust,
|
|
677
|
+
): Promise<void> {
|
|
678
|
+
const target = new Map<string, { objectId: ObjectId; mode: number }>();
|
|
679
|
+
for (const e of entries) target.set(e.path, e);
|
|
680
|
+
const plan = await planFlatRestore(this.blobs, target, new Set(target.keys()), "mv", {
|
|
681
|
+
symlinks: true,
|
|
682
|
+
windows: worktree.capabilities?.windowsPaths === true,
|
|
683
|
+
reservedNames: worktree.capabilities?.reservedNames,
|
|
684
|
+
});
|
|
685
|
+
const attributes = new Map<string, ObjectId>();
|
|
686
|
+
for (const [path, e] of index)
|
|
687
|
+
if (path.endsWith(".gitattributes")) attributes.set(path, e.objectId);
|
|
688
|
+
await writeTreeRestorePlan(worktree, this.blobs, plan, "mv", {
|
|
689
|
+
symlinks: trust.symlinks,
|
|
690
|
+
gitlinks: true,
|
|
691
|
+
replaceInTheWay: true,
|
|
692
|
+
discardUntracked: true,
|
|
693
|
+
attributes: { direction: "checkout", index: attributesIndexOf(attributes) },
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* `submodule_gitfile_path`: the repository of the submodule at `src` (its gitfile's
|
|
699
|
+
* target, relative to the worktree root), or {@link SUBMODULE_WITH_GITDIR}; dies on a
|
|
700
|
+
* directory the index holds as no submodule, and on unstaged `.gitmodules` changes.
|
|
701
|
+
*/
|
|
702
|
+
private async submoduleGitfilePath(
|
|
703
|
+
worktree: Worktree,
|
|
704
|
+
src: string,
|
|
705
|
+
entry: IndexEntry,
|
|
706
|
+
): Promise<SubmoduleGitfile> {
|
|
707
|
+
if (entry.mode !== FileMode.GITLINK) {
|
|
708
|
+
throw new MvFailedError(`fatal: Directory ${src} is in index and no submodule?`);
|
|
709
|
+
}
|
|
710
|
+
if (!(await this.stagingGitmodulesOk(worktree))) {
|
|
711
|
+
throw new MvFailedError(
|
|
712
|
+
"fatal: Please stage your changes to .gitmodules or stash them to proceed",
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
const dotGit = await worktree.getEntry(`${src}/.git`).catch(() => undefined);
|
|
716
|
+
if (!dotGit || dotGit.isDirectory) return SUBMODULE_WITH_GITDIR;
|
|
717
|
+
const text = await readText(worktree, `${src}/.git`);
|
|
718
|
+
const m = /^gitdir: (.*?)\s*$/m.exec(text);
|
|
719
|
+
if (!m?.[1]) return SUBMODULE_WITH_GITDIR;
|
|
720
|
+
const target = m[1];
|
|
721
|
+
if (target.startsWith("/")) return target;
|
|
722
|
+
// relative to the submodule: as a path from the worktree's top (it may climb out)
|
|
723
|
+
const out: string[] = [];
|
|
724
|
+
for (const part of `${src}/${target}`.split("/")) {
|
|
725
|
+
if (part === "" || part === ".") continue;
|
|
726
|
+
if (part === ".." && out.length > 0 && out[out.length - 1] !== "..") out.pop();
|
|
727
|
+
else out.push(part);
|
|
728
|
+
}
|
|
729
|
+
return out.join("/") || ".";
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/** `is_staging_gitmodules_ok`: `.gitmodules` holds no change the index does not. */
|
|
733
|
+
private async stagingGitmodulesOk(worktree: Worktree): Promise<boolean> {
|
|
734
|
+
const entry = await this.staging.getEntry(".gitmodules");
|
|
735
|
+
if (!entry) return true;
|
|
736
|
+
const file = await worktree.getEntry(".gitmodules").catch(() => undefined);
|
|
737
|
+
if (!file || file.isDirectory) return true;
|
|
738
|
+
const compared = await compareWithWorktree(worktree, entry, {
|
|
739
|
+
trust: worktreeModeTrust(this.workingCopy, worktree),
|
|
740
|
+
indexTime: this.staging.getUpdateTime(),
|
|
741
|
+
}).catch(() => undefined);
|
|
742
|
+
if (compared?.kind !== "modified") return true;
|
|
743
|
+
const id = compared.hashedId ?? (await worktree.computeHash(".gitmodules"));
|
|
744
|
+
return id === entry.objectId;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* `update_path_in_gitmodules`: the `path` of the `.gitmodules` section naming `oldPath`
|
|
749
|
+
* set to `newPath` (the line rewritten as `git config` writes it). Returns whether the
|
|
750
|
+
* file changed; nothing without a `.gitmodules`, git's warning without a section.
|
|
751
|
+
*/
|
|
752
|
+
private async updatePathInGitmodules(
|
|
753
|
+
worktree: Worktree,
|
|
754
|
+
oldPath: string,
|
|
755
|
+
newPath: string,
|
|
756
|
+
warnings: string[],
|
|
757
|
+
): Promise<boolean> {
|
|
758
|
+
const file = await worktree.getEntry(".gitmodules").catch(() => undefined);
|
|
759
|
+
if (!file || file.isDirectory) return false;
|
|
760
|
+
for await (const e of this.staging.entries()) {
|
|
761
|
+
if (e.path === ".gitmodules" && e.stage !== 0) {
|
|
762
|
+
throw new MvFailedError(
|
|
763
|
+
"fatal: Cannot change unmerged .gitmodules, resolve merge conflicts first",
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
const text = await readText(worktree, ".gitmodules");
|
|
768
|
+
const declared = parseGitmodules(text).filter((s) => s.path === oldPath);
|
|
769
|
+
const submodule = declared[declared.length - 1];
|
|
770
|
+
if (!submodule) {
|
|
771
|
+
warnings.push(`warning: Could not find section in .gitmodules where path=${oldPath}`);
|
|
772
|
+
return false;
|
|
773
|
+
}
|
|
774
|
+
const updated = setGitmodulesPath(text, submodule.name, newPath);
|
|
775
|
+
if (updated === undefined) return false;
|
|
776
|
+
await worktree.writeContent(".gitmodules", new TextEncoder().encode(updated), { raw: true });
|
|
777
|
+
return true;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/** `index_name_pos`: the position of `name` at stage 0, or `-(insertion point) - 1`. */
|
|
782
|
+
function indexNamePos(cache: readonly IndexEntry[], name: string): number {
|
|
783
|
+
let lo = 0;
|
|
784
|
+
let hi = cache.length;
|
|
785
|
+
while (lo < hi) {
|
|
786
|
+
const mid = (lo + hi) >>> 1;
|
|
787
|
+
const e = cache[mid] as IndexEntry;
|
|
788
|
+
const c = compareGitPaths(e.path, name) || e.stage;
|
|
789
|
+
if (c === 0) return mid;
|
|
790
|
+
if (c < 0) lo = mid + 1;
|
|
791
|
+
else hi = mid;
|
|
792
|
+
}
|
|
793
|
+
return -lo - 1;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* `ie_modified` of an index entry against its file: the content (or mode) differs. An
|
|
798
|
+
* intent-to-add entry always differs (`ie_match_stat`), unless `refresh` asks as
|
|
799
|
+
* `refresh_cache_entry` does for an entry it may take a new stat for.
|
|
800
|
+
*/
|
|
801
|
+
async function entryModified(
|
|
802
|
+
worktree: Worktree,
|
|
803
|
+
entry: IndexEntry,
|
|
804
|
+
trust: WorktreeModeTrust,
|
|
805
|
+
indexTime: number,
|
|
806
|
+
refresh = false,
|
|
807
|
+
): Promise<boolean> {
|
|
808
|
+
if (entry.intentToAdd && !refresh) return true;
|
|
809
|
+
const compared = await compareWithWorktree(worktree, entry, { trust, indexTime }).catch(
|
|
810
|
+
() => undefined,
|
|
811
|
+
);
|
|
812
|
+
return compared === undefined || compared.kind !== undefined;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/** `has_symlink_leading_path`: a leading directory of `path` is a symbolic link. */
|
|
816
|
+
async function hasSymlinkLeadingPath(worktree: Worktree, path: string): Promise<boolean> {
|
|
817
|
+
const parts = path.split("/");
|
|
818
|
+
for (let k = 1; k < parts.length; k++) {
|
|
819
|
+
const entry = await worktree.getEntry(parts.slice(0, k).join("/")).catch(() => undefined);
|
|
820
|
+
if (!entry) return (await statThroughLeadingLinks(worktree, path)) !== undefined;
|
|
821
|
+
if (entry.mode === FileMode.SYMLINK) return true;
|
|
822
|
+
if (!entry.isDirectory) return false;
|
|
823
|
+
}
|
|
824
|
+
return false;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* `rename(2)` through the worktree: a link moves as the link, a directory with everything
|
|
829
|
+
* in it. A worktree without rename copies the file and removes the original. A destination
|
|
830
|
+
* that is the source itself (a case-only rename where the filesystem folds case, or the
|
|
831
|
+
* same file under another name) is never removed first: the entry is renamed directly, as
|
|
832
|
+
* git's `rename` does; a directory moved beneath itself fails (`EINVAL`): one of the
|
|
833
|
+
* destination's leading directories is the source (the same path, the same inode where the
|
|
834
|
+
* worktree reports one, or a case variant the filesystem folds onto it: `core.ignoreCase`
|
|
835
|
+
* alone folds nothing, as on a case-sensitive filesystem `D` and `d` are two). A file at the
|
|
836
|
+
* destination is replaced by the rename itself, atomically as `rename(2)` does, so a move
|
|
837
|
+
* that fails leaves it in place; only a worktree without rename removes it first. An empty
|
|
838
|
+
* directory at the destination is removed first (never one holding anything: `ENOTEMPTY`).
|
|
839
|
+
*/
|
|
840
|
+
async function renamePath(worktree: Worktree, src: string, dst: string): Promise<void> {
|
|
841
|
+
const fail = (code: string): never => {
|
|
842
|
+
throw Object.assign(new Error(code), { code });
|
|
843
|
+
};
|
|
844
|
+
const source = await worktree.getEntry(src).catch(() => undefined);
|
|
845
|
+
if (!source) fail("ENOENT");
|
|
846
|
+
const sameInode = (other: { ino?: number; dev?: number } | undefined) =>
|
|
847
|
+
other !== undefined &&
|
|
848
|
+
source?.ino !== undefined &&
|
|
849
|
+
source.ino !== 0 &&
|
|
850
|
+
source.ino === other.ino &&
|
|
851
|
+
source.dev === other.dev;
|
|
852
|
+
if (source?.isDirectory) {
|
|
853
|
+
for (let at = dst.lastIndexOf("/"); at > 0; at = dst.lastIndexOf("/", at - 1)) {
|
|
854
|
+
const ancestor = dst.slice(0, at);
|
|
855
|
+
if (ancestor === src || (await sameEntryByCase(worktree, ancestor, src))) fail("EINVAL");
|
|
856
|
+
if (sameInode(await worktree.getEntry(ancestor).catch(() => undefined))) fail("EINVAL");
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
// rename(2) creates no leading directory: ENOENT for a missing one, ENOTDIR for a file
|
|
860
|
+
// (a link included) among them
|
|
861
|
+
const slash = dst.lastIndexOf("/");
|
|
862
|
+
if (slash > 0) {
|
|
863
|
+
const parent = await worktree.getEntry(dst.slice(0, slash)).catch(() => undefined);
|
|
864
|
+
if (!parent) {
|
|
865
|
+
const through = await statThroughLeadingLinks(worktree, `${dst.slice(0, slash)}/x`);
|
|
866
|
+
fail(through === undefined ? "ENOENT" : "ENOTDIR");
|
|
867
|
+
} else if (!parent.isDirectory) fail("ENOTDIR");
|
|
868
|
+
}
|
|
869
|
+
const target = await worktree.getEntry(dst).catch(() => undefined);
|
|
870
|
+
const sameEntry =
|
|
871
|
+
target !== undefined &&
|
|
872
|
+
(src === dst || sameInode(target) || (await sameEntryByCase(worktree, src, dst)));
|
|
873
|
+
const canRename = typeof worktree.rename === "function";
|
|
874
|
+
if (target && !sameEntry) {
|
|
875
|
+
if (target.isDirectory) {
|
|
876
|
+
// rename(2) of a directory over an empty one replaces it; anything else fails
|
|
877
|
+
if (!source?.isDirectory) fail("EISDIR");
|
|
878
|
+
if (!(await removeDirectoryIfEmpty(worktree, dst).catch(() => false))) fail("ENOTEMPTY");
|
|
879
|
+
} else if (source?.isDirectory) {
|
|
880
|
+
fail("ENOTDIR");
|
|
881
|
+
} else if (!canRename) {
|
|
882
|
+
await worktree.remove(dst);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (canRename) {
|
|
886
|
+
await worktree.rename(src, dst);
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
if (sameEntry) fail("EINVAL");
|
|
890
|
+
const chunks: Uint8Array[] = [];
|
|
891
|
+
for await (const chunk of worktree.readContent(src)) chunks.push(chunk);
|
|
892
|
+
await worktree.writeContent(dst, concat(chunks), { raw: true });
|
|
893
|
+
await worktree.remove(src);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Whether `a` and `b`, two spellings of one path that differ in case only, name one entry
|
|
898
|
+
* (the filesystem folds case): each differing component's directory lists only one of the
|
|
899
|
+
* two names. A directory never lists one entry twice, so where both are listed (a
|
|
900
|
+
* case-sensitive filesystem holding `D` and `d`) they are two.
|
|
901
|
+
*/
|
|
902
|
+
async function sameEntryByCase(worktree: Worktree, a: string, b: string): Promise<boolean> {
|
|
903
|
+
const pa = a.split("/");
|
|
904
|
+
const pb = b.split("/");
|
|
905
|
+
if (a === b || pa.length !== pb.length || a.toLowerCase() !== b.toLowerCase()) return false;
|
|
906
|
+
for (let k = 0; k < pa.length; k++) {
|
|
907
|
+
const na = pa[k] as string;
|
|
908
|
+
const nb = pb[k] as string;
|
|
909
|
+
if (na === nb) continue;
|
|
910
|
+
const parent = pa.slice(0, k).join("/");
|
|
911
|
+
const listed = new Set<string>();
|
|
912
|
+
const inside = worktree.walk({
|
|
913
|
+
...(parent ? { pathPrefix: parent } : {}),
|
|
914
|
+
includeIgnored: true,
|
|
915
|
+
includeDirectories: true,
|
|
916
|
+
maxDepth: 0,
|
|
917
|
+
});
|
|
918
|
+
try {
|
|
919
|
+
for await (const entry of inside) {
|
|
920
|
+
const name = parent ? entry.path.slice(parent.length + 1) : entry.path;
|
|
921
|
+
if (!name.includes("/")) listed.add(name);
|
|
922
|
+
}
|
|
923
|
+
} catch {
|
|
924
|
+
return false;
|
|
925
|
+
}
|
|
926
|
+
if (listed.has(na) && listed.has(nb)) return false;
|
|
927
|
+
}
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* `git config -f .gitmodules submodule.<name>.path <value>`: the `path` line of the last
|
|
933
|
+
* section of that name replaced by `\tpath = <value>` (quoted and escaped as git writes it).
|
|
934
|
+
*/
|
|
935
|
+
function setGitmodulesPath(text: string, name: string, value: string): string | undefined {
|
|
936
|
+
const lines = text.split(/(?<=\n)/);
|
|
937
|
+
let inSection = false;
|
|
938
|
+
let at = -1;
|
|
939
|
+
for (let i = 0; i < lines.length; i++) {
|
|
940
|
+
const line = lines[i] as string;
|
|
941
|
+
const trimmed = line.trimStart();
|
|
942
|
+
if (trimmed.startsWith("[")) {
|
|
943
|
+
const m = /^\[\s*submodule\s+"((?:[^"\\]|\\.)*)"\s*\]/i.exec(trimmed);
|
|
944
|
+
inSection = m !== null && m[1]?.replace(/\\(.)/g, "$1") === name;
|
|
945
|
+
continue;
|
|
946
|
+
}
|
|
947
|
+
if (inSection && /^\s*path\s*(=|$)/i.test(line)) at = i;
|
|
948
|
+
}
|
|
949
|
+
if (at < 0) return undefined;
|
|
950
|
+
const quote = /^\s|\s$|[;#]/.test(value) ? '"' : "";
|
|
951
|
+
const escaped = value
|
|
952
|
+
.replace(/\\/g, "\\\\")
|
|
953
|
+
.replace(/"/g, '\\"')
|
|
954
|
+
.replace(/\n/g, "\\n")
|
|
955
|
+
.replace(/\t/g, "\\t");
|
|
956
|
+
lines[at] = `\tpath = ${quote}${escaped}${quote}\n`;
|
|
957
|
+
return lines.join("");
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
async function readText(worktree: Worktree, path: string): Promise<string> {
|
|
961
|
+
const chunks: Uint8Array[] = [];
|
|
962
|
+
for await (const chunk of worktree.readContent(path)) chunks.push(chunk);
|
|
963
|
+
return new TextDecoder().decode(concat(chunks));
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function concat(chunks: Uint8Array[]): Uint8Array {
|
|
967
|
+
let size = 0;
|
|
968
|
+
for (const c of chunks) size += c.length;
|
|
969
|
+
const out = new Uint8Array(size);
|
|
970
|
+
let at = 0;
|
|
971
|
+
for (const c of chunks) {
|
|
972
|
+
out.set(c, at);
|
|
973
|
+
at += c.length;
|
|
974
|
+
}
|
|
975
|
+
return out;
|
|
976
|
+
}
|