@statewalker/vcs-commands 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -8
- package/dist/commands/add-command.d.ts +265 -34
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-interactive.d.ts +46 -0
- package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
- package/dist/commands/add-patch/add-patch.d.ts +139 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
- package/dist/commands/add-patch/index.d.ts +6 -0
- package/dist/commands/add-patch/index.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-backend.d.ts +80 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-modes.d.ts +71 -0
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-session.d.ts +49 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
- package/dist/commands/am/am-command.d.ts +175 -0
- package/dist/commands/am/am-command.d.ts.map +1 -0
- package/dist/commands/am/index.d.ts +3 -0
- package/dist/commands/am/index.d.ts.map +1 -0
- package/dist/commands/am/mailinfo.d.ts +58 -0
- package/dist/commands/am/mailinfo.d.ts.map +1 -0
- package/dist/commands/am/patch-format.d.ts +24 -0
- package/dist/commands/am/patch-format.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts +153 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -0
- package/dist/commands/apply/apply-engine.d.ts +195 -0
- package/dist/commands/apply/apply-engine.d.ts.map +1 -0
- package/dist/commands/apply/apply-parse.d.ts +86 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -0
- package/dist/commands/apply/apply-types.d.ts +70 -0
- package/dist/commands/apply/apply-types.d.ts.map +1 -0
- package/dist/commands/apply/index.d.ts +6 -0
- package/dist/commands/apply/index.d.ts.map +1 -0
- package/dist/commands/apply/latin1.d.ts +32 -0
- package/dist/commands/apply/latin1.d.ts.map +1 -0
- package/dist/commands/apply/whitespace.d.ts +58 -0
- package/dist/commands/apply/whitespace.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +26 -0
- package/dist/commands/attributes-source.d.ts.map +1 -0
- package/dist/commands/backfill-command.d.ts +110 -0
- package/dist/commands/backfill-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
- package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-command.d.ts +201 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-engine.d.ts +219 -0
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-graph.d.ts +127 -0
- package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-quote.d.ts +27 -0
- package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
- package/dist/commands/bisect/index.d.ts +5 -0
- package/dist/commands/bisect/index.d.ts.map +1 -0
- package/dist/commands/blame-command.d.ts +122 -131
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +52 -2
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-tracking.d.ts +98 -0
- package/dist/commands/branch-tracking.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +299 -34
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +124 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +50 -42
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +67 -4
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +179 -7
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +311 -17
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +93 -0
- package/dist/commands/core-config.d.ts.map +1 -0
- package/dist/commands/date-format.d.ts +58 -0
- package/dist/commands/date-format.d.ts.map +1 -0
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +377 -30
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-textconv.d.ts +40 -0
- package/dist/commands/diff-textconv.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +244 -23
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts +164 -0
- package/dist/commands/format-patch-command.d.ts.map +1 -0
- package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts +225 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +68 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +115 -0
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
- package/dist/commands/fsck/index.d.ts +6 -0
- package/dist/commands/fsck/index.d.ts.map +1 -0
- package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +43 -0
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +66 -0
- package/dist/commands/git-date.d.ts.map +1 -0
- package/dist/commands/git-describe.d.ts +67 -0
- package/dist/commands/git-describe.d.ts.map +1 -0
- package/dist/commands/git-hooks.d.ts +416 -0
- package/dist/commands/git-hooks.d.ts.map +1 -0
- package/dist/commands/git-ident.d.ts +128 -0
- package/dist/commands/git-ident.d.ts.map +1 -0
- package/dist/commands/hook-command.d.ts +96 -0
- package/dist/commands/hook-command.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +231 -0
- package/dist/commands/index-adder.d.ts.map +1 -0
- package/dist/commands/index-host.d.ts +86 -0
- package/dist/commands/index-host.d.ts.map +1 -0
- package/dist/commands/index.d.ts +55 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +12 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/local-clone.d.ts +60 -0
- package/dist/commands/local-clone.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +117 -0
- package/dist/commands/local-transport.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +216 -24
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +120 -0
- package/dist/commands/log-graph.d.ts.map +1 -0
- package/dist/commands/log-output.d.ts +323 -0
- package/dist/commands/log-output.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +23 -7
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +31 -0
- package/dist/commands/mailmap.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +85 -0
- package/dist/commands/merge-bases.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +209 -74
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +13 -0
- package/dist/commands/merge-config.d.ts.map +1 -0
- package/dist/commands/merge-drivers.d.ts +130 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +252 -0
- package/dist/commands/merge-support.d.ts.map +1 -0
- package/dist/commands/message-cleanup.d.ts +86 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -0
- package/dist/commands/mv-command.d.ts +94 -0
- package/dist/commands/mv-command.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts +256 -0
- package/dist/commands/notes-command.d.ts.map +1 -0
- package/dist/commands/notes-commands.d.ts +41 -0
- package/dist/commands/notes-commands.d.ts.map +1 -0
- package/dist/commands/notes-merge-command.d.ts +105 -0
- package/dist/commands/notes-merge-command.d.ts.map +1 -0
- package/dist/commands/notes-support.d.ts +125 -0
- package/dist/commands/notes-support.d.ts.map +1 -0
- package/dist/commands/notes-tree.d.ts +106 -0
- package/dist/commands/notes-tree.d.ts.map +1 -0
- package/dist/commands/object-id-input.d.ts +20 -0
- package/dist/commands/object-id-input.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +59 -0
- package/dist/commands/octopus-merge.d.ts.map +1 -0
- package/dist/commands/ort-merge.d.ts +126 -0
- package/dist/commands/ort-merge.d.ts.map +1 -0
- package/dist/commands/ort-recursive.d.ts +53 -0
- package/dist/commands/ort-recursive.d.ts.map +1 -0
- package/dist/commands/pack-refs-command.d.ts +20 -0
- package/dist/commands/pack-refs-command.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +41 -0
- package/dist/commands/patch-id.d.ts.map +1 -0
- package/dist/commands/pathspec-attributes.d.ts +64 -0
- package/dist/commands/pathspec-attributes.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +324 -0
- package/dist/commands/pathspec.d.ts.map +1 -0
- package/dist/commands/post-index-change.d.ts +33 -0
- package/dist/commands/post-index-change.d.ts.map +1 -0
- package/dist/commands/pretty-format.d.ts +222 -0
- package/dist/commands/pretty-format.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts +80 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -0
- package/dist/commands/pull-command.d.ts +41 -8
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +24 -8
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +112 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -0
- package/dist/commands/rebase-command.d.ts +507 -75
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/rebase-todo.d.ts +130 -0
- package/dist/commands/rebase-todo.d.ts.map +1 -0
- package/dist/commands/ref-decoration-filter.d.ts +53 -0
- package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
- package/dist/commands/reflog-messages.d.ts +98 -0
- package/dist/commands/reflog-messages.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +146 -6
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +120 -0
- package/dist/commands/remote-transport.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +161 -7
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +103 -0
- package/dist/commands/restore-command.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +78 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -0
- package/dist/commands/rev-parse-command.d.ts +80 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -0
- package/dist/commands/revert-command.d.ts +46 -38
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-filenames.d.ts +95 -0
- package/dist/commands/revision-filenames.d.ts.map +1 -0
- package/dist/commands/revision-range.d.ts +67 -0
- package/dist/commands/revision-range.d.ts.map +1 -0
- package/dist/commands/revision-resolver.d.ts +321 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -0
- package/dist/commands/rm-command.d.ts +69 -7
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +191 -0
- package/dist/commands/sequencer-pick.d.ts.map +1 -0
- package/dist/commands/sequencer-support.d.ts +125 -0
- package/dist/commands/sequencer-support.d.ts.map +1 -0
- package/dist/commands/serve-repository.d.ts +52 -0
- package/dist/commands/serve-repository.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts +190 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-support.d.ts +268 -0
- package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +69 -13
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +214 -26
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +10 -2
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-list-command.d.ts +2 -4
- package/dist/commands/stash-list-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +95 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +320 -28
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-format.d.ts +155 -0
- package/dist/commands/status-format.d.ts.map +1 -0
- package/dist/commands/status-header.d.ts +64 -0
- package/dist/commands/status-header.d.ts.map +1 -0
- package/dist/commands/strerror.d.ts +7 -0
- package/dist/commands/strerror.d.ts.map +1 -0
- package/dist/commands/submodule-config.d.ts +38 -0
- package/dist/commands/submodule-config.d.ts.map +1 -0
- package/dist/commands/submodule-summary-command.d.ts +80 -0
- package/dist/commands/submodule-summary-command.d.ts.map +1 -0
- package/dist/commands/submodule-summary.d.ts +150 -0
- package/dist/commands/submodule-summary.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +132 -0
- package/dist/commands/switch-command.d.ts.map +1 -0
- package/dist/commands/tag-command.d.ts +23 -2
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tracking-info.d.ts +64 -0
- package/dist/commands/tracking-info.d.ts.map +1 -0
- package/dist/commands/trailers.d.ts +73 -0
- package/dist/commands/trailers.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +137 -6
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +53 -0
- package/dist/commands/untracked-cache-support.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +108 -0
- package/dist/commands/worktree-add-command.d.ts.map +1 -0
- package/dist/commands/worktree-list-command.d.ts +69 -0
- package/dist/commands/worktree-list-command.d.ts.map +1 -0
- package/dist/commands/worktree-lock-command.d.ts +44 -0
- package/dist/commands/worktree-lock-command.d.ts.map +1 -0
- package/dist/commands/worktree-overwrite-checks.d.ts +204 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
- package/dist/commands/worktree-prune-command.d.ts +48 -0
- package/dist/commands/worktree-prune-command.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +59 -0
- package/dist/commands/worktree-remove-command.d.ts.map +1 -0
- package/dist/commands/worktree-repair-command.d.ts +35 -0
- package/dist/commands/worktree-repair-command.d.ts.map +1 -0
- package/dist/commands/worktree-support.d.ts +64 -0
- package/dist/commands/worktree-support.d.ts.map +1 -0
- package/dist/commands-DnmlfwGV.js +61620 -0
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/core-commands/index.d.ts +0 -3
- package/dist/core-commands/index.d.ts.map +1 -1
- package/dist/errors/add-errors.d.ts +55 -0
- package/dist/errors/add-errors.d.ts.map +1 -1
- package/dist/errors/checkout-errors.d.ts +29 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts +77 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/commit-errors.d.ts +9 -0
- package/dist/errors/commit-errors.d.ts.map +1 -1
- package/dist/errors/git-api-error.d.ts +59 -2
- package/dist/errors/git-api-error.d.ts.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +371 -19
- package/dist/errors/rebase-errors.d.ts +9 -0
- package/dist/errors/rebase-errors.d.ts.map +1 -1
- package/dist/errors/ref-errors.d.ts +32 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/transport-errors.d.ts +12 -2
- package/dist/errors/transport-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +35 -0
- package/dist/errors/worktree-errors.d.ts.map +1 -0
- package/dist/git-command-DxvwPrPB.js +7612 -0
- package/dist/git-command.d.ts +422 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +326 -5
- package/dist/git.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/index.d.ts +1 -0
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +123 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +41 -0
- package/dist/remote-config/remote-refs.d.ts.map +1 -0
- package/dist/rename/detect-renames.d.ts +148 -0
- package/dist/rename/detect-renames.d.ts.map +1 -0
- package/dist/rename/git-similarity.d.ts +44 -0
- package/dist/rename/git-similarity.d.ts.map +1 -0
- package/dist/rename/index.d.ts +2 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/binary-patch.d.ts +11 -0
- package/dist/results/binary-patch.d.ts.map +1 -0
- package/dist/results/blame-format.d.ts +55 -0
- package/dist/results/blame-format.d.ts.map +1 -0
- package/dist/results/cherry-pick-result.d.ts +10 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +16 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +77 -0
- package/dist/results/combined-diff.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +32 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +34 -60
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-order.d.ts +25 -0
- package/dist/results/diff-order.d.ts.map +1 -0
- package/dist/results/diff-output.d.ts +249 -0
- package/dist/results/diff-output.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +24 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +5 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -252
- package/dist/results/merge-result.d.ts +15 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +12 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +42 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/quote-path.d.ts +27 -0
- package/dist/results/quote-path.d.ts.map +1 -0
- package/dist/results/rebase-result.d.ts +28 -1
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +10 -0
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +5 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +143 -18
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BZGa2Z3I.js +2934 -0
- package/dist/transport-command.d.ts +56 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -10
- package/src/commands/add-command.ts +1291 -224
- package/src/commands/add-patch/add-interactive.ts +941 -0
- package/src/commands/add-patch/add-patch.ts +1169 -0
- package/src/commands/add-patch/index.ts +5 -0
- package/src/commands/add-patch/patch-backend.ts +239 -0
- package/src/commands/add-patch/patch-modes.ts +249 -0
- package/src/commands/add-patch/patch-session.ts +159 -0
- package/src/commands/am/am-command.ts +1111 -0
- package/src/commands/am/index.ts +2 -0
- package/src/commands/am/mailinfo.ts +1015 -0
- package/src/commands/am/patch-format.ts +121 -0
- package/src/commands/apply/apply-command.ts +832 -0
- package/src/commands/apply/apply-engine.ts +1603 -0
- package/src/commands/apply/apply-parse.ts +1209 -0
- package/src/commands/apply/apply-types.ts +112 -0
- package/src/commands/apply/index.ts +5 -0
- package/src/commands/apply/latin1.ts +171 -0
- package/src/commands/apply/whitespace.ts +260 -0
- package/src/commands/attributes-source.ts +96 -0
- package/src/commands/backfill-command.ts +694 -0
- package/src/commands/bisect/bisect-checkout.ts +217 -0
- package/src/commands/bisect/bisect-command.ts +788 -0
- package/src/commands/bisect/bisect-engine.ts +1079 -0
- package/src/commands/bisect/bisect-graph.ts +595 -0
- package/src/commands/bisect/bisect-quote.ts +92 -0
- package/src/commands/bisect/index.ts +4 -0
- package/src/commands/blame-command.ts +711 -986
- package/src/commands/branch-command.ts +354 -32
- package/src/commands/branch-tracking.ts +331 -0
- package/src/commands/checkout-command.ts +1426 -297
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +532 -85
- package/src/commands/clone-command.ts +826 -55
- package/src/commands/commit-command.ts +1781 -166
- package/src/commands/core-config.ts +196 -0
- package/src/commands/date-format.ts +668 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1898 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +1038 -79
- package/src/commands/format-patch-command.ts +969 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3347 -0
- package/src/commands/fsck/fsck-loose.ts +287 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1044 -0
- package/src/commands/fsck/fsck-object-table.ts +363 -0
- package/src/commands/fsck/fsck-pack.ts +604 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +249 -0
- package/src/commands/gc-command.ts +147 -1
- package/src/commands/git-date.ts +895 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1472 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +706 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +83 -0
- package/src/commands/init-command.ts +60 -11
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1915 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +101 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1386 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1198 -0
- package/src/commands/message-cleanup.ts +275 -0
- package/src/commands/mv-command.ts +976 -0
- package/src/commands/notes-command.ts +890 -0
- package/src/commands/notes-commands.ts +87 -0
- package/src/commands/notes-merge-command.ts +768 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +602 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +377 -0
- package/src/commands/ort-merge.ts +1660 -0
- package/src/commands/ort-recursive.ts +160 -0
- package/src/commands/pack-refs-command.ts +39 -22
- package/src/commands/patch-id.ts +196 -0
- package/src/commands/pathspec-attributes.ts +162 -0
- package/src/commands/pathspec.ts +1199 -0
- package/src/commands/post-index-change.ts +62 -0
- package/src/commands/pretty-format.ts +1431 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +207 -22
- package/src/commands/push-command.ts +236 -23
- package/src/commands/read-tree-command.ts +857 -0
- package/src/commands/rebase-command.ts +3808 -371
- package/src/commands/rebase-todo.ts +584 -0
- package/src/commands/ref-decoration-filter.ts +118 -0
- package/src/commands/reflog-messages.ts +177 -0
- package/src/commands/remote-command.ts +500 -19
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +828 -91
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +277 -0
- package/src/commands/revert-command.ts +152 -399
- package/src/commands/revision-filenames.ts +254 -0
- package/src/commands/revision-range.ts +222 -0
- package/src/commands/revision-resolver.ts +1379 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +869 -0
- package/src/commands/sequencer-support.ts +869 -0
- package/src/commands/serve-repository.ts +125 -0
- package/src/commands/sparse-checkout-command.ts +1389 -0
- package/src/commands/sparse-checkout-support.ts +793 -0
- package/src/commands/stash-apply-command.ts +692 -124
- package/src/commands/stash-create-command.ts +752 -89
- package/src/commands/stash-drop-command.ts +67 -6
- package/src/commands/stash-list-command.ts +10 -4
- package/src/commands/stash-working-tree.ts +387 -0
- package/src/commands/status-command.ts +1426 -97
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +330 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +334 -0
- package/src/commands/submodule-summary.ts +446 -0
- package/src/commands/switch-command.ts +402 -0
- package/src/commands/tag-command.ts +129 -41
- package/src/commands/tracking-info.ts +201 -0
- package/src/commands/trailers.ts +417 -0
- package/src/commands/tree-restore.ts +344 -15
- package/src/commands/untracked-cache-support.ts +194 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +208 -0
- package/src/commands/worktree-lock-command.ts +96 -0
- package/src/commands/worktree-overwrite-checks.ts +641 -0
- package/src/commands/worktree-prune-command.ts +99 -0
- package/src/commands/worktree-remove-command.ts +186 -0
- package/src/commands/worktree-repair-command.ts +59 -0
- package/src/commands/worktree-support.ts +214 -0
- package/src/core-commands/add.command.impl.ts +9 -5
- package/src/core-commands/index.ts +0 -8
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +46 -2
- package/src/errors/command-errors.ts +101 -1
- package/src/errors/commit-errors.ts +18 -2
- package/src/errors/git-api-error.ts +82 -2
- package/src/errors/index.ts +1 -0
- package/src/errors/merge-errors.ts +2 -2
- package/src/errors/rebase-errors.ts +12 -0
- package/src/errors/ref-errors.ts +56 -2
- package/src/errors/remote-errors.ts +2 -2
- package/src/errors/stash-errors.ts +1 -1
- package/src/errors/transport-errors.ts +20 -4
- package/src/errors/worktree-errors.ts +49 -0
- package/src/git-command.ts +1218 -118
- package/src/git.ts +552 -11
- package/src/index.ts +1 -1
- package/src/remote-config/index.ts +1 -0
- package/src/remote-config/remote-config-store.ts +326 -16
- package/src/remote-config/remote-refs.ts +119 -0
- package/src/rename/detect-renames.ts +711 -0
- package/src/rename/git-similarity.ts +116 -0
- package/src/rename/index.ts +2 -0
- package/src/results/binary-patch.ts +401 -0
- package/src/results/blame-format.ts +239 -0
- package/src/results/cherry-pick-result.ts +10 -0
- package/src/results/clone-result.ts +18 -0
- package/src/results/combined-diff.ts +585 -0
- package/src/results/diff-entry.ts +35 -0
- package/src/results/diff-formatter.ts +152 -288
- package/src/results/diff-order.ts +64 -0
- package/src/results/diff-output.ts +1051 -0
- package/src/results/fetch-result.ts +24 -1
- package/src/results/index.ts +5 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +12 -3
- package/src/results/push-result.ts +43 -0
- package/src/results/quote-path.ts +103 -0
- package/src/results/rebase-result.ts +37 -0
- package/src/results/revert-result.ts +10 -0
- package/src/results/stash-result.ts +6 -0
- package/src/results/status-result.ts +288 -27
- package/src/transport-command.ts +139 -2
- package/dist/commands-BpeXZTC3.js +0 -10278
- package/dist/core-commands/checkout.command.d.ts +0 -103
- package/dist/core-commands/checkout.command.d.ts.map +0 -1
- package/dist/core-commands/checkout.command.impl.d.ts +0 -110
- package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
- package/dist/status-result-BapZoQaR.js +0 -411
- package/src/core-commands/checkout.command.impl.ts +0 -564
- package/src/core-commands/checkout.command.ts +0 -125
|
@@ -1,51 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Implements JGit-compatible fluent API for `git add` command:
|
|
5
|
-
* - Add new files to index
|
|
6
|
-
* - Update modified files in index
|
|
7
|
-
* - Optionally remove deleted files (--all mode)
|
|
8
|
-
* - Support for update-only mode (-u flag)
|
|
9
|
-
*
|
|
10
|
-
* Reference: jgit/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* // Add specific files
|
|
15
|
-
* await git.add()
|
|
16
|
-
* .addFilepattern("src/")
|
|
17
|
-
* .addFilepattern("lib/")
|
|
18
|
-
* .call();
|
|
19
|
-
*
|
|
20
|
-
* // Update only tracked files (git add -u)
|
|
21
|
-
* await git.add()
|
|
22
|
-
* .addFilepattern(".")
|
|
23
|
-
* .setUpdate(true)
|
|
24
|
-
* .call();
|
|
25
|
-
*
|
|
26
|
-
* // Add all changes including deletions (git add -A)
|
|
27
|
-
* await git.add()
|
|
28
|
-
* .addFilepattern(".")
|
|
29
|
-
* .setAll(true)
|
|
30
|
-
* .call();
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
import { EMPTY_BLOB_ID, FileMode } from "@statewalker/vcs-core";
|
|
1
|
+
import { FileMode } from "@statewalker/vcs-core";
|
|
2
|
+
import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
|
|
35
3
|
import {
|
|
36
|
-
|
|
37
|
-
|
|
4
|
+
applyStatUpdate,
|
|
5
|
+
compareWithWorktree,
|
|
6
|
+
IndexPathLookup,
|
|
7
|
+
type IndexStatUpdate,
|
|
8
|
+
type NestedRepositoryState,
|
|
9
|
+
type SparseCheckoutPatterns,
|
|
10
|
+
type StagingEntry,
|
|
11
|
+
statUpdateOf,
|
|
12
|
+
unreadableDirectoryWarning,
|
|
38
13
|
type Worktree,
|
|
14
|
+
type WorktreeEntry,
|
|
15
|
+
withWorktreeEntries,
|
|
16
|
+
worktreeEntryChunks,
|
|
39
17
|
} from "@statewalker/vcs-working-tree";
|
|
40
|
-
import { storeWorktreeFile } from "../core-commands/index.js";
|
|
41
18
|
|
|
42
19
|
import {
|
|
20
|
+
AddFailedError,
|
|
43
21
|
IncompatibleOptionsError,
|
|
22
|
+
InvalidArgumentError,
|
|
44
23
|
NoFilepatternError,
|
|
45
24
|
StoreNotAvailableError,
|
|
46
25
|
} from "../errors/index.js";
|
|
47
26
|
import { GitCommand } from "../git-command.js";
|
|
48
|
-
|
|
27
|
+
import {
|
|
28
|
+
type AddInteractiveResult,
|
|
29
|
+
type PatchOptions,
|
|
30
|
+
type PatchResult,
|
|
31
|
+
type PatchSelector,
|
|
32
|
+
patchModeFor,
|
|
33
|
+
runAddInteractive,
|
|
34
|
+
runPatchSelection,
|
|
35
|
+
} from "./add-patch/index.js";
|
|
36
|
+
import { coreBool, worktreeModeTrust } from "./core-config.js";
|
|
37
|
+
import {
|
|
38
|
+
AddToIndexError,
|
|
39
|
+
chmodIndexEntries,
|
|
40
|
+
gitlinkHeadState,
|
|
41
|
+
IndexAdder,
|
|
42
|
+
IndexDirnameCase,
|
|
43
|
+
readGitlinkHead,
|
|
44
|
+
} from "./index-adder.js";
|
|
45
|
+
import { configBool } from "./merge-config.js";
|
|
46
|
+
import {
|
|
47
|
+
DO_MATCH_DIRECTORY,
|
|
48
|
+
DO_MATCH_LEADING_PATHSPEC,
|
|
49
|
+
excludeMatchesPathspec,
|
|
50
|
+
matchPathspec,
|
|
51
|
+
matchPathspecSeen,
|
|
52
|
+
type PathspecItem,
|
|
53
|
+
type PathspecOriginStyle,
|
|
54
|
+
parsePathspec,
|
|
55
|
+
pathspecErrors,
|
|
56
|
+
pathspecItemPath,
|
|
57
|
+
} from "./pathspec.js";
|
|
58
|
+
import { PathspecAttributes } from "./pathspec-attributes.js";
|
|
59
|
+
import { sparsePathAdvice } from "./sparse-checkout-support.js";
|
|
49
60
|
/**
|
|
50
61
|
* Result of AddCommand execution.
|
|
51
62
|
*
|
|
@@ -55,82 +66,39 @@ export interface AddResult {
|
|
|
55
66
|
/** Paths that were added or updated in the index */
|
|
56
67
|
readonly added: string[];
|
|
57
68
|
|
|
58
|
-
/** Paths that were skipped (ignored files) */
|
|
69
|
+
/** Paths that were skipped (ignored files the pathspec matches) */
|
|
59
70
|
readonly skipped: string[];
|
|
60
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The ignored paths git reports ("The following paths are ignored by one of your
|
|
74
|
+
* .gitignore files"): those the pathspec names, not merely matches. When there are any,
|
|
75
|
+
* `call` writes the index and then rejects with an `AddFailedError` carrying this result.
|
|
76
|
+
*/
|
|
77
|
+
readonly ignored: string[];
|
|
78
|
+
|
|
61
79
|
/** Paths that were removed from index (deleted files in --all mode) */
|
|
62
80
|
readonly removed: string[];
|
|
63
81
|
|
|
64
82
|
/** Total number of files processed */
|
|
65
83
|
readonly totalProcessed: number;
|
|
66
|
-
}
|
|
67
84
|
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* - "*" matches within a single path component
|
|
74
|
-
* - "**" matches across path separators
|
|
75
|
-
* - Exact directory prefix matches (e.g., "src" matches "src/file.ts")
|
|
76
|
-
*/
|
|
77
|
-
function matchesPattern(path: string, patterns: string[]): boolean {
|
|
78
|
-
for (const pattern of patterns) {
|
|
79
|
-
if (matchGlob(path, pattern)) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Simple glob matching.
|
|
88
|
-
*/
|
|
89
|
-
function matchGlob(path: string, pattern: string): boolean {
|
|
90
|
-
// "." matches everything
|
|
91
|
-
if (pattern === ".") {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Exact match
|
|
96
|
-
if (path === pattern) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Directory prefix (e.g., "src" matches "src/file")
|
|
101
|
-
if (path.startsWith(`${pattern}/`)) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Extension patterns like "*.ts"
|
|
106
|
-
if (pattern.startsWith("*.") && !pattern.includes("/")) {
|
|
107
|
-
const extension = pattern.slice(1);
|
|
108
|
-
return path.endsWith(extension);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Handle **/* pattern (matches all files)
|
|
112
|
-
if (pattern === "**/*") {
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Glob patterns with * or **
|
|
117
|
-
if (pattern.includes("*")) {
|
|
118
|
-
// Escape regex special chars except * and ?
|
|
119
|
-
const escapedPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
85
|
+
/**
|
|
86
|
+
* The warnings git prints while adding (`core.safecrlf=warn`: "in the working copy of
|
|
87
|
+
* 'x', LF will be replaced by CRLF the next time Git touches it"), in order
|
|
88
|
+
*/
|
|
89
|
+
readonly warnings: string[];
|
|
120
90
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
.replace(/<<<DOUBLESTAR>>>/g, ".*")
|
|
127
|
-
.replace(/\?/g, ".");
|
|
91
|
+
/**
|
|
92
|
+
* What `git add --verbose` (and `--dry-run`) prints: `add '<path>'` for each path given a
|
|
93
|
+
* new entry, `remove '<path>'` for each removed, in git's order
|
|
94
|
+
*/
|
|
95
|
+
readonly output: string[];
|
|
128
96
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
97
|
+
/** With {@link AddCommand.setPatch}: what the hunk selection printed and applied */
|
|
98
|
+
readonly patch?: PatchResult;
|
|
132
99
|
|
|
133
|
-
|
|
100
|
+
/** With {@link AddCommand.setInteractive}: what `git add -i` printed and did */
|
|
101
|
+
readonly interactive?: AddInteractiveResult;
|
|
134
102
|
}
|
|
135
103
|
|
|
136
104
|
/**
|
|
@@ -145,7 +113,107 @@ export class AddCommand extends GitCommand<AddResult> {
|
|
|
145
113
|
private all: boolean | undefined;
|
|
146
114
|
private force = false;
|
|
147
115
|
private intentToAdd = false;
|
|
116
|
+
private renormalize = false;
|
|
117
|
+
private dryRun = false;
|
|
118
|
+
private ignoreMissing = false;
|
|
119
|
+
private ignoreErrors: boolean | undefined;
|
|
120
|
+
private warnEmbeddedRepo = true;
|
|
148
121
|
private worktreeIterator: Worktree | undefined;
|
|
122
|
+
private writeIndex = true;
|
|
123
|
+
private chmod: string | undefined;
|
|
124
|
+
private refreshOnly = false;
|
|
125
|
+
private compatibility: PathspecOriginStyle = "2.56";
|
|
126
|
+
private attributes?: PathspecAttributes;
|
|
127
|
+
private filesToCache = false;
|
|
128
|
+
private pathspecItems: PathspecItem[] = [];
|
|
129
|
+
/** The sparse checkout's patterns, read at the start (undefined: not a sparse checkout) */
|
|
130
|
+
private sparsePatterns?: SparseCheckoutPatterns;
|
|
131
|
+
private verbose = false;
|
|
132
|
+
private patch = false;
|
|
133
|
+
private interactive = false;
|
|
134
|
+
private patchSelector?: PatchSelector;
|
|
135
|
+
private patchOptions: PatchOptions = {};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* `git add --chmod=(+|-)x`: after adding, the index entries of the regular files the
|
|
139
|
+
* pathspec matches get the executable bit set (`+x`) or cleared (`-x`), the files on disk
|
|
140
|
+
* left as they are. Only with a pathspec, as in git. An entry that is no regular file (a
|
|
141
|
+
* symbolic link, a submodule) is not changed: git's "error: cannot chmod +x '<path>'",
|
|
142
|
+
* the command then rejects with `AddFailedError` after writing the index. Any other value
|
|
143
|
+
* throws git's "fatal: --chmod param '<value>' must be either -x or +x".
|
|
144
|
+
*/
|
|
145
|
+
setChmod(chmod: string | undefined): this {
|
|
146
|
+
this.checkCallable();
|
|
147
|
+
this.chmod = chmod;
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* `git add --refresh`: nothing is added; the index entries the pathspec matches whose
|
|
153
|
+
* files still hold their content get the files' fresh stat (git's `refresh_index`). The
|
|
154
|
+
* result's `output` holds what git prints: "<path>: needs merge" for a conflicted path,
|
|
155
|
+
* and with {@link setVerbose} the porcelain lines ("Unstaged changes after refreshing
|
|
156
|
+
* the index:", then `M`, `D`, `T`, `A` or `U`, a tab and the path) of every entry that
|
|
157
|
+
* differs. An element that matches no entry throws git's "fatal: pathspec '<p>' did not
|
|
158
|
+
* match any files" before the index is written.
|
|
159
|
+
*/
|
|
160
|
+
setRefresh(refresh: boolean): this {
|
|
161
|
+
this.checkCallable();
|
|
162
|
+
this.refreshOnly = refresh;
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* `git add --verbose`: changes what {@link setRefresh} reports (the porcelain lines);
|
|
168
|
+
* the paths added and removed are in `output` either way.
|
|
169
|
+
*/
|
|
170
|
+
setVerbose(verbose: boolean): this {
|
|
171
|
+
this.checkCallable();
|
|
172
|
+
this.verbose = verbose;
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Only tell what would be added or removed (`git add --dry-run`): the result lists the
|
|
178
|
+
* paths and `output` git's lines, nothing is stored and the index is left as it is.
|
|
179
|
+
*/
|
|
180
|
+
setDryRun(dryRun: boolean): this {
|
|
181
|
+
this.checkCallable();
|
|
182
|
+
this.dryRun = dryRun;
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* With {@link setDryRun}, pass over pathspec elements that match no file, reporting the
|
|
188
|
+
* ignored ones (`git add --dry-run --ignore-missing`); refused without a dry run, as git
|
|
189
|
+
* refuses it.
|
|
190
|
+
*/
|
|
191
|
+
setIgnoreMissing(ignoreMissing: boolean): this {
|
|
192
|
+
this.checkCallable();
|
|
193
|
+
this.ignoreMissing = ignoreMissing;
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Go on past files that cannot be added (`git add --ignore-errors`, `add.ignoreErrors`):
|
|
199
|
+
* the others are added and the index written, then `call` rejects with an
|
|
200
|
+
* `AddFailedError` naming the failed paths.
|
|
201
|
+
*/
|
|
202
|
+
setIgnoreErrors(ignoreErrors: boolean): this {
|
|
203
|
+
this.checkCallable();
|
|
204
|
+
this.ignoreErrors = ignoreErrors;
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Whether adding a repository found inside the worktree warns "adding embedded git
|
|
210
|
+
* repository" (default; `git add --no-warn-embedded-repo` turns it off).
|
|
211
|
+
*/
|
|
212
|
+
setWarnEmbeddedRepo(warn: boolean): this {
|
|
213
|
+
this.checkCallable();
|
|
214
|
+
this.warnEmbeddedRepo = warn;
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
149
217
|
|
|
150
218
|
/**
|
|
151
219
|
* Add a path to a file/directory whose content should be added.
|
|
@@ -155,6 +223,12 @@ export class AddCommand extends GitCommand<AddResult> {
|
|
|
155
223
|
*
|
|
156
224
|
* If pattern "." is added, all changes in the repository will be added.
|
|
157
225
|
*
|
|
226
|
+
* Each pattern is a git pathspec from the top of the worktree (`*.ts` matches at any
|
|
227
|
+
* depth, `:(glob)`, `:!` excludes, ...). As in git, `call` fails with "fatal: pathspec
|
|
228
|
+
* 'x' did not match any files" (nothing changed) when one names nothing in the worktree
|
|
229
|
+
* or the index, and with an `AddFailedError` (the index written) when one names ignored
|
|
230
|
+
* files without {@link setForce}.
|
|
231
|
+
*
|
|
158
232
|
* @param filepattern Repository-relative path (with "/" as separator)
|
|
159
233
|
* @returns this for chaining
|
|
160
234
|
*/
|
|
@@ -259,6 +333,29 @@ export class AddCommand extends GitCommand<AddResult> {
|
|
|
259
333
|
return this.intentToAdd;
|
|
260
334
|
}
|
|
261
335
|
|
|
336
|
+
/**
|
|
337
|
+
* Apply the clean conversion freshly to every tracked file and add it again, whatever its
|
|
338
|
+
* stat says (`git add --renormalize`): after a change of `.gitattributes` or
|
|
339
|
+
* `core.autocrlf`, the index takes the line endings the new settings give. CRLF already in
|
|
340
|
+
* the index does not hold the conversion back. Only tracked files are touched; as git, it
|
|
341
|
+
* needs a pathspec unless {@link setUpdate} or {@link setAll} is set.
|
|
342
|
+
*
|
|
343
|
+
* @param renormalize Whether to renormalise
|
|
344
|
+
* @returns this for chaining
|
|
345
|
+
*/
|
|
346
|
+
setRenormalize(renormalize: boolean): this {
|
|
347
|
+
this.checkCallable();
|
|
348
|
+
this.renormalize = renormalize;
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Whether renormalisation is enabled.
|
|
354
|
+
*/
|
|
355
|
+
isRenormalize(): boolean {
|
|
356
|
+
return this.renormalize;
|
|
357
|
+
}
|
|
358
|
+
|
|
262
359
|
/**
|
|
263
360
|
* Set a custom working tree iterator.
|
|
264
361
|
*
|
|
@@ -273,6 +370,173 @@ export class AddCommand extends GitCommand<AddResult> {
|
|
|
273
370
|
return this;
|
|
274
371
|
}
|
|
275
372
|
|
|
373
|
+
/**
|
|
374
|
+
* Stage as git's `add_files_to_cache` alone (`commit -i <paths>`, with {@link setUpdate}):
|
|
375
|
+
* an element naming no file is not refused as `git add` refuses it ("did not match any
|
|
376
|
+
* files"); one matching no index entry fails with "error: pathspec '<element>' did not
|
|
377
|
+
* match any file(s) known to git".
|
|
378
|
+
*
|
|
379
|
+
* @internal
|
|
380
|
+
*/
|
|
381
|
+
setFilesToCache(filesToCache: boolean): this {
|
|
382
|
+
this.checkCallable();
|
|
383
|
+
this.filesToCache = filesToCache;
|
|
384
|
+
return this;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* The git version whose messages are reproduced where versions differ (default 2.56):
|
|
389
|
+
* the advice's last hint, `Disable this message with "git config set advice.<name>
|
|
390
|
+
* false"` in 2.5x, `"git config advice.<name> false"` in 2.43; and 2.43 refuses
|
|
391
|
+
* `:(attr:...)` elements ("pathspec magic not supported by this command: 'attr'").
|
|
392
|
+
*/
|
|
393
|
+
setCompatibility(version: PathspecOriginStyle): this {
|
|
394
|
+
this.checkCallable();
|
|
395
|
+
this.compatibility = version;
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** git's closing hint of an advice (`advise_if_enabled`), as the version words it. */
|
|
400
|
+
private disableHint(name: string): string {
|
|
401
|
+
const command = this.compatibility === "2.43" ? "git config" : "git config set";
|
|
402
|
+
return `hint: Disable this message with "${command} advice.${name} false"`;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Whether the index is written at the end (the default). Without, the staging area is
|
|
407
|
+
* only updated in memory and the caller writes it: git commit's partial commit
|
|
408
|
+
* (`add_remove_files`), whose index is written only once the commit is made.
|
|
409
|
+
*
|
|
410
|
+
* @internal
|
|
411
|
+
*/
|
|
412
|
+
setWriteIndex(write: boolean): this {
|
|
413
|
+
this.checkCallable();
|
|
414
|
+
this.writeIndex = write;
|
|
415
|
+
return this;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* `git add -p` (`--patch`): the changes between the index and the worktree are offered
|
|
420
|
+
* hunk by hunk, as git's add-patch.c does, and the selected hunks are staged. The
|
|
421
|
+
* prompts are answered by {@link setPatchSelector}; the result's `patch` carries git's
|
|
422
|
+
* transcript. Untracked files are not offered (`add -N` them first), binary files are
|
|
423
|
+
* passed over. The other options but the pathspec do not apply.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* const answers = ["y", "n", "s", "y", "q"];
|
|
428
|
+
* const { patch } = await git.add().setPatch(true).setPatchSelector(() => answers.shift()).call();
|
|
429
|
+
* process.stdout.write(patch?.output ?? "");
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
setPatch(patch: boolean): this {
|
|
433
|
+
this.checkCallable();
|
|
434
|
+
this.patch = patch;
|
|
435
|
+
return this;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* `git add -i` (`--interactive`): add-interactive.c's session. The status of the paths
|
|
440
|
+
* the pathspec names is listed, then the "*** Commands ***" menu offers status, update,
|
|
441
|
+
* revert, add untracked, patch, diff, quit and help until `quit` (or the end of input).
|
|
442
|
+
* Every read git makes from standard input goes to {@link setPatchSelector}: the menus and
|
|
443
|
+
* file selections as `choose` requests ("What now> ", "Update>> ", ...), patch mode's
|
|
444
|
+
* prompts as `add -p` asks them. The result's `interactive` carries git's standard output
|
|
445
|
+
* and standard error; {@link setCompatibility} picks the version (2.43 takes no `-U`,
|
|
446
|
+
* `--inter-hunk-context` or `--no-auto-advance` from {@link setPatchOptions}). The other
|
|
447
|
+
* options but the pathspec do not apply ({@link setPatch} wins when both are set).
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* const answers = ["u", "1-2", "", "q"];
|
|
452
|
+
* const { interactive } = await git.add().setInteractive(true)
|
|
453
|
+
* .setPatchSelector(() => answers.shift()).call();
|
|
454
|
+
* process.stdout.write(interactive?.output ?? "");
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
setInteractive(interactive: boolean): this {
|
|
458
|
+
this.checkCallable();
|
|
459
|
+
this.interactive = interactive;
|
|
460
|
+
return this;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** Answers the prompts of {@link setPatch} (git's reads from standard input and its editor). */
|
|
464
|
+
setPatchSelector(selector: PatchSelector): this {
|
|
465
|
+
this.checkCallable();
|
|
466
|
+
this.patchSelector = selector;
|
|
467
|
+
return this;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** `-U<n>`, `--inter-hunk-context=<n>` and `--no-auto-advance` of {@link setPatch}. */
|
|
471
|
+
setPatchOptions(options: PatchOptions): this {
|
|
472
|
+
this.checkCallable();
|
|
473
|
+
this.patchOptions = { ...options };
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** `git add -p`: the selection, staged through `git apply --cached`. */
|
|
478
|
+
private async callPatch(): Promise<AddResult> {
|
|
479
|
+
if (this.dryRun) {
|
|
480
|
+
throw new IncompatibleOptionsError(
|
|
481
|
+
["--dry-run", "--interactive/--patch"],
|
|
482
|
+
"fatal: options '--dry-run' and '--interactive/--patch' cannot be used together",
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
const patch = await runPatchSelection(this.workingCopy, {
|
|
486
|
+
hookSource: this,
|
|
487
|
+
...this.patchOptions,
|
|
488
|
+
mode: patchModeFor("add"),
|
|
489
|
+
selector: this.patchSelector,
|
|
490
|
+
paths: this.filepatterns,
|
|
491
|
+
compatibility: this.compatibility,
|
|
492
|
+
});
|
|
493
|
+
return {
|
|
494
|
+
added: patch.applied,
|
|
495
|
+
skipped: [],
|
|
496
|
+
ignored: [],
|
|
497
|
+
removed: [],
|
|
498
|
+
totalProcessed: patch.applied.length,
|
|
499
|
+
warnings: [],
|
|
500
|
+
output: [],
|
|
501
|
+
patch,
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** `git add -i`: the session, staging through `add_file_to_index` (this command's kind). */
|
|
506
|
+
private async callInteractive(): Promise<AddResult> {
|
|
507
|
+
if (this.dryRun) {
|
|
508
|
+
throw new IncompatibleOptionsError(
|
|
509
|
+
["--dry-run", "--interactive/--patch"],
|
|
510
|
+
"fatal: options '--dry-run' and '--interactive/--patch' cannot be used together",
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
const selector = this.patchSelector;
|
|
514
|
+
if (!selector) {
|
|
515
|
+
throw new InvalidArgumentError(
|
|
516
|
+
"patchSelector",
|
|
517
|
+
undefined,
|
|
518
|
+
"interactive mode needs a selector (setPatchSelector) to answer its prompts",
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
const interactive = await runAddInteractive(this.workingCopy, {
|
|
522
|
+
...this.patchOptions,
|
|
523
|
+
selector,
|
|
524
|
+
paths: this.filepatterns,
|
|
525
|
+
compatibility: this.compatibility,
|
|
526
|
+
hookSource: this,
|
|
527
|
+
});
|
|
528
|
+
return {
|
|
529
|
+
added: interactive.added,
|
|
530
|
+
skipped: [],
|
|
531
|
+
ignored: [],
|
|
532
|
+
removed: [],
|
|
533
|
+
totalProcessed: interactive.added.length,
|
|
534
|
+
warnings: [],
|
|
535
|
+
output: [],
|
|
536
|
+
interactive,
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
276
540
|
/**
|
|
277
541
|
* Execute the add command.
|
|
278
542
|
*
|
|
@@ -283,26 +547,55 @@ export class AddCommand extends GitCommand<AddResult> {
|
|
|
283
547
|
async call(): Promise<AddResult> {
|
|
284
548
|
this.checkCallable();
|
|
285
549
|
this.setCallable(false);
|
|
550
|
+
// the index as it is now, before the worktree or a ref is touched: one another writer
|
|
551
|
+
// replaced is read again (git reads the index at its start), unless this instance holds
|
|
552
|
+
// unwritten edits (refused)
|
|
553
|
+
await this.readCurrentIndex();
|
|
554
|
+
if (this.patch) return this.callPatch();
|
|
555
|
+
if (this.interactive) return this.callInteractive();
|
|
556
|
+
this.sparsePatterns = await this.sparseCheckoutPatterns();
|
|
286
557
|
|
|
287
558
|
// Validate options - update and all are mutually exclusive
|
|
288
559
|
if (this.update && this.all !== undefined) {
|
|
289
560
|
throw new IncompatibleOptionsError(["--update", "--all/--no-all"]);
|
|
290
561
|
}
|
|
562
|
+
if (this.ignoreMissing && !this.dryRun) {
|
|
563
|
+
throw new InvalidArgumentError(
|
|
564
|
+
"ignoreMissing",
|
|
565
|
+
true,
|
|
566
|
+
"fatal: the option '--ignore-missing' requires '--dry-run'",
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
if (this.chmod !== undefined && !/^[+-]x$/.test(this.chmod)) {
|
|
570
|
+
throw new InvalidArgumentError(
|
|
571
|
+
"chmod",
|
|
572
|
+
this.chmod,
|
|
573
|
+
`fatal: --chmod param '${this.chmod}' must be either -x or +x`,
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
// git's require_pathspec ("Nothing specified, nothing added."), a renormalisation
|
|
577
|
+
// included: only `-u` and `-A` go without one
|
|
578
|
+
if (this.filepatterns.length === 0 && !(this.update || this.all === true)) {
|
|
579
|
+
// (git prints it with a hint and exits 0)
|
|
580
|
+
throw new NoFilepatternError("Nothing specified, nothing added.").withExitCode(0);
|
|
581
|
+
}
|
|
291
582
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (this.all === undefined && !this.update) {
|
|
303
|
-
this.all = true;
|
|
304
|
-
}
|
|
583
|
+
let items: PathspecItem[];
|
|
584
|
+
try {
|
|
585
|
+
// git 2.43's cmd_add masks PATHSPEC_ATTR: `:(attr:...)` is refused there
|
|
586
|
+
items = parsePathspec(this.filepatterns, { attr: this.compatibility !== "2.43" });
|
|
587
|
+
} catch (error) {
|
|
588
|
+
throw new InvalidArgumentError(
|
|
589
|
+
"filepattern",
|
|
590
|
+
this.filepatterns,
|
|
591
|
+
`fatal: ${(error as Error).message}`,
|
|
592
|
+
);
|
|
305
593
|
}
|
|
594
|
+
// the elements as given (and the "." git adds when every element excludes)
|
|
595
|
+
const originals =
|
|
596
|
+
items.length > this.filepatterns.length
|
|
597
|
+
? [...this.filepatterns, "."]
|
|
598
|
+
: [...this.filepatterns];
|
|
306
599
|
|
|
307
600
|
// Get working tree iterator
|
|
308
601
|
const worktree = this.getWorktreeIterator();
|
|
@@ -313,15 +606,21 @@ export class AddCommand extends GitCommand<AddResult> {
|
|
|
313
606
|
"Ensure WorkingCopy has worktree or call setWorktreeStore().",
|
|
314
607
|
);
|
|
315
608
|
}
|
|
609
|
+
await checkSymlinkLeadingPaths(worktree, items, originals);
|
|
610
|
+
// `:(attr:...)`: the attributes of the index's paths (the worktree's read as it is walked)
|
|
611
|
+
this.pathspecItems = items;
|
|
612
|
+
this.attributes = PathspecAttributes.forWorktree(items, worktree);
|
|
613
|
+
if (this.attributes) await this.attributes.load((await this.indexGroups()).map((g) => g.path));
|
|
316
614
|
|
|
317
|
-
//
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
615
|
+
// one worktree batch: the ignore rules, the configuration and the attributes files are
|
|
616
|
+
// read once for all the files
|
|
617
|
+
const run = () =>
|
|
618
|
+
this.refreshOnly
|
|
619
|
+
? this.refreshFiles(worktree, items, originals)
|
|
620
|
+
: this.renormalize
|
|
621
|
+
? this.renormalizeFiles(worktree, items, originals)
|
|
622
|
+
: this.processFiles(worktree, items, originals);
|
|
623
|
+
return worktree.batch ? worktree.batch(run) : run();
|
|
325
624
|
}
|
|
326
625
|
|
|
327
626
|
/**
|
|
@@ -336,150 +635,918 @@ export class AddCommand extends GitCommand<AddResult> {
|
|
|
336
635
|
return this.worktreeAccess;
|
|
337
636
|
}
|
|
338
637
|
|
|
638
|
+
/** `add.ignoreErrors` (or `add.ignore-errors`) unless set on the command. */
|
|
639
|
+
private ignoringErrors(): boolean {
|
|
640
|
+
if (this.ignoreErrors !== undefined) return this.ignoreErrors;
|
|
641
|
+
try {
|
|
642
|
+
return (
|
|
643
|
+
configBool(this.workingCopy, "add.ignoreErrors", false) ||
|
|
644
|
+
configBool(this.workingCopy, "add.ignore-errors", false)
|
|
645
|
+
);
|
|
646
|
+
} catch {
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/** `advice.<name>`, true unless the configuration turns it off. */
|
|
652
|
+
private advice(name: string): boolean {
|
|
653
|
+
try {
|
|
654
|
+
return configBool(this.workingCopy, `advice.${name}`, true);
|
|
655
|
+
} catch {
|
|
656
|
+
return true;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
339
660
|
/**
|
|
340
|
-
*
|
|
661
|
+
* git's `cmd_add` without `--renormalize`:
|
|
662
|
+
*
|
|
663
|
+
* 1. the untracked files the pathspec matches are found (`fill_directory`, unless `-u`),
|
|
664
|
+
* ignored ones the pathspec names collected for the report, a repository inside the
|
|
665
|
+
* worktree found as one entry (a gitlink to come);
|
|
666
|
+
* 2. an element that matched nothing, in the worktree or the index, names no file: git's
|
|
667
|
+
* "fatal: pathspec '<element>' did not match any files" before anything changes;
|
|
668
|
+
* 3. the tracked paths the pathspec matches are brought up to date (`add_files_to_cache`):
|
|
669
|
+
* a file gone, or a directory in its place that holds no repository with a commit, is
|
|
670
|
+
* removed (unless `--no-all`), a changed one added again, a conflict resolved;
|
|
671
|
+
* 4. the untracked files are added (`add_files`), and the index written; ignored paths,
|
|
672
|
+
* or files `--ignore-errors` passed over, then fail the command (git's exit status 1).
|
|
341
673
|
*/
|
|
342
674
|
private async processFiles(
|
|
343
675
|
worktree: Worktree,
|
|
344
|
-
|
|
345
|
-
|
|
676
|
+
items: PathspecItem[],
|
|
677
|
+
originals: string[],
|
|
346
678
|
): Promise<AddResult> {
|
|
347
679
|
const added: string[] = [];
|
|
348
680
|
const skipped: string[] = [];
|
|
349
681
|
const removed: string[] = [];
|
|
682
|
+
const warnings: string[] = [];
|
|
683
|
+
const output: string[] = [];
|
|
684
|
+
const ignoreErrors = this.ignoringErrors();
|
|
685
|
+
const addNewFiles = !this.update;
|
|
686
|
+
// `-A` (the default with a pathspec), or `-u`: removals are staged; `--no-all` keeps them
|
|
687
|
+
const ignoreRemoval = !(this.update || this.all !== false);
|
|
350
688
|
|
|
351
|
-
|
|
352
|
-
const filesToProcess: Array<{
|
|
353
|
-
path: string;
|
|
354
|
-
exists: boolean;
|
|
355
|
-
isIgnored: boolean;
|
|
356
|
-
}> = [];
|
|
689
|
+
const index = await this.indexGroups();
|
|
357
690
|
|
|
358
|
-
//
|
|
359
|
-
|
|
360
|
-
|
|
691
|
+
// 1. the untracked files (git's fill_directory and prune_directory)
|
|
692
|
+
const seen = items.map(() => 0);
|
|
693
|
+
const untracked: Array<{ path: string; entry: WorktreeEntry; repository: boolean }> = [];
|
|
694
|
+
let ignored: string[] = [];
|
|
695
|
+
if (addNewFiles) {
|
|
696
|
+
const scan = await this.scanUntracked(worktree, items, index, seen);
|
|
697
|
+
untracked.push(...scan.untracked);
|
|
698
|
+
skipped.push(...scan.skipped);
|
|
699
|
+
warnings.push(...scan.warnings);
|
|
700
|
+
ignored = scan.ignored;
|
|
701
|
+
}
|
|
702
|
+
// what the index has matches too (add_pathspec_matches_against_index with
|
|
703
|
+
// PS_IGNORE_SKIP_WORKTREE: a skip-worktree entry is advised on instead)
|
|
704
|
+
for (const group of index) {
|
|
705
|
+
if (isSkipWorktree(group) || this.outsideSparse(group.path)) continue;
|
|
706
|
+
matchPathspecSeen(items, group.path, group.gitlink ? DO_MATCH_DIRECTORY : 0, seen);
|
|
707
|
+
}
|
|
361
708
|
|
|
362
|
-
|
|
363
|
-
|
|
709
|
+
// 2. an element that matched nothing must name an existing file, unless it matches
|
|
710
|
+
// entries outside the sparse checkout (git's advice, the command failing in the end)
|
|
711
|
+
const sparse: string[] = [];
|
|
712
|
+
let skipSeen: number[] | undefined;
|
|
713
|
+
// (not for `commit -i`, which calls add_files_to_cache alone)
|
|
714
|
+
for (let i = 0; i < items.length && !this.filesToCache; i++) {
|
|
715
|
+
const item = items[i] as PathspecItem;
|
|
716
|
+
if (item.exclude || seen[i]) continue;
|
|
717
|
+
skipSeen ??= skipWorktreeSeen(items, index, (path) => this.outsideSparse(path));
|
|
718
|
+
if (skipSeen[i]) {
|
|
719
|
+
sparse.push(originals[i] as string);
|
|
364
720
|
continue;
|
|
365
721
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
722
|
+
// "Don't complain at 'git add .' on empty repo"
|
|
723
|
+
if (item.match === "") continue;
|
|
724
|
+
// reported as given, its "/" kept (git's dir_add_ignored of the match)
|
|
725
|
+
const literal = pathspecItemPath(item);
|
|
726
|
+
const path = literal.replace(/\/+$/, "");
|
|
727
|
+
if (!(await namesFile(worktree, item))) {
|
|
728
|
+
if (!this.ignoreMissing) {
|
|
729
|
+
throw new InvalidArgumentError(
|
|
730
|
+
"filepattern",
|
|
731
|
+
originals[i],
|
|
732
|
+
`fatal: pathspec '${originals[i]}' did not match any files`,
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
if (await worktree.isIgnored(path, path !== literal)) ignored.push(literal);
|
|
371
736
|
}
|
|
372
|
-
|
|
373
|
-
filesToProcess.push({
|
|
374
|
-
path: entry.path,
|
|
375
|
-
exists: true,
|
|
376
|
-
isIgnored: entry.isIgnored,
|
|
377
|
-
});
|
|
378
737
|
}
|
|
379
738
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
739
|
+
const trust = worktreeModeTrust(this.workingCopy, worktree);
|
|
740
|
+
const adder = await IndexAdder.open(this.staging, this.blobs, trust, { pretend: this.dryRun });
|
|
741
|
+
const failed: string[] = [];
|
|
742
|
+
const errors: string[] = [];
|
|
743
|
+
const addedSet = new Set<string>();
|
|
744
|
+
// add_to_index's adjust_dirname_case (core.ignorecase): a new file's leading directories
|
|
745
|
+
// take the index's spelling, built on first use, without the entries this command
|
|
746
|
+
// removed before (remove_name_hash drops a directory they leave empty; a dry run,
|
|
747
|
+
// ADD_CACHE_PRETEND, removes nothing)
|
|
748
|
+
let dirnameCase: IndexDirnameCase | undefined;
|
|
749
|
+
const indexName = (path: string): string => {
|
|
750
|
+
if (!coreBool(this.workingCopy, "ignorecase", false) || !path.includes("/")) return path;
|
|
751
|
+
if (!dirnameCase) {
|
|
752
|
+
dirnameCase = new IndexDirnameCase(index.map((group) => group.path));
|
|
753
|
+
if (!this.dryRun) for (const gone of removed) dirnameCase.forget(gone);
|
|
754
|
+
}
|
|
755
|
+
const name = dirnameCase.adjust(path);
|
|
756
|
+
if (!this.dryRun) dirnameCase.note(name);
|
|
757
|
+
return name;
|
|
758
|
+
};
|
|
759
|
+
const addOne = async (
|
|
760
|
+
path: string,
|
|
761
|
+
entry: WorktreeEntry,
|
|
762
|
+
displayPath: string,
|
|
763
|
+
indexed?: StagingEntry,
|
|
764
|
+
untrackedFile = false,
|
|
765
|
+
): Promise<"ok" | "failed"> => {
|
|
766
|
+
try {
|
|
767
|
+
const name = untrackedFile ? indexName(path) : path;
|
|
768
|
+
const outcome = await adder.add(worktree, path, entry, {
|
|
769
|
+
intentToAdd: this.intentToAdd,
|
|
770
|
+
displayPath,
|
|
771
|
+
onWarning: (message) => warnings.push(message),
|
|
772
|
+
...(indexed ? { indexed } : {}),
|
|
773
|
+
...(name !== path ? { indexPath: name } : {}),
|
|
774
|
+
});
|
|
775
|
+
// a file turned repository is met twice (`add .`): tracked, then untracked
|
|
776
|
+
if (!addedSet.has(path)) {
|
|
777
|
+
addedSet.add(path);
|
|
778
|
+
added.push(path);
|
|
386
779
|
}
|
|
780
|
+
if (outcome === "added") output.push(`add '${displayPath}'`);
|
|
781
|
+
return "ok";
|
|
782
|
+
} catch (error) {
|
|
783
|
+
if (!(error instanceof AddToIndexError)) throw error;
|
|
784
|
+
errors.push(...error.lines);
|
|
785
|
+
failed.push(path);
|
|
786
|
+
return "failed";
|
|
387
787
|
}
|
|
788
|
+
};
|
|
388
789
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
790
|
+
// 3. the tracked paths (add_files_to_cache: run_diff_files and update_callback)
|
|
791
|
+
const psMatched = items.map(() => 0);
|
|
792
|
+
const matched = index.filter((group) =>
|
|
793
|
+
matchPathspecSeen(items, group.path, group.gitlink ? DO_MATCH_DIRECTORY : 0, psMatched),
|
|
794
|
+
);
|
|
795
|
+
// the stat pass over the matched paths, a chunk at a time (git's preload_index)
|
|
796
|
+
const stated = (group: (typeof index)[number]) => {
|
|
797
|
+
const first = group.entries[0] as StagingEntry;
|
|
798
|
+
return first.stage !== 0 || !(first.skipWorktree || first.assumeValid);
|
|
799
|
+
};
|
|
800
|
+
// one promise per chunk: the entries clean by their stat (most of them) are settled in
|
|
801
|
+
// the loop, without a call into the adder
|
|
802
|
+
const quick = !this.intentToAdd;
|
|
803
|
+
for await (const chunk of worktreeEntryChunks(worktree, matched, stated)) {
|
|
804
|
+
for (let at = 0; at < chunk.items.length; at++) {
|
|
805
|
+
const group = chunk.items[at] as IndexGroup;
|
|
806
|
+
const found = chunk.current[at];
|
|
807
|
+
const { path, entries } = group;
|
|
808
|
+
const first = entries[0] as StagingEntry;
|
|
809
|
+
const unmerged = first.stage !== 0;
|
|
810
|
+
// up to date by promise: skip-worktree, assume-unchanged (CE_VALID)
|
|
811
|
+
if (found === undefined) continue;
|
|
812
|
+
// update_callback passes over paths outside the sparse checkout's patterns
|
|
813
|
+
if (this.outsideSparse(path)) continue;
|
|
814
|
+
// add_to_index of a file whose stat still matches its entry: nothing to do
|
|
815
|
+
if (quick && found && adder.unchangedByStat(first, found)) {
|
|
816
|
+
if (!addedSet.has(path)) {
|
|
817
|
+
addedSet.add(path);
|
|
818
|
+
added.push(path);
|
|
819
|
+
}
|
|
392
820
|
continue;
|
|
393
821
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
822
|
+
const current = found ?? undefined;
|
|
823
|
+
if (!current && (await worktree.isSpecialFile?.(path))) {
|
|
824
|
+
// a FIFO, socket or device took its place: add_to_index refuses it
|
|
825
|
+
errors.push(
|
|
826
|
+
`error: ${path}: can only add regular files, symbolic links or git-directories`,
|
|
827
|
+
);
|
|
828
|
+
failed.push(path);
|
|
829
|
+
if (ignoreErrors) continue;
|
|
830
|
+
throw new AddFailedError(
|
|
831
|
+
[...errors, "fatal: updating files failed"].join("\n"),
|
|
832
|
+
[],
|
|
833
|
+
failed,
|
|
834
|
+
undefined,
|
|
835
|
+
output,
|
|
836
|
+
warnings,
|
|
837
|
+
).withExitCode(128);
|
|
838
|
+
}
|
|
839
|
+
const removal = await this.removalState(worktree, first, current);
|
|
840
|
+
if (removal === "unknown") {
|
|
841
|
+
warnings.push(unreadableRepositoryWarning(path));
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
const gone = removal === "removed";
|
|
845
|
+
if (gone && !ignoreRemoval) {
|
|
846
|
+
adder.remove(path);
|
|
847
|
+
removed.push(path);
|
|
848
|
+
output.push(`remove '${path}'`);
|
|
849
|
+
continue;
|
|
850
|
+
}
|
|
851
|
+
if (gone && !unmerged) continue;
|
|
852
|
+
if (!current) {
|
|
853
|
+
// an unmerged path asked to be added (`--no-all`) that is not there
|
|
854
|
+
throw new AddFailedError(
|
|
855
|
+
[...errors, `fatal: unable to stat '${path}': No such file or directory`].join("\n"),
|
|
856
|
+
[],
|
|
857
|
+
[...failed, path],
|
|
858
|
+
undefined,
|
|
859
|
+
output,
|
|
860
|
+
warnings,
|
|
861
|
+
).withExitCode(128);
|
|
862
|
+
}
|
|
863
|
+
// an unpopulated submodule is no change (no commit checked out to compare)
|
|
864
|
+
if (!unmerged && first.mode === FileMode.GITLINK && current.isDirectory) {
|
|
865
|
+
if (!(await readGitlinkHead(worktree, path))) continue;
|
|
866
|
+
}
|
|
867
|
+
const indexed = unmerged ? undefined : first;
|
|
868
|
+
if ((await addOne(path, current, path, indexed)) === "failed" && !ignoreErrors) {
|
|
869
|
+
throw new AddFailedError(
|
|
870
|
+
[...errors, "fatal: updating files failed"].join("\n"),
|
|
871
|
+
[],
|
|
872
|
+
failed,
|
|
873
|
+
undefined,
|
|
874
|
+
output,
|
|
875
|
+
warnings,
|
|
876
|
+
).withExitCode(128);
|
|
403
877
|
}
|
|
404
878
|
}
|
|
405
879
|
}
|
|
880
|
+
if (this.update && !ignoreErrors) {
|
|
881
|
+
const problems = pathspecErrors(originals, psMatched);
|
|
882
|
+
if (problems.length > 0) {
|
|
883
|
+
// report_path_error, then exit(128) (add_files_to_cache's callers)
|
|
884
|
+
throw new InvalidArgumentError(
|
|
885
|
+
"filepattern",
|
|
886
|
+
originals.filter((_, i) => !psMatched[i]),
|
|
887
|
+
problems.join("\n"),
|
|
888
|
+
).withExitCode(128);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
406
891
|
|
|
407
|
-
//
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
892
|
+
// 4. the untracked files (add_files)
|
|
893
|
+
const messages: string[] = sparse.length > 0 ? this.sparseAdvice(sparse) : [];
|
|
894
|
+
if (ignored.length > 0) {
|
|
895
|
+
messages.push("The following paths are ignored by one of your .gitignore files:", ...ignored);
|
|
896
|
+
if (this.advice("addIgnoredFile")) {
|
|
897
|
+
messages.push(
|
|
898
|
+
"hint: Use -f if you really want to add them.",
|
|
899
|
+
this.disableHint("addIgnoredFile"),
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
let advisedEmbedded = false;
|
|
904
|
+
// add_files: an untracked file outside the sparse checkout is advised on, not added
|
|
905
|
+
const sparseUntracked: string[] = [];
|
|
906
|
+
for (const file of untracked) {
|
|
907
|
+
// (a repository is the directory entry `sub/`, asked and advised on as such)
|
|
908
|
+
const displayPath = file.repository ? `${file.path}/` : file.path;
|
|
909
|
+
if (this.outsideSparse(displayPath)) {
|
|
910
|
+
sparseUntracked.push(displayPath);
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
const untrackedFile = !file.repository;
|
|
914
|
+
if (
|
|
915
|
+
(await addOne(file.path, file.entry, displayPath, undefined, untrackedFile)) === "failed"
|
|
916
|
+
) {
|
|
917
|
+
if (!ignoreErrors) {
|
|
918
|
+
throw new AddFailedError(
|
|
919
|
+
[...messages, ...errors, "fatal: adding files failed"].join("\n"),
|
|
920
|
+
ignored,
|
|
921
|
+
failed,
|
|
922
|
+
undefined,
|
|
923
|
+
output,
|
|
924
|
+
warnings,
|
|
925
|
+
).withExitCode(128);
|
|
413
926
|
}
|
|
927
|
+
continue;
|
|
414
928
|
}
|
|
929
|
+
if (file.repository && this.warnEmbeddedRepo) {
|
|
930
|
+
warnings.push(`warning: adding embedded git repository: ${file.path}`);
|
|
931
|
+
if (!advisedEmbedded && this.advice("addEmbeddedRepo")) {
|
|
932
|
+
advisedEmbedded = true;
|
|
933
|
+
warnings.push(...embeddedRepoAdvice(file.path), this.disableHint("addEmbeddedRepo"));
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
}
|
|
415
937
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
938
|
+
if (sparseUntracked.length > 0) messages.push(...this.sparseAdvice(sparseUntracked));
|
|
939
|
+
await adder.finish();
|
|
940
|
+
// --chmod: the entries the pathspec matches, once everything is added (chmod_pathspec)
|
|
941
|
+
const chmodErrors = this.chmod && items.length > 0 ? await this.chmodEntries(items) : [];
|
|
942
|
+
// Persist staging changes (required for FileStagingStore)
|
|
943
|
+
if (this.writeIndex && !this.dryRun) await this.writeIfChanged();
|
|
944
|
+
|
|
945
|
+
const result: AddResult = {
|
|
946
|
+
added,
|
|
947
|
+
skipped,
|
|
948
|
+
ignored,
|
|
949
|
+
removed,
|
|
950
|
+
totalProcessed: added.length + removed.length,
|
|
951
|
+
warnings,
|
|
952
|
+
output,
|
|
953
|
+
};
|
|
954
|
+
if (
|
|
955
|
+
ignored.length > 0 ||
|
|
956
|
+
failed.length > 0 ||
|
|
957
|
+
chmodErrors.length > 0 ||
|
|
958
|
+
sparse.length > 0 ||
|
|
959
|
+
sparseUntracked.length > 0
|
|
960
|
+
) {
|
|
961
|
+
throw new AddFailedError(
|
|
962
|
+
[...messages, ...errors, ...chmodErrors].join("\n"),
|
|
963
|
+
ignored,
|
|
964
|
+
failed,
|
|
965
|
+
result,
|
|
966
|
+
output,
|
|
967
|
+
warnings,
|
|
968
|
+
);
|
|
419
969
|
}
|
|
970
|
+
return result;
|
|
971
|
+
}
|
|
420
972
|
|
|
421
|
-
|
|
422
|
-
|
|
973
|
+
/**
|
|
974
|
+
* Writes the index when this add changed it (git's `write_locked_index` with
|
|
975
|
+
* `SKIP_IF_UNCHANGED`: skip-worktree flags cleared on reading alone write nothing), or when
|
|
976
|
+
* the configuration changes it on reading (`core.splitIndex`, `core.untrackedCache`: git's
|
|
977
|
+
* `tweak_split_index` and `tweak_untracked_cache` mark the index changed).
|
|
978
|
+
*/
|
|
979
|
+
private async writeIfChanged(): Promise<void> {
|
|
980
|
+
if (
|
|
981
|
+
this.staging.hasUnwrittenChanges?.() === false &&
|
|
982
|
+
!(await this.staging.wantsRewrite?.({ untrackedCache: true }))
|
|
983
|
+
) {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
await this.staging.write();
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
/** Whether `path` is outside the sparse checkout's patterns (git's `!path_in_sparse_checkout`). */
|
|
990
|
+
private outsideSparse(path: string): boolean {
|
|
991
|
+
return this.sparsePatterns !== undefined && !this.sparsePatterns.includes(path);
|
|
992
|
+
}
|
|
423
993
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
994
|
+
/** `--chmod` over the entries the pathspec matches (see {@link chmodIndexEntries}). */
|
|
995
|
+
private async chmodEntries(items: PathspecItem[]): Promise<string[]> {
|
|
996
|
+
const flip = (this.chmod as string)[0] as "+" | "-";
|
|
997
|
+
const flags = (entry: StagingEntry) =>
|
|
998
|
+
entry.mode === FileMode.GITLINK ? DO_MATCH_DIRECTORY : 0;
|
|
999
|
+
return chmodIndexEntries(
|
|
1000
|
+
this.staging,
|
|
1001
|
+
flip,
|
|
1002
|
+
(e) => !this.outsideSparse(e.path) && matchPathspec(items, e.path, flags(e)) > 0,
|
|
1003
|
+
{
|
|
1004
|
+
pretend: this.dryRun,
|
|
1005
|
+
},
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* `git add --refresh` (git's `refresh` over `refresh_index` with `REFRESH_QUIET`, or
|
|
1011
|
+
* `REFRESH_IN_PORCELAIN` when verbose): the matching entries compared with their files,
|
|
1012
|
+
* those still holding their content given the fresh stat; the lines git prints in
|
|
1013
|
+
* `output`. An element that matches no entry dies before the index is written.
|
|
1014
|
+
*/
|
|
1015
|
+
private async refreshFiles(
|
|
1016
|
+
worktree: Worktree,
|
|
1017
|
+
items: PathspecItem[],
|
|
1018
|
+
originals: string[],
|
|
1019
|
+
): Promise<AddResult> {
|
|
1020
|
+
const output: string[] = [];
|
|
1021
|
+
let first = true;
|
|
1022
|
+
const show = (porcelain: string, plain: string | undefined) => {
|
|
1023
|
+
if (this.verbose) {
|
|
1024
|
+
if (first) output.push("Unstaged changes after refreshing the index:");
|
|
1025
|
+
first = false;
|
|
1026
|
+
output.push(porcelain);
|
|
1027
|
+
} else if (plain !== undefined) output.push(plain);
|
|
1028
|
+
};
|
|
1029
|
+
const trust = worktreeModeTrust(this.workingCopy, worktree);
|
|
1030
|
+
const indexTime = this.staging.getUpdateTime();
|
|
1031
|
+
const seen = items.map(() => 0);
|
|
1032
|
+
const updates: IndexStatUpdate[] = [];
|
|
1033
|
+
const matched = new Map<StagingEntry, boolean>();
|
|
1034
|
+
const list = this.staging.entryList?.();
|
|
1035
|
+
const entries: StagingEntry[] = [];
|
|
1036
|
+
for await (const entry of list ?? this.staging.entries()) entries.push(entry);
|
|
1037
|
+
// the stat pass over the stage-0 entries the pathspec matches (refresh_index: skip-worktree
|
|
1038
|
+
// entries are passed over before the pathspec is asked)
|
|
1039
|
+
for (const entry of entries) {
|
|
1040
|
+
if (entry.skipWorktree) continue;
|
|
1041
|
+
const flags = entry.mode === FileMode.GITLINK ? DO_MATCH_DIRECTORY : 0;
|
|
1042
|
+
matched.set(entry, matchPathspecSeen(items, entry.path, flags, seen) > 0);
|
|
1043
|
+
}
|
|
1044
|
+
const stated = (entry: StagingEntry) =>
|
|
1045
|
+
entry.stage === 0 &&
|
|
1046
|
+
matched.get(entry) === true &&
|
|
1047
|
+
!entry.assumeValid &&
|
|
1048
|
+
entry.mode !== FileMode.GITLINK;
|
|
1049
|
+
let lastUnmerged: string | undefined;
|
|
1050
|
+
for await (const { item: entry, current } of withWorktreeEntries(worktree, entries, stated)) {
|
|
1051
|
+
if (!matched.has(entry)) continue;
|
|
1052
|
+
if (entry.stage !== 0) {
|
|
1053
|
+
if (entry.path === lastUnmerged) continue;
|
|
1054
|
+
lastUnmerged = entry.path;
|
|
1055
|
+
if (matched.get(entry)) show(`U\t${entry.path}`, `${entry.path}: needs merge`);
|
|
429
1056
|
continue;
|
|
430
1057
|
}
|
|
431
|
-
|
|
432
|
-
if (
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
// the empty blob's id, flagged intent-to-add, as git records it (never an empty
|
|
438
|
-
// or all-zero id, which a worktree hash could be compared against)
|
|
439
|
-
new UpdateStagingEntry(
|
|
440
|
-
file.path,
|
|
441
|
-
EMPTY_BLOB_ID,
|
|
442
|
-
mode,
|
|
443
|
-
{ size: 0, mtime: Date.now() },
|
|
444
|
-
{ intentToAdd: true },
|
|
445
|
-
),
|
|
446
|
-
);
|
|
447
|
-
added.push(file.path);
|
|
1058
|
+
// up to date by promise (CE_VALID without --really-refresh)
|
|
1059
|
+
if (!matched.get(entry) || entry.assumeValid) continue;
|
|
1060
|
+
const compared = await compareWithWorktree(worktree, entry, { trust, indexTime }, current);
|
|
1061
|
+
if (!compared.kind && !entry.intentToAdd) {
|
|
1062
|
+
const update = statUpdateOf(entry, compared);
|
|
1063
|
+
if (update && !update.smudge) updates.push(update);
|
|
448
1064
|
continue;
|
|
449
1065
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
1066
|
+
// quiet unless verbose: git prints nothing for an entry that needs updating
|
|
1067
|
+
const code =
|
|
1068
|
+
compared.kind === "deleted"
|
|
1069
|
+
? "D"
|
|
1070
|
+
: entry.intentToAdd
|
|
1071
|
+
? "A"
|
|
1072
|
+
: compared.kind === "typechange"
|
|
1073
|
+
? "T"
|
|
1074
|
+
: "M";
|
|
1075
|
+
show(`${code}\t${entry.path}`, undefined);
|
|
1076
|
+
}
|
|
1077
|
+
// an element that matched nothing dies, unless it matches entries outside the sparse
|
|
1078
|
+
// checkout: git advises on those, writes the index and fails
|
|
1079
|
+
const sparse: string[] = [];
|
|
1080
|
+
let skipSeen: number[] | undefined;
|
|
1081
|
+
for (let i = 0; i < items.length; i++) {
|
|
1082
|
+
if ((items[i] as PathspecItem).exclude || seen[i]) continue;
|
|
1083
|
+
skipSeen ??= skipWorktreeSeen(items, entries.map(groupOf), (path) =>
|
|
1084
|
+
this.outsideSparse(path),
|
|
1085
|
+
);
|
|
1086
|
+
// (git asks the element itself as a path too: `path_in_sparse_checkout(original)`)
|
|
1087
|
+
if (skipSeen[i] || this.outsideSparse(originals[i] as string)) {
|
|
1088
|
+
sparse.push(originals[i] as string);
|
|
455
1089
|
continue;
|
|
456
1090
|
}
|
|
1091
|
+
throw new InvalidArgumentError(
|
|
1092
|
+
"filepattern",
|
|
1093
|
+
originals[i],
|
|
1094
|
+
`fatal: pathspec '${originals[i]}' did not match any files`,
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
// (written with `--dry-run` too: git's refresh-only add ignores it)
|
|
1098
|
+
if (updates.length > 0) {
|
|
1099
|
+
const now = Date.now();
|
|
1100
|
+
const editor = this.staging.createEditor();
|
|
1101
|
+
for (const update of updates) {
|
|
1102
|
+
editor.add({
|
|
1103
|
+
path: update.path,
|
|
1104
|
+
apply: (existing) => applyStatUpdate(existing, update, now) ?? existing,
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
await editor.finish();
|
|
1108
|
+
if (this.writeIndex) await this.staging.write();
|
|
1109
|
+
}
|
|
1110
|
+
const result: AddResult = {
|
|
1111
|
+
added: [],
|
|
1112
|
+
skipped: [],
|
|
1113
|
+
ignored: [],
|
|
1114
|
+
removed: [],
|
|
1115
|
+
totalProcessed: 0,
|
|
1116
|
+
warnings: [],
|
|
1117
|
+
output,
|
|
1118
|
+
};
|
|
1119
|
+
if (sparse.length > 0) {
|
|
1120
|
+
throw new AddFailedError(this.sparseAdvice(sparse).join("\n"), [], [], result, output);
|
|
1121
|
+
}
|
|
1122
|
+
return result;
|
|
1123
|
+
}
|
|
457
1124
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
1125
|
+
/**
|
|
1126
|
+
* git's `advise_on_updating_sparse_paths`: the elements that matched only entries outside
|
|
1127
|
+
* the sparse checkout, and (unless `advice.updateSparsePath` is off) the hint, as git 2.5x
|
|
1128
|
+
* words it (2.43 ends with "git config advice.updateSparsePath false").
|
|
1129
|
+
*/
|
|
1130
|
+
private sparseAdvice(elements: string[]): string[] {
|
|
1131
|
+
return sparsePathAdvice(elements, this.advice("updateSparsePath"), this.compatibility);
|
|
1132
|
+
}
|
|
461
1133
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
1134
|
+
/**
|
|
1135
|
+
* git's `check_removed` for the index entry `entry` and what the worktree has at its path
|
|
1136
|
+
* (`current`): `"removed"` when missing, or a directory where a file was that is no
|
|
1137
|
+
* repository with a commit checked out (a gitlink keeps its directory, populated or not):
|
|
1138
|
+
* no repository, or one without a commit; `"unknown"` for a directory whose repository
|
|
1139
|
+
* cannot be read here (its `.git`, commondir or HEAD names a place beyond the worktree's
|
|
1140
|
+
* storage, or cannot be read), which git might stage as a gitlink.
|
|
1141
|
+
*/
|
|
1142
|
+
private async removalState(
|
|
1143
|
+
worktree: Worktree,
|
|
1144
|
+
entry: StagingEntry,
|
|
1145
|
+
current: WorktreeEntry | undefined,
|
|
1146
|
+
): Promise<"removed" | "present" | "unknown"> {
|
|
1147
|
+
if (!current) return "removed";
|
|
1148
|
+
if (!current.isDirectory || entry.mode === FileMode.GITLINK) return "present";
|
|
1149
|
+
const head = await gitlinkHeadState(worktree, entry.path);
|
|
1150
|
+
if (head.state === "commit") return "present";
|
|
1151
|
+
return head.state === "unknown" ? "unknown" : "removed";
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
/** The index's entries, every stage, grouped by path in the index's order. */
|
|
1155
|
+
private async indexGroups(): Promise<IndexGroup[]> {
|
|
1156
|
+
const groups: IndexGroup[] = [];
|
|
1157
|
+
const list = this.staging.entryList?.();
|
|
1158
|
+
const entries: Iterable<StagingEntry> | AsyncIterable<StagingEntry> =
|
|
1159
|
+
list ?? this.staging.entries();
|
|
1160
|
+
let last: IndexGroup | undefined;
|
|
1161
|
+
const take = (entry: StagingEntry) => {
|
|
1162
|
+
if (last && last.path === entry.path) {
|
|
1163
|
+
last.entries.push(entry);
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
last = { path: entry.path, entries: [entry], gitlink: entry.mode === FileMode.GITLINK };
|
|
1167
|
+
groups.push(last);
|
|
1168
|
+
};
|
|
1169
|
+
// a list in memory is read without a promise per entry
|
|
1170
|
+
if (list) for (const entry of list) take(entry);
|
|
1171
|
+
else for await (const entry of entries) take(entry);
|
|
1172
|
+
return groups;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* git's `fill_directory` with `DIR_COLLECT_IGNORED` and `prune_directory`: the untracked
|
|
1177
|
+
* files the pathspec matches (marking `seen`), a repository inside the worktree as one
|
|
1178
|
+
* entry (`sub/`), and the ignored paths the pathspec names (the topmost ignored directory
|
|
1179
|
+
* or file: git does not look inside an ignored directory). With `--force` nothing is
|
|
1180
|
+
* ignored.
|
|
1181
|
+
*
|
|
1182
|
+
* A directory is a repository of its own unless the index has a gitlink there or paths
|
|
1183
|
+
* under it (git's `directory_exists_in_index`): a tracked file replaced by a repository is
|
|
1184
|
+
* one too. A directory whose `.git` holds no repository is entered, its `.git` passed
|
|
1185
|
+
* over; one whose repository cannot be read here is skipped with a warning.
|
|
1186
|
+
*/
|
|
1187
|
+
private async scanUntracked(
|
|
1188
|
+
worktree: Worktree,
|
|
1189
|
+
items: PathspecItem[],
|
|
1190
|
+
index: IndexGroup[],
|
|
1191
|
+
seen: number[],
|
|
1192
|
+
): Promise<{
|
|
1193
|
+
untracked: Array<{ path: string; entry: WorktreeEntry; repository: boolean }>;
|
|
1194
|
+
skipped: string[];
|
|
1195
|
+
ignored: string[];
|
|
1196
|
+
warnings: string[];
|
|
1197
|
+
}> {
|
|
1198
|
+
const untracked: Array<{ path: string; entry: WorktreeEntry; repository: boolean }> = [];
|
|
1199
|
+
const skipped: string[] = [];
|
|
1200
|
+
const ignored: string[] = [];
|
|
1201
|
+
const warnings: string[] = [];
|
|
1202
|
+
const indexPaths = new Set<string>();
|
|
1203
|
+
const gitlinkPaths = new Set<string>();
|
|
1204
|
+
for (const group of index) {
|
|
1205
|
+
indexPaths.add(group.path);
|
|
1206
|
+
if (group.gitlink) gitlinkPaths.add(group.path);
|
|
470
1207
|
}
|
|
1208
|
+
const trackedDirs = new Set<string>();
|
|
1209
|
+
for (const path of indexPaths) {
|
|
1210
|
+
for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) {
|
|
1211
|
+
trackedDirs.add(path.slice(0, at));
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
// dir.c asks the index through its name hashes, which fold case under core.ignorecase:
|
|
1215
|
+
// a file differing from an index path only by case is tracked (treat_path's
|
|
1216
|
+
// index_file_exists, dir_add_name), a directory so differing from a tracked one is
|
|
1217
|
+
// entered (directory_exists_in_index_icase); an ignored directory is checked exactly
|
|
1218
|
+
// (dir_add_ignored's index_name_is_other)
|
|
1219
|
+
const lookup = new IndexPathLookup([...indexPaths], {
|
|
1220
|
+
ignoreCase: coreBool(this.workingCopy, "ignorecase", false),
|
|
1221
|
+
gitlinks: gitlinkPaths,
|
|
1222
|
+
});
|
|
1223
|
+
const ignoredDirs = new Set<string>();
|
|
1224
|
+
const prefix = await this.walkPrefix(worktree, items);
|
|
1225
|
+
if (prefix && !this.force) {
|
|
1226
|
+
// the topmost ignored directory on the way down to the prefix stands for all in it
|
|
1227
|
+
for (let at = 0; at >= 0 && at <= prefix.length; ) {
|
|
1228
|
+
const next = prefix.indexOf("/", at);
|
|
1229
|
+
const dir = next < 0 ? prefix : prefix.slice(0, next);
|
|
1230
|
+
if (await worktree.isIgnored(dir)) {
|
|
1231
|
+
ignoredDirs.add(prefix);
|
|
1232
|
+
if (!indexPaths.has(dir) && excludeMatchesPathspec(items, dir)) ignored.push(dir);
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
at = next < 0 ? -1 : next + 1;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
const parentOf = (path: string) => path.slice(0, Math.max(0, path.lastIndexOf("/")));
|
|
1239
|
+
for await (const entry of worktree.walk({
|
|
1240
|
+
includeIgnored: true,
|
|
1241
|
+
includeDirectories: true,
|
|
1242
|
+
// a directory whose `.git` is no repository is an ordinary one (git's treat_directory)
|
|
1243
|
+
enterNonRepositoryGitDirs: true,
|
|
1244
|
+
// a tracked file is passed over (below too), unstat'ed (git's treat_path)
|
|
1245
|
+
skipFile: (path) => lookup.has(path),
|
|
1246
|
+
...(prefix ? { pathPrefix: prefix } : {}),
|
|
1247
|
+
// git's "could not open directory" for a directory its scan opens: not one it passes
|
|
1248
|
+
// over as ignored, nor one the pathspec cannot reach into
|
|
1249
|
+
onUnreadable: (path, error) => {
|
|
1250
|
+
if (path === "" || GIT_COMPONENT.test(path)) return;
|
|
1251
|
+
if (!this.force && (ignoredDirs.has(path) || ignoredDirs.has(parentOf(path)))) return;
|
|
1252
|
+
if (!matchPathspec(items, path, DO_MATCH_DIRECTORY | DO_MATCH_LEADING_PATHSPEC)) return;
|
|
1253
|
+
warnings.push(unreadableDirectoryWarning(path, error));
|
|
1254
|
+
},
|
|
1255
|
+
})) {
|
|
1256
|
+
// ...but git never adds a `.git` (treat_path)
|
|
1257
|
+
if (entry.path.includes(".git") && GIT_COMPONENT.test(entry.path)) continue;
|
|
1258
|
+
if (this.attributes && !(await this.reachableByAttributes(entry.path, trackedDirs))) {
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
const parent = parentOf(entry.path);
|
|
1262
|
+
const underIgnored = parent !== "" && ignoredDirs.has(parent);
|
|
1263
|
+
if (!this.force && (entry.isIgnored || underIgnored)) {
|
|
1264
|
+
if (entry.isDirectory) ignoredDirs.add(entry.path);
|
|
1265
|
+
if (entry.isDirectory ? indexPaths.has(entry.path) : lookup.has(entry.path)) continue;
|
|
1266
|
+
if (!entry.isDirectory && matchPathspec(items, entry.path, 0)) skipped.push(entry.path);
|
|
1267
|
+
if (!underIgnored && excludeMatchesPathspec(items, entry.path)) ignored.push(entry.path);
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
if (entry.isDirectory) {
|
|
1271
|
+
// a repository of its own, nothing of it tracked: one entry, `sub/`
|
|
1272
|
+
if (entry.mode !== FileMode.GITLINK || lookup.indexDirectory(entry.path)) continue;
|
|
1273
|
+
const state = await nestedRepositoryState(worktree, entry.path);
|
|
1274
|
+
if (state === "repository") {
|
|
1275
|
+
if (matchPathspecSeen(items, entry.path, DO_MATCH_DIRECTORY, seen)) {
|
|
1276
|
+
untracked.push({ path: entry.path, entry, repository: true });
|
|
1277
|
+
}
|
|
1278
|
+
} else if (state === "unknown" && matchPathspec(items, entry.path, DO_MATCH_DIRECTORY)) {
|
|
1279
|
+
warnings.push(unreadableRepositoryWarning(entry.path));
|
|
1280
|
+
}
|
|
1281
|
+
continue;
|
|
1282
|
+
}
|
|
1283
|
+
if (lookup.has(entry.path)) continue;
|
|
1284
|
+
if (matchPathspecSeen(items, entry.path, 0, seen)) {
|
|
1285
|
+
untracked.push({ path: entry.path, entry, repository: false });
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
// git's order: the names' bytes, a directory's with its "/"
|
|
1289
|
+
const key = (u: { path: string; repository: boolean }) =>
|
|
1290
|
+
u.repository ? `${u.path}/` : u.path;
|
|
1291
|
+
untracked.sort((a, b) => compareGitPaths(key(a), key(b)));
|
|
1292
|
+
ignored.sort(compareGitPaths);
|
|
1293
|
+
return { untracked, skipped, ignored, warnings };
|
|
1294
|
+
}
|
|
471
1295
|
|
|
472
|
-
|
|
473
|
-
|
|
1296
|
+
/**
|
|
1297
|
+
* With `:(attr:...)` elements: the attributes of a walked path loaded, and whether dir.c's
|
|
1298
|
+
* walk reaches it: each untracked directory above it (one holding no index entry) must
|
|
1299
|
+
* match the pathspec as a leading path by its own name and attributes (`treat_directory`).
|
|
1300
|
+
*/
|
|
1301
|
+
private async reachableByAttributes(path: string, trackedDirs: Set<string>): Promise<boolean> {
|
|
1302
|
+
const attributes = this.attributes as PathspecAttributes;
|
|
1303
|
+
return attributes.reachable(this.pathspecItems, path, trackedDirs);
|
|
1304
|
+
}
|
|
474
1305
|
|
|
475
|
-
|
|
476
|
-
|
|
1306
|
+
/**
|
|
1307
|
+
* The directory every positive element's literal part lies in, where the scan for
|
|
1308
|
+
* untracked files can start (empty: the whole worktree). A real directory of the
|
|
1309
|
+
* worktree, never a link or a repository of its own.
|
|
1310
|
+
*/
|
|
1311
|
+
private async walkPrefix(worktree: Worktree, items: PathspecItem[]): Promise<string> {
|
|
1312
|
+
const positive = items.filter((i) => !i.exclude);
|
|
1313
|
+
if (positive.length === 0 || positive.some((i) => i.icase || i.prefix !== undefined)) {
|
|
1314
|
+
return "";
|
|
1315
|
+
}
|
|
1316
|
+
let common: string | undefined;
|
|
1317
|
+
for (const item of positive) {
|
|
1318
|
+
const literal = item.match.slice(0, item.nowildcardLen);
|
|
1319
|
+
const cut = literal.lastIndexOf("/");
|
|
1320
|
+
const dirBytes = cut < 0 ? "" : literal.slice(0, cut);
|
|
1321
|
+
const dir = item.bytes ? decodeBytes(dirBytes) : dirBytes;
|
|
1322
|
+
if (common === undefined) common = dir;
|
|
1323
|
+
else {
|
|
1324
|
+
while (common !== "" && dir !== common && !dir.startsWith(`${common}/`)) {
|
|
1325
|
+
common = common.slice(0, Math.max(0, common.lastIndexOf("/")));
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
if (common === "") return "";
|
|
1329
|
+
}
|
|
1330
|
+
let dir = common ?? "";
|
|
1331
|
+
while (dir !== "") {
|
|
1332
|
+
const entry = await worktree.getEntry(dir);
|
|
1333
|
+
if (entry?.isDirectory && entry.mode !== FileMode.GITLINK) return dir;
|
|
1334
|
+
dir = dir.slice(0, Math.max(0, dir.lastIndexOf("/")));
|
|
1335
|
+
}
|
|
1336
|
+
return "";
|
|
1337
|
+
}
|
|
477
1338
|
|
|
478
|
-
|
|
1339
|
+
/**
|
|
1340
|
+
* git's `renormalize_tracked_files`: every tracked regular file and link (stage 0, not
|
|
1341
|
+
* skip-worktree) the pathspec matches is added again, cleaned with renormalisation (each
|
|
1342
|
+
* one's cache-tree path invalidated, as `add_index_entry` does, its content changed or
|
|
1343
|
+
* not), and reported by `--verbose` / `--dry-run` whatever its content. An element that
|
|
1344
|
+
* matches nothing tracked must name an existing file (`--ignore-missing` passes over it).
|
|
1345
|
+
* A tracked file that cannot be stat'ed is fatal (nothing written); one replaced by a
|
|
1346
|
+
* repository is staged as its gitlink, and a path that cannot be added (a directory with no
|
|
1347
|
+
* commit checked out, a FIFO) is reported after the others are written.
|
|
1348
|
+
*/
|
|
1349
|
+
private async renormalizeFiles(
|
|
1350
|
+
worktree: Worktree,
|
|
1351
|
+
items: PathspecItem[],
|
|
1352
|
+
originals: string[],
|
|
1353
|
+
): Promise<AddResult> {
|
|
1354
|
+
const added: string[] = [];
|
|
1355
|
+
const warnings: string[] = [];
|
|
1356
|
+
const output: string[] = [];
|
|
1357
|
+
const errors: string[] = [];
|
|
1358
|
+
const failed: string[] = [];
|
|
1359
|
+
const index = await this.indexGroups();
|
|
1360
|
+
const seen = items.map(() => 0);
|
|
1361
|
+
for (const group of index) {
|
|
1362
|
+
matchPathspecSeen(items, group.path, group.gitlink ? DO_MATCH_DIRECTORY : 0, seen);
|
|
1363
|
+
}
|
|
1364
|
+
for (let i = 0; i < items.length; i++) {
|
|
1365
|
+
const item = items[i] as PathspecItem;
|
|
1366
|
+
if (item.exclude || seen[i] || item.match === "") continue;
|
|
1367
|
+
// with --ignore-missing git collects an ignored one, but reports none here
|
|
1368
|
+
if (!this.ignoreMissing && !(await namesFile(worktree, item))) {
|
|
1369
|
+
throw new InvalidArgumentError(
|
|
1370
|
+
"filepattern",
|
|
1371
|
+
originals[i],
|
|
1372
|
+
`fatal: pathspec '${originals[i]}' did not match any files`,
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
const trust = worktreeModeTrust(this.workingCopy, worktree);
|
|
1377
|
+
const adder = await IndexAdder.open(this.staging, this.blobs, trust, { pretend: this.dryRun });
|
|
1378
|
+
for (const { path, entries } of index) {
|
|
1379
|
+
const entry = entries[0] as StagingEntry;
|
|
1380
|
+
if (entry.stage !== 0 || entry.skipWorktree || this.outsideSparse(path)) continue;
|
|
1381
|
+
const kind = entry.mode & 0o170000;
|
|
1382
|
+
if (kind !== 0o100000 && kind !== 0o120000) continue;
|
|
1383
|
+
if (!matchPathspec(items, path, 0)) continue;
|
|
1384
|
+
const worktreeEntry = await worktree.getEntry(path);
|
|
1385
|
+
if (!worktreeEntry) {
|
|
1386
|
+
if (await worktree.isSpecialFile?.(path)) {
|
|
1387
|
+
errors.push(
|
|
1388
|
+
`error: ${path}: can only add regular files, symbolic links or git-directories`,
|
|
1389
|
+
);
|
|
1390
|
+
failed.push(path);
|
|
1391
|
+
continue;
|
|
1392
|
+
}
|
|
1393
|
+
// git's add_file_to_index dies on a tracked file it cannot stat (the index is left
|
|
1394
|
+
// as it was)
|
|
1395
|
+
throw new AddFailedError(
|
|
1396
|
+
[...errors, `fatal: unable to stat '${path}': No such file or directory`].join("\n"),
|
|
1397
|
+
[],
|
|
1398
|
+
[...failed, path],
|
|
1399
|
+
undefined,
|
|
1400
|
+
output,
|
|
1401
|
+
warnings,
|
|
1402
|
+
).withExitCode(128);
|
|
1403
|
+
}
|
|
1404
|
+
try {
|
|
1405
|
+
await adder.add(worktree, path, worktreeEntry, {
|
|
1406
|
+
renormalize: true,
|
|
1407
|
+
onWarning: (message) => warnings.push(message),
|
|
1408
|
+
});
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
if (!(error instanceof AddToIndexError)) throw error;
|
|
1411
|
+
errors.push(...error.lines);
|
|
1412
|
+
failed.push(path);
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
// no alias is looked up with ADD_CACHE_RENORMALIZE: git's was_same is false
|
|
1416
|
+
output.push(`add '${path}'`);
|
|
1417
|
+
added.push(path);
|
|
1418
|
+
}
|
|
1419
|
+
await adder.finish();
|
|
1420
|
+
if (this.writeIndex && !this.dryRun) await this.writeIfChanged();
|
|
1421
|
+
const result: AddResult = {
|
|
479
1422
|
added,
|
|
480
|
-
skipped,
|
|
481
|
-
|
|
482
|
-
|
|
1423
|
+
skipped: [],
|
|
1424
|
+
ignored: [],
|
|
1425
|
+
removed: [],
|
|
1426
|
+
totalProcessed: added.length,
|
|
1427
|
+
warnings,
|
|
1428
|
+
output,
|
|
483
1429
|
};
|
|
1430
|
+
if (failed.length > 0) {
|
|
1431
|
+
throw new AddFailedError(errors.join("\n"), [], failed, result, output, warnings);
|
|
1432
|
+
}
|
|
1433
|
+
return result;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
/** The index entries of one path (its stages, in order). */
|
|
1438
|
+
interface IndexGroup {
|
|
1439
|
+
path: string;
|
|
1440
|
+
entries: StagingEntry[];
|
|
1441
|
+
gitlink: boolean;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
/** Whether the path's entry is a skip-worktree one (outside the sparse checkout). */
|
|
1445
|
+
function isSkipWorktree(group: IndexGroup): boolean {
|
|
1446
|
+
const first = group.entries[0] as StagingEntry;
|
|
1447
|
+
return first.stage === 0 && first.skipWorktree === true;
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
/** One entry as its own group. */
|
|
1451
|
+
function groupOf(entry: StagingEntry): IndexGroup {
|
|
1452
|
+
return { path: entry.path, entries: [entry], gitlink: entry.mode === FileMode.GITLINK };
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
/**
|
|
1456
|
+
* git's `find_pathspecs_matching_skip_worktree`: which elements match a skip-worktree entry
|
|
1457
|
+
* or one outside the sparse checkout's patterns (`matches_skip_worktree`).
|
|
1458
|
+
*/
|
|
1459
|
+
function skipWorktreeSeen(
|
|
1460
|
+
items: PathspecItem[],
|
|
1461
|
+
index: readonly IndexGroup[],
|
|
1462
|
+
outsideSparse: (path: string) => boolean,
|
|
1463
|
+
): number[] {
|
|
1464
|
+
const seen = items.map(() => 0);
|
|
1465
|
+
for (const group of index) {
|
|
1466
|
+
if (!isSkipWorktree(group) && !outsideSparse(group.path)) continue;
|
|
1467
|
+
matchPathspecSeen(items, group.path, group.gitlink ? DO_MATCH_DIRECTORY : 0, seen);
|
|
484
1468
|
}
|
|
1469
|
+
return seen;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
/** A path with a `.git` component: never added (git's treat_path). */
|
|
1473
|
+
const GIT_COMPONENT = /(^|\/)\.git(\/|$)/;
|
|
1474
|
+
|
|
1475
|
+
/** What the add says of a directory whose repository it cannot read. */
|
|
1476
|
+
function unreadableRepositoryWarning(path: string): string {
|
|
1477
|
+
return `warning: skipping '${path}/': the repository its .git names cannot be read here`;
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
/** Whether the directory at `path` holds a repository of its own, as far as `worktree` tells. */
|
|
1481
|
+
async function nestedRepositoryState(
|
|
1482
|
+
worktree: Worktree,
|
|
1483
|
+
path: string,
|
|
1484
|
+
): Promise<NestedRepositoryState> {
|
|
1485
|
+
if (worktree.repositoryState) return worktree.repositoryState(path);
|
|
1486
|
+
if (worktree.isRepository) return (await worktree.isRepository(path)) ? "repository" : "none";
|
|
1487
|
+
return "repository";
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
/**
|
|
1491
|
+
* git's `file_exists` check of a pathspec element that matched nothing: a literal path
|
|
1492
|
+
* there (`lstat`), a directory when it ends with "/" (`a/` names no file `a`); a glob or
|
|
1493
|
+
* case-folding element never names a file.
|
|
1494
|
+
*/
|
|
1495
|
+
async function namesFile(worktree: Worktree, item: PathspecItem): Promise<boolean> {
|
|
1496
|
+
if (item.glob || item.icase) return false;
|
|
1497
|
+
const literal = pathspecItemPath(item);
|
|
1498
|
+
const path = literal.replace(/\/+$/, "");
|
|
1499
|
+
const entry = await worktree.getEntry(path);
|
|
1500
|
+
if (!entry) return false;
|
|
1501
|
+
return path === literal || entry.isDirectory;
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
/**
|
|
1505
|
+
* git's `PATHSPEC_SYMLINK_LEADING_PATH` (`has_symlink_leading_path` of each element's
|
|
1506
|
+
* match): an element reaching through a symbolic link is fatal, before anything changes.
|
|
1507
|
+
*/
|
|
1508
|
+
async function checkSymlinkLeadingPaths(
|
|
1509
|
+
worktree: Worktree,
|
|
1510
|
+
items: PathspecItem[],
|
|
1511
|
+
originals: string[],
|
|
1512
|
+
): Promise<void> {
|
|
1513
|
+
for (let i = 0; i < items.length; i++) {
|
|
1514
|
+
const path = pathspecItemPath(items[i] as PathspecItem);
|
|
1515
|
+
const cut = path.lastIndexOf("/");
|
|
1516
|
+
for (let at = path.indexOf("/"); at > 0 && at <= cut; at = path.indexOf("/", at + 1)) {
|
|
1517
|
+
const entry = await worktree.getEntry(path.slice(0, at));
|
|
1518
|
+
if (entry?.mode === FileMode.SYMLINK) {
|
|
1519
|
+
throw new InvalidArgumentError(
|
|
1520
|
+
"filepattern",
|
|
1521
|
+
originals[i],
|
|
1522
|
+
`fatal: pathspec '${originals[i]}' is beyond a symbolic link`,
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1525
|
+
if (!entry?.isDirectory) break;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/** A string of one character per byte, decoded as a path. */
|
|
1531
|
+
function decodeBytes(bytes: string): string {
|
|
1532
|
+
return pathspecItemPath({ match: bytes, bytes: true } as PathspecItem);
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
/** git's advice after the first embedded repository added (`advice.addEmbeddedRepo`). */
|
|
1536
|
+
function embeddedRepoAdvice(path: string): string[] {
|
|
1537
|
+
return [
|
|
1538
|
+
"hint: You've added another git repository inside your current repository.",
|
|
1539
|
+
"hint: Clones of the outer repository will not contain the contents of",
|
|
1540
|
+
"hint: the embedded repository and will not know how to obtain it.",
|
|
1541
|
+
"hint: If you meant to add a submodule, use:",
|
|
1542
|
+
"hint:",
|
|
1543
|
+
`hint: \tgit submodule add <url> ${path}`,
|
|
1544
|
+
"hint:",
|
|
1545
|
+
"hint: If you added this path by mistake, you can remove it from the",
|
|
1546
|
+
"hint: index with:",
|
|
1547
|
+
"hint:",
|
|
1548
|
+
`hint: \tgit rm --cached ${path}`,
|
|
1549
|
+
"hint:",
|
|
1550
|
+
'hint: See "git help submodule" for more information.',
|
|
1551
|
+
];
|
|
485
1552
|
}
|