@fern-api/replay 0.10.0 → 0.10.2
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/cli.cjs +22 -5
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +22 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -984,7 +984,7 @@ function applyBothPatches(baseLines, oursPatches, theirsPatches) {
|
|
|
984
984
|
}
|
|
985
985
|
|
|
986
986
|
// src/ReplayApplicator.ts
|
|
987
|
-
import { mkdir, mkdtemp, readFile, rm, writeFile } from "fs/promises";
|
|
987
|
+
import { mkdir, mkdtemp, readFile, rm, unlink, writeFile } from "fs/promises";
|
|
988
988
|
import { tmpdir } from "os";
|
|
989
989
|
import { dirname as dirname2, extname, join as join2 } from "path";
|
|
990
990
|
import { minimatch } from "minimatch";
|
|
@@ -1213,9 +1213,10 @@ var ReplayApplicator = class {
|
|
|
1213
1213
|
const resolvedPath = await this.resolveFilePath(filePath, baseGen.tree_hash, currentTreeHash);
|
|
1214
1214
|
const base = await this.git.showFile(baseGen.tree_hash, filePath);
|
|
1215
1215
|
const theirs = await this.applyPatchToContent(base, patch.patch_content, filePath, tempGit, tempDir);
|
|
1216
|
-
|
|
1216
|
+
const effectiveTheirs = theirs ?? await readFile(join2(this.outputDir, resolvedPath), "utf-8").catch(() => null);
|
|
1217
|
+
if (effectiveTheirs) {
|
|
1217
1218
|
this.fileTheirsAccumulator.set(resolvedPath, {
|
|
1218
|
-
content:
|
|
1219
|
+
content: effectiveTheirs,
|
|
1219
1220
|
baseGeneration: patch.base_generation
|
|
1220
1221
|
});
|
|
1221
1222
|
}
|
|
@@ -1259,8 +1260,12 @@ var ReplayApplicator = class {
|
|
|
1259
1260
|
};
|
|
1260
1261
|
} catch {
|
|
1261
1262
|
for (const [resolvedPath, content] of snapshots) {
|
|
1263
|
+
const fullPath = join2(this.outputDir, resolvedPath);
|
|
1262
1264
|
if (content != null) {
|
|
1263
|
-
await writeFile(
|
|
1265
|
+
await writeFile(fullPath, content);
|
|
1266
|
+
} else {
|
|
1267
|
+
await unlink(fullPath).catch(() => {
|
|
1268
|
+
});
|
|
1264
1269
|
}
|
|
1265
1270
|
}
|
|
1266
1271
|
}
|
|
@@ -1375,7 +1380,7 @@ var ReplayApplicator = class {
|
|
|
1375
1380
|
}
|
|
1376
1381
|
let useAccumulatorAsMergeBase = false;
|
|
1377
1382
|
const accumulatorEntry = this.fileTheirsAccumulator.get(resolvedPath);
|
|
1378
|
-
if (!theirs
|
|
1383
|
+
if (accumulatorEntry && (!theirs || base == null)) {
|
|
1379
1384
|
theirs = await this.applyPatchToContent(
|
|
1380
1385
|
accumulatorEntry.content,
|
|
1381
1386
|
patch.patch_content,
|
|
@@ -1417,12 +1422,16 @@ var ReplayApplicator = class {
|
|
|
1417
1422
|
}
|
|
1418
1423
|
}
|
|
1419
1424
|
if (base == null && !ours && effective_theirs) {
|
|
1425
|
+
this.fileTheirsAccumulator.set(resolvedPath, {
|
|
1426
|
+
content: effective_theirs,
|
|
1427
|
+
baseGeneration: patch.base_generation
|
|
1428
|
+
});
|
|
1420
1429
|
const outDir2 = dirname2(oursPath);
|
|
1421
1430
|
await mkdir(outDir2, { recursive: true });
|
|
1422
1431
|
await writeFile(oursPath, effective_theirs);
|
|
1423
1432
|
return { file: resolvedPath, status: "merged", reason: "new-file" };
|
|
1424
1433
|
}
|
|
1425
|
-
if (base == null && ours && effective_theirs) {
|
|
1434
|
+
if (base == null && ours && effective_theirs && !useAccumulatorAsMergeBase) {
|
|
1426
1435
|
const merged2 = threeWayMerge("", ours, effective_theirs);
|
|
1427
1436
|
const outDir2 = dirname2(oursPath);
|
|
1428
1437
|
await mkdir(outDir2, { recursive: true });
|
|
@@ -1605,16 +1614,24 @@ var ReplayApplicator = class {
|
|
|
1605
1614
|
const addedLines = [];
|
|
1606
1615
|
let inTargetFile = false;
|
|
1607
1616
|
let inHunk = false;
|
|
1617
|
+
let isNewFile = false;
|
|
1608
1618
|
let noTrailingNewline = false;
|
|
1609
1619
|
for (const line of lines) {
|
|
1610
1620
|
if (line.startsWith("diff --git")) {
|
|
1611
1621
|
if (inTargetFile) break;
|
|
1612
1622
|
inTargetFile = isDiffLineForFile(line, filePath);
|
|
1613
1623
|
inHunk = false;
|
|
1624
|
+
isNewFile = false;
|
|
1614
1625
|
continue;
|
|
1615
1626
|
}
|
|
1616
1627
|
if (!inTargetFile) continue;
|
|
1628
|
+
if (!inHunk) {
|
|
1629
|
+
if (line === "--- /dev/null" || line.startsWith("new file mode")) {
|
|
1630
|
+
isNewFile = true;
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1617
1633
|
if (line.startsWith("@@")) {
|
|
1634
|
+
if (!isNewFile) return null;
|
|
1618
1635
|
inHunk = true;
|
|
1619
1636
|
continue;
|
|
1620
1637
|
}
|