@statewalker/vcs-commands 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/add-command.d.ts +32 -0
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-patch.d.ts +7 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
- package/dist/commands/am/am-command.d.ts +47 -0
- package/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-command.d.ts +2 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.d.ts +7 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -1
- package/dist/commands/apply/index.d.ts +1 -1
- package/dist/commands/apply/index.d.ts.map +1 -1
- package/dist/commands/blame-command.d.ts +303 -8
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/blame-ignore.d.ts +48 -0
- package/dist/commands/blame-ignore.d.ts.map +1 -0
- package/dist/commands/check-mailmap-command.d.ts +49 -0
- package/dist/commands/check-mailmap-command.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +7 -0
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +4 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -1
- package/dist/commands/cherry-command.d.ts +61 -0
- package/dist/commands/cherry-command.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +23 -1
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +32 -0
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clean-interactive.d.ts +56 -0
- package/dist/commands/clean-interactive.d.ts.map +1 -0
- package/dist/commands/clone-command.d.ts +116 -2
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +50 -2
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/describe-command.d.ts +71 -64
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +118 -6
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/fetch-command.d.ts +60 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fetch-multiple-command.d.ts +193 -0
- package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
- package/dist/commands/format-patch-command.d.ts +28 -2
- package/dist/commands/format-patch-command.d.ts.map +1 -1
- package/dist/commands/git-describe.d.ts +77 -4
- package/dist/commands/git-describe.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +15 -1
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/index.d.ts +12 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +5 -3
- package/dist/commands/init-command.d.ts +89 -0
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/line-log.d.ts +161 -0
- package/dist/commands/line-log.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +235 -6
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +4 -2
- package/dist/commands/log-graph.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +66 -1
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +24 -1
- package/dist/commands/mailmap.d.ts.map +1 -1
- package/dist/commands/merge-command.d.ts +51 -1
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-drivers.d.ts +2 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -1
- package/dist/commands/merge-strategy-options.d.ts +69 -0
- package/dist/commands/merge-strategy-options.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +10 -0
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/message-cleanup.d.ts +2 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -1
- package/dist/commands/name-rev-command.d.ts +65 -0
- package/dist/commands/name-rev-command.d.ts.map +1 -0
- package/dist/commands/name-rev.d.ts +110 -22
- package/dist/commands/name-rev.d.ts.map +1 -1
- package/dist/commands/octopus-merge.d.ts +26 -1
- package/dist/commands/octopus-merge.d.ts.map +1 -1
- package/dist/commands/ort-merge.d.ts +16 -0
- package/dist/commands/ort-merge.d.ts.map +1 -1
- package/dist/commands/ort-recursive.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +58 -0
- package/dist/commands/patch-id.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts +182 -38
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +65 -0
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/range-diff/index.d.ts +4 -0
- package/dist/commands/range-diff/index.d.ts.map +1 -0
- package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
- package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
- package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff.d.ts +106 -0
- package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
- package/dist/commands/read-tree-command.d.ts +14 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +21 -2
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/remerge-diff.d.ts +59 -0
- package/dist/commands/remerge-diff.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +41 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-show-command.d.ts +204 -0
- package/dist/commands/remote-show-command.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +19 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +7 -0
- package/dist/commands/restore-command.d.ts.map +1 -1
- package/dist/commands/rev-list-command.d.ts +75 -3
- package/dist/commands/rev-list-command.d.ts.map +1 -1
- package/dist/commands/revert-command.d.ts +22 -1
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +2 -0
- package/dist/commands/revision-range.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +102 -1
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts +10 -1
- package/dist/commands/sequencer-support.d.ts.map +1 -1
- package/dist/commands/shortlog-command.d.ts +109 -0
- package/dist/commands/shortlog-command.d.ts.map +1 -0
- package/dist/commands/shortlog.d.ts +151 -0
- package/dist/commands/shortlog.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +31 -2
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/submodule-commands.d.ts +90 -2
- package/dist/commands/submodule-commands.d.ts.map +1 -1
- package/dist/commands/submodule-fetch.d.ts +149 -0
- package/dist/commands/submodule-fetch.d.ts.map +1 -0
- package/dist/commands/submodule-model.d.ts +8 -0
- package/dist/commands/submodule-model.d.ts.map +1 -1
- package/dist/commands/submodule-unpack.d.ts +120 -0
- package/dist/commands/submodule-unpack.d.ts.map +1 -0
- package/dist/commands/submodule-update-command.d.ts +8 -0
- package/dist/commands/submodule-update-command.d.ts.map +1 -1
- package/dist/commands/subtree-shift.d.ts +27 -0
- package/dist/commands/subtree-shift.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +3 -0
- package/dist/commands/switch-command.d.ts.map +1 -1
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/{commands-ISM52N0n.js → commands-CNvli5bl.js} +39426 -61169
- package/dist/errors/command-errors.d.ts +25 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/index.js +29 -1
- package/dist/fsck-CPeDh9fh.js +5138 -0
- package/dist/git-command.d.ts +31 -1
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +97 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/guarded-transport-command.d.ts +82 -0
- package/dist/guarded-transport-command.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/remote-transport-CCmBadm-.js +1606 -0
- package/dist/rename/detect-renames.d.ts +20 -0
- package/dist/rename/detect-renames.d.ts.map +1 -1
- package/dist/rename/diffcore-break.d.ts +51 -0
- package/dist/rename/diffcore-break.d.ts.map +1 -0
- package/dist/rename/index.d.ts +1 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/blame-format.d.ts +62 -1
- package/dist/results/blame-format.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +9 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/diff-dirstat.d.ts +36 -0
- package/dist/results/diff-dirstat.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +10 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-output.d.ts +18 -0
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/fetch-result.d.ts +12 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +2 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/init-result.d.ts +8 -1
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/line-range-hunks.d.ts +27 -0
- package/dist/results/line-range-hunks.d.ts.map +1 -0
- package/dist/results/merge-result.d.ts +8 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +11 -0
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +5 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +1 -1
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BDuEgdLU.js +46847 -0
- package/dist/transport-command.d.ts +14 -0
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/commands/add-command.ts +115 -0
- package/src/commands/add-patch/add-patch.ts +8 -0
- package/src/commands/add-patch/patch-backend.ts +20 -2
- package/src/commands/am/am-command.ts +138 -4
- package/src/commands/apply/apply-command.ts +52 -9
- package/src/commands/apply/apply-parse.ts +10 -0
- package/src/commands/apply/index.ts +8 -1
- package/src/commands/blame-command.ts +1450 -51
- package/src/commands/blame-ignore.ts +307 -0
- package/src/commands/check-mailmap-command.ts +129 -0
- package/src/commands/checkout-command.ts +97 -12
- package/src/commands/checkout-paths.ts +28 -0
- package/src/commands/cherry-command.ts +187 -0
- package/src/commands/cherry-pick-command.ts +42 -1
- package/src/commands/clean-command.ts +92 -12
- package/src/commands/clean-interactive.ts +522 -0
- package/src/commands/clone-command.ts +596 -44
- package/src/commands/commit-command.ts +180 -47
- package/src/commands/describe-command.ts +341 -254
- package/src/commands/diff-command.ts +616 -56
- package/src/commands/fetch-command.ts +353 -6
- package/src/commands/fetch-multiple-command.ts +665 -0
- package/src/commands/format-patch-command.ts +189 -77
- package/src/commands/git-describe.ts +456 -217
- package/src/commands/git-hooks.ts +42 -3
- package/src/commands/index.ts +17 -0
- package/src/commands/init-command.ts +603 -49
- package/src/commands/line-log.ts +931 -0
- package/src/commands/log-command.ts +1414 -177
- package/src/commands/log-graph.ts +6 -3
- package/src/commands/log-output.ts +173 -10
- package/src/commands/mailmap.ts +41 -5
- package/src/commands/merge-command.ts +274 -16
- package/src/commands/merge-drivers.ts +3 -0
- package/src/commands/merge-strategy-options.ts +224 -0
- package/src/commands/merge-support.ts +101 -21
- package/src/commands/message-cleanup.ts +1 -1
- package/src/commands/name-rev-command.ts +184 -0
- package/src/commands/name-rev.ts +700 -109
- package/src/commands/octopus-merge.ts +35 -11
- package/src/commands/ort-merge.ts +41 -7
- package/src/commands/ort-recursive.ts +40 -2
- package/src/commands/patch-id.ts +109 -0
- package/src/commands/pull-command.ts +718 -224
- package/src/commands/push-command.ts +353 -3
- package/src/commands/range-diff/index.ts +3 -0
- package/src/commands/range-diff/linear-assignment.ts +203 -0
- package/src/commands/range-diff/range-diff-command.ts +433 -0
- package/src/commands/range-diff/range-diff.ts +617 -0
- package/src/commands/read-tree-command.ts +74 -3
- package/src/commands/rebase-command.ts +141 -65
- package/src/commands/remerge-diff.ts +241 -0
- package/src/commands/remote-command.ts +98 -10
- package/src/commands/remote-show-command.ts +836 -0
- package/src/commands/reset-command.ts +78 -3
- package/src/commands/restore-command.ts +15 -0
- package/src/commands/rev-list-command.ts +187 -11
- package/src/commands/revert-command.ts +41 -1
- package/src/commands/revision-range.ts +3 -1
- package/src/commands/sequencer-pick.ts +323 -29
- package/src/commands/sequencer-support.ts +164 -2
- package/src/commands/shortlog-command.ts +354 -0
- package/src/commands/shortlog.ts +361 -0
- package/src/commands/show-command.ts +2 -1
- package/src/commands/status-command.ts +115 -25
- package/src/commands/status-format.ts +1 -1
- package/src/commands/submodule-commands.ts +321 -3
- package/src/commands/submodule-fetch.ts +789 -0
- package/src/commands/submodule-model.ts +9 -1
- package/src/commands/submodule-unpack.ts +265 -0
- package/src/commands/submodule-update-command.ts +39 -5
- package/src/commands/subtree-shift.ts +215 -0
- package/src/commands/switch-command.ts +9 -0
- package/src/commands/tree-restore.ts +6 -1
- package/src/commands/worktree-overwrite-checks.ts +5 -0
- package/src/errors/command-errors.ts +35 -0
- package/src/git-command.ts +87 -1
- package/src/git.ts +146 -0
- package/src/guarded-transport-command.ts +171 -0
- package/src/index.ts +1 -0
- package/src/rename/detect-renames.ts +42 -8
- package/src/rename/diffcore-break.ts +166 -0
- package/src/rename/index.ts +1 -0
- package/src/results/blame-format.ts +268 -43
- package/src/results/clone-result.ts +6 -0
- package/src/results/diff-dirstat.ts +117 -0
- package/src/results/diff-entry.ts +12 -0
- package/src/results/diff-formatter.ts +1 -0
- package/src/results/diff-output.ts +127 -2
- package/src/results/fetch-result.ts +12 -1
- package/src/results/index.ts +2 -0
- package/src/results/init-result.ts +10 -1
- package/src/results/line-range-hunks.ts +126 -0
- package/src/results/merge-result.ts +9 -0
- package/src/results/pull-result.ts +7 -0
- package/src/results/push-result.ts +5 -0
- package/src/results/status-result.ts +2 -2
- package/src/transport-command.ts +34 -3
- package/dist/fsck-DLRpbwTj.js +0 -13405
- package/dist/results-TB2IJ64h.js +0 -4700
|
@@ -33,6 +33,15 @@ import {
|
|
|
33
33
|
import { GitCommand } from "../git-command.js";
|
|
34
34
|
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
35
35
|
import { AddCommand } from "./add-command.js";
|
|
36
|
+
import {
|
|
37
|
+
type PatchCompatibility,
|
|
38
|
+
type PatchOptions,
|
|
39
|
+
type PatchResult,
|
|
40
|
+
type PatchSelector,
|
|
41
|
+
patchModeFor,
|
|
42
|
+
runPatchSelection,
|
|
43
|
+
type TemporaryIndex,
|
|
44
|
+
} from "./add-patch/index.js";
|
|
36
45
|
import {
|
|
37
46
|
amendCommitText,
|
|
38
47
|
autosquashSubject,
|
|
@@ -54,10 +63,10 @@ import {
|
|
|
54
63
|
} from "./git-ident.js";
|
|
55
64
|
import { IndexAdder, readGitlinkHead } from "./index-adder.js";
|
|
56
65
|
import { reencodedCommitParts } from "./log-output.js";
|
|
57
|
-
import { readRepositoryMailmap } from "./mailmap.js";
|
|
58
66
|
import {
|
|
59
67
|
flatTree,
|
|
60
68
|
OperationState,
|
|
69
|
+
rewriteIndex,
|
|
61
70
|
updateIndexCacheTree,
|
|
62
71
|
writeIndexAsTree,
|
|
63
72
|
} from "./merge-support.js";
|
|
@@ -163,6 +172,8 @@ export interface CommitResult extends Commit {
|
|
|
163
172
|
* ```
|
|
164
173
|
*/
|
|
165
174
|
export class CommitCommand extends GitCommand<CommitResult> {
|
|
175
|
+
/** git's `error:` lines that do not stop the commit ({@link getWarnings}) */
|
|
176
|
+
private readonly stderrLines: string[] = [];
|
|
166
177
|
private message?: string;
|
|
167
178
|
private author?: PersonIdent;
|
|
168
179
|
private committer?: PersonIdent;
|
|
@@ -215,6 +226,12 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
215
226
|
private squashFrom?: string;
|
|
216
227
|
/** --fixup, parsed when the commit runs */
|
|
217
228
|
private fixup?: { kind: FixupKind; target: string };
|
|
229
|
+
/** `-p` / `--patch` */
|
|
230
|
+
private patch = false;
|
|
231
|
+
private patchSelector?: PatchSelector;
|
|
232
|
+
private patchOptions: PatchOptions = {};
|
|
233
|
+
private patchCompatibility: PatchCompatibility = "2.56";
|
|
234
|
+
private patchResult?: PatchResult;
|
|
218
235
|
|
|
219
236
|
/**
|
|
220
237
|
* Set the commit message, as git's `commit -m` takes it: its last line is ended and it is
|
|
@@ -535,6 +552,59 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
535
552
|
return this;
|
|
536
553
|
}
|
|
537
554
|
|
|
555
|
+
/**
|
|
556
|
+
* `git commit -p` (`--patch`): the changes between the index and the worktree are offered
|
|
557
|
+
* hunk by hunk as `git add -p` offers them, and the selected hunks are committed along
|
|
558
|
+
* with what is staged already. As git's prepare_index for `--interactive`: the index lock
|
|
559
|
+
* is taken and the refreshed index written into it, the hunks are applied to that
|
|
560
|
+
* temporary index (`GIT_INDEX_FILE` at the lock), and the commit is made from it; the lock
|
|
561
|
+
* becomes the index once HEAD has moved, and on any failure (nothing selected: "no changes
|
|
562
|
+
* added to commit") the index stays as it was. The paths of {@link setOnly} limit the
|
|
563
|
+
* hunks offered. The prompts are answered by {@link setPatchSelector}; what patch mode
|
|
564
|
+
* printed is {@link getPatchResult}'s. Refused with {@link setAll} and
|
|
565
|
+
* {@link setInclude}.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```typescript
|
|
569
|
+
* const answers = ["y", "n"];
|
|
570
|
+
* const commit = git.commit().setMessage("Part").setPatch(true)
|
|
571
|
+
* .setPatchSelector(() => answers.shift());
|
|
572
|
+
* await commit.call();
|
|
573
|
+
* process.stdout.write(commit.getPatchResult()?.output ?? "");
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
setPatch(patch: boolean): this {
|
|
577
|
+
this.checkCallable();
|
|
578
|
+
this.patch = patch;
|
|
579
|
+
return this;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** Answers the prompts of {@link setPatch} (git's reads from standard input and its editor). */
|
|
583
|
+
setPatchSelector(selector: PatchSelector): this {
|
|
584
|
+
this.checkCallable();
|
|
585
|
+
this.patchSelector = selector;
|
|
586
|
+
return this;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** `-U<n>` and `--inter-hunk-context=<n>` of {@link setPatch}. */
|
|
590
|
+
setPatchOptions(options: PatchOptions): this {
|
|
591
|
+
this.checkCallable();
|
|
592
|
+
this.patchOptions = { ...options };
|
|
593
|
+
return this;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/** The git version whose patch-mode prompts {@link setPatch} reproduces (default 2.56). */
|
|
597
|
+
setCompatibility(version: PatchCompatibility): this {
|
|
598
|
+
this.checkCallable();
|
|
599
|
+
this.patchCompatibility = version;
|
|
600
|
+
return this;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** What {@link setPatch}'s selection printed and applied; read after {@link call}. */
|
|
604
|
+
getPatchResult(): PatchResult | undefined {
|
|
605
|
+
return this.patchResult;
|
|
606
|
+
}
|
|
607
|
+
|
|
538
608
|
/**
|
|
539
609
|
* Set whether to auto-stage modified tracked files before committing.
|
|
540
610
|
*
|
|
@@ -1258,6 +1328,7 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
1258
1328
|
// the index as it is now: one another writer replaced is read again (git reads the
|
|
1259
1329
|
// index at its start), unless this instance holds unwritten edits (refused)
|
|
1260
1330
|
await this.readCurrentIndex();
|
|
1331
|
+
if (this.patch) return this.commitPatch();
|
|
1261
1332
|
this.applyPathspecFile();
|
|
1262
1333
|
if (this.include) return this.commitIncluded();
|
|
1263
1334
|
// `--fixup=reword:` is a partial commit of no path: HEAD's tree (git sets `only`)
|
|
@@ -1279,6 +1350,85 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
1279
1350
|
}
|
|
1280
1351
|
}
|
|
1281
1352
|
|
|
1353
|
+
/**
|
|
1354
|
+
* `-p` (git's prepare_index for `interactive`): the option checks, then the index lock held
|
|
1355
|
+
* and the hunks selected into the index it holds (`interactive_add` with `GIT_INDEX_FILE`
|
|
1356
|
+
* at the lock), then the commit from it.
|
|
1357
|
+
*/
|
|
1358
|
+
private async commitPatch(): Promise<CommitResult> {
|
|
1359
|
+
// parse_and_validate_options: -i, -o, -a and --interactive/-p exclude each other
|
|
1360
|
+
if (this.include || this.all) {
|
|
1361
|
+
const other = this.include ? "-i/--include" : "-a/--all";
|
|
1362
|
+
throw new IncompatibleOptionsError(
|
|
1363
|
+
[other, "--interactive/-p/--patch"],
|
|
1364
|
+
`fatal: options '${other}' and '--interactive/-p/--patch' cannot be used together`,
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1367
|
+
if (this.pathspecFile.given) {
|
|
1368
|
+
throw new IncompatibleOptionsError(
|
|
1369
|
+
["--pathspec-from-file", "--interactive/--patch"],
|
|
1370
|
+
"fatal: options '--pathspec-from-file' and '--interactive/--patch' cannot be used together",
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
const index = await this.holdIndex();
|
|
1374
|
+
try {
|
|
1375
|
+
// refresh_cache_or_die: an unmerged entry dies before anything is asked
|
|
1376
|
+
if (await this.staging.hasConflicts())
|
|
1377
|
+
throw unmergedPathsError(await this.staging.getConflictedPaths());
|
|
1378
|
+
const temporary: TemporaryIndex = new Map();
|
|
1379
|
+
const entries = new Map<string, StagingEntry>();
|
|
1380
|
+
for await (const entry of this.staging.entries()) {
|
|
1381
|
+
if (entry.stage !== 0) continue;
|
|
1382
|
+
entries.set(entry.path, entry);
|
|
1383
|
+
const { path: _p, mode, objectId, stage: _s, ...carried } = entry;
|
|
1384
|
+
temporary.set(entry.path, { mode, objectId, carried });
|
|
1385
|
+
}
|
|
1386
|
+
this.patchResult = await runPatchSelection(this.workingCopy, {
|
|
1387
|
+
hookSource: this,
|
|
1388
|
+
...this.patchOptions,
|
|
1389
|
+
mode: patchModeFor("add"),
|
|
1390
|
+
selector: this.patchSelector,
|
|
1391
|
+
paths: this.onlyPaths,
|
|
1392
|
+
compatibility: this.patchCompatibility,
|
|
1393
|
+
temporaryIndex: temporary,
|
|
1394
|
+
});
|
|
1395
|
+
// the temporary index read back into the held index: entries apply rewrote (no stat
|
|
1396
|
+
// data, as `apply --cached` writes them), and the paths it removed
|
|
1397
|
+
const changes = new Map<string, StagingEntry[]>();
|
|
1398
|
+
for (const [path, entry] of temporary) {
|
|
1399
|
+
const old = entries.get(path);
|
|
1400
|
+
// an entry apply rewrote with the same blob (an empty intent-to-add file staged)
|
|
1401
|
+
// loses its intent-to-add flag, so it is no longer the entry it was
|
|
1402
|
+
if (
|
|
1403
|
+
old &&
|
|
1404
|
+
old.mode === entry.mode &&
|
|
1405
|
+
old.objectId === entry.objectId &&
|
|
1406
|
+
!!old.intentToAdd === !!entry.carried?.intentToAdd
|
|
1407
|
+
) {
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
changes.set(path, [
|
|
1411
|
+
{
|
|
1412
|
+
path,
|
|
1413
|
+
mode: entry.mode,
|
|
1414
|
+
objectId: entry.objectId,
|
|
1415
|
+
stage: 0,
|
|
1416
|
+
size: 0,
|
|
1417
|
+
mtime: 0,
|
|
1418
|
+
} as StagingEntry,
|
|
1419
|
+
]);
|
|
1420
|
+
}
|
|
1421
|
+
for (const path of entries.keys()) if (!temporary.has(path)) changes.set(path, []);
|
|
1422
|
+
if (changes.size > 0) {
|
|
1423
|
+
await rewriteIndex(this.staging, changes, { upToDate: false, write: false });
|
|
1424
|
+
}
|
|
1425
|
+
return await this.withOneIndexWrite("first", () => this.commitWith(false, index));
|
|
1426
|
+
} catch (error) {
|
|
1427
|
+
await index.release();
|
|
1428
|
+
throw error;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1282
1432
|
/**
|
|
1283
1433
|
* `-i <paths>` (git's prepare_index for `also`): the option checks of
|
|
1284
1434
|
* parse_and_validate_options and prepare_index, then the index lock held from before the
|
|
@@ -1328,29 +1478,6 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
1328
1478
|
if (this.forceDate) this.forcedDate();
|
|
1329
1479
|
}
|
|
1330
1480
|
|
|
1331
|
-
/** A blob's bytes, undefined when it cannot be read. */
|
|
1332
|
-
private async readBlobBytes(id: ObjectId): Promise<Uint8Array | undefined> {
|
|
1333
|
-
try {
|
|
1334
|
-
const content = await this.blobs.load(id);
|
|
1335
|
-
if (!content) return undefined;
|
|
1336
|
-
const chunks: Uint8Array[] = [];
|
|
1337
|
-
let size = 0;
|
|
1338
|
-
for await (const c of content) {
|
|
1339
|
-
chunks.push(c);
|
|
1340
|
-
size += c.length;
|
|
1341
|
-
}
|
|
1342
|
-
const out = new Uint8Array(size);
|
|
1343
|
-
let at = 0;
|
|
1344
|
-
for (const c of chunks) {
|
|
1345
|
-
out.set(c, at);
|
|
1346
|
-
at += c.length;
|
|
1347
|
-
}
|
|
1348
|
-
return out;
|
|
1349
|
-
} catch {
|
|
1350
|
-
return undefined;
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
1481
|
/**
|
|
1355
1482
|
* `--date` (parse_force_date): the date as `parse_date` reads it, else as `approxidate`
|
|
1356
1483
|
* does, refused as git refuses it.
|
|
@@ -1367,6 +1494,14 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
1367
1494
|
return date;
|
|
1368
1495
|
}
|
|
1369
1496
|
|
|
1497
|
+
/**
|
|
1498
|
+
* git's `error:` lines that did not stop the command (the mailmap's, read for an
|
|
1499
|
+
* `--author` that is no `Name <email>`), in order; also after a failure.
|
|
1500
|
+
*/
|
|
1501
|
+
getWarnings(): string[] {
|
|
1502
|
+
return [...this.stderrLines];
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1370
1505
|
/**
|
|
1371
1506
|
* builtin/commit.c's find_author_by_nickname: the first commit of `rev-list --all -i
|
|
1372
1507
|
* --author=<name>` (newest first, the mailmap applied before matching) gives `%aN <%aE>`.
|
|
@@ -1382,18 +1517,10 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
1382
1517
|
`fatal: '${name}': ${error instanceof Error ? error.message : String(error)}`,
|
|
1383
1518
|
);
|
|
1384
1519
|
}
|
|
1385
|
-
|
|
1386
|
-
const
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
environment: hostEnvironmentOf(this.workingCopy),
|
|
1390
|
-
readBlobNamed: async (blob) => {
|
|
1391
|
-
const id = await this.revisionResolver()
|
|
1392
|
-
.resolve(blob)
|
|
1393
|
-
.catch(() => undefined);
|
|
1394
|
-
return id ? this.readBlobBytes(id) : undefined;
|
|
1395
|
-
},
|
|
1396
|
-
});
|
|
1520
|
+
// rev.mailmap's read; pretty.c reads it again for the `%aN <%aE>` of the match
|
|
1521
|
+
const mailmapErrors: string[] = [];
|
|
1522
|
+
const mailmap = await this.readMailmap((line) => mailmapErrors.push(line));
|
|
1523
|
+
this.stderrLines.push(...mailmapErrors);
|
|
1397
1524
|
const encoder = new TextEncoder();
|
|
1398
1525
|
// revision.c's walk of --all: refs under refs/ in name order, then HEAD, tags peeled;
|
|
1399
1526
|
// commits come out by commit date, newest first
|
|
@@ -1437,6 +1564,7 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
1437
1564
|
if (!next) break;
|
|
1438
1565
|
const who = mailmap.map(next.commit.author.name, next.commit.author.email);
|
|
1439
1566
|
if (pattern.test(encoder.encode(`${who.name} <${who.email}>`))) {
|
|
1567
|
+
this.stderrLines.push(...mailmapErrors);
|
|
1440
1568
|
return `${who.name} <${who.email}>`;
|
|
1441
1569
|
}
|
|
1442
1570
|
for (const parent of next.commit.parents) await put(parent);
|
|
@@ -1517,7 +1645,8 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
1517
1645
|
`fatal: reword option of '--fixup' and path '${path}' cannot be used together`,
|
|
1518
1646
|
);
|
|
1519
1647
|
}
|
|
1520
|
-
|
|
1648
|
+
// check_fixup_reword_options: patch_interactive || interactive || all || also || only
|
|
1649
|
+
if (this.all || this.include || this.patch) {
|
|
1521
1650
|
throw new IncompatibleOptionsError(
|
|
1522
1651
|
["--fixup", "--all"],
|
|
1523
1652
|
"fatal: reword option of '--fixup' and '--patch/--interactive/--all/--include/--only' cannot be used together",
|
|
@@ -1668,16 +1797,7 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
1668
1797
|
// Check for conflicts (a partial commit records HEAD and the named paths: other
|
|
1669
1798
|
// unmerged paths stay in the index, as git's)
|
|
1670
1799
|
if (!partial && (await this.staging.hasConflicts())) {
|
|
1671
|
-
|
|
1672
|
-
throw new UnmergedPathsError(
|
|
1673
|
-
conflictPaths,
|
|
1674
|
-
[
|
|
1675
|
-
"error: Committing is not possible because you have unmerged files.",
|
|
1676
|
-
"hint: Fix them up in the work tree, and then use 'git add/rm <file>'",
|
|
1677
|
-
"hint: as appropriate to mark resolution and make a commit.",
|
|
1678
|
-
"fatal: Exiting because of an unresolved conflict.",
|
|
1679
|
-
].join("\n"),
|
|
1680
|
-
);
|
|
1800
|
+
throw unmergedPathsError(await this.staging.getConflictedPaths());
|
|
1681
1801
|
}
|
|
1682
1802
|
|
|
1683
1803
|
// a merge, cherry-pick or revert in progress (git's whence: MERGE_HEAD,
|
|
@@ -2719,6 +2839,19 @@ export class CommitCommand extends GitCommand<CommitResult> {
|
|
|
2719
2839
|
}
|
|
2720
2840
|
}
|
|
2721
2841
|
|
|
2842
|
+
/** git's `die_resolve_conflict("commit")`. */
|
|
2843
|
+
function unmergedPathsError(paths: string[]): UnmergedPathsError {
|
|
2844
|
+
return new UnmergedPathsError(
|
|
2845
|
+
paths,
|
|
2846
|
+
[
|
|
2847
|
+
"error: Committing is not possible because you have unmerged files.",
|
|
2848
|
+
"hint: Fix them up in the work tree, and then use 'git add/rm <file>'",
|
|
2849
|
+
"hint: as appropriate to mark resolution and make a commit.",
|
|
2850
|
+
"fatal: Exiting because of an unresolved conflict.",
|
|
2851
|
+
].join("\n"),
|
|
2852
|
+
);
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2722
2855
|
/** git's "paths '<first> ...' with -a does not make sense". */
|
|
2723
2856
|
function pathsWithAllError(paths: readonly string[]): IncompatibleOptionsError {
|
|
2724
2857
|
return new IncompatibleOptionsError(
|