@statewalker/vcs-commands 0.7.0 → 0.8.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 +38 -0
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/am/am-command.d.ts +55 -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.map +1 -1
- package/dist/commands/apply/apply-engine.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.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/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/checkout-command.d.ts +19 -3
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/cherry-pick-command.d.ts +59 -0
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +12 -0
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +191 -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/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 +252 -5
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/fetch-command.d.ts +20 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- 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 +41 -1
- 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 +4 -0
- package/dist/commands/git-describe.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +35 -0
- 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 +26 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -3
- package/dist/commands/interpret-trailers-command.d.ts +90 -0
- package/dist/commands/interpret-trailers-command.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 +296 -11
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +26 -1
- package/dist/commands/log-graph.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +133 -5
- 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 +30 -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 +96 -9
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-support.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.d.ts +48 -0
- package/dist/commands/name-rev.d.ts.map +1 -0
- package/dist/commands/notes-command.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 +10 -0
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +160 -9
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +6 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +168 -6
- 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/remote-command.d.ts +138 -29
- package/dist/commands/remote-command.d.ts.map +1 -1
- 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 +2 -3
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +2 -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 +154 -2
- package/dist/commands/rev-list-command.d.ts.map +1 -1
- package/dist/commands/revert-command.d.ts +32 -0
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +32 -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 +84 -4
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts +2 -0
- 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/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.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 +375 -0
- package/dist/commands/submodule-commands.d.ts.map +1 -0
- package/dist/commands/submodule-model.d.ts +288 -0
- package/dist/commands/submodule-model.d.ts.map +1 -0
- package/dist/commands/submodule-update-command.d.ts +198 -0
- package/dist/commands/submodule-update-command.d.ts.map +1 -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-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-ISM52N0n.js} +70736 -54492
- 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.map +1 -1
- package/dist/errors/index.js +57 -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/{git-command-BGiOJ8Zk.js → fsck-DLRpbwTj.js} +6230 -71
- package/dist/git-command.d.ts +27 -1
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +267 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/index.d.ts +1 -1
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +55 -0
- package/dist/remote-config/remote-config-store.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-output.d.ts +85 -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/index.d.ts +4 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/push-result.d.ts +7 -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-WVlBhVb1.js → results-TB2IJ64h.js} +2168 -403
- 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 +178 -17
- package/src/commands/am/am-command.ts +262 -42
- package/src/commands/am/index.ts +1 -0
- package/src/commands/am/mailsplit.ts +326 -0
- package/src/commands/apply/apply-command.ts +6 -6
- package/src/commands/apply/apply-engine.ts +1 -1
- package/src/commands/apply/apply-parse.ts +7 -8
- package/src/commands/bisect/bisect-command.ts +18 -5
- 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/checkout-command.ts +69 -43
- package/src/commands/cherry-pick-command.ts +143 -0
- package/src/commands/clean-command.ts +34 -3
- package/src/commands/clone-command.ts +2 -1
- package/src/commands/commit-command.ts +782 -64
- 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/diff-color-config.ts +274 -0
- package/src/commands/diff-command.ts +1009 -49
- package/src/commands/fetch-command.ts +142 -8
- 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 +314 -46
- package/src/commands/fsck/fetch-fsck.ts +172 -18
- package/src/commands/gc-command.ts +31 -1
- package/src/commands/git-describe.ts +31 -11
- package/src/commands/git-hooks.ts +81 -0
- 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 +26 -0
- package/src/commands/interpret-trailers-command.ts +256 -0
- package/src/commands/local-transport.ts +109 -10
- package/src/commands/log-command.ts +1246 -210
- package/src/commands/log-graph.ts +123 -26
- package/src/commands/log-output.ts +280 -21
- package/src/commands/ls-remote-command.ts +5 -0
- package/src/commands/mailmap.ts +119 -0
- package/src/commands/merge-base-command.ts +170 -0
- package/src/commands/merge-bases.ts +63 -8
- package/src/commands/merge-command.ts +330 -82
- package/src/commands/merge-support.ts +14 -1
- package/src/commands/mv-command.ts +6 -3
- package/src/commands/name-rev.ts +171 -0
- package/src/commands/notes-command.ts +11 -1
- 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 +26 -7
- package/src/commands/push-command.ts +682 -65
- package/src/commands/read-tree-command.ts +28 -1
- package/src/commands/rebase-command.ts +933 -129
- 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/remote-command.ts +449 -69
- package/src/commands/remote-transport.ts +9 -1
- package/src/commands/reset-command.ts +36 -31
- package/src/commands/restore-command.ts +12 -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 +402 -15
- package/src/commands/revert-command.ts +82 -0
- package/src/commands/revision-range.ts +204 -4
- package/src/commands/revision-resolver.ts +23 -8
- package/src/commands/rm-command.ts +282 -21
- package/src/commands/sequencer-pick.ts +498 -85
- package/src/commands/sequencer-support.ts +20 -2
- package/src/commands/serve-repository.ts +18 -3
- package/src/commands/show-command.ts +490 -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 +5 -2
- 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 +1517 -0
- package/src/commands/submodule-model.ts +930 -0
- package/src/commands/submodule-update-command.ts +1092 -0
- package/src/commands/switch-command.ts +3 -1
- package/src/commands/tag-command.ts +876 -64
- package/src/commands/trailers.ts +837 -100
- package/src/commands/tree-restore.ts +38 -10
- package/src/commands/verify-command.ts +235 -0
- package/src/commands/worktree-add-command.ts +268 -24
- 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 +2 -1
- package/src/errors/ref-errors.ts +23 -0
- package/src/errors/worktree-errors.ts +8 -1
- package/src/git-command.ts +66 -1
- package/src/git.ts +404 -1
- package/src/remote-config/index.ts +2 -0
- package/src/remote-config/remote-config-store.ts +101 -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-output.ts +195 -30
- package/src/results/diff-pickaxe.ts +304 -0
- package/src/results/diff-words.ts +395 -0
- package/src/results/index.ts +4 -0
- package/src/results/push-result.ts +7 -0
- package/src/results/rebase-result.ts +3 -0
- package/src/results/stash-result.ts +7 -0
- 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
|
@@ -0,0 +1,657 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signature checks as git's gpg-interface.c makes them (statewalker/statewalker-root#318):
|
|
3
|
+
* `check_signature` over a commit's `gpgsig` header (`verify_commit_buffer`) or a tag's
|
|
4
|
+
* appended signature (`parse_signature`), through the host's {@link Verifier}
|
|
5
|
+
* (`GitHostEnvironment.verifier`), its output parsed as `parse_gpg_output` and
|
|
6
|
+
* `parse_ssh_output` parse it. `verify-commit`, `verify-tag`, the `%G` placeholders, `log
|
|
7
|
+
* --show-signature` and `merge`/`pull --verify-signatures` read their answers from here.
|
|
8
|
+
*
|
|
9
|
+
* Without a verifier a check goes as git's goes when its program cannot be run: `error:
|
|
10
|
+
* cannot run gpg: No such file or directory` and an empty output (`%G?` is `N` for openpgp
|
|
11
|
+
* and x509, `B` for ssh, whose empty output parses as a bad signature).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const check = await verifyCommitBytes(workingCopy, rawCommit, { cwd });
|
|
16
|
+
* check.result; // "G", "B", "E", "X", "Y", "R" or "N"
|
|
17
|
+
* check.output; // what `git verify-commit` prints on stderr
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { type ObjectFormat, SHA1_OBJECT_FORMAT } from "@statewalker/vcs-utils";
|
|
23
|
+
import type {
|
|
24
|
+
SigningFormat,
|
|
25
|
+
VerificationOutcome,
|
|
26
|
+
WorkingCopy,
|
|
27
|
+
} from "@statewalker/vcs-working-tree";
|
|
28
|
+
|
|
29
|
+
import { GitApiError } from "../errors/index.js";
|
|
30
|
+
import { hostEnvironmentOf } from "./git-ident.js";
|
|
31
|
+
import { signingConfigOf } from "./signing.js";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* git's `sigc->result`: `G` good, `B` bad, `E` cannot be checked (missing key, several
|
|
35
|
+
* signatures), `X` good but expired, `Y` good by an expired key, `R` good by a revoked key,
|
|
36
|
+
* `N` none (or not checked further).
|
|
37
|
+
*/
|
|
38
|
+
export type SignatureResult = "G" | "B" | "E" | "X" | "Y" | "R" | "N";
|
|
39
|
+
|
|
40
|
+
/** git's `enum signature_trust_level`, as `%GT` shows it. */
|
|
41
|
+
export type SignatureTrustLevel = "undefined" | "never" | "marginal" | "fully" | "ultimate";
|
|
42
|
+
|
|
43
|
+
const TRUST_ORDER: readonly SignatureTrustLevel[] = [
|
|
44
|
+
"undefined",
|
|
45
|
+
"never",
|
|
46
|
+
"marginal",
|
|
47
|
+
"fully",
|
|
48
|
+
"ultimate",
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
/** The rank of a trust level (git's enum value). */
|
|
52
|
+
export function trustRank(level: SignatureTrustLevel): number {
|
|
53
|
+
return TRUST_ORDER.indexOf(level);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** What git's `struct signature_check` holds after a check. */
|
|
57
|
+
export interface SignatureCheck {
|
|
58
|
+
/** `%G?` before trust is applied (see {@link SignatureResult}) */
|
|
59
|
+
result: SignatureResult;
|
|
60
|
+
/** `%GT` */
|
|
61
|
+
trustLevel: SignatureTrustLevel;
|
|
62
|
+
/** `%GS`: the signer */
|
|
63
|
+
signer?: string;
|
|
64
|
+
/** `%GK`: the key */
|
|
65
|
+
key?: string;
|
|
66
|
+
/** `%GF`: the key's fingerprint */
|
|
67
|
+
fingerprint?: string;
|
|
68
|
+
/** `%GP`: the primary key's fingerprint */
|
|
69
|
+
primaryKeyFingerprint?: string;
|
|
70
|
+
/** `%GG`, what `verify-commit` prints on stderr (absent: nothing to show) */
|
|
71
|
+
output?: string;
|
|
72
|
+
/** What `verify-commit --raw` prints on stderr */
|
|
73
|
+
status?: string;
|
|
74
|
+
/** The payload checked (what `verify-commit -v` prints), when there was a signature */
|
|
75
|
+
payload?: Uint8Array;
|
|
76
|
+
/** git's non-zero `check_signature`: the signature is not good enough (or absent) */
|
|
77
|
+
failed: boolean;
|
|
78
|
+
/** What git printed on stderr while checking (`error: ...`, `warning: ...`) */
|
|
79
|
+
messages: string[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What is signed: the ident whose date ssh checks keys against. */
|
|
83
|
+
export type SignaturePayloadType = "commit" | "tag" | "other";
|
|
84
|
+
|
|
85
|
+
/** The armor lines that start a signature of each format (gpg-interface.c's `sigs`). */
|
|
86
|
+
const SIGNATURE_STARTS: readonly [SigningFormat, string][] = [
|
|
87
|
+
["openpgp", "-----BEGIN PGP SIGNATURE-----"],
|
|
88
|
+
["openpgp", "-----BEGIN PGP MESSAGE-----"],
|
|
89
|
+
["x509", "-----BEGIN SIGNED MESSAGE-----"],
|
|
90
|
+
["ssh", "-----BEGIN SSH SIGNATURE-----"],
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
const encoder = new TextEncoder();
|
|
94
|
+
const decoder = new TextDecoder();
|
|
95
|
+
|
|
96
|
+
function startsWithBytes(bytes: Uint8Array, at: number, prefix: string): boolean {
|
|
97
|
+
if (at + prefix.length > bytes.length) return false;
|
|
98
|
+
for (let i = 0; i < prefix.length; i++) {
|
|
99
|
+
if (bytes[at + i] !== prefix.charCodeAt(i)) return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** git's `get_format_by_sig`: the format whose armor `signature` starts with. */
|
|
105
|
+
export function signatureFormatAt(bytes: Uint8Array, at = 0): SigningFormat | undefined {
|
|
106
|
+
for (const [format, start] of SIGNATURE_STARTS) {
|
|
107
|
+
if (startsWithBytes(bytes, at, start)) return format;
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function concat(parts: Uint8Array[]): Uint8Array {
|
|
113
|
+
let size = 0;
|
|
114
|
+
for (const p of parts) size += p.length;
|
|
115
|
+
const out = new Uint8Array(size);
|
|
116
|
+
let at = 0;
|
|
117
|
+
for (const p of parts) {
|
|
118
|
+
out.set(p, at);
|
|
119
|
+
at += p.length;
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function lineEnd(bytes: Uint8Array, at: number): number {
|
|
125
|
+
const nl = bytes.indexOf(10, at);
|
|
126
|
+
return nl < 0 ? bytes.length : nl + 1;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* git's `parse_signed_buffer`: where the last line starting a signature begins (the end of
|
|
131
|
+
* `bytes` when none does).
|
|
132
|
+
*/
|
|
133
|
+
export function parseSignedBuffer(bytes: Uint8Array): number {
|
|
134
|
+
let match = bytes.length;
|
|
135
|
+
let at = 0;
|
|
136
|
+
while (at < bytes.length) {
|
|
137
|
+
if (signatureFormatAt(bytes, at)) match = at;
|
|
138
|
+
at = lineEnd(bytes, at);
|
|
139
|
+
}
|
|
140
|
+
return match;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const SIGNATURE_HEADERS = ["gpgsig", "gpgsig-sha256"];
|
|
144
|
+
|
|
145
|
+
/** git's `remove_signature`: the bytes without their `gpgsig`/`gpgsig-sha256` headers. */
|
|
146
|
+
export function removeSignatureHeaders(bytes: Uint8Array): Uint8Array {
|
|
147
|
+
const parts: Uint8Array[] = [];
|
|
148
|
+
let inSignature = false;
|
|
149
|
+
let at = 0;
|
|
150
|
+
while (at < bytes.length) {
|
|
151
|
+
let next = lineEnd(bytes, at);
|
|
152
|
+
if (inSignature && bytes[at] === 32) {
|
|
153
|
+
// still inside a signature
|
|
154
|
+
} else if (startsWithBytes(bytes, at, "gpgsig")) {
|
|
155
|
+
for (const header of SIGNATURE_HEADERS) {
|
|
156
|
+
if (startsWithBytes(bytes, at, `${header} `)) inSignature = true;
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
// the message: dumped whole
|
|
160
|
+
if (bytes[at] === 10) next = bytes.length;
|
|
161
|
+
inSignature = false;
|
|
162
|
+
parts.push(bytes.subarray(at, next));
|
|
163
|
+
}
|
|
164
|
+
at = next;
|
|
165
|
+
}
|
|
166
|
+
return concat(parts);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* git's `parse_signature` (a tag, a mergetag, a push certificate): the payload before the
|
|
171
|
+
* signature (its own `gpgsig` headers removed) and the signature, or undefined when it has
|
|
172
|
+
* none.
|
|
173
|
+
*/
|
|
174
|
+
export function parseSignature(
|
|
175
|
+
bytes: Uint8Array,
|
|
176
|
+
): { payload: Uint8Array; signature: Uint8Array } | undefined {
|
|
177
|
+
const match = parseSignedBuffer(bytes);
|
|
178
|
+
if (match === bytes.length) return undefined;
|
|
179
|
+
return {
|
|
180
|
+
payload: removeSignatureHeaders(bytes.subarray(0, match)),
|
|
181
|
+
signature: bytes.subarray(match),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* git's `parse_buffer_signed_by_header`: a commit's payload (the commit without the
|
|
187
|
+
* signature headers of every format) and the signature in `header` (`gpgsig`, or
|
|
188
|
+
* `gpgsig-sha256` in a SHA-256 repository), undefined when that header is absent.
|
|
189
|
+
*/
|
|
190
|
+
export function parseBufferSignedByHeader(
|
|
191
|
+
bytes: Uint8Array,
|
|
192
|
+
header: string,
|
|
193
|
+
): { payload: Uint8Array; signature: Uint8Array } | undefined {
|
|
194
|
+
const payload: Uint8Array[] = [];
|
|
195
|
+
const signature: Uint8Array[] = [];
|
|
196
|
+
let inSignature = false;
|
|
197
|
+
let sawSignature = false;
|
|
198
|
+
let otherSignature = false;
|
|
199
|
+
let at = 0;
|
|
200
|
+
while (at < bytes.length) {
|
|
201
|
+
let next = lineEnd(bytes, at);
|
|
202
|
+
let sig = -1;
|
|
203
|
+
if (inSignature && bytes[at] === 32) sig = at + 1;
|
|
204
|
+
else if (startsWithBytes(bytes, at, header) && bytes[at + header.length] === 32) {
|
|
205
|
+
sig = at + header.length + 1;
|
|
206
|
+
otherSignature = false;
|
|
207
|
+
} else if (startsWithBytes(bytes, at, "gpgsig")) otherSignature = true;
|
|
208
|
+
else if (otherSignature && bytes[at] !== 32) otherSignature = false;
|
|
209
|
+
if (sig >= 0) {
|
|
210
|
+
signature.push(bytes.subarray(sig, next));
|
|
211
|
+
sawSignature = true;
|
|
212
|
+
inSignature = true;
|
|
213
|
+
} else {
|
|
214
|
+
if (bytes[at] === 10) next = bytes.length;
|
|
215
|
+
if (!otherSignature) payload.push(bytes.subarray(at, next));
|
|
216
|
+
inSignature = false;
|
|
217
|
+
}
|
|
218
|
+
at = next;
|
|
219
|
+
}
|
|
220
|
+
return sawSignature ? { payload: concat(payload), signature: concat(signature) } : undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** git's `find_commit_header`: the value of the header `name`, before the message. */
|
|
224
|
+
function findHeader(bytes: Uint8Array, name: string): Uint8Array | undefined {
|
|
225
|
+
let at = 0;
|
|
226
|
+
while (at < bytes.length) {
|
|
227
|
+
const nl = bytes.indexOf(10, at);
|
|
228
|
+
const eol = nl < 0 ? bytes.length : nl;
|
|
229
|
+
if (eol === at) return undefined;
|
|
230
|
+
if (startsWithBytes(bytes, at, name) && bytes[at + name.length] === 32) {
|
|
231
|
+
return bytes.subarray(at + name.length + 1, eol);
|
|
232
|
+
}
|
|
233
|
+
at = eol + 1;
|
|
234
|
+
}
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* gpg-interface.c's `parse_payload_metadata`: the date of the committer (tagger) ident, 0
|
|
240
|
+
* without one; undefined when the payload has no such ident (git's check then fails without
|
|
241
|
+
* running anything).
|
|
242
|
+
*/
|
|
243
|
+
function payloadTimestamp(payload: Uint8Array, type: SignaturePayloadType): number | undefined {
|
|
244
|
+
if (type === "other") return 0;
|
|
245
|
+
const ident = findHeader(payload, type === "commit" ? "committer" : "tagger");
|
|
246
|
+
if (!ident || ident.length === 0) return undefined;
|
|
247
|
+
// split_ident_line: a mail between the last '<' ... '>' pair; the date after it
|
|
248
|
+
const text = decoder.decode(ident);
|
|
249
|
+
const lt = text.indexOf("<");
|
|
250
|
+
if (lt < 0) return undefined;
|
|
251
|
+
const gt = text.lastIndexOf(">");
|
|
252
|
+
if (gt < lt) return undefined;
|
|
253
|
+
const m = /^ *(\d+)/.exec(text.slice(gt + 1));
|
|
254
|
+
return m ? Number(m[1]) : 0;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const STATUS_STARTS: readonly {
|
|
258
|
+
result?: SignatureResult;
|
|
259
|
+
check: string;
|
|
260
|
+
exclusive?: boolean;
|
|
261
|
+
keyId?: boolean;
|
|
262
|
+
uid?: boolean;
|
|
263
|
+
fingerprint?: boolean;
|
|
264
|
+
trust?: boolean;
|
|
265
|
+
}[] = [
|
|
266
|
+
{ result: "G", check: "GOODSIG ", exclusive: true, keyId: true, uid: true },
|
|
267
|
+
{ result: "B", check: "BADSIG ", exclusive: true, keyId: true, uid: true },
|
|
268
|
+
{ result: "E", check: "ERRSIG ", exclusive: true, keyId: true },
|
|
269
|
+
{ result: "X", check: "EXPSIG ", exclusive: true, keyId: true, uid: true },
|
|
270
|
+
{ result: "Y", check: "EXPKEYSIG ", exclusive: true, keyId: true, uid: true },
|
|
271
|
+
{ result: "R", check: "REVKEYSIG ", exclusive: true, keyId: true, uid: true },
|
|
272
|
+
{ check: "VALIDSIG ", fingerprint: true },
|
|
273
|
+
{ check: "TRUST_", trust: true },
|
|
274
|
+
];
|
|
275
|
+
|
|
276
|
+
type ParsedFields = Pick<
|
|
277
|
+
SignatureCheck,
|
|
278
|
+
"result" | "trustLevel" | "signer" | "key" | "fingerprint" | "primaryKeyFingerprint"
|
|
279
|
+
>;
|
|
280
|
+
|
|
281
|
+
/** gpg-interface.c's `parse_gpg_output` over gpg's status lines. */
|
|
282
|
+
export function parseGpgOutput(status: string, check: ParsedFields): void {
|
|
283
|
+
const buf = status;
|
|
284
|
+
const end = buf.length;
|
|
285
|
+
// strchrnul over the buffer
|
|
286
|
+
const chrnul = (from: number, ch: string) => {
|
|
287
|
+
const i = buf.indexOf(ch, from);
|
|
288
|
+
return i < 0 ? end : i;
|
|
289
|
+
};
|
|
290
|
+
let seenExclusive = 0;
|
|
291
|
+
let line = 0;
|
|
292
|
+
const fail = () => {
|
|
293
|
+
check.result = "E";
|
|
294
|
+
delete check.primaryKeyFingerprint;
|
|
295
|
+
delete check.fingerprint;
|
|
296
|
+
delete check.signer;
|
|
297
|
+
delete check.key;
|
|
298
|
+
};
|
|
299
|
+
while (line < end) {
|
|
300
|
+
while (buf[line] === "\n") line++;
|
|
301
|
+
if (line >= end) break;
|
|
302
|
+
if (buf.startsWith("[GNUPG:] ", line)) {
|
|
303
|
+
line += 9;
|
|
304
|
+
for (const s of STATUS_STARTS) {
|
|
305
|
+
if (!buf.startsWith(s.check, line)) continue;
|
|
306
|
+
line += s.check.length;
|
|
307
|
+
if (s.exclusive && seenExclusive++) {
|
|
308
|
+
fail();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (s.result) check.result = s.result;
|
|
312
|
+
if (s.keyId) {
|
|
313
|
+
let next = chrnul(line, " ");
|
|
314
|
+
check.key = buf.slice(line, next);
|
|
315
|
+
if (next < end && s.uid) {
|
|
316
|
+
line = next + 1;
|
|
317
|
+
next = chrnul(line, "\n");
|
|
318
|
+
check.signer = buf.slice(line, next);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (s.trust) {
|
|
322
|
+
let size = 0;
|
|
323
|
+
while (line + size < end && buf[line + size] !== " " && buf[line + size] !== "\n") size++;
|
|
324
|
+
const trust = buf.slice(line, line + size).toLowerCase() as SignatureTrustLevel;
|
|
325
|
+
if (
|
|
326
|
+
buf.slice(line, line + size) !== trust.toUpperCase() ||
|
|
327
|
+
!TRUST_ORDER.includes(trust)
|
|
328
|
+
) {
|
|
329
|
+
fail();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
check.trustLevel = trust;
|
|
333
|
+
}
|
|
334
|
+
if (s.fingerprint) {
|
|
335
|
+
let next = chrnul(line, " ");
|
|
336
|
+
check.fingerprint = buf.slice(line, next);
|
|
337
|
+
const limit = chrnul(line, "\n");
|
|
338
|
+
let j = 9;
|
|
339
|
+
for (; j > 0; j--) {
|
|
340
|
+
if (next >= end || limit <= next) break;
|
|
341
|
+
line = next + 1;
|
|
342
|
+
next = chrnul(line, " ");
|
|
343
|
+
}
|
|
344
|
+
if (!j) {
|
|
345
|
+
next = chrnul(line, "\n");
|
|
346
|
+
check.primaryKeyFingerprint = buf.slice(line, next);
|
|
347
|
+
} else delete check.primaryKeyFingerprint;
|
|
348
|
+
}
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// the next line: strchrnul(line + 1, '\n')
|
|
353
|
+
line = line + 1 > end ? end : chrnul(line + 1, "\n");
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** gpg-interface.c's `parse_ssh_output` over the first line of ssh-keygen's output. */
|
|
358
|
+
export function parseSshOutput(output: string, check: ParsedFields): void {
|
|
359
|
+
check.result = "B";
|
|
360
|
+
check.trustLevel = "never";
|
|
361
|
+
const nl = output.indexOf("\n");
|
|
362
|
+
let line = nl < 0 ? output : output.slice(0, nl);
|
|
363
|
+
const forPrefix = 'Good "git" signature for ';
|
|
364
|
+
const withPrefix = 'Good "git" signature with ';
|
|
365
|
+
if (line.startsWith(forPrefix)) {
|
|
366
|
+
line = line.slice(forPrefix.length);
|
|
367
|
+
const principal = line;
|
|
368
|
+
let at = 0;
|
|
369
|
+
for (;;) {
|
|
370
|
+
const search = line.indexOf(" with ", at);
|
|
371
|
+
if (search < 0) break;
|
|
372
|
+
at = search + 1;
|
|
373
|
+
}
|
|
374
|
+
if (at === 0) return;
|
|
375
|
+
check.result = "G";
|
|
376
|
+
check.trustLevel = "fully";
|
|
377
|
+
check.signer = principal.slice(0, at - 1);
|
|
378
|
+
line = line.slice(at);
|
|
379
|
+
} else if (line.startsWith(withPrefix)) {
|
|
380
|
+
check.result = "G";
|
|
381
|
+
check.trustLevel = "undefined";
|
|
382
|
+
line = line.slice(withPrefix.length);
|
|
383
|
+
} else return;
|
|
384
|
+
const key = line.indexOf("key ");
|
|
385
|
+
if (key >= 0) {
|
|
386
|
+
check.fingerprint = line.slice(key + 4);
|
|
387
|
+
check.key = check.fingerprint;
|
|
388
|
+
} else check.result = "B";
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Where a check runs and what it is of. */
|
|
392
|
+
export interface CheckSignatureOptions {
|
|
393
|
+
/** What is signed (default `other`: no ident, no time for ssh) */
|
|
394
|
+
payloadType?: SignaturePayloadType;
|
|
395
|
+
/** The host directory the program runs in (the worktree top) */
|
|
396
|
+
cwd?: string;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** git's `start_command` failure of a program it cannot find. */
|
|
400
|
+
function cannotRun(program: string): string {
|
|
401
|
+
return program.includes("/")
|
|
402
|
+
? `error: cannot exec '${program}': No such file or directory`
|
|
403
|
+
: `error: cannot run ${program}: No such file or directory`;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** What git's verification does when its program cannot be run (no verifier). */
|
|
407
|
+
function withoutVerifier(format: SigningFormat, program: string): VerificationOutcome {
|
|
408
|
+
if (format !== "ssh") {
|
|
409
|
+
return { failed: true, output: "", status: "", messages: [cannotRun(program)] };
|
|
410
|
+
}
|
|
411
|
+
// find-principals cannot run, nor can check-novalidate
|
|
412
|
+
return {
|
|
413
|
+
failed: true,
|
|
414
|
+
output: "",
|
|
415
|
+
status: "",
|
|
416
|
+
messages: [cannotRun(program), cannotRun(program)],
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* git's `check_signature`: `signature` over `payload` checked through the host's verifier
|
|
422
|
+
* with the configuration's program, its output parsed, the result held to
|
|
423
|
+
* `gpg.minTrustLevel`.
|
|
424
|
+
*
|
|
425
|
+
* @throws GitApiError `fatal: bad/incompatible signature '<signature>'` (exit 128) for a
|
|
426
|
+
* signature of no known format, as git dies
|
|
427
|
+
* @throws InvalidConfigError for a bad signing variable
|
|
428
|
+
*/
|
|
429
|
+
export async function checkSignature(
|
|
430
|
+
workingCopy: WorkingCopy,
|
|
431
|
+
payload: Uint8Array,
|
|
432
|
+
signature: Uint8Array,
|
|
433
|
+
options: CheckSignatureOptions = {},
|
|
434
|
+
): Promise<SignatureCheck> {
|
|
435
|
+
const check: SignatureCheck = {
|
|
436
|
+
result: "N",
|
|
437
|
+
trustLevel: "undefined",
|
|
438
|
+
payload,
|
|
439
|
+
failed: true,
|
|
440
|
+
messages: [],
|
|
441
|
+
};
|
|
442
|
+
const format = signatureFormatAt(signature);
|
|
443
|
+
if (!format) {
|
|
444
|
+
const text = decoder.decode(signature);
|
|
445
|
+
const nul = text.indexOf("\0");
|
|
446
|
+
throw new GitApiError(
|
|
447
|
+
`fatal: bad/incompatible signature '${nul < 0 ? text : text.slice(0, nul)}'`,
|
|
448
|
+
{ exitCode: 128 },
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
const time = payloadTimestamp(payload, options.payloadType ?? "other");
|
|
452
|
+
if (time === undefined) return check;
|
|
453
|
+
const config = signingConfigOf(workingCopy);
|
|
454
|
+
const program = config.programs[format];
|
|
455
|
+
let outcome: VerificationOutcome;
|
|
456
|
+
if (format === "ssh" && config.allowedSignersFile === undefined) {
|
|
457
|
+
check.messages.push(
|
|
458
|
+
"error: gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verification",
|
|
459
|
+
);
|
|
460
|
+
return check;
|
|
461
|
+
}
|
|
462
|
+
const verifier = hostEnvironmentOf(workingCopy)?.verifier;
|
|
463
|
+
if (verifier) {
|
|
464
|
+
outcome = await verifier({
|
|
465
|
+
format,
|
|
466
|
+
payload,
|
|
467
|
+
signature,
|
|
468
|
+
program,
|
|
469
|
+
...(config.allowedSignersFile !== undefined
|
|
470
|
+
? { allowedSignersFile: config.allowedSignersFile }
|
|
471
|
+
: {}),
|
|
472
|
+
...(config.revocationFile !== undefined ? { revocationFile: config.revocationFile } : {}),
|
|
473
|
+
...(time ? { verifyTime: time } : {}),
|
|
474
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
475
|
+
});
|
|
476
|
+
} else outcome = withoutVerifier(format, program);
|
|
477
|
+
if (outcome.messages) check.messages.push(...outcome.messages);
|
|
478
|
+
if (outcome.output !== undefined) {
|
|
479
|
+
check.output = outcome.output;
|
|
480
|
+
check.status = outcome.status ?? outcome.output;
|
|
481
|
+
if (format === "ssh") parseSshOutput(outcome.output, check);
|
|
482
|
+
else parseGpgOutput(check.status, check);
|
|
483
|
+
}
|
|
484
|
+
let failed = outcome.failed;
|
|
485
|
+
if (failed && check.output === undefined) {
|
|
486
|
+
check.failed = true;
|
|
487
|
+
return check;
|
|
488
|
+
}
|
|
489
|
+
// git 2.43 takes only G for good; 2.5x a good signature by an expired key too
|
|
490
|
+
const legacy = verifier?.compatibility === "2.43";
|
|
491
|
+
failed ||= check.result !== "G" && (legacy || check.result !== "Y");
|
|
492
|
+
if (config.minTrustLevel !== undefined) {
|
|
493
|
+
failed ||= trustRank(check.trustLevel) < trustRank(config.minTrustLevel as SignatureTrustLevel);
|
|
494
|
+
}
|
|
495
|
+
check.failed = failed;
|
|
496
|
+
return check;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* git's `verify_commit_buffer`: the signature in the commit's `gpgsig` header
|
|
501
|
+
* (`gpgsig-sha256` in a SHA-256 repository) checked over the rest; result `N` and a failure
|
|
502
|
+
* when it has none.
|
|
503
|
+
*/
|
|
504
|
+
export async function verifyCommitBytes(
|
|
505
|
+
workingCopy: WorkingCopy,
|
|
506
|
+
bytes: Uint8Array,
|
|
507
|
+
options: { objectFormat?: ObjectFormat; cwd?: string } = {},
|
|
508
|
+
): Promise<SignatureCheck> {
|
|
509
|
+
const header = (options.objectFormat ?? SHA1_OBJECT_FORMAT).signatureHeader;
|
|
510
|
+
const parsed = parseBufferSignedByHeader(bytes, header);
|
|
511
|
+
if (!parsed) return { result: "N", trustLevel: "undefined", failed: true, messages: [] };
|
|
512
|
+
return checkSignature(workingCopy, parsed.payload, parsed.signature, {
|
|
513
|
+
payloadType: "commit",
|
|
514
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* tag.c's `run_gpg_verify`: the signature appended to a tag checked over the tag before it;
|
|
520
|
+
* undefined when the tag has none.
|
|
521
|
+
*/
|
|
522
|
+
export async function verifyTagBytes(
|
|
523
|
+
workingCopy: WorkingCopy,
|
|
524
|
+
bytes: Uint8Array,
|
|
525
|
+
options: { cwd?: string } = {},
|
|
526
|
+
): Promise<SignatureCheck | undefined> {
|
|
527
|
+
const parsed = parseSignature(bytes);
|
|
528
|
+
if (!parsed) return undefined;
|
|
529
|
+
return checkSignature(workingCopy, parsed.payload, parsed.signature, {
|
|
530
|
+
payloadType: "tag",
|
|
531
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/** pretty.c's `%G?`: `U` for a good signature of undefined or never trust. */
|
|
536
|
+
export function signatureLetter(check: SignatureCheck): string {
|
|
537
|
+
if (check.result === "G") {
|
|
538
|
+
return check.trustLevel === "undefined" || check.trustLevel === "never" ? "U" : "G";
|
|
539
|
+
}
|
|
540
|
+
return check.result;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** The `mergetag` headers of a commit, each tag object's bytes. */
|
|
544
|
+
export function mergetagsOf(bytes: Uint8Array): Uint8Array[] {
|
|
545
|
+
const tags: Uint8Array[] = [];
|
|
546
|
+
let current: Uint8Array[] | undefined;
|
|
547
|
+
let at = 0;
|
|
548
|
+
while (at < bytes.length) {
|
|
549
|
+
const next = lineEnd(bytes, at);
|
|
550
|
+
if (bytes[at] === 10) break;
|
|
551
|
+
if (current && bytes[at] === 32) current.push(bytes.subarray(at + 1, next));
|
|
552
|
+
else {
|
|
553
|
+
if (current) tags.push(concat(current));
|
|
554
|
+
current = undefined;
|
|
555
|
+
if (startsWithBytes(bytes, at, "mergetag ")) current = [bytes.subarray(at + 9, next)];
|
|
556
|
+
}
|
|
557
|
+
at = next;
|
|
558
|
+
}
|
|
559
|
+
if (current) tags.push(concat(current));
|
|
560
|
+
// the header's value has no final newline of its own: read_commit_extra_header_lines keeps
|
|
561
|
+
// each continuation's, so the tag ends with its last line's newline
|
|
562
|
+
return tags;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/** `text` as bytes. */
|
|
566
|
+
export function bytesOf(text: string): Uint8Array {
|
|
567
|
+
return encoder.encode(text);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* `merge --verify-signatures` refusing a commit (commit.c's `verify_merge_signature`): git's
|
|
572
|
+
* lines (what the check printed, then `fatal: Commit <id> ...`), exit 128.
|
|
573
|
+
*/
|
|
574
|
+
export class SignatureVerificationError extends GitApiError {
|
|
575
|
+
/** The commit refused */
|
|
576
|
+
readonly commitId: string;
|
|
577
|
+
/** Its check */
|
|
578
|
+
readonly check: SignatureCheck;
|
|
579
|
+
|
|
580
|
+
constructor(message: string, commitId: string, check: SignatureCheck) {
|
|
581
|
+
super(message, { exitCode: 128 });
|
|
582
|
+
this.name = "SignatureVerificationError";
|
|
583
|
+
this.commitId = commitId;
|
|
584
|
+
this.check = check;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* commit.c's `verify_merge_signature`: the commit's signature must be good (and, with
|
|
590
|
+
* `checkTrust`, of at least marginal trust; `gpg.minTrustLevel` set turns that off and
|
|
591
|
+
* `check_signature` holds the result to it instead). Returns git's stdout line for a good
|
|
592
|
+
* one, `Commit <abbrev> has a good GPG signature by <signer>`.
|
|
593
|
+
*
|
|
594
|
+
* @throws SignatureVerificationError with git's death: `Commit <abbrev> has an untrusted GPG
|
|
595
|
+
* signature, allegedly by <signer>.`, `... has a bad GPG signature allegedly by <signer>.`,
|
|
596
|
+
* `... does not have a GPG signature.`
|
|
597
|
+
*/
|
|
598
|
+
export async function verifyMergeSignature(
|
|
599
|
+
workingCopy: WorkingCopy,
|
|
600
|
+
bytes: Uint8Array | undefined,
|
|
601
|
+
options: {
|
|
602
|
+
commitId: string;
|
|
603
|
+
abbreviated: string;
|
|
604
|
+
objectFormat?: ObjectFormat;
|
|
605
|
+
cwd?: string;
|
|
606
|
+
checkTrust: boolean;
|
|
607
|
+
},
|
|
608
|
+
): Promise<string> {
|
|
609
|
+
const check: SignatureCheck = bytes
|
|
610
|
+
? await verifyCommitBytes(workingCopy, bytes, {
|
|
611
|
+
...(options.objectFormat ? { objectFormat: options.objectFormat } : {}),
|
|
612
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
613
|
+
})
|
|
614
|
+
: { result: "N", trustLevel: "undefined", failed: true, messages: [] };
|
|
615
|
+
const hex = options.abbreviated;
|
|
616
|
+
const signer = check.signer ?? "(null)";
|
|
617
|
+
const die = (line: string): never => {
|
|
618
|
+
throw new SignatureVerificationError(
|
|
619
|
+
[...check.messages, `fatal: ${line}`].join("\n"),
|
|
620
|
+
options.commitId,
|
|
621
|
+
check,
|
|
622
|
+
);
|
|
623
|
+
};
|
|
624
|
+
switch (check.result) {
|
|
625
|
+
case "G":
|
|
626
|
+
if (
|
|
627
|
+
check.failed ||
|
|
628
|
+
(options.checkTrust && trustRank(check.trustLevel) < trustRank("marginal"))
|
|
629
|
+
)
|
|
630
|
+
die(`Commit ${hex} has an untrusted GPG signature, allegedly by ${signer}.`);
|
|
631
|
+
break;
|
|
632
|
+
case "B":
|
|
633
|
+
die(`Commit ${hex} has a bad GPG signature allegedly by ${signer}.`);
|
|
634
|
+
break;
|
|
635
|
+
default:
|
|
636
|
+
die(`Commit ${hex} does not have a GPG signature.`);
|
|
637
|
+
}
|
|
638
|
+
return `Commit ${hex} has a good GPG signature by ${signer}`;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/** An object's bytes as stored (undefined when absent or unreadable). */
|
|
642
|
+
export async function readStoredObjectBytes(
|
|
643
|
+
workingCopy: WorkingCopy,
|
|
644
|
+
id: string,
|
|
645
|
+
): Promise<Uint8Array | undefined> {
|
|
646
|
+
const objects = workingCopy.history?.objects;
|
|
647
|
+
if (!objects) return undefined;
|
|
648
|
+
try {
|
|
649
|
+
const obj = await objects.get(id);
|
|
650
|
+
if (!obj) return undefined;
|
|
651
|
+
const chunks: Uint8Array[] = [];
|
|
652
|
+
for await (const c of obj.content) chunks.push(c);
|
|
653
|
+
return concat(chunks);
|
|
654
|
+
} catch {
|
|
655
|
+
return undefined;
|
|
656
|
+
}
|
|
657
|
+
}
|