@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
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's heuristics for the lines of an ignored commit (blame.c): each changed line of the
|
|
3
|
+
* ignored version is matched with a line of its parent's version by fingerprint
|
|
4
|
+
* (`fuzzy_find_matching_lines` within the diff chunk, then `scan_parent_range` over the
|
|
5
|
+
* whole parent), so `git blame --ignore-rev` can blame it on the commit that wrote that line.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const parentFps = lineFingerprints(parentContent);
|
|
10
|
+
* const targetFps = lineFingerprints(targetContent);
|
|
11
|
+
* // a chunk replacing parent lines [3, 5) by target lines [3, 7)
|
|
12
|
+
* const blames = guessLineBlames(parentFps, targetFps, 3, 0, 7, 2);
|
|
13
|
+
* blames[0]; // { isParent: true, sLno: 3 } or { isParent: false, sLno: 3 }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A fingerprint (`struct fingerprint`): the multiset of the lower-cased byte pairs of a line,
|
|
21
|
+
* whitespace (as `\0`) added at both ends, whitespace pairs left out; each pair (`c0 | c1 << 8`)
|
|
22
|
+
* mapped to its count
|
|
23
|
+
*/
|
|
24
|
+
export type Fingerprint = Map<number, number>;
|
|
25
|
+
|
|
26
|
+
/** git's isspace: tab, line feed, carriage return and space */
|
|
27
|
+
const isSpace = (c: number) => c === 0x20 || c === 0x09 || c === 0x0a || c === 0x0d;
|
|
28
|
+
|
|
29
|
+
/** git's `find_line_starts`: where each line starts, and the length at the end */
|
|
30
|
+
export function lineStartsOf(content: Uint8Array): Int32Array {
|
|
31
|
+
let num = 0;
|
|
32
|
+
for (let i = 0; i < content.length; i++) if (content[i] === 0x0a) num++;
|
|
33
|
+
if (content.length > 0 && content[content.length - 1] !== 0x0a) num++;
|
|
34
|
+
const starts = new Int32Array(num + 1);
|
|
35
|
+
let n = 1;
|
|
36
|
+
for (let i = 0; i < content.length - 1; i++) if (content[i] === 0x0a) starts[n++] = i + 1;
|
|
37
|
+
starts[num] = content.length;
|
|
38
|
+
return starts;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** git's `get_fingerprint` of `content[begin, end]` (`end` itself read as whitespace) */
|
|
42
|
+
function fingerprint(content: Uint8Array, begin: number, end: number): Fingerprint {
|
|
43
|
+
const map: Fingerprint = new Map();
|
|
44
|
+
let c0 = 0;
|
|
45
|
+
for (let p = begin; p <= end; p++) {
|
|
46
|
+
let c1 = 0;
|
|
47
|
+
if (p !== end) {
|
|
48
|
+
const c = content[p];
|
|
49
|
+
if (!isSpace(c)) c1 = c >= 0x41 && c <= 0x5a ? c + 0x20 : c;
|
|
50
|
+
}
|
|
51
|
+
const hash = c0 | (c1 << 8);
|
|
52
|
+
c0 = c1;
|
|
53
|
+
if (hash === 0) continue;
|
|
54
|
+
map.set(hash, (map.get(hash) ?? 0) + 1);
|
|
55
|
+
}
|
|
56
|
+
return map;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** git's `get_line_fingerprints` over every line (`fill_origin_fingerprints`) */
|
|
60
|
+
export function lineFingerprints(content: Uint8Array): Fingerprint[] {
|
|
61
|
+
const starts = lineStartsOf(content);
|
|
62
|
+
const out: Fingerprint[] = new Array(starts.length - 1);
|
|
63
|
+
for (let i = 0; i < out.length; i++) out[i] = fingerprint(content, starts[i], starts[i + 1]);
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** git's `fingerprint_similarity`: the size of the multisets' intersection */
|
|
68
|
+
function similarity(a: Fingerprint, b: Fingerprint): number {
|
|
69
|
+
let n = 0;
|
|
70
|
+
for (const [hash, countB] of b) {
|
|
71
|
+
const countA = a.get(hash);
|
|
72
|
+
if (countA !== undefined) n += countA < countB ? countA : countB;
|
|
73
|
+
}
|
|
74
|
+
return n;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** git's `fingerprint_subtract`: `b`'s pairs taken out of `a`, in place */
|
|
78
|
+
function subtract(a: Fingerprint, b: Fingerprint): void {
|
|
79
|
+
for (const [hash, countB] of b) {
|
|
80
|
+
const countA = a.get(hash);
|
|
81
|
+
if (countA === undefined) continue;
|
|
82
|
+
if (countA <= countB) a.delete(hash);
|
|
83
|
+
else a.set(hash, countA - countB);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const CERTAIN_NOTHING_MATCHES = -2;
|
|
88
|
+
const CERTAINTY_NOT_CALCULATED = -1;
|
|
89
|
+
|
|
90
|
+
interface Mapping {
|
|
91
|
+
destinationStart: number;
|
|
92
|
+
destinationLength: number;
|
|
93
|
+
sourceStart: number;
|
|
94
|
+
sourceLength: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** git's `map_line_number`: a line of B mapped onto the middle of its share of A */
|
|
98
|
+
function mapLineNumber(line: number, m: Mapping): number {
|
|
99
|
+
return (
|
|
100
|
+
Math.trunc((((line - m.sourceStart) * 2 + 1) * m.destinationLength) / (m.sourceLength * 2)) +
|
|
101
|
+
m.destinationStart
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* git's `fuzzy_find_matching_lines`: for each target line of `[tlno, same)` the parent line
|
|
107
|
+
* of `[parentSlno, parentSlno + parentLen)` it matches (-1 for none), the line order kept;
|
|
108
|
+
* undefined when the parent chunk is empty. The matched parent fingerprints are reduced by
|
|
109
|
+
* what was matched (`parentFps` changes).
|
|
110
|
+
*/
|
|
111
|
+
export function fuzzyFindMatchingLines(
|
|
112
|
+
parentFps: Fingerprint[],
|
|
113
|
+
targetFps: Fingerprint[],
|
|
114
|
+
tlno: number,
|
|
115
|
+
parentSlno: number,
|
|
116
|
+
same: number,
|
|
117
|
+
parentLen: number,
|
|
118
|
+
): Int32Array | undefined {
|
|
119
|
+
const startA0 = parentSlno;
|
|
120
|
+
const lengthA0 = parentLen;
|
|
121
|
+
const startB0 = tlno;
|
|
122
|
+
const lengthB0 = same - tlno;
|
|
123
|
+
const mapping: Mapping = {
|
|
124
|
+
destinationStart: startA0,
|
|
125
|
+
destinationLength: lengthA0,
|
|
126
|
+
sourceStart: startB0,
|
|
127
|
+
sourceLength: lengthB0,
|
|
128
|
+
};
|
|
129
|
+
if (lengthA0 <= 0) return undefined;
|
|
130
|
+
let maxA = 10;
|
|
131
|
+
if (maxA >= lengthA0) maxA = lengthA0 ? lengthA0 - 1 : 0;
|
|
132
|
+
const maxB = Math.trunc(((2 * maxA + 1) * lengthB0 - 1) / lengthA0);
|
|
133
|
+
const width = maxA * 2 + 1;
|
|
134
|
+
const result = new Int32Array(lengthB0).fill(-1);
|
|
135
|
+
const secondBest = new Int32Array(lengthB0).fill(-1);
|
|
136
|
+
const certainties = new Int32Array(lengthB0).fill(CERTAINTY_NOT_CALCULATED);
|
|
137
|
+
const similarities = new Int32Array(lengthB0 * width).fill(-1);
|
|
138
|
+
|
|
139
|
+
/** `get_similarity`'s index: `lineA` and `closestA` relative to the chunk of A */
|
|
140
|
+
const simAt = (lineA: number, row: number, closestA: number) =>
|
|
141
|
+
lineA - closestA + maxA + row * width;
|
|
142
|
+
|
|
143
|
+
/** `find_best_line_matches` for B's line `row` (`bOff + local`) */
|
|
144
|
+
const findBest = (
|
|
145
|
+
startA: number,
|
|
146
|
+
lengthA: number,
|
|
147
|
+
startB: number,
|
|
148
|
+
local: number,
|
|
149
|
+
row: number,
|
|
150
|
+
) => {
|
|
151
|
+
if (certainties[row] !== CERTAINTY_NOT_CALCULATED) return;
|
|
152
|
+
const closest = mapLineNumber(local + startB, mapping) - startA;
|
|
153
|
+
const searchStart = Math.max(0, closest - maxA);
|
|
154
|
+
const searchEnd = Math.min(lengthA, closest + maxA + 1);
|
|
155
|
+
let best = 0;
|
|
156
|
+
let secondBestSim = 0;
|
|
157
|
+
let bestIndex = 0;
|
|
158
|
+
let secondBestIndex = 0;
|
|
159
|
+
const fb = targetFps[startB + local];
|
|
160
|
+
for (let i = searchStart; i < searchEnd; i++) {
|
|
161
|
+
const at = simAt(i, row, closest);
|
|
162
|
+
if (similarities[at] === -1) {
|
|
163
|
+
similarities[at] = similarity(parentFps[startA + i], fb) * (1000 - Math.abs(i - closest));
|
|
164
|
+
}
|
|
165
|
+
const sim = similarities[at];
|
|
166
|
+
if (sim > best) {
|
|
167
|
+
secondBestSim = best;
|
|
168
|
+
secondBestIndex = bestIndex;
|
|
169
|
+
best = sim;
|
|
170
|
+
bestIndex = i;
|
|
171
|
+
} else if (sim > secondBestSim) {
|
|
172
|
+
secondBestSim = sim;
|
|
173
|
+
secondBestIndex = i;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (best === 0) {
|
|
177
|
+
certainties[row] = CERTAIN_NOTHING_MATCHES;
|
|
178
|
+
result[row] = -1;
|
|
179
|
+
} else {
|
|
180
|
+
certainties[row] = best * 2 - secondBestSim;
|
|
181
|
+
result[row] = startA + bestIndex;
|
|
182
|
+
secondBest[row] = startA + secondBestIndex;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// fuzzy_find_matching_lines_recurse, its recursion as a stack (first half first)
|
|
187
|
+
const stack: Array<[number, number, number, number, number]> = [
|
|
188
|
+
[startA0, startB0, lengthA0, lengthB0, 0],
|
|
189
|
+
];
|
|
190
|
+
while (stack.length > 0) {
|
|
191
|
+
const [startA, startB, lengthA, lengthB, bOff] = stack.pop() as [
|
|
192
|
+
number,
|
|
193
|
+
number,
|
|
194
|
+
number,
|
|
195
|
+
number,
|
|
196
|
+
number,
|
|
197
|
+
];
|
|
198
|
+
let mostCertainLocalB = -1;
|
|
199
|
+
let mostCertainty = -1;
|
|
200
|
+
for (let i = 0; i < lengthB; i++) {
|
|
201
|
+
findBest(startA, lengthA, startB, i, bOff + i);
|
|
202
|
+
if (certainties[bOff + i] > mostCertainty) {
|
|
203
|
+
mostCertainty = certainties[bOff + i];
|
|
204
|
+
mostCertainLocalB = i;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (mostCertainLocalB === -1) continue;
|
|
208
|
+
const mostCertainA = result[bOff + mostCertainLocalB];
|
|
209
|
+
subtract(parentFps[mostCertainA], targetFps[startB + mostCertainLocalB]);
|
|
210
|
+
const invalidateMin = Math.max(0, mostCertainLocalB - maxB);
|
|
211
|
+
const invalidateMax = Math.min(lengthB, mostCertainLocalB + maxB + 1);
|
|
212
|
+
for (let i = invalidateMin; i < invalidateMax; i++) {
|
|
213
|
+
const closest = mapLineNumber(i + startB, mapping) - startA;
|
|
214
|
+
if (Math.abs(mostCertainA - startA - closest) > maxA) continue;
|
|
215
|
+
similarities[simAt(mostCertainA - startA, bOff + i, closest)] = -1;
|
|
216
|
+
}
|
|
217
|
+
for (let i = mostCertainLocalB - 1; i >= invalidateMin; i--) {
|
|
218
|
+
const row = bOff + i;
|
|
219
|
+
if (
|
|
220
|
+
certainties[row] >= 0 &&
|
|
221
|
+
(result[row] >= mostCertainA || secondBest[row] >= mostCertainA)
|
|
222
|
+
) {
|
|
223
|
+
certainties[row] = CERTAINTY_NOT_CALCULATED;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (let i = mostCertainLocalB + 1; i < invalidateMax; i++) {
|
|
227
|
+
const row = bOff + i;
|
|
228
|
+
if (
|
|
229
|
+
certainties[row] >= 0 &&
|
|
230
|
+
(result[row] <= mostCertainA || secondBest[row] <= mostCertainA)
|
|
231
|
+
) {
|
|
232
|
+
certainties[row] = CERTAINTY_NOT_CALCULATED;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// pushed second half first: the first half (and all it splits into) runs before it
|
|
236
|
+
if (mostCertainLocalB + 1 < lengthB) {
|
|
237
|
+
const offsetB = mostCertainLocalB + 1;
|
|
238
|
+
stack.push([
|
|
239
|
+
mostCertainA,
|
|
240
|
+
startB + offsetB,
|
|
241
|
+
lengthA + startA - mostCertainA,
|
|
242
|
+
lengthB - offsetB,
|
|
243
|
+
bOff + offsetB,
|
|
244
|
+
]);
|
|
245
|
+
}
|
|
246
|
+
if (mostCertainLocalB > 0) {
|
|
247
|
+
stack.push([startA, startB, mostCertainA + 1 - startA, mostCertainLocalB, bOff]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** git's `scan_parent_range`: the parent line most like a target line (at least 10 pairs) */
|
|
254
|
+
function scanParentRange(
|
|
255
|
+
parentFps: Fingerprint[],
|
|
256
|
+
targetFps: Fingerprint[],
|
|
257
|
+
tIdx: number,
|
|
258
|
+
from: number,
|
|
259
|
+
count: number,
|
|
260
|
+
): number {
|
|
261
|
+
let bestSim = 10;
|
|
262
|
+
let bestIdx = -1;
|
|
263
|
+
for (let p = from; p < from + count; p++) {
|
|
264
|
+
const sim = similarity(parentFps[p], targetFps[tIdx]);
|
|
265
|
+
if (sim < bestSim) continue;
|
|
266
|
+
if (sim === bestSim && bestIdx !== -1 && Math.abs(bestIdx - tIdx) < Math.abs(p - tIdx)) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
bestSim = sim;
|
|
270
|
+
bestIdx = p;
|
|
271
|
+
}
|
|
272
|
+
return bestIdx;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Where a changed line of an ignored commit is blamed (`struct blame_line_tracker`) */
|
|
276
|
+
export interface LineBlame {
|
|
277
|
+
/** Whether it goes to the parent (else it stays with the ignored commit: unblamable) */
|
|
278
|
+
isParent: boolean;
|
|
279
|
+
/** Its line in the parent, or its own line in the target */
|
|
280
|
+
sLno: number;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* git's `guess_line_blames`: for the target lines `[tlno, same)` of a diff chunk whose parent
|
|
285
|
+
* side is `parentLen` lines at `tlno + offset`, the parent line each came from, by the fuzzy
|
|
286
|
+
* match within the chunk, else the best match in the whole parent.
|
|
287
|
+
*/
|
|
288
|
+
export function guessLineBlames(
|
|
289
|
+
parentFps: Fingerprint[],
|
|
290
|
+
targetFps: Fingerprint[],
|
|
291
|
+
tlno: number,
|
|
292
|
+
offset: number,
|
|
293
|
+
same: number,
|
|
294
|
+
parentLen: number,
|
|
295
|
+
): LineBlame[] {
|
|
296
|
+
const fuzzy = fuzzyFindMatchingLines(parentFps, targetFps, tlno, tlno + offset, same, parentLen);
|
|
297
|
+
const out: LineBlame[] = new Array(same - tlno);
|
|
298
|
+
for (let i = 0; i < same - tlno; i++) {
|
|
299
|
+
const targetIdx = tlno + i;
|
|
300
|
+
const best =
|
|
301
|
+
fuzzy && fuzzy[i] >= 0
|
|
302
|
+
? fuzzy[i]
|
|
303
|
+
: scanParentRange(parentFps, targetFps, targetIdx, 0, parentFps.length);
|
|
304
|
+
out[i] = best >= 0 ? { isParent: true, sLno: best } : { isParent: false, sLno: targetIdx };
|
|
305
|
+
}
|
|
306
|
+
return out;
|
|
307
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git check-mailmap` (builtin/check-mailmap.c): each contact as the repository's mailmap
|
|
3
|
+
* maps it (`.mailmap`, `mailmap.blob`, `mailmap.file`, plus `--mailmap-blob` and
|
|
4
|
+
* `--mailmap-file`).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // git check-mailmap "nick1 <bugs@company.xx>"
|
|
9
|
+
* await git.checkMailmap().addContact("nick1 <bugs@company.xx>").call();
|
|
10
|
+
* // "Some Dude <some@dude.xx>\n"
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
15
|
+
import { GitApiError } from "../errors/index.js";
|
|
16
|
+
import { GitCommand } from "../git-command.js";
|
|
17
|
+
import { hostEnvironmentOf } from "./git-ident.js";
|
|
18
|
+
import { type Mailmap, readMailmapBlob, readMailmapFile } from "./mailmap.js";
|
|
19
|
+
import { inputLines, splitIdent } from "./shortlog.js";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The contacts of `git check-mailmap <contact>...` (and `--stdin`'s lines after them), one
|
|
23
|
+
* output line each: `Name <email>`, or `<email>` when the result has no name.
|
|
24
|
+
*
|
|
25
|
+
* git 2.43 (`setCompatibility("2.43")`) takes only `Name <email>` contacts (`fatal: unable
|
|
26
|
+
* to parse contact: <contact>`) and has no `--mailmap-file`/`--mailmap-blob`; 2.47 and later
|
|
27
|
+
* also map a bare address. Where git dies, the error carries what was printed before
|
|
28
|
+
* ({@link getOutput}).
|
|
29
|
+
*/
|
|
30
|
+
export class CheckMailmapCommand extends GitCommand<string> {
|
|
31
|
+
private readonly contacts: string[] = [];
|
|
32
|
+
private stdin?: string;
|
|
33
|
+
private mailmapFile?: string;
|
|
34
|
+
private mailmapBlob?: string;
|
|
35
|
+
private compatibility: "2.43" | "2.56" = "2.56";
|
|
36
|
+
private output = "";
|
|
37
|
+
private readonly errors: string[] = [];
|
|
38
|
+
|
|
39
|
+
/** A contact argument. */
|
|
40
|
+
addContact(contact: string): this {
|
|
41
|
+
this.checkCallable();
|
|
42
|
+
this.contacts.push(contact);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `--stdin`: these lines (git's stdin) checked after the arguments. */
|
|
47
|
+
setStdin(text: string): this {
|
|
48
|
+
this.checkCallable();
|
|
49
|
+
this.stdin = text;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** `--mailmap-file=<file>` (git 2.47+): more entries from this host file. */
|
|
54
|
+
setMailmapFile(path: string): this {
|
|
55
|
+
this.checkCallable();
|
|
56
|
+
this.mailmapFile = path;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** `--mailmap-blob=<blob>` (git 2.47+): more entries from this blob. */
|
|
61
|
+
setMailmapBlob(name: string): this {
|
|
62
|
+
this.checkCallable();
|
|
63
|
+
this.mailmapBlob = name;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The git version whose behaviour to follow (default 2.56). */
|
|
68
|
+
setCompatibility(version: "2.43" | "2.56"): this {
|
|
69
|
+
this.checkCallable();
|
|
70
|
+
this.compatibility = version;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** What was printed on stdout (also after a death). */
|
|
75
|
+
getOutput(): string {
|
|
76
|
+
return this.output;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** git's `error:` lines (a mailmap blob that is no blob). */
|
|
80
|
+
getErrors(): string[] {
|
|
81
|
+
return [...this.errors];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The output. */
|
|
85
|
+
async call(): Promise<string> {
|
|
86
|
+
this.checkCallable();
|
|
87
|
+
this.setCallable(false);
|
|
88
|
+
const legacy = this.compatibility === "2.43";
|
|
89
|
+
if (legacy && (this.mailmapFile !== undefined || this.mailmapBlob !== undefined)) {
|
|
90
|
+
const option = this.mailmapFile !== undefined ? "mailmap-file" : "mailmap-blob";
|
|
91
|
+
throw new GitApiError(
|
|
92
|
+
`error: unknown option \`${option}'\nusage: git check-mailmap [<options>] <contact>...`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (this.contacts.length === 0 && this.stdin === undefined)
|
|
96
|
+
throw new GitApiError("fatal: no contacts specified");
|
|
97
|
+
const onError = (line: string) => this.errors.push(line);
|
|
98
|
+
const mailmap = await this.readMailmap(onError);
|
|
99
|
+
if (this.mailmapBlob !== undefined) {
|
|
100
|
+
const bytes = await readMailmapBlob(
|
|
101
|
+
{ readObjectNamed: (name) => this.readObjectNamed(name), onError },
|
|
102
|
+
this.mailmapBlob,
|
|
103
|
+
);
|
|
104
|
+
if (bytes) mailmap.read(decodeGitPath(bytes));
|
|
105
|
+
}
|
|
106
|
+
if (this.mailmapFile !== undefined) {
|
|
107
|
+
const bytes = await readMailmapFile(
|
|
108
|
+
this.mailmapFile,
|
|
109
|
+
hostEnvironmentOf(this._workingCopy),
|
|
110
|
+
this.worktreeAccess,
|
|
111
|
+
);
|
|
112
|
+
if (bytes) mailmap.read(decodeGitPath(bytes));
|
|
113
|
+
}
|
|
114
|
+
for (const contact of this.contacts) this.check(mailmap, contact, legacy);
|
|
115
|
+
if (this.stdin !== undefined)
|
|
116
|
+
for (const line of inputLines(this.stdin)) this.check(mailmap, line, legacy);
|
|
117
|
+
return this.output;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private check(mailmap: Mailmap, contact: string, legacy: boolean): void {
|
|
121
|
+
let ident = splitIdent(contact);
|
|
122
|
+
if (!ident) {
|
|
123
|
+
if (legacy) throw new GitApiError(`fatal: unable to parse contact: ${contact}`);
|
|
124
|
+
ident = { name: "", email: contact };
|
|
125
|
+
}
|
|
126
|
+
const mapped = mailmap.map(ident.name, ident.email);
|
|
127
|
+
this.output += `${mapped.name ? `${mapped.name} ` : ""}<${mapped.email}>\n`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -96,6 +96,7 @@ import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
|
|
|
96
96
|
import { StashApplyCommand } from "./stash-apply-command.js";
|
|
97
97
|
import { StashCreateCommand } from "./stash-create-command.js";
|
|
98
98
|
import { STASH_REF } from "./stash-list-command.js";
|
|
99
|
+
import { recursesIntoSubmodules, SubmoduleUnpack } from "./submodule-unpack.js";
|
|
99
100
|
import { planTreeRestore, restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
|
|
100
101
|
import {
|
|
101
102
|
entryNotUptodate,
|
|
@@ -293,6 +294,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
293
294
|
private conflictStyle?: ConflictStyle;
|
|
294
295
|
private quiet = false;
|
|
295
296
|
private countCheckoutPaths = false;
|
|
297
|
+
private recurseSubmodules?: boolean;
|
|
296
298
|
/** `--pathspec-from-file` */
|
|
297
299
|
private readonly pathspecFile = new PathspecFile();
|
|
298
300
|
/** Set by a `merge` checkout the two-way merge refused: what the autostash needs */
|
|
@@ -642,6 +644,17 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
642
644
|
return this;
|
|
643
645
|
}
|
|
644
646
|
|
|
647
|
+
/**
|
|
648
|
+
* `--[no-]recurse-submodules` (default `submodule.recurse`): the active submodules' worktrees
|
|
649
|
+
* are switched with the superproject's, their HEADs detached at the recorded commits, and
|
|
650
|
+
* local changes in them refuse the switch as git's unpack-trees refuses them.
|
|
651
|
+
*/
|
|
652
|
+
setRecurseSubmodules(recurse: boolean): this {
|
|
653
|
+
this.checkCallable();
|
|
654
|
+
this.recurseSubmodules = recurse;
|
|
655
|
+
return this;
|
|
656
|
+
}
|
|
657
|
+
|
|
645
658
|
/** `-q`: a path checkout reports no counts and no "path is unmerged" warnings. */
|
|
646
659
|
setQuiet(quiet: boolean): this {
|
|
647
660
|
this.checkCallable();
|
|
@@ -1021,6 +1034,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1021
1034
|
if (this.startPoint !== undefined) copy.setStartPoint(this.startPoint);
|
|
1022
1035
|
if (this.guess !== undefined) copy.setGuess(this.guess);
|
|
1023
1036
|
if (this.hasReflogAction()) copy.setReflogAction(this.reflogAction("checkout"));
|
|
1037
|
+
if (this.recurseSubmodules !== undefined) copy.setRecurseSubmodules(this.recurseSubmodules);
|
|
1024
1038
|
return copy;
|
|
1025
1039
|
}
|
|
1026
1040
|
|
|
@@ -1059,6 +1073,9 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1059
1073
|
quiet: this.quiet,
|
|
1060
1074
|
countCheckoutPaths: this.countCheckoutPaths,
|
|
1061
1075
|
globalMagic: this.globalPathspecMagic(),
|
|
1076
|
+
...(this.recurseSubmodules !== undefined
|
|
1077
|
+
? { recurseSubmodules: this.recurseSubmodules }
|
|
1078
|
+
: {}),
|
|
1062
1079
|
});
|
|
1063
1080
|
return pathCheckoutResult(outcome);
|
|
1064
1081
|
}
|
|
@@ -1171,6 +1188,15 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1171
1188
|
});
|
|
1172
1189
|
const quiet = (path: string) => sparse?.leavesAlone(path) === true;
|
|
1173
1190
|
const writes = (path: string) => !sparse || sparse.writes(path);
|
|
1191
|
+
// --recurse-submodules: unpack-trees' submodule checks and moves (forced: o->reset)
|
|
1192
|
+
const subs = this.worktreeAccess
|
|
1193
|
+
? await SubmoduleUnpack.start(this.workingCopy, {
|
|
1194
|
+
recurse: recursesIntoSubmodules(this.workingCopy, this.recurseSubmodules),
|
|
1195
|
+
reset: this.force,
|
|
1196
|
+
})
|
|
1197
|
+
: undefined;
|
|
1198
|
+
/** New submodules whose checks replace the untracked-file checks (verify_absent_1) */
|
|
1199
|
+
const submodulePaths = new Set<string>();
|
|
1174
1200
|
|
|
1175
1201
|
// git's two-way merge (unpack-trees `twoway_merge`, checkout without -f): a path HEAD
|
|
1176
1202
|
// and the target agree on keeps its index entry and worktree file as they are (local
|
|
@@ -1230,6 +1256,11 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1230
1256
|
const h = head.get(path);
|
|
1231
1257
|
const t = target.get(path);
|
|
1232
1258
|
if (initial && t) {
|
|
1259
|
+
if (subs && !quiet(path)) {
|
|
1260
|
+
const absent = await subs.absentRefuses(path, t);
|
|
1261
|
+
if (absent !== undefined) submodulePaths.add(path);
|
|
1262
|
+
if (!absent) await subs.mergedRefuses(path, index.get(path), t);
|
|
1263
|
+
}
|
|
1233
1264
|
switched.push(path);
|
|
1234
1265
|
continue;
|
|
1235
1266
|
}
|
|
@@ -1242,6 +1273,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1242
1273
|
continue;
|
|
1243
1274
|
}
|
|
1244
1275
|
if (quiet(path)) continue;
|
|
1276
|
+
// merged_entry's submodule check (FORCE): the submodule must be able to move
|
|
1277
|
+
if (subs && t && !sameSide(i, t)) await subs.mergedRefuses(path, i, t);
|
|
1245
1278
|
if (!sameSide(i, t) || t) switched.push(path);
|
|
1246
1279
|
continue;
|
|
1247
1280
|
}
|
|
@@ -1258,6 +1291,29 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1258
1291
|
if (i !== undefined || t !== undefined) local.push(path);
|
|
1259
1292
|
continue;
|
|
1260
1293
|
}
|
|
1294
|
+
if (subs && worktree && !quiet(path)) {
|
|
1295
|
+
if (i !== undefined && i.mode === FileMode.GITLINK) {
|
|
1296
|
+
// deleted_entry's verify_absent_if_directory of the submodule going away
|
|
1297
|
+
if (!t && (await subs.isSubmodule(path, i)) && (await subs.exists(path))) {
|
|
1298
|
+
await subs.refuses(path, (h ?? i).objectId, null);
|
|
1299
|
+
}
|
|
1300
|
+
const refused = await subs.notUptodate(path, i);
|
|
1301
|
+
if (refused) {
|
|
1302
|
+
local.push(path);
|
|
1303
|
+
continue;
|
|
1304
|
+
}
|
|
1305
|
+
if (refused === false) {
|
|
1306
|
+
if (t && t.mode !== FileMode.GITLINK) await subs.fileReplacesRefuses(path, i);
|
|
1307
|
+
if (t) await subs.mergedRefuses(path, i, t);
|
|
1308
|
+
switched.push(path);
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
} else if (i === undefined && t) {
|
|
1312
|
+
const absent = await subs.absentRefuses(path, t);
|
|
1313
|
+
if (absent !== undefined) submodulePaths.add(path);
|
|
1314
|
+
if (!absent) await subs.mergedRefuses(path, undefined, t);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1261
1317
|
if (
|
|
1262
1318
|
i !== undefined &&
|
|
1263
1319
|
worktree &&
|
|
@@ -1267,6 +1323,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1267
1323
|
local.push(path);
|
|
1268
1324
|
continue;
|
|
1269
1325
|
}
|
|
1326
|
+
if (subs && i !== undefined && t && !quiet(path)) await subs.mergedRefuses(path, i, t);
|
|
1270
1327
|
switched.push(path);
|
|
1271
1328
|
}
|
|
1272
1329
|
|
|
@@ -1275,7 +1332,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1275
1332
|
// component, untracked files in a directory a file replaces
|
|
1276
1333
|
if (worktree && !this.force) {
|
|
1277
1334
|
const found = await findInTheWay(worktree, {
|
|
1278
|
-
writes: switched.filter((p) => target.has(p) && writes(p)),
|
|
1335
|
+
writes: switched.filter((p) => target.has(p) && writes(p) && !submodulePaths.has(p)),
|
|
1279
1336
|
removes: new Set(switched.filter((p) => !target.has(p))),
|
|
1280
1337
|
index,
|
|
1281
1338
|
...(await restoreCaseOptions(worktree, ignoreCase)),
|
|
@@ -1366,20 +1423,29 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1366
1423
|
: await this.abbreviateObjectId(headId),
|
|
1367
1424
|
};
|
|
1368
1425
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1426
|
+
const submodules = subs?.rejected ?? [];
|
|
1427
|
+
if (
|
|
1428
|
+
local.length + untracked.length + untrackedRemoved.length + lostDirs.length > 0 ||
|
|
1429
|
+
submodules.length > 0
|
|
1430
|
+
) {
|
|
1431
|
+
// a forced switch runs unpack-trees without porcelain messages (reset_tree)
|
|
1432
|
+
const message =
|
|
1433
|
+
this.force && subs
|
|
1434
|
+
? subs.refusalLines(true).join("\n")
|
|
1435
|
+
: overwriteMessage("checkout", {
|
|
1436
|
+
local,
|
|
1437
|
+
lostDirs,
|
|
1438
|
+
untracked,
|
|
1439
|
+
untrackedRemoved,
|
|
1440
|
+
submodules,
|
|
1441
|
+
});
|
|
1376
1442
|
return {
|
|
1377
1443
|
status: CheckoutStatus.CONFLICTS,
|
|
1378
1444
|
updated: [],
|
|
1379
1445
|
removed: [],
|
|
1380
|
-
conflicts: [...local, ...lostDirs, ...untracked, ...untrackedRemoved],
|
|
1446
|
+
conflicts: [...local, ...lostDirs, ...untracked, ...untrackedRemoved, ...submodules],
|
|
1381
1447
|
ref: null,
|
|
1382
|
-
message
|
|
1448
|
+
message: `${subs?.printed() ?? ""}${message ?? ""}`,
|
|
1383
1449
|
};
|
|
1384
1450
|
}
|
|
1385
1451
|
|
|
@@ -1411,7 +1477,9 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1411
1477
|
}
|
|
1412
1478
|
for (const path of switched) {
|
|
1413
1479
|
if (target.has(path) || quiet(path)) continue;
|
|
1414
|
-
|
|
1480
|
+
const old = index.get(path);
|
|
1481
|
+
if (subs && old?.mode === FileMode.GITLINK) await subs.unlink(worktree, path, old);
|
|
1482
|
+
else await worktree.remove(path);
|
|
1415
1483
|
await pruneEmptyParents(worktree, path);
|
|
1416
1484
|
removed.push(path);
|
|
1417
1485
|
}
|
|
@@ -1425,11 +1493,23 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1425
1493
|
if (this.force) {
|
|
1426
1494
|
for (const path of index.keys()) {
|
|
1427
1495
|
if (!target.has(path) && !switching.has(path) && !quiet(path)) {
|
|
1428
|
-
|
|
1496
|
+
const old = index.get(path);
|
|
1497
|
+
if (subs && old?.mode === FileMode.GITLINK) await subs.unlink(worktree, path, old);
|
|
1498
|
+
else await worktree.remove(path);
|
|
1429
1499
|
removed.push(path);
|
|
1430
1500
|
}
|
|
1431
1501
|
}
|
|
1432
1502
|
}
|
|
1503
|
+
// a file replacing a submodule: its directory goes (checkout_entry's remove_subtree)
|
|
1504
|
+
if (subs) {
|
|
1505
|
+
for (const path of switched) {
|
|
1506
|
+
const old = index.get(path);
|
|
1507
|
+
const t = target.get(path);
|
|
1508
|
+
if (old?.mode === FileMode.GITLINK && t && t.mode !== FileMode.GITLINK && writes(path)) {
|
|
1509
|
+
await subs.removeForFile(worktree, path, old);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1433
1513
|
// in a sparse checkout, only the paths in its patterns are written
|
|
1434
1514
|
const only = plan && {
|
|
1435
1515
|
...plan,
|
|
@@ -1458,6 +1538,11 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1458
1538
|
});
|
|
1459
1539
|
updated.push(...only.entries.map((e) => e.path));
|
|
1460
1540
|
for (const e of [...only.entries, ...only.gitlinks]) written.add(e.path);
|
|
1541
|
+
if (subs) {
|
|
1542
|
+
// check_updates: `.gitmodules` read again, then the submodules checked out
|
|
1543
|
+
subs.reload();
|
|
1544
|
+
for (const e of only.gitlinks) await subs.checkout(worktree, e.path, e);
|
|
1545
|
+
}
|
|
1461
1546
|
}
|
|
1462
1547
|
}
|
|
1463
1548
|
|