@statewalker/vcs-commands 0.7.0 → 0.9.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/dist/commands/add-command.d.ts +70 -0
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-patch.d.ts +7 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
- package/dist/commands/am/am-command.d.ts +102 -1
- package/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/am/index.d.ts +1 -0
- package/dist/commands/am/index.d.ts.map +1 -1
- package/dist/commands/am/mailsplit.d.ts +88 -0
- package/dist/commands/am/mailsplit.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts +2 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-engine.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.d.ts +7 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -1
- package/dist/commands/apply/index.d.ts +1 -1
- package/dist/commands/apply/index.d.ts.map +1 -1
- package/dist/commands/bisect/bisect-command.d.ts +2 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
- package/dist/commands/blame-command.d.ts +303 -8
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/blame-ignore.d.ts +48 -0
- package/dist/commands/blame-ignore.d.ts.map +1 -0
- package/dist/commands/branch-command.d.ts +148 -18
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-info-command.d.ts +55 -0
- package/dist/commands/branch-info-command.d.ts.map +1 -0
- package/dist/commands/branch-tracking.d.ts +106 -17
- package/dist/commands/branch-tracking.d.ts.map +1 -1
- package/dist/commands/branch-upstream-command.d.ts +83 -0
- package/dist/commands/branch-upstream-command.d.ts.map +1 -0
- package/dist/commands/check-mailmap-command.d.ts +49 -0
- package/dist/commands/check-mailmap-command.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +26 -3
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +4 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -1
- package/dist/commands/cherry-command.d.ts +61 -0
- package/dist/commands/cherry-command.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +82 -1
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +44 -0
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clean-interactive.d.ts +56 -0
- package/dist/commands/clean-interactive.d.ts.map +1 -0
- package/dist/commands/clone-command.d.ts +116 -2
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +239 -5
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/commit-reuse.d.ts +33 -0
- package/dist/commands/commit-reuse.d.ts.map +1 -0
- package/dist/commands/config-command.d.ts +236 -0
- package/dist/commands/config-command.d.ts.map +1 -0
- package/dist/commands/config-value-types.d.ts +91 -0
- package/dist/commands/config-value-types.d.ts.map +1 -0
- package/dist/commands/core-config.d.ts +20 -0
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/describe-command.d.ts +71 -64
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-color-config.d.ts +73 -0
- package/dist/commands/diff-color-config.d.ts.map +1 -0
- package/dist/commands/diff-command.d.ts +369 -10
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/fetch-command.d.ts +80 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fetch-multiple-command.d.ts +193 -0
- package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
- package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
- package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
- package/dist/commands/fork-point.d.ts +38 -0
- package/dist/commands/fork-point.d.ts.map +1 -0
- package/dist/commands/format-patch-command.d.ts +69 -3
- package/dist/commands/format-patch-command.d.ts.map +1 -1
- package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
- package/dist/commands/gc-command.d.ts +8 -0
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-describe.d.ts +81 -4
- package/dist/commands/git-describe.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +50 -1
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/grep/grep-command.d.ts +210 -0
- package/dist/commands/grep/grep-command.d.ts.map +1 -0
- package/dist/commands/grep/grep-engine.d.ts +218 -0
- package/dist/commands/grep/grep-engine.d.ts.map +1 -0
- package/dist/commands/grep/index.d.ts +3 -0
- package/dist/commands/grep/index.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +13 -2
- package/dist/commands/index-adder.d.ts.map +1 -1
- package/dist/commands/index.d.ts +38 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +5 -3
- package/dist/commands/init-command.d.ts +89 -0
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/interpret-trailers-command.d.ts +90 -0
- package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
- package/dist/commands/line-log.d.ts +161 -0
- package/dist/commands/line-log.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +36 -5
- package/dist/commands/local-transport.d.ts.map +1 -1
- package/dist/commands/log-command.d.ts +527 -13
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +30 -3
- package/dist/commands/log-graph.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +199 -6
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/ls-remote-command.d.ts +2 -0
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +53 -0
- package/dist/commands/mailmap.d.ts.map +1 -1
- package/dist/commands/merge-base-command.d.ts +60 -0
- package/dist/commands/merge-base-command.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +23 -0
- package/dist/commands/merge-bases.d.ts.map +1 -1
- package/dist/commands/merge-command.d.ts +147 -10
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-drivers.d.ts +2 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -1
- package/dist/commands/merge-strategy-options.d.ts +69 -0
- package/dist/commands/merge-strategy-options.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +10 -0
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/message-cleanup.d.ts +2 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -1
- package/dist/commands/mv-command.d.ts +4 -0
- package/dist/commands/mv-command.d.ts.map +1 -1
- package/dist/commands/name-rev-command.d.ts +65 -0
- package/dist/commands/name-rev-command.d.ts.map +1 -0
- package/dist/commands/name-rev.d.ts +136 -0
- package/dist/commands/name-rev.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts.map +1 -1
- package/dist/commands/octopus-merge.d.ts +26 -1
- package/dist/commands/octopus-merge.d.ts.map +1 -1
- package/dist/commands/ort-merge.d.ts +16 -0
- package/dist/commands/ort-merge.d.ts.map +1 -1
- package/dist/commands/ort-recursive.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +58 -0
- package/dist/commands/patch-id.d.ts.map +1 -1
- package/dist/commands/pathspec-file.d.ts +39 -0
- package/dist/commands/pathspec-file.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +3 -0
- package/dist/commands/pathspec.d.ts.map +1 -1
- package/dist/commands/pretty-format.d.ts +43 -3
- package/dist/commands/pretty-format.d.ts.map +1 -1
- package/dist/commands/promisor-remote.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts +186 -32
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +225 -9
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/range-diff/index.d.ts +4 -0
- package/dist/commands/range-diff/index.d.ts.map +1 -0
- package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
- package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
- package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff.d.ts +106 -0
- package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
- package/dist/commands/read-tree-command.d.ts +20 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +189 -8
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
- package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
- package/dist/commands/ref-filter/index.d.ts +8 -0
- package/dist/commands/ref-filter/index.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
- package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
- package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-format.d.ts +222 -0
- package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
- package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
- package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
- package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
- package/dist/commands/ref-filter/version-compare.d.ts +20 -0
- package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
- package/dist/commands/reflog-command.d.ts +120 -0
- package/dist/commands/reflog-command.d.ts.map +1 -1
- package/dist/commands/reflog-walk.d.ts +72 -0
- package/dist/commands/reflog-walk.d.ts.map +1 -0
- package/dist/commands/remerge-diff.d.ts +59 -0
- package/dist/commands/remerge-diff.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +179 -29
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-show-command.d.ts +204 -0
- package/dist/commands/remote-show-command.d.ts.map +1 -0
- package/dist/commands/remote-transport.d.ts +7 -1
- package/dist/commands/remote-transport.d.ts.map +1 -1
- package/dist/commands/reset-command.d.ts +21 -4
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +9 -3
- package/dist/commands/restore-command.d.ts.map +1 -1
- package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
- package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
- package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
- package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
- package/dist/commands/rev-filter/index.d.ts +3 -0
- package/dist/commands/rev-filter/index.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +226 -2
- package/dist/commands/rev-list-command.d.ts.map +1 -1
- package/dist/commands/revert-command.d.ts +54 -1
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +34 -1
- package/dist/commands/revision-range.d.ts.map +1 -1
- package/dist/commands/revision-resolver.d.ts +15 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -1
- package/dist/commands/rm-command.d.ts +70 -2
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +186 -5
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts +12 -1
- package/dist/commands/sequencer-support.d.ts.map +1 -1
- package/dist/commands/serve-repository.d.ts +7 -0
- package/dist/commands/serve-repository.d.ts.map +1 -1
- package/dist/commands/shortlog-command.d.ts +109 -0
- package/dist/commands/shortlog-command.d.ts.map +1 -0
- package/dist/commands/shortlog.d.ts +151 -0
- package/dist/commands/shortlog.d.ts.map +1 -0
- package/dist/commands/show-command.d.ts +130 -0
- package/dist/commands/show-command.d.ts.map +1 -0
- package/dist/commands/show-commit.d.ts +11 -0
- package/dist/commands/show-commit.d.ts.map +1 -0
- package/dist/commands/signature-check.d.ts +164 -0
- package/dist/commands/signature-check.d.ts.map +1 -0
- package/dist/commands/signing.d.ts +160 -0
- package/dist/commands/signing.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
- package/dist/commands/sparse-index-view.d.ts +45 -0
- package/dist/commands/sparse-index-view.d.ts.map +1 -0
- package/dist/commands/ssh-signer.d.ts +29 -0
- package/dist/commands/ssh-signer.d.ts.map +1 -0
- package/dist/commands/ssh-verifier.d.ts +42 -0
- package/dist/commands/ssh-verifier.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +5 -0
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-branch-command.d.ts +34 -0
- package/dist/commands/stash-branch-command.d.ts.map +1 -0
- package/dist/commands/stash-create-command.d.ts +17 -0
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-info.d.ts +93 -0
- package/dist/commands/stash-info.d.ts.map +1 -0
- package/dist/commands/stash-list-command.d.ts +16 -0
- package/dist/commands/stash-list-command.d.ts.map +1 -1
- package/dist/commands/stash-pop-command.d.ts +39 -0
- package/dist/commands/stash-pop-command.d.ts.map +1 -0
- package/dist/commands/stash-show-command.d.ts +48 -0
- package/dist/commands/stash-show-command.d.ts.map +1 -0
- package/dist/commands/stash-store-command.d.ts +29 -0
- package/dist/commands/stash-store-command.d.ts.map +1 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts +31 -2
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-header.d.ts +5 -0
- package/dist/commands/status-header.d.ts.map +1 -1
- package/dist/commands/submodule-add-command.d.ts +89 -0
- package/dist/commands/submodule-add-command.d.ts.map +1 -0
- package/dist/commands/submodule-auth.d.ts +90 -0
- package/dist/commands/submodule-auth.d.ts.map +1 -0
- package/dist/commands/submodule-commands.d.ts +463 -0
- package/dist/commands/submodule-commands.d.ts.map +1 -0
- package/dist/commands/submodule-fetch.d.ts +149 -0
- package/dist/commands/submodule-fetch.d.ts.map +1 -0
- package/dist/commands/submodule-model.d.ts +296 -0
- package/dist/commands/submodule-model.d.ts.map +1 -0
- package/dist/commands/submodule-unpack.d.ts +120 -0
- package/dist/commands/submodule-unpack.d.ts.map +1 -0
- package/dist/commands/submodule-update-command.d.ts +206 -0
- package/dist/commands/submodule-update-command.d.ts.map +1 -0
- package/dist/commands/subtree-shift.d.ts +27 -0
- package/dist/commands/subtree-shift.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +3 -0
- package/dist/commands/switch-command.d.ts.map +1 -1
- package/dist/commands/tag-command.d.ts +259 -10
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/trailers.d.ts +218 -17
- package/dist/commands/trailers.d.ts.map +1 -1
- package/dist/commands/tree-restore.d.ts +7 -0
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/verify-command.d.ts +92 -0
- package/dist/commands/verify-command.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +79 -7
- package/dist/commands/worktree-add-command.d.ts.map +1 -1
- package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/commands/worktree-path-rules.d.ts +66 -0
- package/dist/commands/worktree-path-rules.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +10 -3
- package/dist/commands/worktree-remove-command.d.ts.map +1 -1
- package/dist/commands/worktree-repair-command.d.ts +15 -2
- package/dist/commands/worktree-repair-command.d.ts.map +1 -1
- package/dist/commands/worktree-support.d.ts +5 -0
- package/dist/commands/worktree-support.d.ts.map +1 -1
- package/dist/{commands-DIJ91NnD.js → commands-CNvli5bl.js} +49442 -54941
- package/dist/errors/checkout-errors.d.ts +19 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts +25 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/index.js +85 -3
- package/dist/errors/ref-errors.d.ts +19 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +6 -1
- package/dist/errors/worktree-errors.d.ts.map +1 -1
- package/dist/fsck-CPeDh9fh.js +5138 -0
- package/dist/git-command.d.ts +58 -2
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +363 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/guarded-transport-command.d.ts +82 -0
- package/dist/guarded-transport-command.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/remote-config/index.d.ts +1 -1
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +55 -0
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-transport-CCmBadm-.js +1606 -0
- package/dist/rename/detect-renames.d.ts +20 -0
- package/dist/rename/detect-renames.d.ts.map +1 -1
- package/dist/rename/diffcore-break.d.ts +51 -0
- package/dist/rename/diffcore-break.d.ts.map +1 -0
- package/dist/rename/index.d.ts +1 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/blame-format.d.ts +62 -1
- package/dist/results/blame-format.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +9 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +3 -0
- package/dist/results/combined-diff.d.ts.map +1 -1
- package/dist/results/diff-check.d.ts +38 -0
- package/dist/results/diff-check.d.ts.map +1 -0
- package/dist/results/diff-color.d.ts +135 -0
- package/dist/results/diff-color.d.ts.map +1 -0
- package/dist/results/diff-dirstat.d.ts +36 -0
- package/dist/results/diff-dirstat.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +10 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-output.d.ts +103 -1
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/diff-pickaxe.d.ts +67 -0
- package/dist/results/diff-pickaxe.d.ts.map +1 -0
- package/dist/results/diff-words.d.ts +55 -0
- package/dist/results/diff-words.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +12 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +6 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/init-result.d.ts +8 -1
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/line-range-hunks.d.ts +27 -0
- package/dist/results/line-range-hunks.d.ts.map +1 -0
- package/dist/results/merge-result.d.ts +8 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +11 -0
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +12 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/rebase-result.d.ts +2 -0
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +6 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +1 -1
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BDuEgdLU.js +46847 -0
- package/dist/transport-command.d.ts +14 -0
- package/dist/transport-command.d.ts.map +1 -1
- package/dist/whitespace/index.d.ts +2 -0
- package/dist/whitespace/index.d.ts.map +1 -0
- package/dist/whitespace/whitespace-rule.d.ts +94 -0
- package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
- package/package.json +12 -12
- package/src/commands/add-command.ts +293 -17
- package/src/commands/add-patch/add-patch.ts +8 -0
- package/src/commands/add-patch/patch-backend.ts +20 -2
- package/src/commands/am/am-command.ts +400 -46
- package/src/commands/am/index.ts +1 -0
- package/src/commands/am/mailsplit.ts +326 -0
- package/src/commands/apply/apply-command.ts +58 -15
- package/src/commands/apply/apply-engine.ts +1 -1
- package/src/commands/apply/apply-parse.ts +17 -8
- package/src/commands/apply/index.ts +8 -1
- package/src/commands/bisect/bisect-command.ts +18 -5
- package/src/commands/blame-command.ts +1450 -51
- package/src/commands/blame-ignore.ts +307 -0
- package/src/commands/branch-command.ts +528 -53
- package/src/commands/branch-info-command.ts +150 -0
- package/src/commands/branch-tracking.ts +335 -60
- package/src/commands/branch-upstream-command.ts +218 -0
- package/src/commands/check-mailmap-command.ts +129 -0
- package/src/commands/checkout-command.ts +166 -55
- package/src/commands/checkout-paths.ts +28 -0
- package/src/commands/cherry-command.ts +187 -0
- package/src/commands/cherry-pick-command.ts +185 -1
- package/src/commands/clean-command.ts +126 -15
- package/src/commands/clean-interactive.ts +522 -0
- package/src/commands/clone-command.ts +598 -45
- package/src/commands/commit-command.ts +925 -74
- package/src/commands/commit-reuse.ts +94 -0
- package/src/commands/config-command.ts +1256 -0
- package/src/commands/config-value-types.ts +358 -0
- package/src/commands/core-config.ts +40 -0
- package/src/commands/describe-command.ts +341 -254
- package/src/commands/diff-color-config.ts +274 -0
- package/src/commands/diff-command.ts +1619 -99
- package/src/commands/fetch-command.ts +495 -14
- package/src/commands/fetch-multiple-command.ts +665 -0
- package/src/commands/fmt-merge-msg-command.ts +715 -0
- package/src/commands/fork-point.ts +63 -0
- package/src/commands/format-patch-command.ts +496 -116
- package/src/commands/fsck/fetch-fsck.ts +172 -18
- package/src/commands/gc-command.ts +31 -1
- package/src/commands/git-describe.ts +460 -201
- package/src/commands/git-hooks.ts +123 -3
- package/src/commands/grep/grep-command.ts +1077 -0
- package/src/commands/grep/grep-engine.ts +1024 -0
- package/src/commands/grep/index.ts +2 -0
- package/src/commands/index-adder.ts +46 -7
- package/src/commands/index.ts +43 -0
- package/src/commands/init-command.ts +603 -49
- package/src/commands/interpret-trailers-command.ts +256 -0
- package/src/commands/line-log.ts +931 -0
- package/src/commands/local-transport.ts +109 -10
- package/src/commands/log-command.ts +2599 -326
- package/src/commands/log-graph.ts +129 -29
- package/src/commands/log-output.ts +449 -27
- package/src/commands/ls-remote-command.ts +5 -0
- package/src/commands/mailmap.ts +155 -0
- package/src/commands/merge-base-command.ts +170 -0
- package/src/commands/merge-bases.ts +63 -8
- package/src/commands/merge-command.ts +601 -95
- package/src/commands/merge-drivers.ts +3 -0
- package/src/commands/merge-strategy-options.ts +224 -0
- package/src/commands/merge-support.ts +115 -22
- package/src/commands/message-cleanup.ts +1 -1
- package/src/commands/mv-command.ts +6 -3
- package/src/commands/name-rev-command.ts +184 -0
- package/src/commands/name-rev.ts +762 -0
- package/src/commands/notes-command.ts +11 -1
- package/src/commands/octopus-merge.ts +35 -11
- package/src/commands/ort-merge.ts +41 -7
- package/src/commands/ort-recursive.ts +40 -2
- package/src/commands/patch-id.ts +109 -0
- package/src/commands/pathspec-file.ts +72 -0
- package/src/commands/pathspec.ts +14 -2
- package/src/commands/pretty-format.ts +103 -19
- package/src/commands/promisor-remote.ts +10 -1
- package/src/commands/pull-command.ts +734 -221
- package/src/commands/push-command.ts +1035 -68
- package/src/commands/range-diff/index.ts +3 -0
- package/src/commands/range-diff/linear-assignment.ts +203 -0
- package/src/commands/range-diff/range-diff-command.ts +433 -0
- package/src/commands/range-diff/range-diff.ts +617 -0
- package/src/commands/read-tree-command.ts +102 -4
- package/src/commands/rebase-command.ts +1074 -194
- package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
- package/src/commands/ref-filter/index.ts +7 -0
- package/src/commands/ref-filter/ref-atoms.ts +581 -0
- package/src/commands/ref-filter/ref-filter.ts +651 -0
- package/src/commands/ref-filter/ref-format.ts +1070 -0
- package/src/commands/ref-filter/ref-listing-command.ts +421 -0
- package/src/commands/ref-filter/ref-quote.ts +69 -0
- package/src/commands/ref-filter/version-compare.ts +177 -0
- package/src/commands/reflog-command.ts +492 -2
- package/src/commands/reflog-walk.ts +234 -0
- package/src/commands/remerge-diff.ts +241 -0
- package/src/commands/remote-command.ts +537 -69
- package/src/commands/remote-show-command.ts +836 -0
- package/src/commands/remote-transport.ts +9 -1
- package/src/commands/reset-command.ts +114 -34
- package/src/commands/restore-command.ts +27 -41
- package/src/commands/rev-filter/commit-filter.ts +159 -0
- package/src/commands/rev-filter/commit-grep.ts +444 -0
- package/src/commands/rev-filter/index.ts +2 -0
- package/src/commands/rev-list-command.ts +578 -15
- package/src/commands/revert-command.ts +123 -1
- package/src/commands/revision-range.ts +207 -5
- package/src/commands/revision-resolver.ts +23 -8
- package/src/commands/rm-command.ts +282 -21
- package/src/commands/sequencer-pick.ts +818 -111
- package/src/commands/sequencer-support.ts +184 -4
- package/src/commands/serve-repository.ts +18 -3
- package/src/commands/shortlog-command.ts +354 -0
- package/src/commands/shortlog.ts +361 -0
- package/src/commands/show-command.ts +491 -0
- package/src/commands/show-commit.ts +24 -0
- package/src/commands/signature-check.ts +657 -0
- package/src/commands/signing.ts +385 -0
- package/src/commands/sparse-checkout-command.ts +2 -9
- package/src/commands/sparse-checkout-support.ts +2 -2
- package/src/commands/sparse-index-view.ts +135 -0
- package/src/commands/ssh-signer.ts +199 -0
- package/src/commands/ssh-verifier.ts +523 -0
- package/src/commands/stash-apply-command.ts +16 -4
- package/src/commands/stash-branch-command.ts +88 -0
- package/src/commands/stash-create-command.ts +28 -0
- package/src/commands/stash-info.ts +243 -0
- package/src/commands/stash-list-command.ts +33 -0
- package/src/commands/stash-pop-command.ts +83 -0
- package/src/commands/stash-show-command.ts +141 -0
- package/src/commands/stash-store-command.ts +82 -0
- package/src/commands/stash-working-tree.ts +2 -2
- package/src/commands/status-command.ts +120 -27
- package/src/commands/status-format.ts +1 -1
- package/src/commands/status-header.ts +41 -7
- package/src/commands/submodule-add-command.ts +509 -0
- package/src/commands/submodule-auth.ts +276 -0
- package/src/commands/submodule-commands.ts +1835 -0
- package/src/commands/submodule-fetch.ts +789 -0
- package/src/commands/submodule-model.ts +938 -0
- package/src/commands/submodule-unpack.ts +265 -0
- package/src/commands/submodule-update-command.ts +1126 -0
- package/src/commands/subtree-shift.ts +215 -0
- package/src/commands/switch-command.ts +12 -1
- package/src/commands/tag-command.ts +876 -64
- package/src/commands/trailers.ts +837 -100
- package/src/commands/tree-restore.ts +44 -11
- package/src/commands/verify-command.ts +235 -0
- package/src/commands/worktree-add-command.ts +268 -24
- package/src/commands/worktree-overwrite-checks.ts +5 -0
- package/src/commands/worktree-path-rules.ts +183 -0
- package/src/commands/worktree-remove-command.ts +39 -5
- package/src/commands/worktree-repair-command.ts +52 -5
- package/src/commands/worktree-support.ts +22 -1
- package/src/errors/checkout-errors.ts +29 -0
- package/src/errors/command-errors.ts +37 -1
- package/src/errors/ref-errors.ts +23 -0
- package/src/errors/worktree-errors.ts +8 -1
- package/src/git-command.ts +153 -2
- package/src/git.ts +550 -1
- package/src/guarded-transport-command.ts +171 -0
- package/src/index.ts +1 -0
- package/src/remote-config/index.ts +2 -0
- package/src/remote-config/remote-config-store.ts +101 -0
- package/src/rename/detect-renames.ts +42 -8
- package/src/rename/diffcore-break.ts +166 -0
- package/src/rename/index.ts +1 -0
- package/src/results/blame-format.ts +268 -43
- package/src/results/clone-result.ts +6 -0
- package/src/results/combined-diff.ts +38 -18
- package/src/results/diff-check.ts +185 -0
- package/src/results/diff-color.ts +868 -0
- package/src/results/diff-dirstat.ts +117 -0
- package/src/results/diff-entry.ts +12 -0
- package/src/results/diff-formatter.ts +1 -0
- package/src/results/diff-output.ts +322 -32
- package/src/results/diff-pickaxe.ts +304 -0
- package/src/results/diff-words.ts +395 -0
- package/src/results/fetch-result.ts +12 -1
- package/src/results/index.ts +6 -0
- package/src/results/init-result.ts +10 -1
- package/src/results/line-range-hunks.ts +126 -0
- package/src/results/merge-result.ts +9 -0
- package/src/results/pull-result.ts +7 -0
- package/src/results/push-result.ts +12 -0
- package/src/results/rebase-result.ts +3 -0
- package/src/results/stash-result.ts +7 -0
- package/src/results/status-result.ts +2 -2
- package/src/transport-command.ts +34 -3
- package/src/whitespace/index.ts +1 -0
- package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
- package/dist/commands/apply/whitespace.d.ts +0 -58
- package/dist/commands/apply/whitespace.d.ts.map +0 -1
- package/dist/git-command-BGiOJ8Zk.js +0 -7246
- package/dist/results-WVlBhVb1.js +0 -2935
|
@@ -0,0 +1,1077 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git grep` (builtin/grep.c over grep.c): lines matching patterns in the worktree's tracked
|
|
3
|
+
* files, the index (`--cached`), untracked files too (`--untracked`), a directory outside
|
|
4
|
+
* git's control (`--no-index`), or trees and revisions.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // git grep -n -e foo --and --not -e bar HEAD -- src
|
|
9
|
+
* const result = await git
|
|
10
|
+
* .grep()
|
|
11
|
+
* .addPattern("foo")
|
|
12
|
+
* .and()
|
|
13
|
+
* .not()
|
|
14
|
+
* .addPattern("bar")
|
|
15
|
+
* .setLineNumber(true)
|
|
16
|
+
* .setArguments(["HEAD", "--", "src"])
|
|
17
|
+
* .call();
|
|
18
|
+
* process.stdout.write(result.output); // HEAD:src/a.c:12:foo()
|
|
19
|
+
* result.exitCode; // 0 when something matched, else 1
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* What it searches, as git does:
|
|
23
|
+
* - The worktree: every regular file of the index (stage 0 once per unmerged path, skip-worktree
|
|
24
|
+
* entries left out), read from disk, or from the index when the entry is assume-unchanged
|
|
25
|
+
* (an intent-to-add or unmerged one then skipped).
|
|
26
|
+
* - `--cached`: the index's blobs. Trees and revisions (`setArguments`, `addRevision`): their
|
|
27
|
+
* files named `<rev>:<path>` (a blob given as `<rev>:<path>` by that name alone); the diff
|
|
28
|
+
* attributes of a commit's files come from the worktree and index, a tree's files have none.
|
|
29
|
+
* - `--untracked` and `--no-index`: the files of the directory (`.git` never entered), ignored
|
|
30
|
+
* ones left out unless `--no-exclude-standard` (the default of `--no-index`); `--no-index`
|
|
31
|
+
* enters nested repositories. Without a repository, {@link grepNoIndex}.
|
|
32
|
+
*
|
|
33
|
+
* Names are relative to the current directory ({@link GrepCommand.setPrefix}) unless
|
|
34
|
+
* `--full-name`/`grep.fullName`, quoted as `core.quotePath` says (not with `-z`). Binary files
|
|
35
|
+
* (a NUL in their first 8000 bytes, or the `diff` attribute's driver) report `Binary file x
|
|
36
|
+
* matches`; `--textconv` runs `diff.<driver>.textconv` through the runner the host installs
|
|
37
|
+
* (`installTextconvRunner`). `-p`/`-W` use the driver's funcname pattern. Configuration:
|
|
38
|
+
* `grep.lineNumber`, `grep.column`, `grep.fullName`, `grep.patternType`,
|
|
39
|
+
* `grep.extendedRegexp`, `grep.threads`, `color.grep`, `color.grep.<slot>`.
|
|
40
|
+
*
|
|
41
|
+
* Output follows git's threaded grep (its default, `GrepEngine`): with context, every source's
|
|
42
|
+
* output after the first starts with `--`. `--recurse-submodules` (or `submodule.recurse`)
|
|
43
|
+
* is refused; `-O`/`--open-files-in-pager` is not offered.
|
|
44
|
+
*
|
|
45
|
+
* @module
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
import { FileMode, type ObjectId } from "@statewalker/vcs-core";
|
|
49
|
+
import { parseGitBool } from "@statewalker/vcs-utils";
|
|
50
|
+
import type { FindFunction } from "@statewalker/vcs-utils/diff";
|
|
51
|
+
import { userdiffFindFunction } from "@statewalker/vcs-utils/diff";
|
|
52
|
+
import { encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
53
|
+
import {
|
|
54
|
+
type AttributesIndex,
|
|
55
|
+
collectChunks,
|
|
56
|
+
type IndexEntry,
|
|
57
|
+
smudgeContent,
|
|
58
|
+
type Worktree,
|
|
59
|
+
} from "@statewalker/vcs-working-tree";
|
|
60
|
+
|
|
61
|
+
import { RevisionError } from "../../errors/index.js";
|
|
62
|
+
import { GitCommand } from "../../git-command.js";
|
|
63
|
+
import { quotePath } from "../../results/quote-path.js";
|
|
64
|
+
import { parseGitColor } from "../config-value-types.js";
|
|
65
|
+
import { type TextconvRunner, textconvRunnerOf } from "../diff-textconv.js";
|
|
66
|
+
import { configValue } from "../merge-config.js";
|
|
67
|
+
import { MATCHED_FNMATCH, matchPathspec, type PathspecItem, parsePathspec } from "../pathspec.js";
|
|
68
|
+
import type { GrepPatternType } from "../rev-filter/index.js";
|
|
69
|
+
import { type ArgumentFiles, verifyFilename, verifyNonFilename } from "../revision-filenames.js";
|
|
70
|
+
import type { RevisionResolver } from "../revision-resolver.js";
|
|
71
|
+
import {
|
|
72
|
+
DEFAULT_GREP_COLORS,
|
|
73
|
+
type GrepBinaryMode,
|
|
74
|
+
type GrepColors,
|
|
75
|
+
GrepEngine,
|
|
76
|
+
type GrepEngineOptions,
|
|
77
|
+
GrepError,
|
|
78
|
+
type GrepToken,
|
|
79
|
+
grepPattern,
|
|
80
|
+
grepPatternFile,
|
|
81
|
+
} from "./grep-engine.js";
|
|
82
|
+
|
|
83
|
+
/** What `git grep` printed and how it ended. */
|
|
84
|
+
export interface GrepResult {
|
|
85
|
+
/** git's exit status: 0 when something matched (`-L`: a file was listed), else 1 */
|
|
86
|
+
exitCode: 0 | 1;
|
|
87
|
+
/** Whether something matched */
|
|
88
|
+
matched: boolean;
|
|
89
|
+
/** git's stdout */
|
|
90
|
+
output: Uint8Array;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Every option of a grep run (what {@link GrepCommand}'s setters set). */
|
|
94
|
+
export interface GrepOptions
|
|
95
|
+
extends Omit<GrepEngineOptions, "lineNumber" | "column" | "colors" | "patternType"> {
|
|
96
|
+
tokens: GrepToken[];
|
|
97
|
+
/** `-E`/`-F`/`-G`/`-P`; undefined: `grep.patternType`, `grep.extendedRegexp` */
|
|
98
|
+
patternType?: GrepPatternType;
|
|
99
|
+
lineNumber?: boolean;
|
|
100
|
+
column?: boolean;
|
|
101
|
+
/** `--full-name` (undefined: `grep.fullName`) */
|
|
102
|
+
fullName?: boolean;
|
|
103
|
+
/** `--color[=<when>]` (undefined: `color.grep`, `color.ui`; `auto` is off here) */
|
|
104
|
+
color?: boolean;
|
|
105
|
+
cached?: boolean;
|
|
106
|
+
untracked?: boolean;
|
|
107
|
+
noIndex?: boolean;
|
|
108
|
+
/** `--[no-]exclude-standard` */
|
|
109
|
+
excludeStandard?: boolean;
|
|
110
|
+
/** `--max-depth` (-1: none) */
|
|
111
|
+
maxDepth?: number;
|
|
112
|
+
/** `--textconv` */
|
|
113
|
+
textconv?: boolean;
|
|
114
|
+
/** `--recurse-submodules` */
|
|
115
|
+
recurseSubmodules?: boolean;
|
|
116
|
+
/** The current directory below the top (`sub/`), git's prefix */
|
|
117
|
+
prefix?: string;
|
|
118
|
+
/** The revision and path arguments, as given after the pattern */
|
|
119
|
+
args?: string[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const S_IFMT = 0o170000;
|
|
123
|
+
const S_IFREG = 0o100000;
|
|
124
|
+
const isRegular = (mode: number) => (mode & S_IFMT) === S_IFREG;
|
|
125
|
+
|
|
126
|
+
/** An index without in-tree attributes files */
|
|
127
|
+
const NO_INDEX: AttributesIndex = { attributesBlob: () => undefined };
|
|
128
|
+
|
|
129
|
+
/** A diff driver as grep uses it: the funcname pattern read only when needed */
|
|
130
|
+
interface GrepDriver {
|
|
131
|
+
binary?: boolean;
|
|
132
|
+
textconv?: { name: string; command: string; cache: boolean };
|
|
133
|
+
findFunction(): FindFunction | undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** What a grep run reads: the repository's parts, where there is one. */
|
|
137
|
+
interface GrepContext {
|
|
138
|
+
worktree?: Worktree;
|
|
139
|
+
/** A configuration value (the last one) */
|
|
140
|
+
config(key: string): string | undefined;
|
|
141
|
+
/** Whether there is a repository (git's `have_repository`) */
|
|
142
|
+
repository: boolean;
|
|
143
|
+
/** The top of the worktree as the host names it */
|
|
144
|
+
hostTop?: string;
|
|
145
|
+
entries?(): Promise<IndexEntry[]>;
|
|
146
|
+
readBlob?(id: ObjectId): Promise<Uint8Array | undefined>;
|
|
147
|
+
prefetch?(ids: ObjectId[]): Promise<void>;
|
|
148
|
+
treeEntries?(id: ObjectId): Promise<readonly { name: string; mode: number; id: ObjectId }[]>;
|
|
149
|
+
resolver?(): RevisionResolver;
|
|
150
|
+
argumentFiles?(prefix: string): ArgumentFiles;
|
|
151
|
+
textconv?: TextconvRunner;
|
|
152
|
+
inOneOperation<T>(fn: () => Promise<T>): Promise<T>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function die(message: string): never {
|
|
156
|
+
throw new GrepError(`fatal: ${message}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** git's `relative_path(in, prefix)` for two paths from the top (prefix ends with `/`). */
|
|
160
|
+
function relativePath(path: string, prefix: string): string {
|
|
161
|
+
if (!prefix) return path;
|
|
162
|
+
const a = path.split("/");
|
|
163
|
+
const b = prefix.split("/").filter((p) => p !== "");
|
|
164
|
+
let k = 0;
|
|
165
|
+
while (k < a.length - 1 && k < b.length && a[k] === b[k]) k++;
|
|
166
|
+
return [...b.slice(k).map(() => ".."), ...a.slice(k)].join("/");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const SHORT_MAGIC = new Set([..."!\"#%&',-;<=>@_`~^/"]);
|
|
170
|
+
|
|
171
|
+
/** The pathspec argument read against the prefix (`:(top)` and `:/` from the top). */
|
|
172
|
+
function prefixedArg(arg: string, prefix: string): string {
|
|
173
|
+
if (!prefix) return arg;
|
|
174
|
+
if (arg.startsWith(":(")) {
|
|
175
|
+
const close = arg.indexOf(")");
|
|
176
|
+
if (close < 0) return arg;
|
|
177
|
+
const words = arg
|
|
178
|
+
.slice(2, close)
|
|
179
|
+
.split(",")
|
|
180
|
+
.map((w) => w.trim());
|
|
181
|
+
if (words.includes("top")) return arg;
|
|
182
|
+
return arg.slice(0, close + 1) + prefix + arg.slice(close + 1);
|
|
183
|
+
}
|
|
184
|
+
if (arg.startsWith(":")) {
|
|
185
|
+
let i = 1;
|
|
186
|
+
while (i < arg.length && arg[i] !== ":" && SHORT_MAGIC.has(arg[i] as string)) i++;
|
|
187
|
+
const magic = arg.slice(1, i);
|
|
188
|
+
if (arg[i] === ":") i++;
|
|
189
|
+
if (magic.includes("/")) return arg;
|
|
190
|
+
return arg.slice(0, i) + prefix + arg.slice(i);
|
|
191
|
+
}
|
|
192
|
+
return prefix + arg;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The part of an argument after its magic (git's `copyfrom`) */
|
|
196
|
+
function afterMagic(arg: string): string {
|
|
197
|
+
if (arg.startsWith(":(")) {
|
|
198
|
+
const close = arg.indexOf(")");
|
|
199
|
+
return close < 0 ? arg : arg.slice(close + 1);
|
|
200
|
+
}
|
|
201
|
+
if (arg.startsWith(":")) {
|
|
202
|
+
let i = 1;
|
|
203
|
+
while (i < arg.length && arg[i] !== ":" && SHORT_MAGIC.has(arg[i] as string)) i++;
|
|
204
|
+
if (arg[i] === ":") i++;
|
|
205
|
+
return arg.slice(i);
|
|
206
|
+
}
|
|
207
|
+
return arg;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** dir.c's within_depth */
|
|
211
|
+
function withinDepth(name: string, depthIn: number, maxDepth: number): boolean {
|
|
212
|
+
let depth = depthIn;
|
|
213
|
+
for (let i = 0; i < name.length; i++) {
|
|
214
|
+
if (name.charCodeAt(i) !== 0x2f) continue;
|
|
215
|
+
depth++;
|
|
216
|
+
if (depth > maxDepth) return false;
|
|
217
|
+
}
|
|
218
|
+
return depth <= maxDepth;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** match_pathspec with `--max-depth` (git's PATHSPEC_MAXDEPTH, recursive) */
|
|
222
|
+
function pathMatches(items: PathspecItem[], path: string, maxDepth: number): boolean {
|
|
223
|
+
if (maxDepth < 0) return matchPathspec(items, path, 0) !== 0;
|
|
224
|
+
if (items.length === 0) return withinDepth(path, 0, maxDepth);
|
|
225
|
+
const name = latin1(path);
|
|
226
|
+
let positive = 0;
|
|
227
|
+
for (const item of items) {
|
|
228
|
+
if (item.exclude) continue;
|
|
229
|
+
let how = matchPathspec([item], path, 0);
|
|
230
|
+
if (how && how !== MATCHED_FNMATCH) {
|
|
231
|
+
let len = item.match.length;
|
|
232
|
+
if (name[len] === "/") len++;
|
|
233
|
+
how = withinDepth(name.slice(len), 0, maxDepth) ? how : 0;
|
|
234
|
+
}
|
|
235
|
+
positive = Math.max(positive, how);
|
|
236
|
+
}
|
|
237
|
+
if (!positive) return false;
|
|
238
|
+
// an exclude element that matches drops the path
|
|
239
|
+
return !items.some((i) => i.exclude) || matchPathspec(items, path, 0) !== 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** A path as one character per byte (pathspec items hold bytes) */
|
|
243
|
+
function latin1(path: string): string {
|
|
244
|
+
let ascii = true;
|
|
245
|
+
for (let i = 0; i < path.length; i++) if (path.charCodeAt(i) > 0x7f) ascii = false;
|
|
246
|
+
if (ascii) return path;
|
|
247
|
+
let out = "";
|
|
248
|
+
for (const b of encodeGitPath(path)) out += String.fromCharCode(b);
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** One search of `git grep` over a context. */
|
|
253
|
+
class GrepRun {
|
|
254
|
+
private engine!: GrepEngine;
|
|
255
|
+
private items: PathspecItem[] = [];
|
|
256
|
+
private relative = true;
|
|
257
|
+
private quoteFully = true;
|
|
258
|
+
private readonly drivers = new Map<string, Promise<GrepDriver | undefined>>();
|
|
259
|
+
private readonly prefix: string;
|
|
260
|
+
|
|
261
|
+
constructor(
|
|
262
|
+
private readonly ctx: GrepContext,
|
|
263
|
+
private readonly o: GrepOptions,
|
|
264
|
+
) {
|
|
265
|
+
this.prefix = o.prefix ?? "";
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async run(): Promise<GrepResult> {
|
|
269
|
+
const ctx = this.ctx;
|
|
270
|
+
const o = this.o;
|
|
271
|
+
const get = (key: string) => ctx.config(key);
|
|
272
|
+
const bool = (key: string) => {
|
|
273
|
+
const v = get(key);
|
|
274
|
+
return v === undefined ? undefined : (parseGitBool(v) ?? true);
|
|
275
|
+
};
|
|
276
|
+
// grep_config
|
|
277
|
+
let configured: GrepPatternType | undefined;
|
|
278
|
+
const typeValue = get("grep.patternType");
|
|
279
|
+
if (typeValue !== undefined) {
|
|
280
|
+
if (typeValue === "basic" || typeValue === "extended" || typeValue === "fixed") {
|
|
281
|
+
configured = typeValue;
|
|
282
|
+
} else if (typeValue === "perl") configured = "perl";
|
|
283
|
+
else if (typeValue !== "default") die(`bad grep.patterntype argument: ${typeValue}`);
|
|
284
|
+
}
|
|
285
|
+
const threadsValue = get("grep.threads");
|
|
286
|
+
let threads = o.threads ?? (threadsValue !== undefined ? Number(threadsValue) : 0);
|
|
287
|
+
if (threadsValue !== undefined && Number(threadsValue) < 0) {
|
|
288
|
+
die(`invalid number of threads specified (${threadsValue}) for grep.threads`);
|
|
289
|
+
}
|
|
290
|
+
this.relative = o.fullName !== undefined ? !o.fullName : !(bool("grep.fullName") ?? false);
|
|
291
|
+
this.quoteFully = bool("core.quotePath") ?? true;
|
|
292
|
+
const useIndex = !o.noIndex && ctx.repository;
|
|
293
|
+
const recurse = o.recurseSubmodules ?? bool("submodule.recurse") ?? false;
|
|
294
|
+
if (recurse && useIndex) {
|
|
295
|
+
die("--recurse-submodules is not supported by this implementation of git grep");
|
|
296
|
+
}
|
|
297
|
+
const tokens = o.tokens;
|
|
298
|
+
if (tokens.length === 0) die("no pattern given");
|
|
299
|
+
|
|
300
|
+
// revisions, then paths
|
|
301
|
+
const { objects, paths } = await this.readArguments(useIndex);
|
|
302
|
+
this.items = this.parsePaths(paths);
|
|
303
|
+
|
|
304
|
+
if (o.maxCount === 0) return { exitCode: 1, matched: false, output: new Uint8Array(0) };
|
|
305
|
+
if (threads < 0) die(`invalid number of threads specified (${threads})`);
|
|
306
|
+
if (threads === 0) threads = 8;
|
|
307
|
+
|
|
308
|
+
let patternType = o.patternType ?? configured;
|
|
309
|
+
if (patternType === undefined) patternType = bool("grep.extendedRegexp") ? "extended" : "basic";
|
|
310
|
+
this.engine = new GrepEngine(tokens, {
|
|
311
|
+
...o,
|
|
312
|
+
patternType,
|
|
313
|
+
lineNumber: o.lineNumber ?? bool("grep.lineNumber") ?? false,
|
|
314
|
+
column: o.column ?? bool("grep.column") ?? false,
|
|
315
|
+
threads,
|
|
316
|
+
...(this.colorOn() ? { colors: this.colors() } : {}),
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
const incompatible = [
|
|
320
|
+
[!useIndex && !!o.noIndex, "--no-index"],
|
|
321
|
+
[!!o.untracked, "--untracked"],
|
|
322
|
+
[!!o.cached, "--cached"],
|
|
323
|
+
].filter(([on]) => on) as [boolean, string][];
|
|
324
|
+
if (incompatible.length === 3) {
|
|
325
|
+
die("options '--no-index', '--untracked', and '--cached' cannot be used together");
|
|
326
|
+
}
|
|
327
|
+
if (incompatible.length === 2) {
|
|
328
|
+
die(
|
|
329
|
+
`options '${incompatible[0]?.[1]}' and '${incompatible[1]?.[1]}' cannot be used together`,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
let hit: boolean;
|
|
334
|
+
if (!useIndex || o.untracked) {
|
|
335
|
+
const exclude = o.excludeStandard ?? useIndex;
|
|
336
|
+
hit = await ctx.inOneOperation(() => this.grepDirectory(exclude, useIndex));
|
|
337
|
+
} else if (o.excludeStandard !== undefined) {
|
|
338
|
+
die("--[no-]exclude-standard cannot be used for tracked contents");
|
|
339
|
+
} else if (objects.length === 0) {
|
|
340
|
+
hit = await ctx.inOneOperation(() => this.grepCache(!!o.cached));
|
|
341
|
+
} else {
|
|
342
|
+
if (o.cached) die("both --cached and trees are given");
|
|
343
|
+
hit = await ctx.inOneOperation(() => this.grepObjects(objects));
|
|
344
|
+
}
|
|
345
|
+
return { exitCode: hit ? 0 : 1, matched: hit, output: this.engine.output() };
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
private colorOn(): boolean {
|
|
349
|
+
if (this.o.color !== undefined) return this.o.color;
|
|
350
|
+
const value = this.ctx.config("color.grep") ?? this.ctx.config("color.ui");
|
|
351
|
+
if (value === undefined) return false;
|
|
352
|
+
if (value === "always") return true;
|
|
353
|
+
if (value === "auto" || value === "never") return false;
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
private colors(): GrepColors {
|
|
358
|
+
const colors: GrepColors = { ...DEFAULT_GREP_COLORS };
|
|
359
|
+
const slots: [keyof GrepColors, string][] = [
|
|
360
|
+
["context", "context"],
|
|
361
|
+
["filename", "filename"],
|
|
362
|
+
["function", "function"],
|
|
363
|
+
["lineNumber", "lineNumber"],
|
|
364
|
+
["column", "column"],
|
|
365
|
+
["selected", "selected"],
|
|
366
|
+
["separator", "separator"],
|
|
367
|
+
["matchContext", "match"],
|
|
368
|
+
["matchSelected", "match"],
|
|
369
|
+
["matchContext", "matchContext"],
|
|
370
|
+
["matchSelected", "matchSelected"],
|
|
371
|
+
];
|
|
372
|
+
for (const [slot, key] of slots) {
|
|
373
|
+
const value = this.ctx.config(`color.grep.${key}`);
|
|
374
|
+
if (value === undefined) continue;
|
|
375
|
+
const color = parseGitColor(value);
|
|
376
|
+
if (color !== undefined) colors[slot] = color;
|
|
377
|
+
}
|
|
378
|
+
return colors;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** cmd_grep's revision loop and verify_filename */
|
|
382
|
+
private async readArguments(
|
|
383
|
+
useIndex: boolean,
|
|
384
|
+
): Promise<{ objects: { name: string; id: ObjectId; path?: string }[]; paths: string[] }> {
|
|
385
|
+
const ctx = this.ctx;
|
|
386
|
+
const args = this.o.args ?? [];
|
|
387
|
+
const seenDashdash = args.includes("--");
|
|
388
|
+
const allowRevs = useIndex && !this.o.untracked;
|
|
389
|
+
const objects: { name: string; id: ObjectId; path?: string }[] = [];
|
|
390
|
+
let i = 0;
|
|
391
|
+
const resolver = allowRevs ? ctx.resolver?.() : undefined;
|
|
392
|
+
if (resolver) resolver.cwdPrefix = this.prefix;
|
|
393
|
+
const files = ctx.argumentFiles?.(this.prefix);
|
|
394
|
+
for (; i < args.length; i++) {
|
|
395
|
+
const arg = args[i] as string;
|
|
396
|
+
if (arg === "--") {
|
|
397
|
+
i++;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
if (!allowRevs || !resolver) {
|
|
401
|
+
if (seenDashdash) die("--no-index or --untracked cannot be used with revs");
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
const id = await resolver.resolve(arg).catch((e) => {
|
|
405
|
+
if (e instanceof RevisionError) throw e;
|
|
406
|
+
return undefined;
|
|
407
|
+
});
|
|
408
|
+
if (id === undefined) {
|
|
409
|
+
if (seenDashdash) die(`unable to resolve revision: ${arg}`);
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
if (!seenDashdash && files) {
|
|
413
|
+
const message = await verifyNonFilename(files, arg);
|
|
414
|
+
if (message) throw new RevisionError(arg, message);
|
|
415
|
+
}
|
|
416
|
+
objects.push({ name: arg, id, ...this.objectPath(arg) });
|
|
417
|
+
}
|
|
418
|
+
if (!seenDashdash && files && resolver) {
|
|
419
|
+
for (let j = i; j < args.length; j++) {
|
|
420
|
+
await verifyFilename(files, resolver, args[j] as string, j === i && allowRevs);
|
|
421
|
+
}
|
|
422
|
+
} else if (!seenDashdash && files) {
|
|
423
|
+
// diagnose is off: only the resolver's warnings are read
|
|
424
|
+
const quiet = (ctx.resolver?.() ?? { warnings: [] }) as RevisionResolver;
|
|
425
|
+
for (let j = i; j < args.length; j++) {
|
|
426
|
+
await verifyFilename(files, quiet, args[j] as string, false);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return { objects, paths: args.slice(i) };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** The path GET_OID_RECORD_PATH records for `<rev>:<path>` or `:<n>:<path>` */
|
|
433
|
+
private objectPath(arg: string): { path?: string } {
|
|
434
|
+
let at = -1;
|
|
435
|
+
if (arg.startsWith(":")) {
|
|
436
|
+
at = /^:[0-3]:/.test(arg) ? 2 : 0;
|
|
437
|
+
} else {
|
|
438
|
+
let depth = 0;
|
|
439
|
+
for (let i = 0; i < arg.length; i++) {
|
|
440
|
+
const c = arg[i];
|
|
441
|
+
if ((c === "@" || c === "^") && arg[i + 1] === "{") {
|
|
442
|
+
i++;
|
|
443
|
+
depth++;
|
|
444
|
+
} else if (depth > 0 && c === "}") depth--;
|
|
445
|
+
else if (depth === 0 && c === ":") {
|
|
446
|
+
at = i;
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (at < 0) return {};
|
|
452
|
+
let path = arg.slice(at + 1);
|
|
453
|
+
if (path.startsWith("./") || path.startsWith("../") || path === "." || path === "..") {
|
|
454
|
+
const out: string[] = [];
|
|
455
|
+
for (const part of `${this.prefix}${path}`.split("/")) {
|
|
456
|
+
if (part === "" || part === ".") continue;
|
|
457
|
+
if (part === "..") out.pop();
|
|
458
|
+
else out.push(part);
|
|
459
|
+
}
|
|
460
|
+
path = out.join("/");
|
|
461
|
+
}
|
|
462
|
+
return { path };
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/** parse_pathspec with PATHSPEC_PREFER_CWD */
|
|
466
|
+
private parsePaths(paths: string[]): PathspecItem[] {
|
|
467
|
+
const prefix = this.prefix;
|
|
468
|
+
const args = paths.length === 0 && prefix ? ["."] : paths;
|
|
469
|
+
return parsePathspec(
|
|
470
|
+
args.map((arg) => {
|
|
471
|
+
const prefixed = prefixedArg(arg, prefix);
|
|
472
|
+
try {
|
|
473
|
+
parsePathspec([prefixed]);
|
|
474
|
+
} catch (e) {
|
|
475
|
+
if (e instanceof Error && /is outside repository/.test(e.message)) {
|
|
476
|
+
const copy = afterMagic(arg);
|
|
477
|
+
if (!this.ctx.repository) die(`'${copy}' is outside the directory tree`);
|
|
478
|
+
die(`${arg}: '${copy}' is outside repository at '${this.ctx.hostTop ?? ""}'`);
|
|
479
|
+
}
|
|
480
|
+
if (e instanceof Error) die(e.message);
|
|
481
|
+
throw e;
|
|
482
|
+
}
|
|
483
|
+
return prefixed;
|
|
484
|
+
}),
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
private matches(path: string): boolean {
|
|
489
|
+
return pathMatches(this.items, path, this.o.maxDepth ?? -1);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** grep_source_name: the name printed for `path` (after a tree's `<rev>:`) */
|
|
493
|
+
private sourceName(path: string, treeName = ""): Uint8Array {
|
|
494
|
+
const rel = this.relative && this.prefix ? relativePath(path, this.prefix) : path;
|
|
495
|
+
if (this.o.nullFollowingName) return encodeGitPath(treeName + rel);
|
|
496
|
+
return encodeGitPath(treeName + quotePath(rel, this.quoteFully));
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** userdiff_find_by_path: the `diff` attribute's driver */
|
|
500
|
+
private driver(path: string | undefined, withIndex: boolean): Promise<GrepDriver | undefined> {
|
|
501
|
+
if (path === undefined) return Promise.resolve(undefined);
|
|
502
|
+
const key = `${withIndex ? "i" : "w"}:${path}`;
|
|
503
|
+
let found = this.drivers.get(key);
|
|
504
|
+
if (!found) {
|
|
505
|
+
found = this.loadDriver(path, withIndex);
|
|
506
|
+
this.drivers.set(key, found);
|
|
507
|
+
}
|
|
508
|
+
return found;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
private async loadDriver(path: string, withIndex: boolean): Promise<GrepDriver | undefined> {
|
|
512
|
+
const filter = this.ctx.worktree?.contentFilter as
|
|
513
|
+
| {
|
|
514
|
+
attributes?: (
|
|
515
|
+
path: string,
|
|
516
|
+
names?: readonly string[],
|
|
517
|
+
context?: { direction: "checkin"; index?: AttributesIndex },
|
|
518
|
+
) => Promise<Map<string, true | false | string | undefined>>;
|
|
519
|
+
}
|
|
520
|
+
| undefined;
|
|
521
|
+
if (!filter?.attributes) return undefined;
|
|
522
|
+
const attrs = await filter.attributes(
|
|
523
|
+
path,
|
|
524
|
+
["diff"],
|
|
525
|
+
withIndex ? undefined : { direction: "checkin", index: NO_INDEX },
|
|
526
|
+
);
|
|
527
|
+
const value = attrs.get("diff");
|
|
528
|
+
if (value === true) return { binary: false, findFunction: () => undefined };
|
|
529
|
+
if (value === false) return { binary: true, findFunction: () => undefined };
|
|
530
|
+
if (typeof value !== "string") return undefined;
|
|
531
|
+
const get = (key: string) => this.ctx.config(key);
|
|
532
|
+
const binaryValue = get(`diff.${value}.binary`);
|
|
533
|
+
const binary = binaryValue === undefined ? undefined : parseGitBool(binaryValue);
|
|
534
|
+
const command = get(`diff.${value}.textconv`);
|
|
535
|
+
let find: FindFunction | undefined | null = null;
|
|
536
|
+
return {
|
|
537
|
+
...(binary !== undefined ? { binary } : {}),
|
|
538
|
+
...(command !== undefined
|
|
539
|
+
? {
|
|
540
|
+
textconv: {
|
|
541
|
+
name: value,
|
|
542
|
+
command,
|
|
543
|
+
cache: parseGitBool(get(`diff.${value}.cachetextconv`)) ?? false,
|
|
544
|
+
},
|
|
545
|
+
}
|
|
546
|
+
: {}),
|
|
547
|
+
findFunction: () => {
|
|
548
|
+
if (find === null) {
|
|
549
|
+
try {
|
|
550
|
+
find = userdiffFindFunction(value, get);
|
|
551
|
+
} catch (e) {
|
|
552
|
+
die((e as Error).message);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return find;
|
|
556
|
+
},
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** grep_source for one file or blob */
|
|
561
|
+
private async grepOne(
|
|
562
|
+
name: Uint8Array,
|
|
563
|
+
path: string | undefined,
|
|
564
|
+
withIndex: boolean,
|
|
565
|
+
read: () => Promise<Uint8Array | undefined>,
|
|
566
|
+
textconvInput: (content: Uint8Array) => Promise<Uint8Array>,
|
|
567
|
+
): Promise<boolean> {
|
|
568
|
+
const o = this.o;
|
|
569
|
+
const driver = await this.driver(path, withIndex);
|
|
570
|
+
let content = await read();
|
|
571
|
+
let textconv = false;
|
|
572
|
+
if (o.textconv && driver?.textconv && this.ctx.textconv && content !== undefined) {
|
|
573
|
+
const tc = driver.textconv;
|
|
574
|
+
content = await this.ctx.textconv({
|
|
575
|
+
driver: tc.name,
|
|
576
|
+
command: tc.command,
|
|
577
|
+
path: path ?? "",
|
|
578
|
+
content: await textconvInput(content),
|
|
579
|
+
cache: tc.cache,
|
|
580
|
+
});
|
|
581
|
+
textconv = true;
|
|
582
|
+
}
|
|
583
|
+
return this.engine.grepSource({
|
|
584
|
+
name,
|
|
585
|
+
content,
|
|
586
|
+
textconv,
|
|
587
|
+
...(driver?.binary !== undefined ? { binary: driver.binary } : {}),
|
|
588
|
+
findFunction: () => driver?.findFunction(),
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
private async readFile(path: string): Promise<Uint8Array | undefined> {
|
|
593
|
+
const worktree = this.ctx.worktree;
|
|
594
|
+
if (!worktree) return undefined;
|
|
595
|
+
const entry = await worktree.getEntry(path);
|
|
596
|
+
if (!entry || entry.isDirectory || !isRegular(entry.mode)) return undefined;
|
|
597
|
+
try {
|
|
598
|
+
return await collectChunks(worktree.readContent(path));
|
|
599
|
+
} catch {
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
private grepFile(path: string, withIndex: boolean): Promise<boolean> {
|
|
605
|
+
return this.grepOne(
|
|
606
|
+
this.sourceName(path),
|
|
607
|
+
path,
|
|
608
|
+
withIndex,
|
|
609
|
+
() => this.readFile(path),
|
|
610
|
+
async (c) => c,
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
private grepBlob(
|
|
615
|
+
id: ObjectId,
|
|
616
|
+
name: Uint8Array,
|
|
617
|
+
path: string | undefined,
|
|
618
|
+
mode = FileMode.REGULAR_FILE as number,
|
|
619
|
+
): Promise<boolean> {
|
|
620
|
+
const read = () => this.ctx.readBlob?.(id) ?? Promise.resolve(undefined);
|
|
621
|
+
return this.grepOne(name, path, true, read, async (content) =>
|
|
622
|
+
collectChunks(
|
|
623
|
+
await smudgeContent(this.ctx.worktree?.contentFilter, path ?? "", content, mode),
|
|
624
|
+
),
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/** grep_cache */
|
|
629
|
+
private async grepCache(cached: boolean): Promise<boolean> {
|
|
630
|
+
const entries = (await this.ctx.entries?.()) ?? [];
|
|
631
|
+
let hit = false;
|
|
632
|
+
for (let nr = 0; nr < entries.length; nr++) {
|
|
633
|
+
const ce = entries[nr] as IndexEntry;
|
|
634
|
+
if (!cached && ce.skipWorktree) continue;
|
|
635
|
+
if (isRegular(ce.mode) && this.matches(ce.path)) {
|
|
636
|
+
if (cached || ce.assumeValid) {
|
|
637
|
+
if (ce.stage || ce.intentToAdd) continue;
|
|
638
|
+
hit =
|
|
639
|
+
(await this.grepBlob(ce.objectId, this.sourceName(ce.path), ce.path, ce.mode)) || hit;
|
|
640
|
+
} else {
|
|
641
|
+
hit = (await this.grepFile(ce.path, true)) || hit;
|
|
642
|
+
}
|
|
643
|
+
} else continue;
|
|
644
|
+
if (ce.stage) {
|
|
645
|
+
while (nr + 1 < entries.length && entries[nr + 1]?.path === ce.path) nr++;
|
|
646
|
+
}
|
|
647
|
+
if (hit && this.o.statusOnly) break;
|
|
648
|
+
}
|
|
649
|
+
return hit;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/** grep_objects */
|
|
653
|
+
private async grepObjects(
|
|
654
|
+
objects: { name: string; id: ObjectId; path?: string }[],
|
|
655
|
+
): Promise<boolean> {
|
|
656
|
+
const resolver = this.ctx.resolver?.() as RevisionResolver;
|
|
657
|
+
// resolve every object first, then prefetch what a partial clone lacks in one batch
|
|
658
|
+
const work: (() => Promise<boolean>)[] = [];
|
|
659
|
+
const wanted: ObjectId[] = [];
|
|
660
|
+
for (const object of objects) {
|
|
661
|
+
const peeled = await resolver.peelTags(object.id).catch(() => undefined);
|
|
662
|
+
if (!peeled || peeled.type === undefined) die(`invalid object '${object.name}' given.`);
|
|
663
|
+
const { id, type } = peeled;
|
|
664
|
+
if (type === "blob") {
|
|
665
|
+
work.push(() => this.grepBlob(id, this.blobName(object.name), object.path));
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
if (type !== "commit" && type !== "tree") die(`unable to grep from object of type ${type}`);
|
|
669
|
+
const tree = await resolver.peelToType(id, "tree");
|
|
670
|
+
if (!tree) die(`unable to read tree (${id})`);
|
|
671
|
+
const files: { path: string; id: ObjectId; mode: number }[] = [];
|
|
672
|
+
await this.listTree(tree, "", files);
|
|
673
|
+
const base = object.name ? `${object.name}:` : "";
|
|
674
|
+
for (const f of files) wanted.push(f.id);
|
|
675
|
+
work.push(async () => {
|
|
676
|
+
let hit = false;
|
|
677
|
+
for (const f of files) {
|
|
678
|
+
hit =
|
|
679
|
+
(await this.grepBlob(
|
|
680
|
+
f.id,
|
|
681
|
+
this.sourceName(f.path, base),
|
|
682
|
+
type === "commit" ? f.path : undefined,
|
|
683
|
+
f.mode,
|
|
684
|
+
)) || hit;
|
|
685
|
+
if (hit && this.o.statusOnly) break;
|
|
686
|
+
}
|
|
687
|
+
return hit;
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
if (wanted.length > 0) await this.ctx.prefetch?.(wanted);
|
|
691
|
+
let hit = false;
|
|
692
|
+
for (const w of work) {
|
|
693
|
+
if (await w()) {
|
|
694
|
+
hit = true;
|
|
695
|
+
if (this.o.statusOnly) break;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return hit;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* The name of a blob given on the command line: git's grep_oid names it as a path, so it is
|
|
703
|
+
* relative to the prefix too (`../HEAD:./v` from `t/`)
|
|
704
|
+
*/
|
|
705
|
+
private blobName(name: string): Uint8Array {
|
|
706
|
+
return this.sourceName(name);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/** grep_tree's walk: the regular files in tree order that the pathspec takes */
|
|
710
|
+
private async listTree(
|
|
711
|
+
id: ObjectId,
|
|
712
|
+
base: string,
|
|
713
|
+
out: { path: string; id: ObjectId; mode: number }[],
|
|
714
|
+
): Promise<void> {
|
|
715
|
+
const entries = (await this.ctx.treeEntries?.(id)) ?? [];
|
|
716
|
+
for (const e of entries) {
|
|
717
|
+
const path = base + e.name;
|
|
718
|
+
if ((e.mode & S_IFMT) === 0o040000) {
|
|
719
|
+
await this.listTree(e.id, `${path}/`, out);
|
|
720
|
+
} else if (isRegular(e.mode) && this.matches(path)) {
|
|
721
|
+
out.push({ path, id: e.id, mode: e.mode });
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/** grep_directory: fill_directory's files (index unread), sorted */
|
|
727
|
+
private async grepDirectory(exclude: boolean, useIndex: boolean): Promise<boolean> {
|
|
728
|
+
const worktree = this.ctx.worktree;
|
|
729
|
+
if (!worktree) return false;
|
|
730
|
+
const files: string[] = [];
|
|
731
|
+
const host = await worktree.untrackedScanHost?.();
|
|
732
|
+
if (host) {
|
|
733
|
+
const walk = async (dir: string) => {
|
|
734
|
+
if (exclude) await host.loadIgnoreFile(dir);
|
|
735
|
+
let listed: { name: string; kind?: string }[];
|
|
736
|
+
try {
|
|
737
|
+
listed = await host.listDirectory(dir, false);
|
|
738
|
+
} catch {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
for (const entry of listed) {
|
|
742
|
+
if (entry.name === ".git" || entry.name === "." || entry.name === "..") continue;
|
|
743
|
+
const path = dir ? `${dir}/${entry.name}` : entry.name;
|
|
744
|
+
const kind = entry.kind ?? (await host.lstat(path))?.kind;
|
|
745
|
+
if (kind === "directory") {
|
|
746
|
+
if (exclude && host.isExcluded(path, true)) continue;
|
|
747
|
+
if (useIndex && (await host.isNestedRepository(path))) continue;
|
|
748
|
+
await walk(path);
|
|
749
|
+
} else if (kind === "file" || kind === "symlink") {
|
|
750
|
+
if (exclude && host.isExcluded(path, false)) continue;
|
|
751
|
+
if (this.matches(path)) files.push(path);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
await walk("");
|
|
756
|
+
} else {
|
|
757
|
+
for await (const entry of worktree.walk({ includeIgnored: !exclude })) {
|
|
758
|
+
if (!entry.isDirectory && this.matches(entry.path)) files.push(entry.path);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
files.sort((a, b) => compareBytes(encodeGitPath(a), encodeGitPath(b)));
|
|
762
|
+
let hit = false;
|
|
763
|
+
for (const path of files) {
|
|
764
|
+
hit = (await this.grepFile(path, false)) || hit;
|
|
765
|
+
if (hit && this.o.statusOnly) break;
|
|
766
|
+
}
|
|
767
|
+
return hit;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function compareBytes(a: Uint8Array, b: Uint8Array): number {
|
|
772
|
+
const n = Math.min(a.length, b.length);
|
|
773
|
+
for (let i = 0; i < n; i++) if (a[i] !== b[i]) return (a[i] as number) - (b[i] as number);
|
|
774
|
+
return a.length - b.length;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/** The options a {@link GrepCommand} or {@link grepNoIndex} run starts from. */
|
|
778
|
+
function emptyOptions(): GrepOptions {
|
|
779
|
+
return { tokens: [] };
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/** Setters shared by the command and {@link GrepNoIndex} */
|
|
783
|
+
interface GrepSetters {
|
|
784
|
+
readonly options: GrepOptions;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* `git grep`. Patterns: {@link addPattern} (`-e`), {@link addPatternFile} (`-f`), with
|
|
789
|
+
* {@link and}, {@link not}, {@link open}, {@link close} between them (`--or` is the default).
|
|
790
|
+
* Where to search: {@link setArguments} (`[<rev>...] [[--] <path>...]` as git reads them),
|
|
791
|
+
* {@link setCached}, {@link setUntracked}, {@link setNoIndex}. {@link call} resolves with
|
|
792
|
+
* git's stdout and exit status, or throws `GrepError`/`GrepPatternError`/`RevisionError` with
|
|
793
|
+
* git's line where it dies (exit status 128).
|
|
794
|
+
*/
|
|
795
|
+
export class GrepCommand extends GitCommand<GrepResult> implements GrepSetters {
|
|
796
|
+
readonly options: GrepOptions = emptyOptions();
|
|
797
|
+
|
|
798
|
+
private set<K extends keyof GrepOptions>(key: K, value: GrepOptions[K]): this {
|
|
799
|
+
this.checkCallable();
|
|
800
|
+
this.options[key] = value;
|
|
801
|
+
return this;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/** `-e <pattern>` (a string is taken as UTF-8) */
|
|
805
|
+
addPattern(pattern: string | Uint8Array, origin = "-e option"): this {
|
|
806
|
+
this.checkCallable();
|
|
807
|
+
this.options.tokens.push(grepPattern(pattern, origin));
|
|
808
|
+
return this;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/** `-f <file>`: the file's content, one pattern per non-empty line; `name` as given */
|
|
812
|
+
addPatternFile(content: string | Uint8Array, name: string): this {
|
|
813
|
+
this.checkCallable();
|
|
814
|
+
this.options.tokens.push(...grepPatternFile(content, name));
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/** `--and` */
|
|
819
|
+
and(): this {
|
|
820
|
+
return this.token({ kind: "and" });
|
|
821
|
+
}
|
|
822
|
+
/** `--not` */
|
|
823
|
+
not(): this {
|
|
824
|
+
return this.token({ kind: "not" });
|
|
825
|
+
}
|
|
826
|
+
/** `(` */
|
|
827
|
+
open(): this {
|
|
828
|
+
return this.token({ kind: "open" });
|
|
829
|
+
}
|
|
830
|
+
/** `)` */
|
|
831
|
+
close(): this {
|
|
832
|
+
return this.token({ kind: "close" });
|
|
833
|
+
}
|
|
834
|
+
private token(t: GrepToken): this {
|
|
835
|
+
this.checkCallable();
|
|
836
|
+
this.options.tokens.push(t);
|
|
837
|
+
return this;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/** `--all-match` */
|
|
841
|
+
setAllMatch(on: boolean): this {
|
|
842
|
+
return this.set("allMatch", on);
|
|
843
|
+
}
|
|
844
|
+
/** `-E` (`extended`), `-F` (`fixed`), `-G` (`basic`), `-P` (`perl`) */
|
|
845
|
+
setPatternType(type: GrepPatternType | undefined): this {
|
|
846
|
+
return this.set("patternType", type);
|
|
847
|
+
}
|
|
848
|
+
/** `-i` */
|
|
849
|
+
setIgnoreCase(on: boolean): this {
|
|
850
|
+
return this.set("ignoreCase", on);
|
|
851
|
+
}
|
|
852
|
+
/** `-w` */
|
|
853
|
+
setWordRegexp(on: boolean): this {
|
|
854
|
+
return this.set("wordRegexp", on);
|
|
855
|
+
}
|
|
856
|
+
/** `-v` */
|
|
857
|
+
setInvertMatch(on: boolean): this {
|
|
858
|
+
return this.set("invert", on);
|
|
859
|
+
}
|
|
860
|
+
/** `--cached` */
|
|
861
|
+
setCached(on: boolean): this {
|
|
862
|
+
return this.set("cached", on);
|
|
863
|
+
}
|
|
864
|
+
/** `--untracked` */
|
|
865
|
+
setUntracked(on: boolean): this {
|
|
866
|
+
return this.set("untracked", on);
|
|
867
|
+
}
|
|
868
|
+
/** `--no-index` */
|
|
869
|
+
setNoIndex(on: boolean): this {
|
|
870
|
+
return this.set("noIndex", on);
|
|
871
|
+
}
|
|
872
|
+
/** `--exclude-standard` (true) / `--no-exclude-standard` (false) */
|
|
873
|
+
setExcludeStandard(on: boolean | undefined): this {
|
|
874
|
+
return this.set("excludeStandard", on);
|
|
875
|
+
}
|
|
876
|
+
/** `--recurse-submodules`: refused (not supported yet) */
|
|
877
|
+
setRecurseSubmodules(on: boolean): this {
|
|
878
|
+
return this.set("recurseSubmodules", on);
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* The arguments after the pattern: revisions, then paths (`--` between them), checked as
|
|
882
|
+
* git checks them (a path must exist without `--`, a revision must not also be a file)
|
|
883
|
+
*/
|
|
884
|
+
setArguments(args: string[]): this {
|
|
885
|
+
return this.set("args", [...args]);
|
|
886
|
+
}
|
|
887
|
+
/** A revision or tree to search (`<rev>`, `<rev>:<path>`, a tree id) */
|
|
888
|
+
addRevision(revision: string): this {
|
|
889
|
+
const args = this.options.args ?? [];
|
|
890
|
+
const dd = args.indexOf("--");
|
|
891
|
+
const revs = dd < 0 ? args : args.slice(0, dd);
|
|
892
|
+
const paths = dd < 0 ? [] : args.slice(dd + 1);
|
|
893
|
+
return this.set("args", [...revs, revision, "--", ...paths]);
|
|
894
|
+
}
|
|
895
|
+
/** Pathspecs (`-- <path>...`) */
|
|
896
|
+
addPath(...paths: string[]): this {
|
|
897
|
+
const args = this.options.args ?? [];
|
|
898
|
+
return this.set("args", args.includes("--") ? [...args, ...paths] : [...args, "--", ...paths]);
|
|
899
|
+
}
|
|
900
|
+
/** The current directory below the top (`sub/` or `sub`): names are relative to it */
|
|
901
|
+
setPrefix(prefix: string): this {
|
|
902
|
+
const p = prefix.replace(/^\/+|\/+$/g, "");
|
|
903
|
+
return this.set("prefix", p ? `${p}/` : "");
|
|
904
|
+
}
|
|
905
|
+
/** `--max-depth <n>` (-1: none) */
|
|
906
|
+
setMaxDepth(depth: number): this {
|
|
907
|
+
return this.set("maxDepth", depth);
|
|
908
|
+
}
|
|
909
|
+
/** `-n` / `--no-line-number` (undefined: `grep.lineNumber`) */
|
|
910
|
+
setLineNumber(on: boolean | undefined): this {
|
|
911
|
+
return this.set("lineNumber", on);
|
|
912
|
+
}
|
|
913
|
+
/** `--column` (undefined: `grep.column`) */
|
|
914
|
+
setColumn(on: boolean | undefined): this {
|
|
915
|
+
return this.set("column", on);
|
|
916
|
+
}
|
|
917
|
+
/** `-H` (true) / `-h` (false) */
|
|
918
|
+
setShowFilename(on: boolean): this {
|
|
919
|
+
return this.set("pathname", on);
|
|
920
|
+
}
|
|
921
|
+
/** `--full-name` (undefined: `grep.fullName`) */
|
|
922
|
+
setFullName(on: boolean | undefined): this {
|
|
923
|
+
return this.set("fullName", on);
|
|
924
|
+
}
|
|
925
|
+
/** `-z` */
|
|
926
|
+
setNull(on: boolean): this {
|
|
927
|
+
return this.set("nullFollowingName", on);
|
|
928
|
+
}
|
|
929
|
+
/** `-o` */
|
|
930
|
+
setOnlyMatching(on: boolean): this {
|
|
931
|
+
return this.set("onlyMatching", on);
|
|
932
|
+
}
|
|
933
|
+
/** `-c` */
|
|
934
|
+
setCount(on: boolean): this {
|
|
935
|
+
return this.set("count", on);
|
|
936
|
+
}
|
|
937
|
+
/** `-l` */
|
|
938
|
+
setFilesWithMatches(on: boolean): this {
|
|
939
|
+
return this.set("nameOnly", on);
|
|
940
|
+
}
|
|
941
|
+
/** `-L` */
|
|
942
|
+
setFilesWithoutMatch(on: boolean): this {
|
|
943
|
+
return this.set("unmatchNameOnly", on);
|
|
944
|
+
}
|
|
945
|
+
/** `-q` */
|
|
946
|
+
setQuiet(on: boolean): this {
|
|
947
|
+
return this.set("statusOnly", on);
|
|
948
|
+
}
|
|
949
|
+
/** `--break` */
|
|
950
|
+
setBreak(on: boolean): this {
|
|
951
|
+
return this.set("fileBreak", on);
|
|
952
|
+
}
|
|
953
|
+
/** `--heading` */
|
|
954
|
+
setHeading(on: boolean): this {
|
|
955
|
+
return this.set("heading", on);
|
|
956
|
+
}
|
|
957
|
+
/** `-B <n>` */
|
|
958
|
+
setBeforeContext(n: number): this {
|
|
959
|
+
return this.set("preContext", n);
|
|
960
|
+
}
|
|
961
|
+
/** `-A <n>` */
|
|
962
|
+
setAfterContext(n: number): this {
|
|
963
|
+
return this.set("postContext", n);
|
|
964
|
+
}
|
|
965
|
+
/** `-C <n>` */
|
|
966
|
+
setContext(n: number): this {
|
|
967
|
+
this.set("preContext", n);
|
|
968
|
+
return this.set("postContext", n);
|
|
969
|
+
}
|
|
970
|
+
/** `-p` */
|
|
971
|
+
setShowFunction(on: boolean): this {
|
|
972
|
+
return this.set("funcname", on);
|
|
973
|
+
}
|
|
974
|
+
/** `-W` */
|
|
975
|
+
setFunctionContext(on: boolean): this {
|
|
976
|
+
return this.set("funcbody", on);
|
|
977
|
+
}
|
|
978
|
+
/** `-m <n>` (negative: no limit) */
|
|
979
|
+
setMaxCount(n: number): this {
|
|
980
|
+
return this.set("maxCount", n);
|
|
981
|
+
}
|
|
982
|
+
/** `-a` (`text`), `-I` (`nomatch`) */
|
|
983
|
+
setBinary(mode: GrepBinaryMode): this {
|
|
984
|
+
return this.set("binary", mode);
|
|
985
|
+
}
|
|
986
|
+
/** `--textconv` / `--no-textconv` */
|
|
987
|
+
setTextconv(on: boolean): this {
|
|
988
|
+
return this.set("textconv", on);
|
|
989
|
+
}
|
|
990
|
+
/** `--color=always` (true), `--no-color` (false); undefined: `color.grep`/`color.ui` */
|
|
991
|
+
setColor(on: boolean | undefined): this {
|
|
992
|
+
return this.set("color", on);
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* `--threads <n>`: 1 prints as git's single-threaded grep, more (the default) as its
|
|
996
|
+
* threaded one (a hunk mark before each file's context, the first output's first line
|
|
997
|
+
* dropped)
|
|
998
|
+
*/
|
|
999
|
+
setThreads(n: number): this {
|
|
1000
|
+
return this.set("threads", n);
|
|
1001
|
+
}
|
|
1002
|
+
/** The git version to follow (`2.43` or `2.56`, the default); see `GrepEngineOptions` */
|
|
1003
|
+
setCompatibility(compatibility: "2.43" | "2.56"): this {
|
|
1004
|
+
return this.set("compatibility", compatibility);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
async call(): Promise<GrepResult> {
|
|
1008
|
+
this.checkCallable();
|
|
1009
|
+
this.setCallable(false);
|
|
1010
|
+
const wc = this.workingCopy;
|
|
1011
|
+
const worktree = this.worktreeAccess;
|
|
1012
|
+
const get = (key: string) => configValue(wc, key);
|
|
1013
|
+
const ctx: GrepContext = {
|
|
1014
|
+
worktree,
|
|
1015
|
+
config: get,
|
|
1016
|
+
repository: true,
|
|
1017
|
+
hostTop: worktree?.hostPath,
|
|
1018
|
+
entries: async () => {
|
|
1019
|
+
const out: IndexEntry[] = [];
|
|
1020
|
+
for await (const e of this.staging.entries()) out.push(e);
|
|
1021
|
+
return out;
|
|
1022
|
+
},
|
|
1023
|
+
readBlob: async (id) => {
|
|
1024
|
+
const content = await this.blobs.load(id);
|
|
1025
|
+
return content ? collectChunks(content) : undefined;
|
|
1026
|
+
},
|
|
1027
|
+
prefetch: async (ids) => {
|
|
1028
|
+
const promisor = wc.history?.objects?.promisor;
|
|
1029
|
+
if (promisor?.hasPromisorRemote()) await promisor.prefetch(ids);
|
|
1030
|
+
},
|
|
1031
|
+
treeEntries: async (id) =>
|
|
1032
|
+
(await this.treeEntries(id)).map((e) => ({ name: e.name, mode: e.mode, id: e.id })),
|
|
1033
|
+
resolver: () => this.revisionResolver(),
|
|
1034
|
+
argumentFiles: (prefix) => this.argumentFiles(prefix),
|
|
1035
|
+
textconv: textconvRunnerOf(wc),
|
|
1036
|
+
inOneOperation: (fn) => this.inOneOperation(fn),
|
|
1037
|
+
};
|
|
1038
|
+
return new GrepRun(ctx, this.options).run();
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* `git grep --no-index` outside a repository: the files of `worktree` (any `Worktree`, a
|
|
1044
|
+
* `FileWorktree` over the directory), read as git reads them without a repository. Options
|
|
1045
|
+
* are {@link GrepOptions} (`prefix` the current directory below `worktree`'s root);
|
|
1046
|
+
* `config` gives configuration values (the global and system files', if any).
|
|
1047
|
+
*/
|
|
1048
|
+
export async function grepNoIndex(
|
|
1049
|
+
worktree: Worktree,
|
|
1050
|
+
options: Partial<GrepOptions> & { tokens: GrepToken[] },
|
|
1051
|
+
config: (key: string) => string | undefined = () => undefined,
|
|
1052
|
+
): Promise<GrepResult> {
|
|
1053
|
+
const ctx: GrepContext = {
|
|
1054
|
+
worktree,
|
|
1055
|
+
config,
|
|
1056
|
+
repository: false,
|
|
1057
|
+
hostTop: worktree.hostPath,
|
|
1058
|
+
argumentFiles: (prefix) => ({
|
|
1059
|
+
inWorktree: false,
|
|
1060
|
+
prefix,
|
|
1061
|
+
exists: async (path) => {
|
|
1062
|
+
const parts: string[] = [];
|
|
1063
|
+
for (const part of path.split("/")) {
|
|
1064
|
+
if (part === "" || part === ".") continue;
|
|
1065
|
+
if (part === "..") {
|
|
1066
|
+
if (parts.length === 0) return true;
|
|
1067
|
+
parts.pop();
|
|
1068
|
+
} else parts.push(part);
|
|
1069
|
+
}
|
|
1070
|
+
if (parts.length === 0) return true;
|
|
1071
|
+
return (await worktree.getEntry(parts.join("/"))) !== undefined;
|
|
1072
|
+
},
|
|
1073
|
+
}),
|
|
1074
|
+
inOneOperation: (fn) => (worktree.batch ? worktree.batch(fn) : fn()),
|
|
1075
|
+
};
|
|
1076
|
+
return new GrepRun(ctx, { ...options, noIndex: true }).run();
|
|
1077
|
+
}
|