resulgit 1.0.14 → 1.0.16
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/package.json +1 -1
- package/resulgit.js +50 -6
package/package.json
CHANGED
package/resulgit.js
CHANGED
|
@@ -1406,15 +1406,29 @@ async function cmdPush(opts) {
|
|
|
1406
1406
|
const merged = {}
|
|
1407
1407
|
const paths = new Set([...Object.keys(base), ...Object.keys(remote.files), ...Object.keys(local).map(k => k)])
|
|
1408
1408
|
spinnerUpdate(spinner, 'Merging changes...')
|
|
1409
|
+
|
|
1410
|
+
// Helper to check if content has unresolved conflict markers
|
|
1411
|
+
const hasConflictMarkers = (content) => {
|
|
1412
|
+
if (!content) return false
|
|
1413
|
+
return content.includes('<<<<<<<') && content.includes('=======') && content.includes('>>>>>>>')
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1409
1416
|
for (const p of paths) {
|
|
1410
1417
|
const b = p in base ? base[p] : null
|
|
1411
1418
|
const r = p in remote.files ? remote.files[p] : null
|
|
1412
1419
|
const l = p in local ? local[p].content : null
|
|
1413
1420
|
const changedLocal = String(l) !== String(b)
|
|
1414
1421
|
const changedRemote = String(r) !== String(b)
|
|
1415
|
-
|
|
1422
|
+
|
|
1423
|
+
// Check if local file has conflict markers (unresolved)
|
|
1424
|
+
if (l && hasConflictMarkers(l)) {
|
|
1416
1425
|
const line = firstDiffLine(l || '', r || '')
|
|
1417
|
-
conflicts.push({ path: p, line })
|
|
1426
|
+
conflicts.push({ path: p, line, reason: 'Unresolved conflict markers in file' })
|
|
1427
|
+
} else if (changedLocal && changedRemote && String(l) !== String(r)) {
|
|
1428
|
+
// Both changed and different - but if local is the "resolved" version, use it
|
|
1429
|
+
// This happens when user resolved a conflict and is pushing the resolution
|
|
1430
|
+
// The local version wins if it doesn't have conflict markers
|
|
1431
|
+
if (l !== null) merged[p] = l
|
|
1418
1432
|
} else if (changedLocal && !changedRemote) {
|
|
1419
1433
|
// Local changed, use local version
|
|
1420
1434
|
if (l !== null) merged[p] = l
|
|
@@ -1430,14 +1444,44 @@ async function cmdPush(opts) {
|
|
|
1430
1444
|
}
|
|
1431
1445
|
if (conflicts.length > 0) {
|
|
1432
1446
|
spinnerFail(spinner, 'Push blocked by conflicts')
|
|
1447
|
+
|
|
1448
|
+
// Write conflict markers to local files
|
|
1449
|
+
for (const c of conflicts) {
|
|
1450
|
+
const localContent = local[c.path]?.content || ''
|
|
1451
|
+
const remoteContent = remote.files[c.path] || ''
|
|
1452
|
+
|
|
1453
|
+
// Create conflict-marked content
|
|
1454
|
+
const conflictContent = [
|
|
1455
|
+
'<<<<<<< LOCAL (your changes)',
|
|
1456
|
+
localContent,
|
|
1457
|
+
'=======',
|
|
1458
|
+
remoteContent,
|
|
1459
|
+
'>>>>>>> REMOTE (server changes)'
|
|
1460
|
+
].join('\n')
|
|
1461
|
+
|
|
1462
|
+
// Write to local file
|
|
1463
|
+
const conflictPath = path.join(dir, c.path)
|
|
1464
|
+
await fs.promises.mkdir(path.dirname(conflictPath), { recursive: true })
|
|
1465
|
+
await fs.promises.writeFile(conflictPath, conflictContent, 'utf8')
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1433
1468
|
if (opts.json === 'true') {
|
|
1434
|
-
print({ conflicts }, true)
|
|
1469
|
+
print({ conflicts, message: 'Conflict markers written to files. Resolve them and try again.' }, true)
|
|
1435
1470
|
} else {
|
|
1436
|
-
process.stderr.write(color('
|
|
1437
|
-
process.stderr.write(color('Conflicts detected:\\n', 'yellow'))
|
|
1471
|
+
process.stderr.write(color('\nConflicts detected! The following files have been updated with conflict markers:\n', 'red'))
|
|
1438
1472
|
for (const c of conflicts) {
|
|
1439
|
-
process.stderr.write(color(` ${c.path}
|
|
1473
|
+
process.stderr.write(color(` ${c.path}\n`, 'yellow'))
|
|
1440
1474
|
}
|
|
1475
|
+
process.stderr.write(color('\nTo resolve:\n', 'cyan'))
|
|
1476
|
+
process.stderr.write(color(' 1. Open the files above and look for conflict markers:\n', 'dim'))
|
|
1477
|
+
process.stderr.write(color(' <<<<<<< LOCAL (your changes)\n', 'dim'))
|
|
1478
|
+
process.stderr.write(color(' ... your version ...\n', 'dim'))
|
|
1479
|
+
process.stderr.write(color(' =======\n', 'dim'))
|
|
1480
|
+
process.stderr.write(color(' ... server version ...\n', 'dim'))
|
|
1481
|
+
process.stderr.write(color(' >>>>>>> REMOTE (server changes)\n', 'dim'))
|
|
1482
|
+
process.stderr.write(color(' 2. Edit the files to keep the changes you want\n', 'dim'))
|
|
1483
|
+
process.stderr.write(color(' 3. Remove the conflict markers\n', 'dim'))
|
|
1484
|
+
process.stderr.write(color(' 4. Run: resulgit add . && resulgit commit -m "Resolved conflicts" && resulgit push\n\n', 'dim'))
|
|
1441
1485
|
}
|
|
1442
1486
|
return
|
|
1443
1487
|
}
|