next-issue 6.6.119 → 6.6.120
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/git-merge.mjs +31 -8
- package/package.json +1 -1
package/dist/git-merge.mjs
CHANGED
|
@@ -5,7 +5,9 @@ import { commitEverything } from './git-commit.mjs';
|
|
|
5
5
|
import { fetchBase, git, isAncestor, resetHard, succeeds } from './git.mjs';
|
|
6
6
|
export async function startMerge(cwd, base, remote) {
|
|
7
7
|
const target = await git(cwd, ['rev-parse', await fetchBase(cwd, base, remote)]);
|
|
8
|
-
const result = await run('git', ['merge', '--no-ff', '--no-commit', target], {
|
|
8
|
+
const result = await run('git', [...NO_RERERE, 'merge', '--no-ff', '--no-commit', target], {
|
|
9
|
+
cwd,
|
|
10
|
+
});
|
|
9
11
|
if (succeeded(result)) {
|
|
10
12
|
return { target, files: (await merging(cwd)) ? [] : undefined, unmarked: [] };
|
|
11
13
|
}
|
|
@@ -15,12 +17,14 @@ export async function startMerge(cwd, base, remote) {
|
|
|
15
17
|
}
|
|
16
18
|
const unmarked = [];
|
|
17
19
|
for (const file of files) {
|
|
18
|
-
if (!(await hasConflictMarkers(cwd, [file]))) {
|
|
20
|
+
if (!(await hasConflictMarkers(cwd, [file], 'HEAD'))) {
|
|
19
21
|
unmarked.push(file);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
return { target, files, unmarked };
|
|
23
25
|
}
|
|
26
|
+
// A recorded resolution would hide the conflict markers from the fixer.
|
|
27
|
+
const NO_RERERE = ['-c', 'rerere.enabled=false', '-c', 'rerere.autoUpdate=false'];
|
|
24
28
|
async function unmergedFiles(cwd) {
|
|
25
29
|
const args = ['diff', '--name-only', '-z', '--diff-filter=U'];
|
|
26
30
|
const listed = await run('git', args, { cwd });
|
|
@@ -32,13 +36,30 @@ async function unmergedFiles(cwd) {
|
|
|
32
36
|
async function merging(cwd) {
|
|
33
37
|
return succeeds(cwd, ['rev-parse', '--quiet', '--verify', 'MERGE_HEAD']);
|
|
34
38
|
}
|
|
35
|
-
const
|
|
39
|
+
const DEFAULT_MARKER_SIZE = 7;
|
|
40
|
+
function conflictMarker(size) {
|
|
41
|
+
return new RegExp(`^(?:<{${size}}|>{${size}})(?: |$)`, 'm');
|
|
42
|
+
}
|
|
43
|
+
// git writes the markers with the attributes of the branch's own commit, while the merged
|
|
44
|
+
// base or the fixer can change them in the worktree, so both sizes count.
|
|
45
|
+
async function markerSizes(cwd, file, before) {
|
|
46
|
+
return new Set([await markerSize(cwd, file, ['--source', before]), await markerSize(cwd, file)]);
|
|
47
|
+
}
|
|
48
|
+
async function markerSize(cwd, file, source = []) {
|
|
49
|
+
const args = ['check-attr', '-z', ...source, 'conflict-marker-size', '--', file];
|
|
50
|
+
const result = await run('git', args, { cwd });
|
|
51
|
+
if (!succeeded(result)) {
|
|
52
|
+
throw new Error(failedWith(`git ${args.join(' ')}`, result));
|
|
53
|
+
}
|
|
54
|
+
const value = Number(result.stdout.split('\0')[2]);
|
|
55
|
+
return Number.isInteger(value) && value > 0 ? value : DEFAULT_MARKER_SIZE;
|
|
56
|
+
}
|
|
36
57
|
export async function commitMerge(cwd, merge, message) {
|
|
37
58
|
if (!(await merging(cwd))) {
|
|
38
59
|
await refuseUnmerged(cwd, merge);
|
|
39
60
|
return false;
|
|
40
61
|
}
|
|
41
|
-
if (await hasConflictMarkers(cwd, merge.files)) {
|
|
62
|
+
if (await hasConflictMarkers(cwd, merge.files, merge.before)) {
|
|
42
63
|
return false;
|
|
43
64
|
}
|
|
44
65
|
await commitEverything(cwd, message);
|
|
@@ -46,15 +67,17 @@ export async function commitMerge(cwd, merge, message) {
|
|
|
46
67
|
}
|
|
47
68
|
async function refuseUnmerged(cwd, merge) {
|
|
48
69
|
const holdsBase = await isAncestor(cwd, merge.target, 'HEAD');
|
|
49
|
-
if (!holdsBase || (await hasConflictMarkers(cwd, merge.files))) {
|
|
70
|
+
if (!holdsBase || (await hasConflictMarkers(cwd, merge.files, merge.before))) {
|
|
50
71
|
await resetHard(cwd, merge.before);
|
|
51
72
|
}
|
|
52
73
|
}
|
|
53
|
-
async function hasConflictMarkers(cwd, files) {
|
|
74
|
+
async function hasConflictMarkers(cwd, files, before) {
|
|
54
75
|
for (const file of files) {
|
|
55
76
|
const text = await readTextOrEmpty(join(cwd, file));
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
for (const size of await markerSizes(cwd, file, before)) {
|
|
78
|
+
if (conflictMarker(size).test(text)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
58
81
|
}
|
|
59
82
|
}
|
|
60
83
|
return false;
|