-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolve_conflicts.js
More file actions
67 lines (55 loc) · 2.22 KB
/
resolve_conflicts.js
File metadata and controls
67 lines (55 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require('fs');
const path = require('path');
const strategiesDir = path.join(__dirname, 'strategies');
// Files I specifically modified and want to keep my version of
const MY_MODIFIED_FILES = [
'Bear Hug.js',
'65 Eliminator.js',
'Basiers Money Maker.js',
'Moving Half Moon Hot Cold.js', // Also modified this one
'Moving Half Moon Hot Only.js' // And this one maybe? Let's check.
];
function resolveFile(filePath) {
try {
const content = fs.readFileSync(filePath, 'utf8');
if (!content.includes('<<<<<<< HEAD')) return;
console.log(`Resolving conflict in: ${filePath}`);
// Regex to find conflict blocks
// This is a simple regex assuming standard git markers
const conflictRegex = /<<<<<<< HEAD([\s\S]*?)=======([\s\S]*?)>>>>>>> origin\/main/g;
const resolvedContent = content.replace(conflictRegex, (match, localContent, remoteContent) => {
const localTrimmed = localContent.trim();
const remoteTrimmed = remoteContent.trim();
if (localTrimmed === remoteTrimmed) {
console.log(' -> Identical content (ignoring whitespace). Using Local.');
return localContent; // Or remote, doesn't matter
}
const filename = path.basename(filePath);
if (MY_MODIFIED_FILES.some(f => filename.includes(f))) {
console.log(' -> My modified file. Keeping Local (HEAD).');
return localContent;
} else {
console.log(' -> Remote update. Taking Remote (origin/main).');
return remoteContent;
}
});
fs.writeFileSync(filePath, resolvedContent, 'utf8');
} catch (err) {
console.error(`Error processing ${filePath}:`, err);
}
}
function walkDir(dir) {
const files = fs.readdirSync(dir);
for (const file of files) {
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
walkDir(fullPath);
} else {
resolveFile(fullPath);
}
}
}
console.log('Starting conflict resolution...');
walkDir(strategiesDir);
console.log('Conflict resolution complete.');