@statewalker/vcs-commands 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -8
- package/dist/commands/add-command.d.ts +265 -34
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-interactive.d.ts +46 -0
- package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
- package/dist/commands/add-patch/add-patch.d.ts +139 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
- package/dist/commands/add-patch/index.d.ts +6 -0
- package/dist/commands/add-patch/index.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-backend.d.ts +80 -0
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-modes.d.ts +71 -0
- package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
- package/dist/commands/add-patch/patch-session.d.ts +49 -0
- package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
- package/dist/commands/am/am-command.d.ts +175 -0
- package/dist/commands/am/am-command.d.ts.map +1 -0
- package/dist/commands/am/index.d.ts +3 -0
- package/dist/commands/am/index.d.ts.map +1 -0
- package/dist/commands/am/mailinfo.d.ts +58 -0
- package/dist/commands/am/mailinfo.d.ts.map +1 -0
- package/dist/commands/am/patch-format.d.ts +24 -0
- package/dist/commands/am/patch-format.d.ts.map +1 -0
- package/dist/commands/apply/apply-command.d.ts +153 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -0
- package/dist/commands/apply/apply-engine.d.ts +195 -0
- package/dist/commands/apply/apply-engine.d.ts.map +1 -0
- package/dist/commands/apply/apply-parse.d.ts +86 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -0
- package/dist/commands/apply/apply-types.d.ts +70 -0
- package/dist/commands/apply/apply-types.d.ts.map +1 -0
- package/dist/commands/apply/index.d.ts +6 -0
- package/dist/commands/apply/index.d.ts.map +1 -0
- package/dist/commands/apply/latin1.d.ts +32 -0
- package/dist/commands/apply/latin1.d.ts.map +1 -0
- package/dist/commands/apply/whitespace.d.ts +58 -0
- package/dist/commands/apply/whitespace.d.ts.map +1 -0
- package/dist/commands/attributes-source.d.ts +26 -0
- package/dist/commands/attributes-source.d.ts.map +1 -0
- package/dist/commands/backfill-command.d.ts +110 -0
- package/dist/commands/backfill-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
- package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-command.d.ts +201 -0
- package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-engine.d.ts +219 -0
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-graph.d.ts +127 -0
- package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
- package/dist/commands/bisect/bisect-quote.d.ts +27 -0
- package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
- package/dist/commands/bisect/index.d.ts +5 -0
- package/dist/commands/bisect/index.d.ts.map +1 -0
- package/dist/commands/blame-command.d.ts +122 -131
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts +52 -2
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/branch-tracking.d.ts +98 -0
- package/dist/commands/branch-tracking.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +299 -34
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +124 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +50 -42
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +67 -4
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +179 -7
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +311 -17
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +93 -0
- package/dist/commands/core-config.d.ts.map +1 -0
- package/dist/commands/date-format.d.ts +58 -0
- package/dist/commands/date-format.d.ts.map +1 -0
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +377 -30
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/diff-textconv.d.ts +40 -0
- package/dist/commands/diff-textconv.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +244 -23
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts +164 -0
- package/dist/commands/format-patch-command.d.ts.map +1 -0
- package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
- package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-command.d.ts +225 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-loose.d.ts +68 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
- package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
- package/dist/commands/fsck/fsck-pack.d.ts +115 -0
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
- package/dist/commands/fsck/index.d.ts +6 -0
- package/dist/commands/fsck/index.d.ts.map +1 -0
- package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +43 -0
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +66 -0
- package/dist/commands/git-date.d.ts.map +1 -0
- package/dist/commands/git-describe.d.ts +67 -0
- package/dist/commands/git-describe.d.ts.map +1 -0
- package/dist/commands/git-hooks.d.ts +416 -0
- package/dist/commands/git-hooks.d.ts.map +1 -0
- package/dist/commands/git-ident.d.ts +128 -0
- package/dist/commands/git-ident.d.ts.map +1 -0
- package/dist/commands/hook-command.d.ts +96 -0
- package/dist/commands/hook-command.d.ts.map +1 -0
- package/dist/commands/index-adder.d.ts +231 -0
- package/dist/commands/index-adder.d.ts.map +1 -0
- package/dist/commands/index-host.d.ts +86 -0
- package/dist/commands/index-host.d.ts.map +1 -0
- package/dist/commands/index.d.ts +55 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -2
- package/dist/commands/init-command.d.ts +12 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/local-clone.d.ts +60 -0
- package/dist/commands/local-clone.d.ts.map +1 -0
- package/dist/commands/local-transport.d.ts +117 -0
- package/dist/commands/local-transport.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +216 -24
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +120 -0
- package/dist/commands/log-graph.d.ts.map +1 -0
- package/dist/commands/log-output.d.ts +323 -0
- package/dist/commands/log-output.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +23 -7
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +31 -0
- package/dist/commands/mailmap.d.ts.map +1 -0
- package/dist/commands/merge-bases.d.ts +85 -0
- package/dist/commands/merge-bases.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +209 -74
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-config.d.ts +13 -0
- package/dist/commands/merge-config.d.ts.map +1 -0
- package/dist/commands/merge-drivers.d.ts +130 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +252 -0
- package/dist/commands/merge-support.d.ts.map +1 -0
- package/dist/commands/message-cleanup.d.ts +86 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -0
- package/dist/commands/mv-command.d.ts +94 -0
- package/dist/commands/mv-command.d.ts.map +1 -0
- package/dist/commands/notes-command.d.ts +256 -0
- package/dist/commands/notes-command.d.ts.map +1 -0
- package/dist/commands/notes-commands.d.ts +41 -0
- package/dist/commands/notes-commands.d.ts.map +1 -0
- package/dist/commands/notes-merge-command.d.ts +105 -0
- package/dist/commands/notes-merge-command.d.ts.map +1 -0
- package/dist/commands/notes-support.d.ts +125 -0
- package/dist/commands/notes-support.d.ts.map +1 -0
- package/dist/commands/notes-tree.d.ts +106 -0
- package/dist/commands/notes-tree.d.ts.map +1 -0
- package/dist/commands/object-id-input.d.ts +20 -0
- package/dist/commands/object-id-input.d.ts.map +1 -0
- package/dist/commands/octopus-merge.d.ts +59 -0
- package/dist/commands/octopus-merge.d.ts.map +1 -0
- package/dist/commands/ort-merge.d.ts +126 -0
- package/dist/commands/ort-merge.d.ts.map +1 -0
- package/dist/commands/ort-recursive.d.ts +53 -0
- package/dist/commands/ort-recursive.d.ts.map +1 -0
- package/dist/commands/pack-refs-command.d.ts +20 -0
- package/dist/commands/pack-refs-command.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +41 -0
- package/dist/commands/patch-id.d.ts.map +1 -0
- package/dist/commands/pathspec-attributes.d.ts +64 -0
- package/dist/commands/pathspec-attributes.d.ts.map +1 -0
- package/dist/commands/pathspec.d.ts +324 -0
- package/dist/commands/pathspec.d.ts.map +1 -0
- package/dist/commands/post-index-change.d.ts +33 -0
- package/dist/commands/post-index-change.d.ts.map +1 -0
- package/dist/commands/pretty-format.d.ts +222 -0
- package/dist/commands/pretty-format.d.ts.map +1 -0
- package/dist/commands/promisor-remote.d.ts +80 -0
- package/dist/commands/promisor-remote.d.ts.map +1 -0
- package/dist/commands/pull-command.d.ts +41 -8
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +24 -8
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts +112 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -0
- package/dist/commands/rebase-command.d.ts +507 -75
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/rebase-todo.d.ts +130 -0
- package/dist/commands/rebase-todo.d.ts.map +1 -0
- package/dist/commands/ref-decoration-filter.d.ts +53 -0
- package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
- package/dist/commands/reflog-messages.d.ts +98 -0
- package/dist/commands/reflog-messages.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +146 -6
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-transport.d.ts +120 -0
- package/dist/commands/remote-transport.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +161 -7
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +103 -0
- package/dist/commands/restore-command.d.ts.map +1 -0
- package/dist/commands/rev-list-command.d.ts +78 -0
- package/dist/commands/rev-list-command.d.ts.map +1 -0
- package/dist/commands/rev-parse-command.d.ts +80 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -0
- package/dist/commands/revert-command.d.ts +46 -38
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-filenames.d.ts +95 -0
- package/dist/commands/revision-filenames.d.ts.map +1 -0
- package/dist/commands/revision-range.d.ts +67 -0
- package/dist/commands/revision-range.d.ts.map +1 -0
- package/dist/commands/revision-resolver.d.ts +321 -0
- package/dist/commands/revision-resolver.d.ts.map +1 -0
- package/dist/commands/rm-command.d.ts +69 -7
- package/dist/commands/rm-command.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +191 -0
- package/dist/commands/sequencer-pick.d.ts.map +1 -0
- package/dist/commands/sequencer-support.d.ts +125 -0
- package/dist/commands/sequencer-support.d.ts.map +1 -0
- package/dist/commands/serve-repository.d.ts +52 -0
- package/dist/commands/serve-repository.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-command.d.ts +190 -0
- package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
- package/dist/commands/sparse-checkout-support.d.ts +268 -0
- package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +69 -13
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +214 -26
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +10 -2
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-list-command.d.ts +2 -4
- package/dist/commands/stash-list-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +95 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +320 -28
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/status-format.d.ts +155 -0
- package/dist/commands/status-format.d.ts.map +1 -0
- package/dist/commands/status-header.d.ts +64 -0
- package/dist/commands/status-header.d.ts.map +1 -0
- package/dist/commands/strerror.d.ts +7 -0
- package/dist/commands/strerror.d.ts.map +1 -0
- package/dist/commands/submodule-config.d.ts +38 -0
- package/dist/commands/submodule-config.d.ts.map +1 -0
- package/dist/commands/submodule-summary-command.d.ts +80 -0
- package/dist/commands/submodule-summary-command.d.ts.map +1 -0
- package/dist/commands/submodule-summary.d.ts +150 -0
- package/dist/commands/submodule-summary.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +132 -0
- package/dist/commands/switch-command.d.ts.map +1 -0
- package/dist/commands/tag-command.d.ts +23 -2
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tracking-info.d.ts +64 -0
- package/dist/commands/tracking-info.d.ts.map +1 -0
- package/dist/commands/trailers.d.ts +73 -0
- package/dist/commands/trailers.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +137 -6
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +53 -0
- package/dist/commands/untracked-cache-support.d.ts.map +1 -0
- package/dist/commands/worktree-add-command.d.ts +108 -0
- package/dist/commands/worktree-add-command.d.ts.map +1 -0
- package/dist/commands/worktree-list-command.d.ts +69 -0
- package/dist/commands/worktree-list-command.d.ts.map +1 -0
- package/dist/commands/worktree-lock-command.d.ts +44 -0
- package/dist/commands/worktree-lock-command.d.ts.map +1 -0
- package/dist/commands/worktree-overwrite-checks.d.ts +204 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
- package/dist/commands/worktree-prune-command.d.ts +48 -0
- package/dist/commands/worktree-prune-command.d.ts.map +1 -0
- package/dist/commands/worktree-remove-command.d.ts +59 -0
- package/dist/commands/worktree-remove-command.d.ts.map +1 -0
- package/dist/commands/worktree-repair-command.d.ts +35 -0
- package/dist/commands/worktree-repair-command.d.ts.map +1 -0
- package/dist/commands/worktree-support.d.ts +64 -0
- package/dist/commands/worktree-support.d.ts.map +1 -0
- package/dist/commands-DnmlfwGV.js +61620 -0
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/core-commands/index.d.ts +0 -3
- package/dist/core-commands/index.d.ts.map +1 -1
- package/dist/errors/add-errors.d.ts +55 -0
- package/dist/errors/add-errors.d.ts.map +1 -1
- package/dist/errors/checkout-errors.d.ts +29 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/command-errors.d.ts +77 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/commit-errors.d.ts +9 -0
- package/dist/errors/commit-errors.d.ts.map +1 -1
- package/dist/errors/git-api-error.d.ts +59 -2
- package/dist/errors/git-api-error.d.ts.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +371 -19
- package/dist/errors/rebase-errors.d.ts +9 -0
- package/dist/errors/rebase-errors.d.ts.map +1 -1
- package/dist/errors/ref-errors.d.ts +32 -0
- package/dist/errors/ref-errors.d.ts.map +1 -1
- package/dist/errors/transport-errors.d.ts +12 -2
- package/dist/errors/transport-errors.d.ts.map +1 -1
- package/dist/errors/worktree-errors.d.ts +35 -0
- package/dist/errors/worktree-errors.d.ts.map +1 -0
- package/dist/git-command-DxvwPrPB.js +7612 -0
- package/dist/git-command.d.ts +422 -32
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +326 -5
- package/dist/git.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/remote-config/index.d.ts +1 -0
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +123 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +41 -0
- package/dist/remote-config/remote-refs.d.ts.map +1 -0
- package/dist/rename/detect-renames.d.ts +148 -0
- package/dist/rename/detect-renames.d.ts.map +1 -0
- package/dist/rename/git-similarity.d.ts +44 -0
- package/dist/rename/git-similarity.d.ts.map +1 -0
- package/dist/rename/index.d.ts +2 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/binary-patch.d.ts +11 -0
- package/dist/results/binary-patch.d.ts.map +1 -0
- package/dist/results/blame-format.d.ts +55 -0
- package/dist/results/blame-format.d.ts.map +1 -0
- package/dist/results/cherry-pick-result.d.ts +10 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +16 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/combined-diff.d.ts +77 -0
- package/dist/results/combined-diff.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +32 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +34 -60
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-order.d.ts +25 -0
- package/dist/results/diff-order.d.ts.map +1 -0
- package/dist/results/diff-output.d.ts +249 -0
- package/dist/results/diff-output.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +24 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +5 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -252
- package/dist/results/merge-result.d.ts +15 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +12 -3
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +42 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/quote-path.d.ts +27 -0
- package/dist/results/quote-path.d.ts.map +1 -0
- package/dist/results/rebase-result.d.ts +28 -1
- package/dist/results/rebase-result.d.ts.map +1 -1
- package/dist/results/revert-result.d.ts +10 -0
- package/dist/results/revert-result.d.ts.map +1 -1
- package/dist/results/stash-result.d.ts +5 -0
- package/dist/results/stash-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +143 -18
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BZGa2Z3I.js +2934 -0
- package/dist/transport-command.d.ts +56 -1
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +15 -10
- package/src/commands/add-command.ts +1291 -224
- package/src/commands/add-patch/add-interactive.ts +941 -0
- package/src/commands/add-patch/add-patch.ts +1169 -0
- package/src/commands/add-patch/index.ts +5 -0
- package/src/commands/add-patch/patch-backend.ts +239 -0
- package/src/commands/add-patch/patch-modes.ts +249 -0
- package/src/commands/add-patch/patch-session.ts +159 -0
- package/src/commands/am/am-command.ts +1111 -0
- package/src/commands/am/index.ts +2 -0
- package/src/commands/am/mailinfo.ts +1015 -0
- package/src/commands/am/patch-format.ts +121 -0
- package/src/commands/apply/apply-command.ts +832 -0
- package/src/commands/apply/apply-engine.ts +1603 -0
- package/src/commands/apply/apply-parse.ts +1209 -0
- package/src/commands/apply/apply-types.ts +112 -0
- package/src/commands/apply/index.ts +5 -0
- package/src/commands/apply/latin1.ts +171 -0
- package/src/commands/apply/whitespace.ts +260 -0
- package/src/commands/attributes-source.ts +96 -0
- package/src/commands/backfill-command.ts +694 -0
- package/src/commands/bisect/bisect-checkout.ts +217 -0
- package/src/commands/bisect/bisect-command.ts +788 -0
- package/src/commands/bisect/bisect-engine.ts +1079 -0
- package/src/commands/bisect/bisect-graph.ts +595 -0
- package/src/commands/bisect/bisect-quote.ts +92 -0
- package/src/commands/bisect/index.ts +4 -0
- package/src/commands/blame-command.ts +711 -986
- package/src/commands/branch-command.ts +354 -32
- package/src/commands/branch-tracking.ts +331 -0
- package/src/commands/checkout-command.ts +1426 -297
- package/src/commands/checkout-paths.ts +784 -0
- package/src/commands/cherry-pick-command.ts +156 -396
- package/src/commands/clean-command.ts +532 -85
- package/src/commands/clone-command.ts +826 -55
- package/src/commands/commit-command.ts +1781 -166
- package/src/commands/core-config.ts +196 -0
- package/src/commands/date-format.ts +668 -0
- package/src/commands/describe-command.ts +2 -0
- package/src/commands/diff-command.ts +1898 -110
- package/src/commands/diff-textconv.ts +50 -0
- package/src/commands/fetch-command.ts +1038 -79
- package/src/commands/format-patch-command.ts +969 -0
- package/src/commands/fsck/fetch-fsck.ts +229 -0
- package/src/commands/fsck/fsck-command.ts +3347 -0
- package/src/commands/fsck/fsck-loose.ts +287 -0
- package/src/commands/fsck/fsck-msg-ids.ts +176 -0
- package/src/commands/fsck/fsck-object-checks.ts +1044 -0
- package/src/commands/fsck/fsck-object-table.ts +363 -0
- package/src/commands/fsck/fsck-pack.ts +604 -0
- package/src/commands/fsck/index.ts +5 -0
- package/src/commands/fsck/verify-pack-command.ts +249 -0
- package/src/commands/gc-command.ts +147 -1
- package/src/commands/git-date.ts +895 -0
- package/src/commands/git-describe.ts +316 -0
- package/src/commands/git-hooks.ts +1472 -0
- package/src/commands/git-ident.ts +344 -0
- package/src/commands/hook-command.ts +247 -0
- package/src/commands/index-adder.ts +706 -0
- package/src/commands/index-host.ts +291 -0
- package/src/commands/index.ts +83 -0
- package/src/commands/init-command.ts +60 -11
- package/src/commands/local-clone.ts +183 -0
- package/src/commands/local-transport.ts +762 -0
- package/src/commands/log-command.ts +1915 -170
- package/src/commands/log-graph.ts +671 -0
- package/src/commands/log-output.ts +1359 -0
- package/src/commands/ls-remote-command.ts +101 -58
- package/src/commands/mailmap.ts +129 -0
- package/src/commands/merge-bases.ts +296 -0
- package/src/commands/merge-command.ts +1386 -491
- package/src/commands/merge-config.ts +25 -0
- package/src/commands/merge-drivers.ts +306 -0
- package/src/commands/merge-support.ts +1198 -0
- package/src/commands/message-cleanup.ts +275 -0
- package/src/commands/mv-command.ts +976 -0
- package/src/commands/notes-command.ts +890 -0
- package/src/commands/notes-commands.ts +87 -0
- package/src/commands/notes-merge-command.ts +768 -0
- package/src/commands/notes-support.ts +402 -0
- package/src/commands/notes-tree.ts +602 -0
- package/src/commands/object-id-input.ts +27 -0
- package/src/commands/octopus-merge.ts +377 -0
- package/src/commands/ort-merge.ts +1660 -0
- package/src/commands/ort-recursive.ts +160 -0
- package/src/commands/pack-refs-command.ts +39 -22
- package/src/commands/patch-id.ts +196 -0
- package/src/commands/pathspec-attributes.ts +162 -0
- package/src/commands/pathspec.ts +1199 -0
- package/src/commands/post-index-change.ts +62 -0
- package/src/commands/pretty-format.ts +1431 -0
- package/src/commands/promisor-remote.ts +298 -0
- package/src/commands/pull-command.ts +207 -22
- package/src/commands/push-command.ts +236 -23
- package/src/commands/read-tree-command.ts +857 -0
- package/src/commands/rebase-command.ts +3808 -371
- package/src/commands/rebase-todo.ts +584 -0
- package/src/commands/ref-decoration-filter.ts +118 -0
- package/src/commands/reflog-messages.ts +177 -0
- package/src/commands/remote-command.ts +500 -19
- package/src/commands/remote-transport.ts +383 -0
- package/src/commands/reset-command.ts +828 -91
- package/src/commands/restore-command.ts +350 -0
- package/src/commands/rev-list-command.ts +167 -0
- package/src/commands/rev-parse-command.ts +277 -0
- package/src/commands/revert-command.ts +152 -399
- package/src/commands/revision-filenames.ts +254 -0
- package/src/commands/revision-range.ts +222 -0
- package/src/commands/revision-resolver.ts +1379 -0
- package/src/commands/rm-command.ts +613 -67
- package/src/commands/sequencer-pick.ts +869 -0
- package/src/commands/sequencer-support.ts +869 -0
- package/src/commands/serve-repository.ts +125 -0
- package/src/commands/sparse-checkout-command.ts +1389 -0
- package/src/commands/sparse-checkout-support.ts +793 -0
- package/src/commands/stash-apply-command.ts +692 -124
- package/src/commands/stash-create-command.ts +752 -89
- package/src/commands/stash-drop-command.ts +67 -6
- package/src/commands/stash-list-command.ts +10 -4
- package/src/commands/stash-working-tree.ts +387 -0
- package/src/commands/status-command.ts +1426 -97
- package/src/commands/status-format.ts +775 -0
- package/src/commands/status-header.ts +330 -0
- package/src/commands/strerror.ts +29 -0
- package/src/commands/submodule-config.ts +94 -0
- package/src/commands/submodule-summary-command.ts +334 -0
- package/src/commands/submodule-summary.ts +446 -0
- package/src/commands/switch-command.ts +402 -0
- package/src/commands/tag-command.ts +129 -41
- package/src/commands/tracking-info.ts +201 -0
- package/src/commands/trailers.ts +417 -0
- package/src/commands/tree-restore.ts +344 -15
- package/src/commands/untracked-cache-support.ts +194 -0
- package/src/commands/worktree-add-command.ts +458 -0
- package/src/commands/worktree-list-command.ts +208 -0
- package/src/commands/worktree-lock-command.ts +96 -0
- package/src/commands/worktree-overwrite-checks.ts +641 -0
- package/src/commands/worktree-prune-command.ts +99 -0
- package/src/commands/worktree-remove-command.ts +186 -0
- package/src/commands/worktree-repair-command.ts +59 -0
- package/src/commands/worktree-support.ts +214 -0
- package/src/core-commands/add.command.impl.ts +9 -5
- package/src/core-commands/index.ts +0 -8
- package/src/errors/add-errors.ts +45 -0
- package/src/errors/checkout-errors.ts +46 -2
- package/src/errors/command-errors.ts +101 -1
- package/src/errors/commit-errors.ts +18 -2
- package/src/errors/git-api-error.ts +82 -2
- package/src/errors/index.ts +1 -0
- package/src/errors/merge-errors.ts +2 -2
- package/src/errors/rebase-errors.ts +12 -0
- package/src/errors/ref-errors.ts +56 -2
- package/src/errors/remote-errors.ts +2 -2
- package/src/errors/stash-errors.ts +1 -1
- package/src/errors/transport-errors.ts +20 -4
- package/src/errors/worktree-errors.ts +49 -0
- package/src/git-command.ts +1218 -118
- package/src/git.ts +552 -11
- package/src/index.ts +1 -1
- package/src/remote-config/index.ts +1 -0
- package/src/remote-config/remote-config-store.ts +326 -16
- package/src/remote-config/remote-refs.ts +119 -0
- package/src/rename/detect-renames.ts +711 -0
- package/src/rename/git-similarity.ts +116 -0
- package/src/rename/index.ts +2 -0
- package/src/results/binary-patch.ts +401 -0
- package/src/results/blame-format.ts +239 -0
- package/src/results/cherry-pick-result.ts +10 -0
- package/src/results/clone-result.ts +18 -0
- package/src/results/combined-diff.ts +585 -0
- package/src/results/diff-entry.ts +35 -0
- package/src/results/diff-formatter.ts +152 -288
- package/src/results/diff-order.ts +64 -0
- package/src/results/diff-output.ts +1051 -0
- package/src/results/fetch-result.ts +24 -1
- package/src/results/index.ts +5 -0
- package/src/results/merge-result.ts +15 -1
- package/src/results/pull-result.ts +12 -3
- package/src/results/push-result.ts +43 -0
- package/src/results/quote-path.ts +103 -0
- package/src/results/rebase-result.ts +37 -0
- package/src/results/revert-result.ts +10 -0
- package/src/results/stash-result.ts +6 -0
- package/src/results/status-result.ts +288 -27
- package/src/transport-command.ts +139 -2
- package/dist/commands-BpeXZTC3.js +0 -10278
- package/dist/core-commands/checkout.command.d.ts +0 -103
- package/dist/core-commands/checkout.command.d.ts.map +0 -1
- package/dist/core-commands/checkout.command.impl.d.ts +0 -110
- package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
- package/dist/status-result-BapZoQaR.js +0 -411
- package/src/core-commands/checkout.command.impl.ts +0 -564
- package/src/core-commands/checkout.command.ts +0 -125
|
@@ -1,10 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Commit,
|
|
3
|
+
EMPTY_TREE_ID,
|
|
4
|
+
FileMode,
|
|
5
|
+
type ObjectId,
|
|
6
|
+
type PersonIdent,
|
|
7
|
+
type TreeEntry,
|
|
8
|
+
} from "@statewalker/vcs-core";
|
|
9
|
+
import { FileStagingStore } from "@statewalker/vcs-store-files";
|
|
10
|
+
import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
|
|
11
|
+
import type { FilesApi } from "@statewalker/vcs-utils/files";
|
|
12
|
+
import {
|
|
13
|
+
expandUserPath,
|
|
14
|
+
type Staging,
|
|
15
|
+
type StagingEntry,
|
|
16
|
+
type StagingIndexLock,
|
|
17
|
+
type Worktree,
|
|
18
|
+
type WorktreeEntry,
|
|
19
|
+
} from "@statewalker/vcs-working-tree";
|
|
4
20
|
|
|
5
21
|
import {
|
|
6
22
|
EmptyCommitError,
|
|
23
|
+
GitApiError,
|
|
24
|
+
HookFailedError,
|
|
7
25
|
IncompatibleOptionsError,
|
|
26
|
+
IndexLockFailedError,
|
|
27
|
+
InvalidArgumentError,
|
|
8
28
|
NoHeadError,
|
|
9
29
|
NoMessageError,
|
|
10
30
|
RefNotFoundError,
|
|
@@ -12,7 +32,49 @@ import {
|
|
|
12
32
|
UnmergedPathsError,
|
|
13
33
|
} from "../errors/index.js";
|
|
14
34
|
import { GitCommand } from "../git-command.js";
|
|
35
|
+
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
15
36
|
import { AddCommand } from "./add-command.js";
|
|
37
|
+
import { worktreeModeTrust } from "./core-config.js";
|
|
38
|
+
import { DEFAULT_DATE_MODE, showDate } from "./date-format.js";
|
|
39
|
+
import { hostEnvironmentOf, withoutCrud } from "./git-ident.js";
|
|
40
|
+
import { IndexAdder, readGitlinkHead } from "./index-adder.js";
|
|
41
|
+
import {
|
|
42
|
+
flatTree,
|
|
43
|
+
OperationState,
|
|
44
|
+
updateIndexCacheTree,
|
|
45
|
+
writeIndexAsTree,
|
|
46
|
+
} from "./merge-support.js";
|
|
47
|
+
import {
|
|
48
|
+
CleanupMode,
|
|
49
|
+
cleanupWith,
|
|
50
|
+
commentPrefixOf,
|
|
51
|
+
commitCleanupMode,
|
|
52
|
+
completeLine,
|
|
53
|
+
editorCleanupMode,
|
|
54
|
+
stripspace,
|
|
55
|
+
} from "./message-cleanup.js";
|
|
56
|
+
import { copyNotesForAmend } from "./notes-support.js";
|
|
57
|
+
import { canonicalObjectId } from "./object-id-input.js";
|
|
58
|
+
import {
|
|
59
|
+
DO_MATCH_DIRECTORY,
|
|
60
|
+
matchPathspecSeen,
|
|
61
|
+
type PathspecItem,
|
|
62
|
+
parsePathspec,
|
|
63
|
+
pathspecErrors,
|
|
64
|
+
pathspecItemMayMatch,
|
|
65
|
+
} from "./pathspec.js";
|
|
66
|
+
import { PathspecAttributes } from "./pathspec-attributes.js";
|
|
67
|
+
import { type CommitReflogKind, reflogMessages, updateHead } from "./reflog-messages.js";
|
|
68
|
+
import { applyAutostash } from "./sequencer-support.js";
|
|
69
|
+
import {
|
|
70
|
+
cutLine,
|
|
71
|
+
readShowUntrackedFiles,
|
|
72
|
+
StatusCommand,
|
|
73
|
+
type StatusTextResult,
|
|
74
|
+
type UntrackedFilesMode,
|
|
75
|
+
} from "./status-command.js";
|
|
76
|
+
import { type CommitWhence, StatusPrinter } from "./status-format.js";
|
|
77
|
+
import { readDiffSubmoduleConfig } from "./submodule-summary.js";
|
|
16
78
|
|
|
17
79
|
/**
|
|
18
80
|
* Result of a commit operation.
|
|
@@ -25,20 +87,6 @@ export interface CommitResult extends Commit {
|
|
|
25
87
|
id: ObjectId;
|
|
26
88
|
}
|
|
27
89
|
|
|
28
|
-
/**
|
|
29
|
-
* Get current timezone offset as string (+HHMM or -HHMM).
|
|
30
|
-
*/
|
|
31
|
-
function getTimezoneOffset(): string {
|
|
32
|
-
const offset = new Date().getTimezoneOffset();
|
|
33
|
-
const sign = offset <= 0 ? "+" : "-";
|
|
34
|
-
const absOffset = Math.abs(offset);
|
|
35
|
-
const hours = Math.floor(absOffset / 60)
|
|
36
|
-
.toString()
|
|
37
|
-
.padStart(2, "0");
|
|
38
|
-
const minutes = (absOffset % 60).toString().padStart(2, "0");
|
|
39
|
-
return `${sign}${hours}${minutes}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
90
|
/**
|
|
43
91
|
* Create a commit from staged changes.
|
|
44
92
|
*
|
|
@@ -89,15 +137,38 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
89
137
|
private message?: string;
|
|
90
138
|
private author?: PersonIdent;
|
|
91
139
|
private committer?: PersonIdent;
|
|
140
|
+
/** `--author=<name> <email>`: dated when the commit is made */
|
|
141
|
+
private authorName?: { name: string; email: string };
|
|
142
|
+
/** A committer named without a date, dated when the commit is made */
|
|
143
|
+
private committerName?: { name: string; email: string };
|
|
144
|
+
private resetAuthor = false;
|
|
92
145
|
private amend = false;
|
|
146
|
+
private noPostRewrite = false;
|
|
147
|
+
private noVerify = false;
|
|
93
148
|
private allowEmpty = false;
|
|
94
149
|
private parents: ObjectId[] = [];
|
|
95
150
|
private onlyPaths: string[] = [];
|
|
96
151
|
private all = false;
|
|
152
|
+
private include = false;
|
|
153
|
+
private includePaths: string[] = [];
|
|
97
154
|
private worktreeIterator: Worktree | undefined;
|
|
155
|
+
private cleanupMode?: CleanupMode;
|
|
156
|
+
private allowEmptyMessage = false;
|
|
157
|
+
private editor?: CommitEditor;
|
|
158
|
+
private edit?: boolean;
|
|
159
|
+
private includeStatus?: boolean;
|
|
160
|
+
private verbose?: number;
|
|
161
|
+
private untrackedMode?: UntrackedFilesMode;
|
|
162
|
+
private statusFormat?: "long" | "short" | "porcelain";
|
|
163
|
+
private showBranch?: boolean;
|
|
164
|
+
private nullTermination = false;
|
|
165
|
+
private aheadBehind?: boolean;
|
|
166
|
+
private templateFile?: string;
|
|
98
167
|
|
|
99
168
|
/**
|
|
100
|
-
* Set the commit message
|
|
169
|
+
* Set the commit message, as git's `commit -m` takes it: its last line is ended and it is
|
|
170
|
+
* cleaned up (`whitespace` by default, see {@link setCleanupMode}), so `"Fix"` is stored
|
|
171
|
+
* as `"Fix\n"` and the commit gets native git's id.
|
|
101
172
|
*
|
|
102
173
|
* @param message Commit message
|
|
103
174
|
*/
|
|
@@ -107,6 +178,49 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
107
178
|
return this;
|
|
108
179
|
}
|
|
109
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Add a paragraph to the message, as each further `-m` of `git commit` does: the
|
|
183
|
+
* message so far gets its last line ended and a blank line, then this one (`-m a -m b`
|
|
184
|
+
* is `"a\n\nb\n"`). The first call is {@link setMessage}.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* await git.commit().addMessage("Subject").addMessage("Body paragraph.").call();
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* @param message One paragraph of the commit message
|
|
192
|
+
*/
|
|
193
|
+
addMessage(message: string): this {
|
|
194
|
+
this.checkCallable();
|
|
195
|
+
// git's opt_parse_m: a newline before the next -m only when the buffer holds something
|
|
196
|
+
this.message = !this.message
|
|
197
|
+
? message
|
|
198
|
+
: `${this.message}${this.message.endsWith("\n") ? "" : "\n"}\n${message}`;
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* How the message is cleaned up (git's `--cleanup=<mode>`; default `commit.cleanup`, else
|
|
204
|
+
* `default`, which without an editor is `whitespace`: trailing whitespace and surrounding
|
|
205
|
+
* blank lines dropped, blank runs collapsed). `strip` also drops comment lines;
|
|
206
|
+
* `verbatim` keeps the message as given (with its last line ended, as `-m` does).
|
|
207
|
+
*/
|
|
208
|
+
setCleanupMode(mode: CleanupMode): this {
|
|
209
|
+
this.checkCallable();
|
|
210
|
+
this.cleanupMode = mode;
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Allow a message that is empty after its cleanup (git's `--allow-empty-message`);
|
|
216
|
+
* without it such a commit is refused: `Aborting commit due to empty commit message.`
|
|
217
|
+
*/
|
|
218
|
+
setAllowEmptyMessage(allow: boolean): this {
|
|
219
|
+
this.checkCallable();
|
|
220
|
+
this.allowEmptyMessage = allow;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
110
224
|
/**
|
|
111
225
|
* Set the author identity.
|
|
112
226
|
*
|
|
@@ -115,12 +229,10 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
115
229
|
*/
|
|
116
230
|
setAuthor(name: string, email: string): this {
|
|
117
231
|
this.checkCallable();
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
tzOffset: getTimezoneOffset(),
|
|
123
|
-
};
|
|
232
|
+
// git's --author: the name and email; the date is the amended commit's, the picked
|
|
233
|
+
// commit's, else GIT_AUTHOR_DATE or now
|
|
234
|
+
this.author = undefined;
|
|
235
|
+
this.authorName = { name, email };
|
|
124
236
|
return this;
|
|
125
237
|
}
|
|
126
238
|
|
|
@@ -131,6 +243,7 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
131
243
|
*/
|
|
132
244
|
setAuthorIdent(author: PersonIdent): this {
|
|
133
245
|
this.checkCallable();
|
|
246
|
+
this.authorName = undefined;
|
|
134
247
|
this.author = author;
|
|
135
248
|
return this;
|
|
136
249
|
}
|
|
@@ -143,12 +256,9 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
143
256
|
*/
|
|
144
257
|
setCommitter(name: string, email: string): this {
|
|
145
258
|
this.checkCallable();
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
timestamp: Math.floor(Date.now() / 1000),
|
|
150
|
-
tzOffset: getTimezoneOffset(),
|
|
151
|
-
};
|
|
259
|
+
// dated as git dates the committer: GIT_COMMITTER_DATE, else now
|
|
260
|
+
this.committer = undefined;
|
|
261
|
+
this.committerName = { name, email };
|
|
152
262
|
return this;
|
|
153
263
|
}
|
|
154
264
|
|
|
@@ -159,10 +269,44 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
159
269
|
*/
|
|
160
270
|
setCommitterIdent(committer: PersonIdent): this {
|
|
161
271
|
this.checkCallable();
|
|
272
|
+
this.committerName = undefined;
|
|
162
273
|
this.committer = committer;
|
|
163
274
|
return this;
|
|
164
275
|
}
|
|
165
276
|
|
|
277
|
+
/**
|
|
278
|
+
* `--reset-author`: an amended commit, or the commit that concludes a cherry-pick, is
|
|
279
|
+
* authored as a new one (the author resolved as git resolves it, dated now) instead of
|
|
280
|
+
* keeping the earlier commit's author.
|
|
281
|
+
*
|
|
282
|
+
* @param reset Whether to reset the author
|
|
283
|
+
*/
|
|
284
|
+
setResetAuthor(reset: boolean): this {
|
|
285
|
+
this.checkCallable();
|
|
286
|
+
this.resetAuthor = reset;
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* `--no-post-rewrite`: an amend does not carry the amended commit's notes over to the new
|
|
292
|
+
* one (`notes.rewriteRef`, `notes.rewrite.amend`), as git skips its post-rewrite step.
|
|
293
|
+
*/
|
|
294
|
+
setNoPostRewrite(noPostRewrite: boolean): this {
|
|
295
|
+
this.checkCallable();
|
|
296
|
+
this.noPostRewrite = noPostRewrite;
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* `-n` / `--no-verify`: the `pre-commit` and `commit-msg` hooks do not run
|
|
302
|
+
* (`prepare-commit-msg` and `post-commit` still do, as in git).
|
|
303
|
+
*/
|
|
304
|
+
setNoVerify(noVerify: boolean): this {
|
|
305
|
+
this.checkCallable();
|
|
306
|
+
this.noVerify = noVerify;
|
|
307
|
+
return this;
|
|
308
|
+
}
|
|
309
|
+
|
|
166
310
|
/**
|
|
167
311
|
* Set whether to amend the previous commit.
|
|
168
312
|
*
|
|
@@ -195,16 +339,30 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
195
339
|
*/
|
|
196
340
|
setParentIds(...parents: ObjectId[]): this {
|
|
197
341
|
this.checkCallable();
|
|
198
|
-
this.parents = parents;
|
|
342
|
+
this.parents = parents.map(canonicalObjectId);
|
|
199
343
|
return this;
|
|
200
344
|
}
|
|
201
345
|
|
|
202
346
|
/**
|
|
203
|
-
* Set paths to commit (--only
|
|
347
|
+
* Set paths to commit (`git commit --only <paths>`, git's partial commit).
|
|
204
348
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
349
|
+
* The paths are a pathspec, as git reads it (`d/`, `*.md`, `:(glob)d/**`, `:!d/x`,
|
|
350
|
+
* `./a`). As git's `prepare_index`: the index entries (any stage) and HEAD's files the
|
|
351
|
+
* pathspec matches are listed (`list_paths`); an element that matches none of them fails
|
|
352
|
+
* with git's "error: pathspec '<path>' did not match any file(s) known to git". The index
|
|
353
|
+
* lock is then held until HEAD has moved. Each listed path is taken from the worktree
|
|
354
|
+
* literally (`add_remove_files`): a file (ignored or not) is staged as `git add` stages it
|
|
355
|
+
* (cleaned by the content filters; an intent-to-add entry gets the content, a conflicted
|
|
356
|
+
* path is resolved to the file, the entries it clashes with as a file or a directory
|
|
357
|
+
* replaced), a path gone is removed, a submodule takes the commit checked out in it, and a
|
|
358
|
+
* path that is now a directory holding no commit refuses the commit before anything
|
|
359
|
+
* changes ("'<path>' does not have a commit checked out"). The index is
|
|
360
|
+
* written into the lock with the paths updated, and the commit records HEAD's tree with
|
|
361
|
+
* only these paths changed, whatever else is staged. The lock is renamed over the index
|
|
362
|
+
* once the commit is made; on any failure it is removed and the index (and this instance's
|
|
363
|
+
* staging, unwritten edits included) stays as it was. A skip-worktree path keeps its HEAD
|
|
364
|
+
* version. A partial commit during a merge, a cherry-pick or a rebase is refused; other
|
|
365
|
+
* unmerged paths do not stop it (they stay unmerged in the index).
|
|
208
366
|
*
|
|
209
367
|
* Cannot be combined with setAll().
|
|
210
368
|
*
|
|
@@ -213,10 +371,8 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
213
371
|
*/
|
|
214
372
|
setOnly(...paths: string[]): this {
|
|
215
373
|
this.checkCallable();
|
|
216
|
-
//
|
|
217
|
-
if (this.all && paths.length > 0)
|
|
218
|
-
throw new IncompatibleOptionsError(["--only", "--all"]);
|
|
219
|
-
}
|
|
374
|
+
// git's parse_and_validate_options: paths and -a do not go together
|
|
375
|
+
if (this.all && paths.length > 0) throw pathsWithAllError(paths);
|
|
220
376
|
this.onlyPaths = paths;
|
|
221
377
|
return this;
|
|
222
378
|
}
|
|
@@ -225,7 +381,9 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
225
381
|
* Set whether to auto-stage modified tracked files before committing.
|
|
226
382
|
*
|
|
227
383
|
* If true, stages all modified and deleted tracked files before
|
|
228
|
-
* creating the commit. Requires a working tree iterator.
|
|
384
|
+
* creating the commit. Requires a working tree iterator. As git's: the index lock is held
|
|
385
|
+
* from before the files are staged until HEAD has moved, and the index is left as it was
|
|
386
|
+
* when the commit fails.
|
|
229
387
|
*
|
|
230
388
|
* Cannot be combined with setOnly().
|
|
231
389
|
*
|
|
@@ -237,14 +395,39 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
237
395
|
*/
|
|
238
396
|
setAll(all: boolean): this {
|
|
239
397
|
this.checkCallable();
|
|
240
|
-
//
|
|
241
|
-
if (all && this.onlyPaths.length > 0)
|
|
242
|
-
throw new IncompatibleOptionsError(["--all", "--only"]);
|
|
243
|
-
}
|
|
398
|
+
// git's parse_and_validate_options: paths and -a do not go together
|
|
399
|
+
if (all && this.onlyPaths.length > 0) throw pathsWithAllError(this.onlyPaths);
|
|
244
400
|
this.all = all;
|
|
245
401
|
return this;
|
|
246
402
|
}
|
|
247
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Commit the index with the tracked files `paths` names staged first (`git commit -i
|
|
406
|
+
* <paths>` / `--include`, git's `prepare_index` "non partial, non as-is commit"): the index
|
|
407
|
+
* lock is taken, the tracked paths the pathspec matches are staged from the worktree as
|
|
408
|
+
* `git add -u <paths>` stages them (`add_files_to_cache`; untracked files are not added),
|
|
409
|
+
* an element that matches no index entry fails with git's "error: pathspec '<path>' did
|
|
410
|
+
* not match any file(s) known to git" (git 2.5x; 2.43 commits what is staged), and the
|
|
411
|
+
* whole index, written into the lock, is committed; the lock is renamed over the index
|
|
412
|
+
* once HEAD has moved, or removed on failure (the index stays as it was).
|
|
413
|
+
*
|
|
414
|
+
* As git: refused with {@link setOnly} paths ("options '-i/--include' and '-o/--only'
|
|
415
|
+
* cannot be used together"), with {@link setAll} ("options '-i/--include' and
|
|
416
|
+
* '-a/--all' cannot be used together"), and without paths ("No paths with
|
|
417
|
+
* --include/--only does not make sense."), when the commit runs.
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```typescript
|
|
421
|
+
* await git.commit().setInclude("src/a.ts").setMessage("Fix a").call();
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
setInclude(...paths: string[]): this {
|
|
425
|
+
this.checkCallable();
|
|
426
|
+
this.include = true;
|
|
427
|
+
this.includePaths = paths;
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
|
|
248
431
|
/**
|
|
249
432
|
* Whether --all mode is enabled.
|
|
250
433
|
*/
|
|
@@ -261,6 +444,511 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
261
444
|
* @param iterator Custom working tree iterator
|
|
262
445
|
* @returns this for chaining
|
|
263
446
|
*/
|
|
447
|
+
/**
|
|
448
|
+
* The editor of the commit message (git's `core.editor` / `GIT_EDITOR`, which a library
|
|
449
|
+
* cannot launch): called with the path of `COMMIT_EDITMSG` in the git directory and the
|
|
450
|
+
* text written there, the template git prepares (the message so far, then, unless
|
|
451
|
+
* {@link setIncludeStatus} is false, the commented help and status, and with
|
|
452
|
+
* {@link setVerbose} the diff below the scissors line). It returns the edited text, or
|
|
453
|
+
* nothing once it changed the file itself; the result is cleaned up as git cleans up an
|
|
454
|
+
* edited message (`default` strips comments, `scissors` cuts at the scissors line). It is
|
|
455
|
+
* used when no message is given, or with {@link setEdit}.
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```typescript
|
|
459
|
+
* await git.commit().setEditor(async (_path, template) => `Subject\n\n${template}`).call();
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
setEditor(editor: CommitEditor): this {
|
|
463
|
+
this.checkCallable();
|
|
464
|
+
this.editor = editor;
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* `-t <file>` / `--template=<file>`: the editor starts from this file's text (default
|
|
470
|
+
* `commit.template`) when no message is given and nothing is in progress; a message the
|
|
471
|
+
* editor leaves as the template was is refused (`Aborting commit; you did not edit the
|
|
472
|
+
* message.`). A relative path is read from the worktree's top, through the host.
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```typescript
|
|
476
|
+
* await git.commit().setTemplate("/home/me/.gitmessage").setEditor(edit).call();
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
setTemplate(path: string): this {
|
|
480
|
+
this.checkCallable();
|
|
481
|
+
this.templateFile = path;
|
|
482
|
+
return this;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** `-e` / `--no-edit`: edit a given message too, or never edit (default: edit when none is given). */
|
|
486
|
+
setEdit(edit: boolean): this {
|
|
487
|
+
this.checkCallable();
|
|
488
|
+
this.edit = edit;
|
|
489
|
+
return this;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** `--status` / `--no-status`: the status in the editor's template (default `commit.status`, true). */
|
|
493
|
+
setIncludeStatus(include: boolean): this {
|
|
494
|
+
this.checkCallable();
|
|
495
|
+
this.includeStatus = include;
|
|
496
|
+
return this;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* `-v` (1) / `-vv` (2): the staged diff below the template's scissors line (and the
|
|
501
|
+
* unstaged one), or in {@link callDryRun}'s output (default `commit.verbose`)
|
|
502
|
+
*/
|
|
503
|
+
setVerbose(level: number): this {
|
|
504
|
+
this.checkCallable();
|
|
505
|
+
this.verbose = level;
|
|
506
|
+
return this;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** `-u<mode>` / `--untracked-files=<mode>` of the template and the dry run */
|
|
510
|
+
setUntrackedFiles(mode: UntrackedFilesMode): this {
|
|
511
|
+
this.checkCallable();
|
|
512
|
+
this.untrackedMode = mode;
|
|
513
|
+
return this;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** `--short`, `--porcelain`, `--long`: the format of {@link callDryRun} (git's commit has no v2) */
|
|
517
|
+
setStatusFormat(format: "long" | "short" | "porcelain"): this {
|
|
518
|
+
this.checkCallable();
|
|
519
|
+
this.statusFormat = format;
|
|
520
|
+
return this;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** `--branch`: the branch header of the short and porcelain dry runs (default `status.branch`) */
|
|
524
|
+
setShowBranch(show: boolean): this {
|
|
525
|
+
this.checkCallable();
|
|
526
|
+
this.showBranch = show;
|
|
527
|
+
return this;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** `-z`: NUL-terminated dry-run output (porcelain unless another format is set) */
|
|
531
|
+
setNullTermination(z: boolean): this {
|
|
532
|
+
this.checkCallable();
|
|
533
|
+
this.nullTermination = z;
|
|
534
|
+
return this;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** `--[no-]ahead-behind` of the dry run (default `status.aheadBehind` for the human formats) */
|
|
538
|
+
setAheadBehind(full: boolean): this {
|
|
539
|
+
this.checkCallable();
|
|
540
|
+
this.aheadBehind = full;
|
|
541
|
+
return this;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* `git commit --dry-run` (and `--short`, `--porcelain`, `--long`, `-z`, which imply it):
|
|
546
|
+
* the status of what would be committed, in the format set, with git's exit code (0
|
|
547
|
+
* when there is something to commit, else 1). The index is prepared as the commit would
|
|
548
|
+
* prepare it (`-a` stages the tracked changes, {@link setInclude} the named tracked paths,
|
|
549
|
+
* {@link setOnly} builds the index of HEAD with the named paths), then left as it was
|
|
550
|
+
* (rollback_index_files).
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```typescript
|
|
554
|
+
* const { text, exitCode } = await git.commit().setAll(true).callDryRun();
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
async callDryRun(): Promise<CommitDryRunResult> {
|
|
558
|
+
this.checkCallable();
|
|
559
|
+
this.setCallable(false);
|
|
560
|
+
readShowUntrackedFiles(this.workingCopy);
|
|
561
|
+
// ... and git_diff_ui_config: a diff.submodule without a value dies
|
|
562
|
+
readDiffSubmoduleConfig(this.workingCopy);
|
|
563
|
+
await this.readCurrentIndex();
|
|
564
|
+
// `-i` refuses what it refuses for a commit, before anything is read
|
|
565
|
+
if (this.include) this.checkIncludeOptions();
|
|
566
|
+
const state = new OperationState(this.workingCopy.checkout, this.refsStore);
|
|
567
|
+
const mergeHeads = await this.mergeHeads(state);
|
|
568
|
+
const headId = (await this.refsStore.resolve("HEAD"))?.objectId;
|
|
569
|
+
await this.checkAmend(state, mergeHeads, headId);
|
|
570
|
+
const partial = this.onlyPaths.length > 0;
|
|
571
|
+
const z = this.nullTermination;
|
|
572
|
+
const format = this.statusFormat ?? (z ? "porcelain" : "long");
|
|
573
|
+
const run = async (): Promise<StatusTextResult> =>
|
|
574
|
+
this.commitStatus({
|
|
575
|
+
format,
|
|
576
|
+
z,
|
|
577
|
+
...(this.showBranch !== undefined ? { branch: this.showBranch } : {}),
|
|
578
|
+
...(this.aheadBehind !== undefined ? { aheadBehind: this.aheadBehind } : {}),
|
|
579
|
+
verbose: this.verboseLevel(),
|
|
580
|
+
commitTemplate: true,
|
|
581
|
+
amend: this.amend,
|
|
582
|
+
});
|
|
583
|
+
let result: StatusTextResult;
|
|
584
|
+
if (this.include) {
|
|
585
|
+
// `-i <paths>`: the tracked paths staged on the held index, shown, then rolled back
|
|
586
|
+
const index = await this.holdIndex();
|
|
587
|
+
try {
|
|
588
|
+
await this.stageTrackedChanges(this.includePaths);
|
|
589
|
+
result = await run();
|
|
590
|
+
} finally {
|
|
591
|
+
await index.release();
|
|
592
|
+
}
|
|
593
|
+
} else if (this.all) {
|
|
594
|
+
const index = await this.holdIndex();
|
|
595
|
+
try {
|
|
596
|
+
await this.stageTrackedChanges();
|
|
597
|
+
result = await run();
|
|
598
|
+
} finally {
|
|
599
|
+
await index.release();
|
|
600
|
+
}
|
|
601
|
+
} else if (partial) {
|
|
602
|
+
const paths = await this.listPartialPaths(state, mergeHeads, headId);
|
|
603
|
+
const index = await this.holdIndex();
|
|
604
|
+
try {
|
|
605
|
+
// the false index shown, its tree never stored (git writes it into a lock only)
|
|
606
|
+
const falseIndex = await this.preparePartialCommit(paths, headId, index);
|
|
607
|
+
result = await this.withFalseIndex(await this.falseIndexFiles(falseIndex), run);
|
|
608
|
+
} finally {
|
|
609
|
+
await index.release();
|
|
610
|
+
}
|
|
611
|
+
} else {
|
|
612
|
+
// an as-is commit (prepare_index): the index lock taken (git dies when another
|
|
613
|
+
// process holds it), then the status of the index as it is
|
|
614
|
+
const index = await this.holdIndex();
|
|
615
|
+
await index.release();
|
|
616
|
+
result = await run();
|
|
617
|
+
}
|
|
618
|
+
return { ...result, exitCode: result.committable ? 0 : 1 };
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** git's use_editor: an editor is set, and no message is given or `-e` asks for it. */
|
|
622
|
+
private usesEditor(): boolean {
|
|
623
|
+
if (!this.editor || this.edit === false) return false;
|
|
624
|
+
return this.edit === true || this.message === undefined;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* prepare_to_commit with an editor: COMMIT_EDITMSG written with the message so far and
|
|
629
|
+
* (`commit.status`) the commented help, identities and status of the template, the
|
|
630
|
+
* editor run over it, and what it left cleaned up as the commit message.
|
|
631
|
+
*/
|
|
632
|
+
private async editMessage(
|
|
633
|
+
ctx: {
|
|
634
|
+
state: OperationState;
|
|
635
|
+
mergeHeads: ObjectId[];
|
|
636
|
+
pickHead: ObjectId | undefined;
|
|
637
|
+
partialTree: ObjectId | undefined;
|
|
638
|
+
/** The tree the commit records */
|
|
639
|
+
treeId: ObjectId;
|
|
640
|
+
/** HEAD, or HEAD^1 when amending (none: an initial commit, or a root amended) */
|
|
641
|
+
firstParent: ObjectId | undefined;
|
|
642
|
+
previousCommit: Commit | undefined;
|
|
643
|
+
author: PersonIdent;
|
|
644
|
+
committer: PersonIdent;
|
|
645
|
+
authorKept: boolean;
|
|
646
|
+
/** The variables of the commit hooks */
|
|
647
|
+
hookEnv: Record<string, string>;
|
|
648
|
+
},
|
|
649
|
+
editor: CommitEditor,
|
|
650
|
+
): Promise<{ message: string; cleanup: CleanupMode; untouched: boolean }> {
|
|
651
|
+
const { state } = ctx;
|
|
652
|
+
const config = RemoteConfigStore.from(this.workingCopy);
|
|
653
|
+
const mode = editorCleanupMode(this.workingCopy, this.cleanupMode);
|
|
654
|
+
const templateText = await this.readTemplate(config);
|
|
655
|
+
const rebasing = (await state.read("rebase-merge/head-name")) !== undefined;
|
|
656
|
+
const whence: CommitWhence =
|
|
657
|
+
ctx.mergeHeads.length > 0
|
|
658
|
+
? "merge"
|
|
659
|
+
: ctx.pickHead
|
|
660
|
+
? rebasing && (await state.ref("REBASE_HEAD")) === ctx.pickHead
|
|
661
|
+
? "rebase-pick"
|
|
662
|
+
: "cherry-pick"
|
|
663
|
+
: "commit";
|
|
664
|
+
// the message so far
|
|
665
|
+
let sb = "";
|
|
666
|
+
let cutLineAdded = false;
|
|
667
|
+
const mergeMsg = await state.read("MERGE_MSG");
|
|
668
|
+
const squashMsg = await state.read("SQUASH_MSG");
|
|
669
|
+
if (this.message !== undefined) sb = completeLine(this.message);
|
|
670
|
+
else if (this.amend && ctx.previousCommit) {
|
|
671
|
+
sb = ctx.previousCommit.message.replace(/^(?:[ \t\r]*\n)+/, "");
|
|
672
|
+
} else if (mergeMsg !== undefined) {
|
|
673
|
+
sb = `${squashMsg ?? ""}${mergeMsg}`;
|
|
674
|
+
if (mode === CleanupMode.SCISSORS) {
|
|
675
|
+
const cut = `${commentPrefixOf(this.workingCopy)} ------------------------ >8 ------------------------\n`;
|
|
676
|
+
if (mergeMsg.startsWith(cut) || mergeMsg.includes(`\n${cut}`)) cutLineAdded = true;
|
|
677
|
+
}
|
|
678
|
+
} else if (squashMsg !== undefined) sb = squashMsg;
|
|
679
|
+
else if (templateText !== undefined) sb = templateText;
|
|
680
|
+
// clean_message_contents: not for a template, which goes in as it is
|
|
681
|
+
const fromTemplate =
|
|
682
|
+
this.message === undefined &&
|
|
683
|
+
!(this.amend && ctx.previousCommit) &&
|
|
684
|
+
mergeMsg === undefined &&
|
|
685
|
+
squashMsg === undefined &&
|
|
686
|
+
templateText !== undefined;
|
|
687
|
+
if (mode !== CleanupMode.VERBATIM && !fromTemplate) sb = stripspace(sb);
|
|
688
|
+
// core.commentChar=auto: a character the message does not start a line with
|
|
689
|
+
const comment = commentPrefixOf(this.workingCopy, sb);
|
|
690
|
+
// (a prepared message taken without an editor: as `--no-status`, unless asked for)
|
|
691
|
+
const includeStatus =
|
|
692
|
+
this.includeStatus ??
|
|
693
|
+
(this.usesEditor() ? parseBool(config.value("commit.status"), true) : false);
|
|
694
|
+
const verbose = this.verboseLevel();
|
|
695
|
+
let template = sb;
|
|
696
|
+
let committable: boolean;
|
|
697
|
+
const p = new StatusPrinter(comment);
|
|
698
|
+
if (includeStatus) {
|
|
699
|
+
if (whence !== "commit") {
|
|
700
|
+
if (mode === CleanupMode.SCISSORS && !cutLineAdded) {
|
|
701
|
+
p.raw(cutLine(comment));
|
|
702
|
+
cutLineAdded = true;
|
|
703
|
+
}
|
|
704
|
+
const what = whence === "merge" ? "a merge" : "a cherry-pick";
|
|
705
|
+
const ref = whence === "merge" ? "MERGE_HEAD" : "CHERRY_PICK_HEAD";
|
|
706
|
+
p.ln(
|
|
707
|
+
`\nIt looks like you may be committing ${what}.\nIf this is not correct, please run\n\tgit update-ref -d ${ref}\nand try again.\n`,
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
p.raw("\n");
|
|
711
|
+
if (mode === CleanupMode.STRIP) {
|
|
712
|
+
p.printf(
|
|
713
|
+
this.allowEmptyMessage
|
|
714
|
+
? `Please enter the commit message for your changes. Lines starting\nwith '${comment}' will be ignored.\n`
|
|
715
|
+
: `Please enter the commit message for your changes. Lines starting\nwith '${comment}' will be ignored, and an empty message aborts the commit.\n`,
|
|
716
|
+
);
|
|
717
|
+
} else if (mode === CleanupMode.SCISSORS) {
|
|
718
|
+
if (whence === "commit" && !cutLineAdded) {
|
|
719
|
+
p.raw(cutLine(comment));
|
|
720
|
+
cutLineAdded = true;
|
|
721
|
+
}
|
|
722
|
+
} else {
|
|
723
|
+
p.printf(
|
|
724
|
+
this.allowEmptyMessage
|
|
725
|
+
? `Please enter the commit message for your changes. Lines starting\nwith '${comment}' will be kept; you may remove them yourself if you want to.\n`
|
|
726
|
+
: `Please enter the commit message for your changes. Lines starting\nwith '${comment}' will be kept; you may remove them yourself if you want to.\nAn empty message aborts the commit.\n`,
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
let identShown = 0;
|
|
730
|
+
const { author, committer } = ctx;
|
|
731
|
+
if (author.name !== committer.name || author.email !== committer.email) {
|
|
732
|
+
p.ln(`${identShown++ ? "" : "\n"}Author: ${author.name} <${author.email}>`);
|
|
733
|
+
}
|
|
734
|
+
if (ctx.authorKept) {
|
|
735
|
+
const date = showDate(author.timestamp, author.tzOffset, DEFAULT_DATE_MODE);
|
|
736
|
+
p.ln(`${identShown++ ? "" : "\n"}Date: ${date}`);
|
|
737
|
+
}
|
|
738
|
+
if (!this.committerIdentGiven()) {
|
|
739
|
+
p.ln(`${identShown++ ? "" : "\n"}Committer: ${committer.name} <${committer.email}>`);
|
|
740
|
+
}
|
|
741
|
+
p.ln("");
|
|
742
|
+
const run = () =>
|
|
743
|
+
this.commitStatus({
|
|
744
|
+
format: "long",
|
|
745
|
+
commentPrefix: comment,
|
|
746
|
+
hints: false,
|
|
747
|
+
nowarn: true,
|
|
748
|
+
commitTemplate: true,
|
|
749
|
+
amend: this.amend,
|
|
750
|
+
verbose,
|
|
751
|
+
toFile: true,
|
|
752
|
+
cutLineAdded,
|
|
753
|
+
whence,
|
|
754
|
+
});
|
|
755
|
+
const status = ctx.partialTree
|
|
756
|
+
? await this.withIndexOfTree(ctx.partialTree, run)
|
|
757
|
+
: await run();
|
|
758
|
+
committable = status.committable;
|
|
759
|
+
template += p.out + status.text;
|
|
760
|
+
} else {
|
|
761
|
+
// no status in the template: prepare_to_commit's index_differs_from against HEAD
|
|
762
|
+
// (HEAD^1 when amending), intent-to-add entries invisible; without that parent,
|
|
763
|
+
// `cache_nr - ita_nr > 0`. The recorded tree says both without a status run.
|
|
764
|
+
const parentTree = ctx.firstParent
|
|
765
|
+
? (await this.commits.load(ctx.firstParent))?.tree
|
|
766
|
+
: EMPTY_TREE_ID;
|
|
767
|
+
committable = ctx.treeId !== parentTree;
|
|
768
|
+
}
|
|
769
|
+
// COMMIT_EDITMSG written in full, then an empty commit refused before the editor runs
|
|
770
|
+
await state.write("COMMIT_EDITMSG", template);
|
|
771
|
+
const isMerge = (ctx.previousCommit?.parents.length ?? 0) > 1;
|
|
772
|
+
if (!committable && whence !== "merge" && !this.allowEmpty && !(this.amend && isMerge)) {
|
|
773
|
+
throw new EmptyCommitError();
|
|
774
|
+
}
|
|
775
|
+
// prepare-commit-msg, the editor over what it left, then commit-msg
|
|
776
|
+
let text = "";
|
|
777
|
+
let edited: unknown;
|
|
778
|
+
const hookArgs = this.prepareMessageHookArgs(
|
|
779
|
+
mergeMsg,
|
|
780
|
+
squashMsg,
|
|
781
|
+
fromTemplate ? templateText : undefined,
|
|
782
|
+
ctx.mergeHeads,
|
|
783
|
+
ctx.pickHead,
|
|
784
|
+
);
|
|
785
|
+
const ran = await this.runMessageHooks(ctx.hookEnv, hookArgs, async () => {
|
|
786
|
+
const current = this.hooks.enabled
|
|
787
|
+
? ((await state.read("COMMIT_EDITMSG")) ?? template)
|
|
788
|
+
: template;
|
|
789
|
+
edited = await editor("COMMIT_EDITMSG", current);
|
|
790
|
+
if (typeof edited === "string") await state.write("COMMIT_EDITMSG", edited);
|
|
791
|
+
});
|
|
792
|
+
if (typeof edited === "string" && !ran) text = edited;
|
|
793
|
+
else text = (await state.read("COMMIT_EDITMSG")) ?? "";
|
|
794
|
+
// cleanup_message
|
|
795
|
+
if (verbose > 0 || mode === CleanupMode.SCISSORS) {
|
|
796
|
+
const cut = `${comment} ------------------------ >8 ------------------------\n`;
|
|
797
|
+
if (text.startsWith(cut)) text = "";
|
|
798
|
+
else {
|
|
799
|
+
const at = text.indexOf(`\n${cut}`);
|
|
800
|
+
if (at >= 0) text = text.slice(0, at + 1);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
if (mode !== CleanupMode.VERBATIM) {
|
|
804
|
+
text = stripspace(text, mode === CleanupMode.STRIP ? comment : undefined);
|
|
805
|
+
}
|
|
806
|
+
return {
|
|
807
|
+
message: text,
|
|
808
|
+
cleanup: mode === CleanupMode.VERBATIM ? mode : CleanupMode.STRIP,
|
|
809
|
+
untouched: templateUntouched(text, templateText, mode, comment),
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* The commit template (`-t`, else `commit.template`, `~/` expanded) read through the host,
|
|
815
|
+
* undefined when none is set; one that cannot be read fails as git's `die_errno`.
|
|
816
|
+
*/
|
|
817
|
+
private async readTemplate(config: RemoteConfigStore): Promise<string | undefined> {
|
|
818
|
+
const configured = config.value("commit.template");
|
|
819
|
+
const file =
|
|
820
|
+
this.templateFile ?? (configured !== undefined && configured !== "" ? configured : undefined);
|
|
821
|
+
if (file === undefined) return undefined;
|
|
822
|
+
const environment = hostEnvironmentOf(this.workingCopy);
|
|
823
|
+
const expanded = expandUserPath(file, environment);
|
|
824
|
+
let bytes: Uint8Array | undefined;
|
|
825
|
+
if (expanded !== undefined && environment) {
|
|
826
|
+
let path = expanded;
|
|
827
|
+
if (!path.startsWith("/")) {
|
|
828
|
+
const base = (this.worktreeAccess as { hostPath?: string } | undefined)?.hostPath;
|
|
829
|
+
if (base) path = `${base.replace(/\/+$/, "")}/${path}`;
|
|
830
|
+
}
|
|
831
|
+
bytes = await environment.readFile(path).catch(() => undefined);
|
|
832
|
+
}
|
|
833
|
+
if (!bytes) {
|
|
834
|
+
throw new GitApiError(`fatal: could not read '${file}': No such file or directory`);
|
|
835
|
+
}
|
|
836
|
+
return new TextDecoder().decode(bytes);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/** committer_ident_sufficiently_given: a name and an email named, not guessed. */
|
|
840
|
+
private committerIdentGiven(): boolean {
|
|
841
|
+
const env = hostEnvironmentOf(this.workingCopy);
|
|
842
|
+
const config = RemoteConfigStore.from(this.workingCopy);
|
|
843
|
+
const name =
|
|
844
|
+
env?.committer?.name !== undefined ||
|
|
845
|
+
config.value("committer.name") !== undefined ||
|
|
846
|
+
config.value("user.name") !== undefined;
|
|
847
|
+
const email =
|
|
848
|
+
env?.committer?.email !== undefined ||
|
|
849
|
+
config.value("committer.email") !== undefined ||
|
|
850
|
+
config.value("user.email") !== undefined ||
|
|
851
|
+
!!env?.defaultEmail;
|
|
852
|
+
return name && email;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/** parse_and_validate_options' checks of `--amend`. */
|
|
856
|
+
private async checkAmend(
|
|
857
|
+
state: OperationState,
|
|
858
|
+
mergeHeads: ObjectId[],
|
|
859
|
+
headId: ObjectId | undefined,
|
|
860
|
+
): Promise<void> {
|
|
861
|
+
if (!this.amend) return;
|
|
862
|
+
if (!headId) {
|
|
863
|
+
throw new InvalidArgumentError("amend", true, "fatal: You have nothing to amend.");
|
|
864
|
+
}
|
|
865
|
+
if (mergeHeads.length > 0) {
|
|
866
|
+
throw new InvalidArgumentError(
|
|
867
|
+
"amend",
|
|
868
|
+
true,
|
|
869
|
+
"fatal: You are in the middle of a merge -- cannot amend.",
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
if (await state.ref("CHERRY_PICK_HEAD")) {
|
|
873
|
+
throw new InvalidArgumentError(
|
|
874
|
+
"amend",
|
|
875
|
+
true,
|
|
876
|
+
"fatal: You are in the middle of a cherry-pick -- cannot amend.",
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/** `-v` as given, else `commit.verbose` (a boolean or a level), else 0. */
|
|
882
|
+
private verboseLevel(): number {
|
|
883
|
+
if (this.verbose !== undefined) return this.verbose;
|
|
884
|
+
const value = RemoteConfigStore.from(this.workingCopy).value("commit.verbose");
|
|
885
|
+
if (value === undefined) return 0;
|
|
886
|
+
if (/^\s*-?\d+\s*$/.test(value)) return Number.parseInt(value, 10);
|
|
887
|
+
const v = value.toLowerCase();
|
|
888
|
+
return v === "" || v === "false" || v === "no" || v === "off" ? 0 : 1;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* run_status for the commit: the status of the prepared index against HEAD (HEAD^1 for
|
|
893
|
+
* `--amend`), its stats not written back (the commit holds the index).
|
|
894
|
+
*/
|
|
895
|
+
private async commitStatus(
|
|
896
|
+
options: Parameters<StatusCommand["callText"]>[0] & object,
|
|
897
|
+
): Promise<StatusTextResult> {
|
|
898
|
+
const status = new StatusCommand(this.workingCopy).setWriteIndex(false);
|
|
899
|
+
if (this.untrackedMode) status.setUntrackedFiles(this.untrackedMode);
|
|
900
|
+
if (this.amend) {
|
|
901
|
+
const headId = await this.resolveHead();
|
|
902
|
+
const head = await this.commits.load(headId);
|
|
903
|
+
status.setReferenceCommit(head?.parents[0] ?? null);
|
|
904
|
+
}
|
|
905
|
+
return status.callText(options);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/** {@link withFalseIndex} with the files of `tree` (a partial commit's stored tree). */
|
|
909
|
+
private async withIndexOfTree<T>(tree: ObjectId, fn: () => Promise<T>): Promise<T> {
|
|
910
|
+
return this.withFalseIndex(await flatTree(this.trees, tree), fn);
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* Runs `fn` while the staging holds the entries `flat` names (a partial commit's false
|
|
915
|
+
* index: HEAD with the named paths), each with the stat of the staging's same entry,
|
|
916
|
+
* then puts the staging back exactly as it was: the same entry objects, so the ones kept
|
|
917
|
+
* as read are still checked for racy-git smudging when the index is written
|
|
918
|
+
* (`saveState`; a staging without it gets its entries rebuilt).
|
|
919
|
+
*/
|
|
920
|
+
private async withFalseIndex<T>(
|
|
921
|
+
flat: Map<string, { objectId: ObjectId; mode: number }>,
|
|
922
|
+
fn: () => Promise<T>,
|
|
923
|
+
): Promise<T> {
|
|
924
|
+
const staging = this.staging;
|
|
925
|
+
const saved = staging.saveState?.();
|
|
926
|
+
const before = (staging.entryList?.() ?? (await collectEntries(staging))).slice();
|
|
927
|
+
const cacheTree = saved ? undefined : staging.getCacheTree?.();
|
|
928
|
+
const known = new Map(before.filter((e) => e.stage === 0).map((e) => [e.path, e]));
|
|
929
|
+
const builder = staging.createBuilder();
|
|
930
|
+
for (const [path, entry] of flat) {
|
|
931
|
+
const same = known.get(path);
|
|
932
|
+
builder.add(
|
|
933
|
+
same && same.objectId === entry.objectId && same.mode === entry.mode
|
|
934
|
+
? same
|
|
935
|
+
: { path, mode: entry.mode, objectId: entry.objectId, stage: 0, size: 0, mtime: 0 },
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
await builder.finish();
|
|
939
|
+
try {
|
|
940
|
+
return await fn();
|
|
941
|
+
} finally {
|
|
942
|
+
if (saved) staging.restoreState?.(saved);
|
|
943
|
+
else {
|
|
944
|
+
const restore = staging.createBuilder();
|
|
945
|
+
for (const entry of before) restore.add(entry);
|
|
946
|
+
await restore.finish();
|
|
947
|
+
staging.setCacheTree?.(cacheTree);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
|
|
264
952
|
setWorktree(iterator: Worktree): this {
|
|
265
953
|
this.checkCallable();
|
|
266
954
|
this.worktreeIterator = iterator;
|
|
@@ -277,65 +965,248 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
277
965
|
*/
|
|
278
966
|
async call(): Promise<CommitResult> {
|
|
279
967
|
this.checkCallable();
|
|
968
|
+
// git commit reads the status configuration first (git_status_config): a bad
|
|
969
|
+
// status.showUntrackedFiles fails it before anything is done
|
|
970
|
+
readShowUntrackedFiles(this.workingCopy);
|
|
971
|
+
// ... and git_diff_ui_config: a diff.submodule without a value dies
|
|
972
|
+
readDiffSubmoduleConfig(this.workingCopy);
|
|
973
|
+
// the index as it is now: one another writer replaced is read again (git reads the
|
|
974
|
+
// index at its start), unless this instance holds unwritten edits (refused)
|
|
975
|
+
await this.readCurrentIndex();
|
|
976
|
+
if (this.include) return this.commitIncluded();
|
|
977
|
+
const partial = this.onlyPaths.length > 0;
|
|
978
|
+
if (!this.all) return this.commitWith(partial, undefined);
|
|
979
|
+
// `-a` (git's COMMIT_NORMAL): the index lock held from before the tracked changes are
|
|
980
|
+
// staged until HEAD has moved
|
|
981
|
+
const index = await this.holdIndex();
|
|
982
|
+
try {
|
|
983
|
+
// git writes the lock once (prepare_index): one post-index-change run, the lock held
|
|
984
|
+
return await this.withOneIndexWrite("first", async () => {
|
|
985
|
+
// Handle --all flag: auto-stage modified tracked files
|
|
986
|
+
await this.stageTrackedChanges();
|
|
987
|
+
return await this.commitWith(partial, index);
|
|
988
|
+
});
|
|
989
|
+
} catch (error) {
|
|
990
|
+
await index.release();
|
|
991
|
+
throw error;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
280
994
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
995
|
+
/**
|
|
996
|
+
* `-i <paths>` (git's prepare_index for `also`): the option checks of
|
|
997
|
+
* parse_and_validate_options and prepare_index, then the index lock held from before the
|
|
998
|
+
* tracked paths are staged until HEAD has moved.
|
|
999
|
+
*/
|
|
1000
|
+
private async commitIncluded(): Promise<CommitResult> {
|
|
1001
|
+
this.checkIncludeOptions();
|
|
1002
|
+
const index = await this.holdIndex();
|
|
1003
|
+
try {
|
|
1004
|
+
await this.stageTrackedChanges(this.includePaths);
|
|
1005
|
+
return await this.commitWith(false, index);
|
|
1006
|
+
} catch (error) {
|
|
1007
|
+
await index.release();
|
|
1008
|
+
throw error;
|
|
284
1009
|
}
|
|
1010
|
+
}
|
|
285
1011
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
1012
|
+
/** `-i <paths>`: parse_and_validate_options' and prepare_index's refusals. */
|
|
1013
|
+
private checkIncludeOptions(): void {
|
|
1014
|
+
if (this.onlyPaths.length > 0) {
|
|
1015
|
+
throw new IncompatibleOptionsError(
|
|
1016
|
+
["-i/--include", "-o/--only"],
|
|
1017
|
+
"fatal: options '-i/--include' and '-o/--only' cannot be used together",
|
|
1018
|
+
);
|
|
1019
|
+
}
|
|
1020
|
+
if (this.all) {
|
|
1021
|
+
throw new IncompatibleOptionsError(
|
|
1022
|
+
["-i/--include", "-a/--all"],
|
|
1023
|
+
"fatal: options '-i/--include' and '-a/--all' cannot be used together",
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
if (this.includePaths.length === 0) {
|
|
1027
|
+
throw new InvalidArgumentError(
|
|
1028
|
+
"include",
|
|
1029
|
+
[],
|
|
1030
|
+
"fatal: No paths with --include/--only does not make sense.",
|
|
1031
|
+
);
|
|
289
1032
|
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* The commit, once `-a` staged the tracked changes (`index`: the index lock it holds).
|
|
1037
|
+
* A partial commit takes the lock itself.
|
|
1038
|
+
*/
|
|
1039
|
+
private async commitWith(partial: boolean, held: HeldIndex | undefined): Promise<CommitResult> {
|
|
1040
|
+
let index = held;
|
|
290
1041
|
|
|
291
|
-
// Check for conflicts
|
|
292
|
-
|
|
1042
|
+
// Check for conflicts (a partial commit records HEAD and the named paths: other
|
|
1043
|
+
// unmerged paths stay in the index, as git's)
|
|
1044
|
+
if (!partial && (await this.staging.hasConflicts())) {
|
|
293
1045
|
const conflictPaths = await this.staging.getConflictedPaths();
|
|
294
|
-
throw new UnmergedPathsError(
|
|
1046
|
+
throw new UnmergedPathsError(
|
|
1047
|
+
conflictPaths,
|
|
1048
|
+
[
|
|
1049
|
+
"error: Committing is not possible because you have unmerged files.",
|
|
1050
|
+
"hint: Fix them up in the work tree, and then use 'git add/rm <file>'",
|
|
1051
|
+
"hint: as appropriate to mark resolution and make a commit.",
|
|
1052
|
+
"fatal: Exiting because of an unresolved conflict.",
|
|
1053
|
+
].join("\n"),
|
|
1054
|
+
);
|
|
295
1055
|
}
|
|
296
1056
|
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
1057
|
+
// a merge, cherry-pick or revert in progress (git's whence: MERGE_HEAD,
|
|
1058
|
+
// CHERRY_PICK_HEAD, REVERT_HEAD), and the message it prepared
|
|
1059
|
+
const state = new OperationState(this.workingCopy.checkout, this.refsStore);
|
|
1060
|
+
const mergeHeads = await this.mergeHeads(state);
|
|
1061
|
+
const pickHead = await state.ref("CHERRY_PICK_HEAD");
|
|
1062
|
+
if (this.amend && mergeHeads.length > 0) {
|
|
1063
|
+
throw new InvalidArgumentError(
|
|
1064
|
+
"amend",
|
|
1065
|
+
true,
|
|
1066
|
+
"fatal: You are in the middle of a merge -- cannot amend.",
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
// a partial commit: the paths named, from the index and HEAD (git's list_paths)
|
|
1070
|
+
const headId = (await this.refsStore.resolve("HEAD"))?.objectId;
|
|
1071
|
+
let partialTree: ObjectId | undefined;
|
|
1072
|
+
let falseIndexFile: FalseIndexFile | undefined;
|
|
1073
|
+
const partialPaths = partial
|
|
1074
|
+
? await this.listPartialPaths(state, mergeHeads, headId)
|
|
1075
|
+
: undefined;
|
|
1076
|
+
if (partialPaths) {
|
|
1077
|
+
// git's partial commit (prepare_index): the index lock taken once the paths are
|
|
1078
|
+
// listed, the named paths taken from the worktree into the index and written into
|
|
1079
|
+
// the lock (renamed over the index once HEAD has moved), the commit's tree HEAD's with
|
|
1080
|
+
// the same paths taken; any failure leaves the index as it was
|
|
1081
|
+
index = await this.holdIndex();
|
|
1082
|
+
try {
|
|
1083
|
+
const falseIndex = await this.preparePartialCommit(partialPaths, headId, index);
|
|
1084
|
+
partialTree = await this.storeFalseIndex(falseIndex);
|
|
1085
|
+
// the hooks are given the false index as a file (git's next-index-<pid>.lock),
|
|
1086
|
+
// removed once the commit is made or given up
|
|
1087
|
+
if (this.hooks.enabled) {
|
|
1088
|
+
falseIndexFile = await this.writeFalseIndexFile(falseIndex);
|
|
1089
|
+
if (falseIndexFile) index = withCleanup(index, falseIndexFile.remove);
|
|
1090
|
+
}
|
|
1091
|
+
} catch (error) {
|
|
1092
|
+
await falseIndexFile?.remove();
|
|
1093
|
+
await index.release();
|
|
1094
|
+
throw error;
|
|
309
1095
|
}
|
|
310
1096
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
1097
|
+
try {
|
|
1098
|
+
return await this.commitPrepared(
|
|
1099
|
+
partialTree,
|
|
1100
|
+
state,
|
|
1101
|
+
mergeHeads,
|
|
1102
|
+
pickHead,
|
|
1103
|
+
index,
|
|
1104
|
+
falseIndexFile,
|
|
1105
|
+
);
|
|
1106
|
+
} catch (error) {
|
|
1107
|
+
await index?.release();
|
|
1108
|
+
throw error;
|
|
314
1109
|
}
|
|
1110
|
+
}
|
|
315
1111
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
let
|
|
325
|
-
let
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (!
|
|
330
|
-
|
|
1112
|
+
/**
|
|
1113
|
+
* A partial commit's false index written as git's `prepare_index` writes it for the hooks
|
|
1114
|
+
* (`$GIT_DIR/next-index-<pid>.lock`): HEAD's tree with the named paths taken, each entry
|
|
1115
|
+
* the index has unchanged keeping its stat data (create_base_index's one-way merge), the
|
|
1116
|
+
* others none. Undefined where the repository's files cannot hold it.
|
|
1117
|
+
*/
|
|
1118
|
+
private async writeFalseIndexFile(falseIndex: FalseIndex): Promise<FalseIndexFile | undefined> {
|
|
1119
|
+
// git names it by its process id; any number no file has will do here
|
|
1120
|
+
let name = "";
|
|
1121
|
+
let target: { files: FilesApi; path: string } | undefined;
|
|
1122
|
+
for (let attempt = 0; attempt < 100; attempt++) {
|
|
1123
|
+
name = `next-index-${10000 + Math.floor(Math.random() * 90000)}.lock`;
|
|
1124
|
+
target = await this.hooks.gitFile(name);
|
|
1125
|
+
if (!target) return undefined;
|
|
1126
|
+
if ((await target.files.stats(target.path)) === undefined) break;
|
|
1127
|
+
target = undefined;
|
|
1128
|
+
}
|
|
1129
|
+
if (!target) throw new Error("could not choose a name for the false index file");
|
|
1130
|
+
const lock = target;
|
|
1131
|
+
const files = await this.falseIndexFiles(falseIndex);
|
|
1132
|
+
const current = new Map<string, StagingEntry>();
|
|
1133
|
+
for await (const entry of this.staging.entries()) {
|
|
1134
|
+
if (entry.stage === 0) current.set(entry.path, entry);
|
|
1135
|
+
}
|
|
1136
|
+
const temp = new FileStagingStore(lock.files, lock.path);
|
|
1137
|
+
const builder = temp.createBuilder();
|
|
1138
|
+
for (const path of [...files.keys()].sort(compareGitPaths)) {
|
|
1139
|
+
const file = files.get(path) as { objectId: ObjectId; mode: number };
|
|
1140
|
+
const kept = current.get(path);
|
|
1141
|
+
if (kept && kept.objectId === file.objectId && kept.mode === file.mode && !kept.intentToAdd) {
|
|
1142
|
+
builder.add(kept);
|
|
1143
|
+
} else {
|
|
1144
|
+
builder.add({ path, mode: file.mode, objectId: file.objectId, size: 0, mtime: 0 });
|
|
331
1145
|
}
|
|
332
1146
|
}
|
|
1147
|
+
await builder.finish();
|
|
1148
|
+
const remove = async () => {
|
|
1149
|
+
await lock.files.remove(lock.path).catch(() => false);
|
|
1150
|
+
};
|
|
1151
|
+
// the file is ours from its first byte: a failure before it is handed over removes it
|
|
1152
|
+
try {
|
|
1153
|
+
await temp.write();
|
|
1154
|
+
return {
|
|
1155
|
+
hostPath: await this.hooks.gitPath(name, true),
|
|
1156
|
+
reread: async () => {
|
|
1157
|
+
await temp.read();
|
|
1158
|
+
return writeIndexAsTree(temp, this.trees, { write: false });
|
|
1159
|
+
},
|
|
1160
|
+
remove,
|
|
1161
|
+
};
|
|
1162
|
+
} catch (error) {
|
|
1163
|
+
await remove();
|
|
1164
|
+
throw error;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
333
1167
|
|
|
334
|
-
|
|
335
|
-
|
|
1168
|
+
/** The commit made from the index (or the partial commit's tree), after the index is ready. */
|
|
1169
|
+
private async commitPrepared(
|
|
1170
|
+
partialTreeIn: ObjectId | undefined,
|
|
1171
|
+
state: OperationState,
|
|
1172
|
+
mergeHeads: ObjectId[],
|
|
1173
|
+
pickHead: ObjectId | undefined,
|
|
1174
|
+
index: HeldIndex | undefined,
|
|
1175
|
+
falseIndexFile?: FalseIndexFile,
|
|
1176
|
+
): Promise<CommitResult> {
|
|
1177
|
+
let partialTree = partialTreeIn;
|
|
1178
|
+
// an editor edits the message (git's use_editor): no message given, or -e; without an
|
|
1179
|
+
// editor set, a merge's or a pick's prepared message (MERGE_MSG, SQUASH_MSG) is taken as
|
|
1180
|
+
// `git commit --no-status` takes it once the editor leaves it as it is (the template
|
|
1181
|
+
// written to COMMIT_EDITMSG; the status too with setIncludeStatus(true)), unless
|
|
1182
|
+
// setEdit(false) (`--no-edit`)
|
|
1183
|
+
const mergeMsgPresent =
|
|
1184
|
+
(await state.read("MERGE_MSG")) !== undefined ||
|
|
1185
|
+
(await state.read("SQUASH_MSG")) !== undefined;
|
|
1186
|
+
const editorLike =
|
|
1187
|
+
this.usesEditor() ||
|
|
1188
|
+
(this.message === undefined && !this.amend && this.edit !== false && mergeMsgPresent);
|
|
1189
|
+
const editor: CommitEditor = this.usesEditor()
|
|
1190
|
+
? (this.editor as CommitEditor)
|
|
1191
|
+
: async () => undefined;
|
|
1192
|
+
const message = this.message;
|
|
1193
|
+
if (!editorLike && message === undefined && !this.amend && !mergeMsgPresent) {
|
|
1194
|
+
throw new NoMessageError();
|
|
336
1195
|
}
|
|
337
|
-
|
|
338
|
-
|
|
1196
|
+
|
|
1197
|
+
// prepare_to_commit's pre-commit hook (not with --no-verify), over the index the commit
|
|
1198
|
+
// records (the lock `-a` and a partial commit wrote); a hook that ran may have changed
|
|
1199
|
+
// the index, which is read again (git's discard_index + read_index_from)
|
|
1200
|
+
// (a partial commit's hooks see its false index; `-a` the index lock, read back from
|
|
1201
|
+
// the lock; a plain commit the index)
|
|
1202
|
+
const hookEnv = await this.commitHookEnv(editorLike, index, falseIndexFile?.hostPath);
|
|
1203
|
+
if (!this.noVerify && this.hooks.enabled) {
|
|
1204
|
+
if (index) await index.write();
|
|
1205
|
+
if (await this.runCommitHook("pre-commit", hookEnv)) {
|
|
1206
|
+
if (falseIndexFile) partialTree = await falseIndexFile.reread();
|
|
1207
|
+
else if (index) await index.reread();
|
|
1208
|
+
else await this.staging.read();
|
|
1209
|
+
}
|
|
339
1210
|
}
|
|
340
1211
|
|
|
341
1212
|
// Determine parents
|
|
@@ -359,27 +1230,211 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
359
1230
|
// Initial commit
|
|
360
1231
|
parents = [];
|
|
361
1232
|
}
|
|
1233
|
+
if (mergeHeads.length > 0) {
|
|
1234
|
+
// a merge commit: HEAD and MERGE_HEAD's commits; reduced to the independent ones
|
|
1235
|
+
// unless MERGE_MODE says no-ff (git's reduce_heads_replace)
|
|
1236
|
+
parents = [...parents, ...mergeHeads.filter((id) => !parents.includes(id))];
|
|
1237
|
+
const mode = (await state.read("MERGE_MODE")) ?? "";
|
|
1238
|
+
if (!/\bno-ff\b/.test(mode)) parents = await this.reduceHeads(parents);
|
|
1239
|
+
}
|
|
362
1240
|
}
|
|
363
1241
|
|
|
364
1242
|
// Generate tree from staging area
|
|
365
1243
|
let treeId: ObjectId;
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
1244
|
+
if (partialTree) {
|
|
1245
|
+
treeId = partialTree;
|
|
1246
|
+
} else if (index) {
|
|
1247
|
+
// `-a`: the index with a fully valid cache-tree (cache_tree_update), written into the
|
|
1248
|
+
// lock
|
|
1249
|
+
treeId = await writeIndexAsTree(this.staging, this.trees, { write: false });
|
|
1250
|
+
await index.write();
|
|
370
1251
|
} else {
|
|
371
|
-
// Normal mode: use full staging area
|
|
372
|
-
|
|
1252
|
+
// Normal mode: use full staging area; as git's prepare_index, the index is written
|
|
1253
|
+
// again with a fully valid cache-tree (cache_tree_update, which keeps the valid nodes:
|
|
1254
|
+
// a stored subtree no edit touched stays the one stored)
|
|
1255
|
+
treeId = await writeIndexAsTree(this.staging, this.trees);
|
|
373
1256
|
}
|
|
1257
|
+
let previousCommit: Commit | undefined;
|
|
1258
|
+
let amendedId: ObjectId | undefined;
|
|
374
1259
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
1260
|
+
if (this.amend) {
|
|
1261
|
+
const headId = await this.resolveHead();
|
|
1262
|
+
amendedId = headId;
|
|
1263
|
+
previousCommit = await this.commits.load(headId);
|
|
1264
|
+
if (!previousCommit) {
|
|
1265
|
+
throw new NoHeadError("Cannot amend: HEAD commit not found");
|
|
380
1266
|
}
|
|
381
1267
|
}
|
|
382
1268
|
|
|
1269
|
+
// The author (git's determine_author_info): the one given; else an amended commit's or
|
|
1270
|
+
// a concluded cherry-pick's author (its date too; `--author` replaces only the name and
|
|
1271
|
+
// email), unless --reset-author; else resolved as git does (GIT_AUTHOR_*, author.*,
|
|
1272
|
+
// user.*, GIT_AUTHOR_DATE or now)
|
|
1273
|
+
let author = this.author;
|
|
1274
|
+
if (!author) {
|
|
1275
|
+
const kept = this.resetAuthor
|
|
1276
|
+
? undefined
|
|
1277
|
+
: this.amend && previousCommit
|
|
1278
|
+
? previousCommit.author
|
|
1279
|
+
: pickHead
|
|
1280
|
+
? (await this.commits.load(pickHead))?.author
|
|
1281
|
+
: undefined;
|
|
1282
|
+
if (kept) {
|
|
1283
|
+
author = this.authorName
|
|
1284
|
+
? {
|
|
1285
|
+
...kept,
|
|
1286
|
+
name: withoutCrud(this.authorName.name),
|
|
1287
|
+
email: withoutCrud(this.authorName.email),
|
|
1288
|
+
}
|
|
1289
|
+
: kept;
|
|
1290
|
+
} else if (this.authorName) author = this.datedIdent("author", this.authorName);
|
|
1291
|
+
else author = this.resolveAuthor(this.committer ?? this.committerName);
|
|
1292
|
+
}
|
|
1293
|
+
// the committer: always resolved (GIT_COMMITTER_*, committer.*, user.*), unless given
|
|
1294
|
+
const committer =
|
|
1295
|
+
this.committer ??
|
|
1296
|
+
(this.committerName
|
|
1297
|
+
? this.datedIdent("committer", this.committerName)
|
|
1298
|
+
: this.resolveCommitter(author));
|
|
1299
|
+
|
|
1300
|
+
let finalMessage: string;
|
|
1301
|
+
let cleanup: CleanupMode;
|
|
1302
|
+
let untouched = false;
|
|
1303
|
+
if (editorLike) {
|
|
1304
|
+
const edited = await this.editMessage(
|
|
1305
|
+
{
|
|
1306
|
+
state,
|
|
1307
|
+
mergeHeads,
|
|
1308
|
+
pickHead,
|
|
1309
|
+
partialTree,
|
|
1310
|
+
treeId,
|
|
1311
|
+
firstParent: parents[0],
|
|
1312
|
+
previousCommit,
|
|
1313
|
+
author,
|
|
1314
|
+
committer,
|
|
1315
|
+
authorKept: !this.author && !this.resetAuthor && (!!previousCommit || !!pickHead),
|
|
1316
|
+
hookEnv,
|
|
1317
|
+
},
|
|
1318
|
+
editor,
|
|
1319
|
+
);
|
|
1320
|
+
finalMessage = edited.message;
|
|
1321
|
+
cleanup = edited.cleanup;
|
|
1322
|
+
untouched = edited.untouched;
|
|
1323
|
+
} else {
|
|
1324
|
+
// prepare_to_commit without an editor: the message so far (`-m`, the amended commit's,
|
|
1325
|
+
// else MERGE_MSG after SQUASH_MSG, or SQUASH_MSG) with its whitespace cleaned up
|
|
1326
|
+
// unless verbatim (`get_cleanup_mode` without an editor: default and scissors are
|
|
1327
|
+
// whitespace) is written to COMMIT_EDITMSG; then a commit with nothing to commit is
|
|
1328
|
+
// refused; then the file's text is cleaned up (cleanup_message) and checked
|
|
1329
|
+
cleanup = commitCleanupMode(this.workingCopy, this.cleanupMode);
|
|
1330
|
+
let sb: string;
|
|
1331
|
+
if (message !== undefined) sb = completeLine(message);
|
|
1332
|
+
else if (previousCommit) sb = previousCommit.message.replace(/^(?:[ \t\r]*\n)+/, "");
|
|
1333
|
+
else {
|
|
1334
|
+
const mergeMsg = await state.read("MERGE_MSG");
|
|
1335
|
+
const squashMsg = await state.read("SQUASH_MSG");
|
|
1336
|
+
sb = mergeMsg !== undefined ? `${squashMsg ?? ""}${mergeMsg}` : (squashMsg ?? "");
|
|
1337
|
+
}
|
|
1338
|
+
if (cleanup !== CleanupMode.VERBATIM) sb = stripspace(sb);
|
|
1339
|
+
await state.write("COMMIT_EDITMSG", sb);
|
|
1340
|
+
await this.refuseNothingToCommit(treeId, parents, mergeHeads, previousCommit);
|
|
1341
|
+
// prepare-commit-msg and commit-msg, which may rewrite COMMIT_EDITMSG: the commit
|
|
1342
|
+
// takes the file's text (cmd_commit reads it back)
|
|
1343
|
+
// (git's hook arguments: read only when hooks can run)
|
|
1344
|
+
const hookArgs = this.hooks.enabled
|
|
1345
|
+
? this.prepareMessageHookArgs(
|
|
1346
|
+
await state.read("MERGE_MSG"),
|
|
1347
|
+
await state.read("SQUASH_MSG"),
|
|
1348
|
+
undefined,
|
|
1349
|
+
mergeHeads,
|
|
1350
|
+
pickHead,
|
|
1351
|
+
)
|
|
1352
|
+
: [];
|
|
1353
|
+
let text = sb;
|
|
1354
|
+
if (await this.runMessageHooks(hookEnv, hookArgs, undefined)) {
|
|
1355
|
+
text = (await state.read("COMMIT_EDITMSG")) ?? "";
|
|
1356
|
+
}
|
|
1357
|
+
// cleanup_message: cut at the scissors line with -v (commit.verbose)
|
|
1358
|
+
if (this.verboseLevel() > 0) {
|
|
1359
|
+
const comment = commentPrefixOf(this.workingCopy, sb);
|
|
1360
|
+
const cut = `${comment} ------------------------ >8 ------------------------\n`;
|
|
1361
|
+
if (text.startsWith(cut)) text = "";
|
|
1362
|
+
else {
|
|
1363
|
+
const at = text.indexOf(`\n${cut}`);
|
|
1364
|
+
if (at >= 0) text = text.slice(0, at + 1);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
finalMessage = cleanupWith(this.workingCopy, text, cleanup, true);
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// git's message_is_empty: nothing but whitespace and sign-offs (any text, verbatim);
|
|
1371
|
+
// then template_untouched (only an editor's message: -m, -F and -C drop the template)
|
|
1372
|
+
if (
|
|
1373
|
+
!this.allowEmptyMessage &&
|
|
1374
|
+
(cleanup !== CleanupMode.VERBATIM || finalMessage.length === 0) &&
|
|
1375
|
+
isEmptyMessage(finalMessage)
|
|
1376
|
+
) {
|
|
1377
|
+
throw new NoMessageError("Aborting commit due to empty commit message.");
|
|
1378
|
+
}
|
|
1379
|
+
if (untouched && !this.allowEmptyMessage) {
|
|
1380
|
+
throw new NoMessageError("Aborting commit; you did not edit the message.");
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
return this.finishCommit(treeId, parents, mergeHeads, pickHead, {
|
|
1384
|
+
author,
|
|
1385
|
+
committer,
|
|
1386
|
+
finalMessage,
|
|
1387
|
+
state,
|
|
1388
|
+
amendedId,
|
|
1389
|
+
commitIndex: index ? () => index.commit() : undefined,
|
|
1390
|
+
editorUsed: editorLike,
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
/**
|
|
1395
|
+
* prepare_to_commit's refusal of a commit with nothing to commit: the tree is its first
|
|
1396
|
+
* parent's (HEAD's, HEAD^1's when amending), or empty without a first parent, unless a merge is concluded, empty commits are
|
|
1397
|
+
* allowed, or a merge commit is amended.
|
|
1398
|
+
*/
|
|
1399
|
+
private async refuseNothingToCommit(
|
|
1400
|
+
treeId: ObjectId,
|
|
1401
|
+
parents: ObjectId[],
|
|
1402
|
+
mergeHeads: ObjectId[],
|
|
1403
|
+
previousCommit: Commit | undefined,
|
|
1404
|
+
): Promise<void> {
|
|
1405
|
+
if (this.allowEmpty || mergeHeads.length > 0) return;
|
|
1406
|
+
if (parents.length === 0) {
|
|
1407
|
+
// no first parent (an initial commit, or --amend of a root commit): git counts the
|
|
1408
|
+
// index, `cache_nr - ita_nr > 0`; only intent-to-add entries (or none) leave the tree
|
|
1409
|
+
// empty
|
|
1410
|
+
if (treeId === EMPTY_TREE_ID) throw new EmptyCommitError();
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
if (this.amend && (previousCommit?.parents.length ?? 0) > 1) return;
|
|
1414
|
+
const parentCommit = await this.commits.load(parents[0] as ObjectId);
|
|
1415
|
+
if (parentCommit && parentCommit.tree === treeId) throw new EmptyCommitError();
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
/** The commit of `treeId` made, HEAD moved to it, and what was in progress ended. */
|
|
1419
|
+
private async finishCommit(
|
|
1420
|
+
treeId: ObjectId,
|
|
1421
|
+
parents: ObjectId[],
|
|
1422
|
+
mergeHeads: ObjectId[],
|
|
1423
|
+
pickHead: ObjectId | undefined,
|
|
1424
|
+
info: {
|
|
1425
|
+
author: PersonIdent;
|
|
1426
|
+
committer: PersonIdent;
|
|
1427
|
+
finalMessage: string;
|
|
1428
|
+
state: OperationState;
|
|
1429
|
+
amendedId: ObjectId | undefined;
|
|
1430
|
+
/** Renames the index lock over the index, once HEAD has moved (git's commit_index_files) */
|
|
1431
|
+
commitIndex?: () => Promise<void>;
|
|
1432
|
+
/** An editor edited the message (git's use_editor): hooks get no `GIT_EDITOR=:` */
|
|
1433
|
+
editorUsed?: boolean;
|
|
1434
|
+
},
|
|
1435
|
+
): Promise<CommitResult> {
|
|
1436
|
+
const { author, committer, finalMessage, state, amendedId } = info;
|
|
1437
|
+
|
|
383
1438
|
// Create commit
|
|
384
1439
|
const commit: Commit = {
|
|
385
1440
|
tree: treeId,
|
|
@@ -391,103 +1446,525 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
391
1446
|
|
|
392
1447
|
const commitId = await this.commits.store(commit);
|
|
393
1448
|
|
|
394
|
-
// Update HEAD/branch ref
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
1449
|
+
// Update HEAD/branch ref, with git's reflog line in the branch's log and HEAD's
|
|
1450
|
+
// (builtin/commit.c: initial, amend, merge, cherry-pick, else plain)
|
|
1451
|
+
const initial = !(await this.refsStore.resolve("HEAD"))?.objectId;
|
|
1452
|
+
const kind: CommitReflogKind = initial
|
|
1453
|
+
? "initial"
|
|
1454
|
+
: this.amend
|
|
1455
|
+
? "amend"
|
|
1456
|
+
: mergeHeads.length > 0
|
|
1457
|
+
? "merge"
|
|
1458
|
+
: pickHead
|
|
1459
|
+
? "cherry-pick"
|
|
1460
|
+
: undefined;
|
|
1461
|
+
const action = this.hasReflogAction() ? this.reflogAction("commit") : undefined;
|
|
1462
|
+
const log = this.reflogLine(reflogMessages.commit(kind, finalMessage, action), committer);
|
|
1463
|
+
if (this.hooks.enabled) {
|
|
1464
|
+
// update_head_with_reflog: one transaction on HEAD expecting the commit's parent (none
|
|
1465
|
+
// for an initial commit), as the reference-transaction hook sees it
|
|
1466
|
+
const current = (await this.refsStore.resolve("HEAD"))?.objectId;
|
|
1467
|
+
const result = await this.refsStore.batch(
|
|
1468
|
+
[{ name: "HEAD", old: current ?? null, new: commitId }],
|
|
1469
|
+
log,
|
|
1470
|
+
);
|
|
1471
|
+
if (!result.ok) {
|
|
1472
|
+
throw new GitApiError(
|
|
1473
|
+
`fatal: cannot lock ref 'HEAD': ${result.rejected.map((r) => r.reason).join(", ")}`,
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
} else await updateHead(this.refsStore, commitId, log);
|
|
403
1477
|
|
|
404
1478
|
this.setCallable(false);
|
|
405
1479
|
|
|
1480
|
+
// the commit ends what was in progress (git's sequencer_post_commit_cleanup and the
|
|
1481
|
+
// state files cmd_commit unlinks), then the new index (commit_index_files), then applies
|
|
1482
|
+
// a merge's autostash
|
|
1483
|
+
await this.cleanupAfterCommit(state, info.commitIndex);
|
|
1484
|
+
|
|
1485
|
+
// the post-commit hook, over the index (whatever the commit recorded)
|
|
1486
|
+
if (this.hooks.enabled) {
|
|
1487
|
+
await this.hooks.run("post-commit", {
|
|
1488
|
+
env: await this.commitHookEnv(info.editorUsed ?? false, undefined),
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
// commit_post_rewrite: the amended commit's notes carried over (notes.rewriteRef), then
|
|
1493
|
+
// the post-rewrite hook told "amend" with "<old> <new>" on stdin
|
|
1494
|
+
if (amendedId && !this.noPostRewrite) {
|
|
1495
|
+
// git exports the amend's author (determine_author_info): the notes commit's too
|
|
1496
|
+
await copyNotesForAmend(this.notesContext(), amendedId, commitId, commit.author);
|
|
1497
|
+
if (this.hooks.enabled) {
|
|
1498
|
+
await this.hooks.run("post-rewrite", {
|
|
1499
|
+
args: ["amend"],
|
|
1500
|
+
stdin: `${amendedId} ${commitId}\n`,
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
|
|
406
1505
|
// Return commit with its ID (like JGit's RevCommit)
|
|
407
1506
|
return { ...commit, id: commitId };
|
|
408
1507
|
}
|
|
409
1508
|
|
|
410
1509
|
/**
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
* @param parentCommitId Parent commit ID
|
|
416
|
-
* @returns Tree ObjectId
|
|
1510
|
+
* The variables of the commit hooks (git's `run_commit_hook`): `GIT_INDEX_FILE` names the
|
|
1511
|
+
* index the commit records (the lock `-a` and a partial commit write; git's false index of
|
|
1512
|
+
* a partial commit is not kept as a file here), and `GIT_EDITOR=:` tells a hook that no
|
|
1513
|
+
* editor runs.
|
|
417
1514
|
*/
|
|
418
|
-
private async
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
1515
|
+
private async commitHookEnv(
|
|
1516
|
+
editorUsed: boolean,
|
|
1517
|
+
index: HeldIndex | undefined,
|
|
1518
|
+
/** A partial commit's false index (its host path), which the hooks see in its place */
|
|
1519
|
+
falseIndexPath?: string,
|
|
1520
|
+
): Promise<Record<string, string>> {
|
|
1521
|
+
if (!this.hooks.enabled) return {};
|
|
1522
|
+
return {
|
|
1523
|
+
GIT_INDEX_FILE:
|
|
1524
|
+
falseIndexPath ??
|
|
1525
|
+
(index ? await this.hooks.gitPath("index.lock", true) : await this.hooks.gitPath("index")),
|
|
1526
|
+
...(editorUsed ? {} : { GIT_EDITOR: ":" }),
|
|
1527
|
+
};
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/** Runs a hook that can refuse the commit; whether it ran. */
|
|
1531
|
+
private async runCommitHook(
|
|
1532
|
+
name: string,
|
|
1533
|
+
env: Record<string, string>,
|
|
1534
|
+
args: string[] = [],
|
|
1535
|
+
): Promise<boolean> {
|
|
1536
|
+
const result = await this.hooks.run(name, { args, env });
|
|
1537
|
+
if (result && result.exitCode !== 0) {
|
|
1538
|
+
throw new HookFailedError(
|
|
1539
|
+
name,
|
|
1540
|
+
result.exitCode,
|
|
1541
|
+
`the ${name} hook refused the commit (exit code ${result.exitCode})`,
|
|
1542
|
+
this.hooks.output,
|
|
1543
|
+
);
|
|
422
1544
|
}
|
|
1545
|
+
return result !== undefined;
|
|
1546
|
+
}
|
|
423
1547
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
1548
|
+
/**
|
|
1549
|
+
* The arguments of prepare-commit-msg after the message file (prepare_to_commit's
|
|
1550
|
+
* hook_arg1 and hook_arg2): where the message came from.
|
|
1551
|
+
*/
|
|
1552
|
+
private prepareMessageHookArgs(
|
|
1553
|
+
mergeMsg: string | undefined,
|
|
1554
|
+
squashMsg: string | undefined,
|
|
1555
|
+
templateText: string | undefined,
|
|
1556
|
+
mergeHeads: ObjectId[],
|
|
1557
|
+
pickHead: ObjectId | undefined,
|
|
1558
|
+
): string[] {
|
|
1559
|
+
if (this.message !== undefined) return ["message"];
|
|
1560
|
+
// --amend without a message reuses HEAD's (git's use_message = "HEAD")
|
|
1561
|
+
if (this.amend) return ["commit", "HEAD"];
|
|
1562
|
+
if (mergeMsg !== undefined) return [squashMsg !== undefined ? "squash" : "merge"];
|
|
1563
|
+
if (squashMsg !== undefined) return ["squash"];
|
|
1564
|
+
if (templateText !== undefined) return ["template"];
|
|
1565
|
+
if (mergeHeads.length > 0) return ["merge"];
|
|
1566
|
+
if (pickHead) return ["commit", "CHERRY_PICK_HEAD"];
|
|
1567
|
+
return [];
|
|
1568
|
+
}
|
|
427
1569
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
1570
|
+
/**
|
|
1571
|
+
* prepare-commit-msg, the editor (when one runs) and commit-msg (not with --no-verify)
|
|
1572
|
+
* over COMMIT_EDITMSG, in prepare_to_commit's order; whether any hook ran (the file is then
|
|
1573
|
+
* to be read back). A non-zero commit-msg refuses the commit, as does prepare-commit-msg.
|
|
1574
|
+
*/
|
|
1575
|
+
private async runMessageHooks(
|
|
1576
|
+
env: Record<string, string>,
|
|
1577
|
+
args: string[],
|
|
1578
|
+
edit: (() => Promise<void>) | undefined,
|
|
1579
|
+
): Promise<boolean> {
|
|
1580
|
+
if (!this.hooks.enabled) {
|
|
1581
|
+
await edit?.();
|
|
1582
|
+
return false;
|
|
435
1583
|
}
|
|
1584
|
+
const file = await this.hooks.gitPath("COMMIT_EDITMSG");
|
|
1585
|
+
let ran = await this.runCommitHook("prepare-commit-msg", env, [file, ...args]);
|
|
1586
|
+
await edit?.();
|
|
1587
|
+
if (!this.noVerify) ran = (await this.runCommitHook("commit-msg", env, [file])) || ran;
|
|
1588
|
+
return ran;
|
|
1589
|
+
}
|
|
436
1590
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
1591
|
+
/** The commits MERGE_HEAD names (one per line), none without a merge in progress. */
|
|
1592
|
+
private async mergeHeads(state: OperationState): Promise<ObjectId[]> {
|
|
1593
|
+
const text = await state.read("MERGE_HEAD");
|
|
1594
|
+
if (text !== undefined) {
|
|
1595
|
+
return text
|
|
1596
|
+
.split("\n")
|
|
1597
|
+
.map((l) => l.trim())
|
|
1598
|
+
.filter((l) => /^[0-9a-f]{40,64}$/.test(l));
|
|
1599
|
+
}
|
|
1600
|
+
const id = await state.ref("MERGE_HEAD");
|
|
1601
|
+
return id ? [id] : [];
|
|
1602
|
+
}
|
|
442
1603
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
1604
|
+
/** The heads none of the others reaches (git's reduce_heads), in their order. */
|
|
1605
|
+
private async reduceHeads(heads: ObjectId[]): Promise<ObjectId[]> {
|
|
1606
|
+
const out: ObjectId[] = [];
|
|
1607
|
+
for (const head of heads) {
|
|
1608
|
+
let reached = false;
|
|
1609
|
+
for (const other of heads) {
|
|
1610
|
+
if (other === head) continue;
|
|
1611
|
+
if (await this.commits.isAncestor(head, other)) {
|
|
1612
|
+
reached = true;
|
|
1613
|
+
break;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
if (!reached) out.push(head);
|
|
452
1617
|
}
|
|
1618
|
+
return out.length > 0 ? out : heads.slice(0, 1);
|
|
1619
|
+
}
|
|
453
1620
|
|
|
454
|
-
|
|
1621
|
+
/**
|
|
1622
|
+
* After the commit: the merge state removed (MERGE_HEAD, MERGE_MSG, MERGE_MODE,
|
|
1623
|
+
* SQUASH_MSG, AUTO_MERGE), a stopped cherry-pick or revert ended (its sequencer state
|
|
1624
|
+
* too once it was the last pick), and MERGE_AUTOSTASH applied back, as `git commit`.
|
|
1625
|
+
*/
|
|
1626
|
+
private async cleanupAfterCommit(
|
|
1627
|
+
state: OperationState,
|
|
1628
|
+
commitIndex: (() => Promise<void>) | undefined,
|
|
1629
|
+
): Promise<void> {
|
|
1630
|
+
if (!state.supported) {
|
|
1631
|
+
await commitIndex?.();
|
|
1632
|
+
return;
|
|
1633
|
+
}
|
|
1634
|
+
const picking =
|
|
1635
|
+
(await state.ref("CHERRY_PICK_HEAD")) !== undefined ||
|
|
1636
|
+
(await state.ref("REVERT_HEAD")) !== undefined;
|
|
1637
|
+
// sequencer_post_commit_cleanup: CHERRY_PICK_HEAD and REVERT_HEAD when there, AUTO_MERGE
|
|
1638
|
+
// in any case (git 2.5x's reference-transaction hook hears of it)
|
|
1639
|
+
await state.removeRef("CHERRY_PICK_HEAD", "REVERT_HEAD");
|
|
1640
|
+
await state.deleteRef("AUTO_MERGE");
|
|
1641
|
+
await state.removeRef("MERGE_HEAD");
|
|
1642
|
+
await state.remove("MERGE_HEAD", "MERGE_MSG", "MERGE_MODE", "SQUASH_MSG");
|
|
1643
|
+
if (picking) {
|
|
1644
|
+
// have_finished_the_last_pick: the todo holds no more than the pick just committed
|
|
1645
|
+
const todo = (await state.read("sequencer/todo")) ?? "";
|
|
1646
|
+
const left = todo.split("\n").filter((l) => l.trim() && !l.trim().startsWith("#"));
|
|
1647
|
+
if (left.length <= 1) await state.remove("sequencer");
|
|
1648
|
+
}
|
|
1649
|
+
await commitIndex?.();
|
|
1650
|
+
const autostash = (await state.read("MERGE_AUTOSTASH"))?.trim();
|
|
1651
|
+
if (autostash) {
|
|
1652
|
+
await state.remove("MERGE_AUTOSTASH");
|
|
1653
|
+
await applyAutostash(
|
|
1654
|
+
{
|
|
1655
|
+
workingCopy: this.workingCopy,
|
|
1656
|
+
worktree: this.worktreeIterator ?? this.worktreeAccess,
|
|
1657
|
+
staging: this.staging,
|
|
1658
|
+
blobs: this.blobs,
|
|
1659
|
+
trees: this.trees,
|
|
1660
|
+
commits: this.commits,
|
|
1661
|
+
refs: this.refsStore,
|
|
1662
|
+
},
|
|
1663
|
+
autostash,
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
455
1667
|
|
|
456
|
-
|
|
457
|
-
|
|
1668
|
+
/**
|
|
1669
|
+
* The index held for a commit that changes it (git's `repo_hold_locked_index`): the
|
|
1670
|
+
* index lock taken now (a staging with an index file), released on failure with the
|
|
1671
|
+
* staging as it was before (read again, or its unwritten edits put back).
|
|
1672
|
+
*/
|
|
1673
|
+
private async holdIndex(): Promise<HeldIndex> {
|
|
1674
|
+
const staging = this.staging;
|
|
1675
|
+
const unwritten = staging.hasUnwrittenChanges?.() !== false;
|
|
1676
|
+
// what the staging held, for a staging that cannot read it back (no index file) or that
|
|
1677
|
+
// holds edits not yet written
|
|
1678
|
+
let lock: StagingIndexLock | undefined;
|
|
1679
|
+
try {
|
|
1680
|
+
lock = staging.lockIndex ? await staging.lockIndex() : undefined;
|
|
1681
|
+
} catch (error) {
|
|
1682
|
+
throw indexLockError(error, this.workingCopy);
|
|
1683
|
+
}
|
|
1684
|
+
// the staging as it is, put back exactly (the entry objects kept as read included)
|
|
1685
|
+
const saved = !lock || unwritten ? staging.saveState?.() : undefined;
|
|
1686
|
+
const snapshot =
|
|
1687
|
+
(!lock || unwritten) && !saved
|
|
1688
|
+
? {
|
|
1689
|
+
entries: (staging.entryList?.() ?? (await collectEntries(staging))).slice(),
|
|
1690
|
+
cacheTree: staging.getCacheTree?.(),
|
|
1691
|
+
}
|
|
1692
|
+
: undefined;
|
|
1693
|
+
let done = false;
|
|
1694
|
+
return {
|
|
1695
|
+
write: async () => {
|
|
1696
|
+
await lock?.write();
|
|
1697
|
+
},
|
|
1698
|
+
reread: async () => {
|
|
1699
|
+
if (lock?.reread) await lock.reread();
|
|
1700
|
+
else if (lock) await staging.read();
|
|
1701
|
+
},
|
|
1702
|
+
commit: async () => {
|
|
1703
|
+
if (lock) await lock.commit();
|
|
1704
|
+
else await staging.write();
|
|
1705
|
+
done = true;
|
|
1706
|
+
},
|
|
1707
|
+
release: async () => {
|
|
1708
|
+
if (done) return;
|
|
1709
|
+
done = true;
|
|
1710
|
+
await lock?.rollback();
|
|
1711
|
+
if (saved) {
|
|
1712
|
+
staging.restoreState?.(saved);
|
|
1713
|
+
return;
|
|
1714
|
+
}
|
|
1715
|
+
if (!snapshot) {
|
|
1716
|
+
await staging.read();
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
const builder = staging.createBuilder();
|
|
1720
|
+
for (const entry of snapshot.entries) builder.add(entry);
|
|
1721
|
+
await builder.finish();
|
|
1722
|
+
staging.setCacheTree?.(snapshot.cacheTree);
|
|
1723
|
+
},
|
|
1724
|
+
};
|
|
458
1725
|
}
|
|
459
1726
|
|
|
460
1727
|
/**
|
|
461
|
-
*
|
|
1728
|
+
* The paths a partial commit takes (git's `list_paths`): those of the index (any stage)
|
|
1729
|
+
* and of HEAD's tree the pathspec matches (`ce_path_match`, magic and globs as git's), in
|
|
1730
|
+
* git's order, each with whether its index entry is skip-worktree. Refused during a
|
|
1731
|
+
* merge, a cherry-pick or a rebase (git's whence), and when an element of the pathspec
|
|
1732
|
+
* matches nothing (`report_path_error`).
|
|
462
1733
|
*/
|
|
463
|
-
private async
|
|
464
|
-
|
|
1734
|
+
private async listPartialPaths(
|
|
1735
|
+
state: OperationState,
|
|
1736
|
+
mergeHeads: ObjectId[],
|
|
1737
|
+
headId: ObjectId | undefined,
|
|
1738
|
+
): Promise<Map<string, boolean>> {
|
|
1739
|
+
if (mergeHeads.length > 0) {
|
|
1740
|
+
throw new InvalidArgumentError(
|
|
1741
|
+
"only",
|
|
1742
|
+
this.onlyPaths,
|
|
1743
|
+
"fatal: cannot do a partial commit during a merge.",
|
|
1744
|
+
);
|
|
1745
|
+
}
|
|
1746
|
+
const pick = await state.ref("CHERRY_PICK_HEAD");
|
|
1747
|
+
if (pick) {
|
|
1748
|
+
// sequencer_determine_whence: a rebase stopped at this pick, else a cherry-pick
|
|
1749
|
+
const rebasing =
|
|
1750
|
+
(await state.read("rebase-merge/head-name")) !== undefined &&
|
|
1751
|
+
(await state.ref("REBASE_HEAD")) === pick;
|
|
1752
|
+
throw new InvalidArgumentError(
|
|
1753
|
+
"only",
|
|
1754
|
+
this.onlyPaths,
|
|
1755
|
+
`fatal: cannot do a partial commit during a ${rebasing ? "rebase" : "cherry-pick"}.`,
|
|
1756
|
+
);
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
let items: PathspecItem[];
|
|
1760
|
+
try {
|
|
1761
|
+
items = parsePathspec(this.onlyPaths, { attr: true });
|
|
1762
|
+
} catch (error) {
|
|
1763
|
+
throw new InvalidArgumentError("only", this.onlyPaths, `fatal: ${(error as Error).message}`);
|
|
1764
|
+
}
|
|
1765
|
+
// the elements as given (and the "." git adds when every element excludes)
|
|
1766
|
+
const originals =
|
|
1767
|
+
items.length > this.onlyPaths.length ? [...this.onlyPaths, "."] : [...this.onlyPaths];
|
|
1768
|
+
// git's overlay_tree_on_index: HEAD's files at stage 1, among the index's entries (its
|
|
1769
|
+
// conflict stages hoisted to 3), a HEAD file the index has at stage 0 left out; matched
|
|
1770
|
+
// in that order (the order decides what an element matched exactly skips, as in git)
|
|
1771
|
+
type Listed = { path: string; key: number; mode: number; skipWorktree: boolean };
|
|
1772
|
+
const listed: Listed[] = [];
|
|
1773
|
+
const stage0 = new Set<string>();
|
|
1774
|
+
for await (const entry of this.staging.entries()) {
|
|
1775
|
+
if (entry.stage === 0) stage0.add(entry.path);
|
|
1776
|
+
listed.push({
|
|
1777
|
+
path: entry.path,
|
|
1778
|
+
key: entry.stage === 0 ? 0 : 3,
|
|
1779
|
+
mode: entry.mode,
|
|
1780
|
+
skipWorktree: entry.skipWorktree === true,
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
if (headId) {
|
|
1784
|
+
const head = await this.commits.load(headId);
|
|
1785
|
+
if (!head) throw new RefNotFoundError(headId, "HEAD commit not found");
|
|
1786
|
+
// only the directories a positive element can match something in are read
|
|
1787
|
+
const positive = items.filter((i) => !i.exclude);
|
|
1788
|
+
const mayMatch = (dir: string) => positive.some((item) => pathspecItemMayMatch(item, dir));
|
|
1789
|
+
const files: Array<{ path: string; mode: number }> = [];
|
|
1790
|
+
await this.collectTreeFiles(head.tree, "", mayMatch, files);
|
|
1791
|
+
for (const file of files) {
|
|
1792
|
+
if (!stage0.has(file.path)) listed.push({ ...file, key: 1, skipWorktree: false });
|
|
1793
|
+
}
|
|
1794
|
+
listed.sort((a, b) => compareGitPaths(a.path, b.path) || a.key - b.key);
|
|
1795
|
+
}
|
|
1796
|
+
// `:(attr:...)`: the attributes of the listed paths (match_pathspec_attrs)
|
|
1797
|
+
const attributes = PathspecAttributes.forWorktree(items, this.getWorktreeIterator());
|
|
1798
|
+
await attributes?.load(listed.map((entry) => entry.path));
|
|
1799
|
+
const seen = items.map(() => 0);
|
|
1800
|
+
const paths = new Map<string, boolean>();
|
|
1801
|
+
for (const entry of listed) {
|
|
1802
|
+
const flags = isGitlink(entry.mode) ? DO_MATCH_DIRECTORY : 0;
|
|
1803
|
+
if (!matchPathspecSeen(items, entry.path, flags, seen)) continue;
|
|
1804
|
+
paths.set(entry.path, (paths.get(entry.path) ?? false) || entry.skipWorktree);
|
|
1805
|
+
}
|
|
1806
|
+
const errors = pathspecErrors(originals, seen);
|
|
1807
|
+
if (errors.length > 0) {
|
|
1808
|
+
// report_path_error: list_paths fails, prepare_index exits 1
|
|
1809
|
+
throw new InvalidArgumentError(
|
|
1810
|
+
"only",
|
|
1811
|
+
originals.filter((_, i) => !seen[i]),
|
|
1812
|
+
errors.join("\n"),
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
// git's string_list: sorted by the paths' bytes
|
|
1816
|
+
return new Map([...paths].sort(([a], [b]) => compareGitPaths(a, b)));
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
/** The files (and gitlinks) of a tree, in the directories `mayMatch` lets in. */
|
|
1820
|
+
private async collectTreeFiles(
|
|
465
1821
|
treeId: ObjectId,
|
|
466
1822
|
prefix: string,
|
|
467
|
-
|
|
1823
|
+
mayMatch: (dir: string) => boolean,
|
|
1824
|
+
files: Array<{ path: string; mode: number }>,
|
|
468
1825
|
): Promise<void> {
|
|
469
1826
|
for await (const entry of this.trees.loadTree(treeId)) {
|
|
470
|
-
const
|
|
1827
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
1828
|
+
if (entry.mode === FileMode.TREE) {
|
|
1829
|
+
if (mayMatch(path)) await this.collectTreeFiles(entry.id, path, mayMatch, files);
|
|
1830
|
+
} else {
|
|
1831
|
+
files.push({ path, mode: entry.mode });
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
/**
|
|
1837
|
+
* git's partial commit (`prepare_index`, `add_remove_files`): each listed path (but the
|
|
1838
|
+
* skip-worktree ones) as git's `add_remove_files` takes it, literally: a file (ignored or
|
|
1839
|
+
* not) hashed and staged, a path gone removed, a submodule staged at the commit checked
|
|
1840
|
+
* out in it, a directory without one refused before anything changes ("'<path>' does not
|
|
1841
|
+
* have a commit checked out"); the index then gets its
|
|
1842
|
+
* cache-tree (none while it holds conflicts) and is written into the lock. The tree
|
|
1843
|
+
* committed is HEAD's with the same paths taken (git's false index), returned as HEAD's
|
|
1844
|
+
* tree and those edits: stored by {@link storeFalseIndex}, never by a dry run.
|
|
1845
|
+
*/
|
|
1846
|
+
private async preparePartialCommit(
|
|
1847
|
+
paths: Map<string, boolean>,
|
|
1848
|
+
headId: ObjectId | undefined,
|
|
1849
|
+
index: HeldIndex,
|
|
1850
|
+
): Promise<FalseIndex> {
|
|
1851
|
+
const taken = [...paths].filter(([, skipWorktree]) => !skipWorktree).map(([path]) => path);
|
|
1852
|
+
// the lstat of each path, before the index is touched
|
|
1853
|
+
const found = new Map<string, WorktreeEntry | undefined>();
|
|
1854
|
+
let worktree: Worktree | undefined;
|
|
1855
|
+
if (taken.length > 0) {
|
|
1856
|
+
worktree = this.getWorktreeIterator();
|
|
1857
|
+
if (!worktree) {
|
|
1858
|
+
throw new StoreNotAvailableError(
|
|
1859
|
+
"Worktree",
|
|
1860
|
+
"Working tree iterator required for a partial commit. " +
|
|
1861
|
+
"Ensure WorkingCopy has worktree or call setWorktreeStore().",
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
if (worktree) {
|
|
1866
|
+
for (const path of taken) {
|
|
1867
|
+
const entry = await worktree.getEntry(path);
|
|
1868
|
+
// add_to_index of a directory: a gitlink to the commit checked out in the repository
|
|
1869
|
+
// there (index_path's resolve_gitlink_ref, a gitfile followed), refused before
|
|
1870
|
+
// anything changes when there is none; git 2.5x adds the "unable to index file" line
|
|
1871
|
+
if (entry?.isDirectory && !(await readGitlinkHead(worktree, path))) {
|
|
1872
|
+
throw new GitApiError(
|
|
1873
|
+
`error: '${path}' does not have a commit checked out\n` +
|
|
1874
|
+
`error: unable to index file '${path}'\nfatal: updating files failed`,
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1877
|
+
found.set(path, entry);
|
|
1878
|
+
}
|
|
1879
|
+
const trust = worktreeModeTrust(this.workingCopy, worktree);
|
|
1880
|
+
const adder = await IndexAdder.open(this.staging, this.blobs, trust);
|
|
1881
|
+
for (const path of taken) {
|
|
1882
|
+
const entry = found.get(path);
|
|
1883
|
+
if (entry) await adder.add(worktree, path, entry);
|
|
1884
|
+
else adder.remove(path);
|
|
1885
|
+
}
|
|
1886
|
+
await adder.finish();
|
|
1887
|
+
}
|
|
1888
|
+
// the real index, with a cache-tree made valid as git's cache_tree_update before
|
|
1889
|
+
// write_locked_index (none while it holds conflicts: the edits' invalidations stay)
|
|
1890
|
+
await updateIndexCacheTree(this.staging, this.trees);
|
|
1891
|
+
await index.write();
|
|
471
1892
|
|
|
472
|
-
|
|
473
|
-
|
|
1893
|
+
// the false index: HEAD's tree with the same paths as the index now has them
|
|
1894
|
+
const edits = new Map<string, { mode: number; id: ObjectId } | null>();
|
|
1895
|
+
for (const path of taken) {
|
|
1896
|
+
const entry = found.get(path) ? await this.staging.getEntry(path) : undefined;
|
|
1897
|
+
edits.set(
|
|
1898
|
+
path,
|
|
1899
|
+
entry && !entry.intentToAdd ? { mode: entry.mode, id: entry.objectId } : null,
|
|
1900
|
+
);
|
|
1901
|
+
}
|
|
1902
|
+
const head = headId ? await this.commits.load(headId) : undefined;
|
|
1903
|
+
if (headId && !head) throw new RefNotFoundError(headId, "HEAD commit not found");
|
|
1904
|
+
return { headTree: head?.tree, edits: [...edits] };
|
|
1905
|
+
}
|
|
474
1906
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
1907
|
+
/** The tree of a partial commit's false index, stored (with the directories it changes). */
|
|
1908
|
+
private async storeFalseIndex(falseIndex: FalseIndex): Promise<ObjectId> {
|
|
1909
|
+
return (await this.editTree(falseIndex.headTree, falseIndex.edits)) ?? this.trees.store([]);
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
/** The files of a partial commit's false index, without storing a tree. */
|
|
1913
|
+
private async falseIndexFiles(
|
|
1914
|
+
falseIndex: FalseIndex,
|
|
1915
|
+
): Promise<Map<string, { objectId: ObjectId; mode: number }>> {
|
|
1916
|
+
const flat: Map<string, { objectId: ObjectId; mode: number }> = await flatTree(
|
|
1917
|
+
this.trees,
|
|
1918
|
+
falseIndex.headTree,
|
|
1919
|
+
);
|
|
1920
|
+
for (const [path, edit] of falseIndex.edits) {
|
|
1921
|
+
if (edit) {
|
|
1922
|
+
// a file in place of a directory of HEAD (or the reverse) replaces it
|
|
1923
|
+
for (const key of [...flat.keys()]) if (key.startsWith(`${path}/`)) flat.delete(key);
|
|
1924
|
+
for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) {
|
|
1925
|
+
flat.delete(path.slice(0, at));
|
|
488
1926
|
}
|
|
1927
|
+
flat.set(path, { objectId: edit.id, mode: edit.mode });
|
|
1928
|
+
} else flat.delete(path);
|
|
1929
|
+
}
|
|
1930
|
+
return flat;
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
/**
|
|
1934
|
+
* A tree with the given files set (or removed, for null), only the directories on their
|
|
1935
|
+
* paths stored again; undefined when nothing is left in it.
|
|
1936
|
+
*/
|
|
1937
|
+
private async editTree(
|
|
1938
|
+
treeId: ObjectId | undefined,
|
|
1939
|
+
edits: Array<[string, { mode: number; id: ObjectId } | null]>,
|
|
1940
|
+
): Promise<ObjectId | undefined> {
|
|
1941
|
+
const entries = new Map<string, TreeEntry>();
|
|
1942
|
+
if (treeId) {
|
|
1943
|
+
for await (const entry of this.trees.loadTree(treeId)) entries.set(entry.name, entry);
|
|
1944
|
+
}
|
|
1945
|
+
const subdirs = new Map<string, Array<[string, { mode: number; id: ObjectId } | null]>>();
|
|
1946
|
+
for (const [path, edit] of edits) {
|
|
1947
|
+
const slash = path.indexOf("/");
|
|
1948
|
+
if (slash >= 0) {
|
|
1949
|
+
const dir = path.slice(0, slash);
|
|
1950
|
+
const list = subdirs.get(dir) ?? [];
|
|
1951
|
+
list.push([path.slice(slash + 1), edit]);
|
|
1952
|
+
subdirs.set(dir, list);
|
|
1953
|
+
} else if (edit) {
|
|
1954
|
+
entries.set(path, { name: path, mode: edit.mode, id: edit.id });
|
|
1955
|
+
} else if (entries.get(path)?.mode !== FileMode.TREE) {
|
|
1956
|
+
entries.delete(path);
|
|
489
1957
|
}
|
|
490
1958
|
}
|
|
1959
|
+
for (const [dir, list] of subdirs) {
|
|
1960
|
+
const existing = entries.get(dir);
|
|
1961
|
+
const base = existing?.mode === FileMode.TREE ? existing.id : undefined;
|
|
1962
|
+
const id = await this.editTree(base, list);
|
|
1963
|
+
if (id) entries.set(dir, { name: dir, mode: FileMode.TREE, id });
|
|
1964
|
+
else if (base) entries.delete(dir);
|
|
1965
|
+
}
|
|
1966
|
+
if (entries.size === 0) return undefined;
|
|
1967
|
+
return this.trees.store([...entries.values()]);
|
|
491
1968
|
}
|
|
492
1969
|
|
|
493
1970
|
/**
|
|
@@ -496,7 +1973,7 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
496
1973
|
* Uses AddCommand with setUpdate(true) to stage changes,
|
|
497
1974
|
* equivalent to `git add -u .` which JGit does for --all.
|
|
498
1975
|
*/
|
|
499
|
-
private async stageTrackedChanges(): Promise<void> {
|
|
1976
|
+
private async stageTrackedChanges(paths: string[] = []): Promise<void> {
|
|
500
1977
|
// Get working tree iterator
|
|
501
1978
|
const worktree = this.getWorktreeIterator();
|
|
502
1979
|
if (!worktree) {
|
|
@@ -508,9 +1985,15 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
508
1985
|
}
|
|
509
1986
|
|
|
510
1987
|
// Use AddCommand to stage all modified tracked files
|
|
1988
|
+
// git's add_files_to_cache without a pathspec (`commit -a`): no element to report
|
|
511
1989
|
const addCommand = new AddCommand(this._workingCopy);
|
|
512
|
-
addCommand.addFilepattern(".");
|
|
513
1990
|
addCommand.setUpdate(true);
|
|
1991
|
+
// `-i <paths>`: the tracked paths they match (report_path_error: an element matching no
|
|
1992
|
+
// index entry fails, exit status 128)
|
|
1993
|
+
for (const path of paths) addCommand.addFilepattern(path);
|
|
1994
|
+
if (paths.length > 0) addCommand.setFilesToCache(true);
|
|
1995
|
+
// into the index lock the commit holds, once the commit's tree is made
|
|
1996
|
+
addCommand.setWriteIndex(false);
|
|
514
1997
|
addCommand.setWorktreeStore(worktree);
|
|
515
1998
|
await addCommand.call();
|
|
516
1999
|
}
|
|
@@ -527,3 +2010,135 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
527
2010
|
return this.worktreeAccess;
|
|
528
2011
|
}
|
|
529
2012
|
}
|
|
2013
|
+
|
|
2014
|
+
/** git's "paths '<first> ...' with -a does not make sense". */
|
|
2015
|
+
function pathsWithAllError(paths: readonly string[]): IncompatibleOptionsError {
|
|
2016
|
+
return new IncompatibleOptionsError(
|
|
2017
|
+
["--all", "--only"],
|
|
2018
|
+
`fatal: paths '${paths[0]} ...' with -a does not make sense`,
|
|
2019
|
+
);
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
/** A partial commit's false index written for the hooks (see `writeFalseIndexFile`). */
|
|
2023
|
+
interface FalseIndexFile {
|
|
2024
|
+
/** Its absolute host path (else its path from the worktree top): `GIT_INDEX_FILE` */
|
|
2025
|
+
hostPath: string;
|
|
2026
|
+
/** Reads it back as a hook left it: the tree to commit */
|
|
2027
|
+
reread(): Promise<ObjectId>;
|
|
2028
|
+
/** Removes it (git's rollback of `false_lock`) */
|
|
2029
|
+
remove(): Promise<void>;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
/** A held index whose commit or release also runs `cleanup` (after the index's own). */
|
|
2033
|
+
function withCleanup(index: HeldIndex, cleanup: () => Promise<void>): HeldIndex {
|
|
2034
|
+
return {
|
|
2035
|
+
write: () => index.write(),
|
|
2036
|
+
reread: () => index.reread(),
|
|
2037
|
+
commit: async () => {
|
|
2038
|
+
try {
|
|
2039
|
+
await index.commit();
|
|
2040
|
+
} finally {
|
|
2041
|
+
await cleanup();
|
|
2042
|
+
}
|
|
2043
|
+
},
|
|
2044
|
+
release: async () => {
|
|
2045
|
+
try {
|
|
2046
|
+
await index.release();
|
|
2047
|
+
} finally {
|
|
2048
|
+
await cleanup();
|
|
2049
|
+
}
|
|
2050
|
+
},
|
|
2051
|
+
};
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
/** A partial commit's false index: HEAD's tree with the named paths set or removed. */
|
|
2055
|
+
interface FalseIndex {
|
|
2056
|
+
headTree: ObjectId | undefined;
|
|
2057
|
+
edits: Array<[string, { mode: number; id: ObjectId } | null]>;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
/**
|
|
2061
|
+
* The index lock another process holds, as git's `unable_to_lock_die` reports it (git 2.5x's
|
|
2062
|
+
* wording: 2.43 adds "e.g. an editor opened by 'git commit'..." instead); other errors as
|
|
2063
|
+
* they are.
|
|
2064
|
+
*/
|
|
2065
|
+
function indexLockError(error: unknown, workingCopy: unknown): unknown {
|
|
2066
|
+
if (!(error instanceof Error) || error.name !== "IndexLockedError") return error;
|
|
2067
|
+
const gitDir = (workingCopy as { config?: { hostGitDir?: string } }).config?.hostGitDir;
|
|
2068
|
+
const lockPath = gitDir ? `${gitDir.replace(/\/+$/, "")}/index.lock` : ".git/index.lock";
|
|
2069
|
+
return new IndexLockFailedError(
|
|
2070
|
+
lockPath,
|
|
2071
|
+
`fatal: Unable to create '${lockPath}': File exists.\n\n` +
|
|
2072
|
+
"Another git process seems to be running in this repository, or the lock file may be stale",
|
|
2073
|
+
{ cause: error },
|
|
2074
|
+
);
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
/** The index a commit holds while it changes it (see `CommitCommand.holdIndex`). */
|
|
2078
|
+
interface HeldIndex {
|
|
2079
|
+
/** Writes the staging's entries into the index lock (nothing without an index file). */
|
|
2080
|
+
write(): Promise<void>;
|
|
2081
|
+
/** Reads the index lock back into the staging, as a hook left it (git's read_index_from). */
|
|
2082
|
+
reread(): Promise<void>;
|
|
2083
|
+
/** The index lock renamed over the index (a staging without one: written). */
|
|
2084
|
+
commit(): Promise<void>;
|
|
2085
|
+
/** On failure: the lock removed, the staging as it was before. Idempotent. */
|
|
2086
|
+
release(): Promise<void>;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
/** Every entry of the staging, in its order. */
|
|
2090
|
+
async function collectEntries(staging: Staging): Promise<StagingEntry[]> {
|
|
2091
|
+
const out: StagingEntry[] = [];
|
|
2092
|
+
for await (const entry of staging.entries()) out.push(entry);
|
|
2093
|
+
return out;
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
const isGitlink = (mode: number) => (mode & 0o170000) === 0o160000;
|
|
2097
|
+
|
|
2098
|
+
/**
|
|
2099
|
+
* git's `template_untouched`: the cleaned-up message is the template (cleaned up the same
|
|
2100
|
+
* way, comments kept unless the mode strips them) followed by nothing but whitespace and
|
|
2101
|
+
* sign-offs. A verbatim message that is not empty is never untouched; nor is any without a
|
|
2102
|
+
* template (or with an empty one).
|
|
2103
|
+
*/
|
|
2104
|
+
function templateUntouched(
|
|
2105
|
+
message: string,
|
|
2106
|
+
template: string | undefined,
|
|
2107
|
+
mode: CleanupMode,
|
|
2108
|
+
comment: string,
|
|
2109
|
+
): boolean {
|
|
2110
|
+
if (mode === CleanupMode.VERBATIM && message.length > 0) return false;
|
|
2111
|
+
if (!template) return false;
|
|
2112
|
+
const tmpl = stripspace(template, mode === CleanupMode.STRIP ? comment : undefined);
|
|
2113
|
+
const rest = message.startsWith(tmpl) ? message.slice(tmpl.length) : message;
|
|
2114
|
+
return isEmptyMessage(rest);
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
/** git's `rest_is_empty`: only whitespace and `Signed-off-by:` lines. */
|
|
2118
|
+
function isEmptyMessage(message: string): boolean {
|
|
2119
|
+
return message
|
|
2120
|
+
.split("\n")
|
|
2121
|
+
.every((line) => line.startsWith("Signed-off-by: ") || /^[ \t\r]*$/.test(line));
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
/** A git boolean (`fallback` when unset or not one). */
|
|
2125
|
+
function parseBool(value: string | undefined, fallback: boolean): boolean {
|
|
2126
|
+
if (value === undefined) return fallback;
|
|
2127
|
+
const v = value.trim().toLowerCase();
|
|
2128
|
+
if (v === "" || v === "false" || v === "no" || v === "off" || v === "0") return false;
|
|
2129
|
+
if (v === "true" || v === "yes" || v === "on" || v === "1") return true;
|
|
2130
|
+
return fallback;
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
/**
|
|
2134
|
+
* The editor of a commit message (`CommitCommand.setEditor`): the path of the message file
|
|
2135
|
+
* within the git directory (`COMMIT_EDITMSG`) and its text; it returns the edited text, or
|
|
2136
|
+
* nothing (anything but a string) when it edited the file in place.
|
|
2137
|
+
*/
|
|
2138
|
+
export type CommitEditor = (path: string, text: string) => Promise<unknown>;
|
|
2139
|
+
|
|
2140
|
+
/** What `CommitCommand.callDryRun` gives: the status text and git's exit code. */
|
|
2141
|
+
export interface CommitDryRunResult extends StatusTextResult {
|
|
2142
|
+
/** 0 when there is something to commit, 1 when not (dry_run_commit) */
|
|
2143
|
+
exitCode: number;
|
|
2144
|
+
}
|