@fern-api/replay 0.17.4 → 0.18.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/index.js CHANGED
@@ -40,6 +40,11 @@ var init_GitClient = __esm({
40
40
  proc.stderr.on("data", (data) => {
41
41
  stderr += data.toString();
42
42
  });
43
+ proc.on("error", (err) => {
44
+ reject(new Error(`git ${args.join(" ")} failed to spawn: ${err.message}`));
45
+ });
46
+ proc.stdin.on("error", () => {
47
+ });
43
48
  proc.on("close", (code) => {
44
49
  if (code === 0) {
45
50
  resolve2(stdout);
@@ -808,7 +813,8 @@ function isBinaryFile(filePath) {
808
813
  var INFRASTRUCTURE_FILES = /* @__PURE__ */ new Set([".fernignore"]);
809
814
  function matchesFernignorePattern(filePath, patterns) {
810
815
  if (patterns.length === 0) return false;
811
- return patterns.some((p) => {
816
+ return patterns.some((rawPattern) => {
817
+ const p = rawPattern.endsWith("/") ? rawPattern.slice(0, -1) : rawPattern;
812
818
  if (filePath === p) return true;
813
819
  if (minimatch2(filePath, p)) return true;
814
820
  if (!p.includes("*") && !p.includes("?") && filePath.startsWith(p + "/")) return true;
@@ -987,20 +993,15 @@ var ReplayDetector = class {
987
993
  continue;
988
994
  }
989
995
  const parents = await this.git.getCommitParents(commit.sha);
990
- let patchContent;
996
+ let filesOutput;
991
997
  try {
992
- patchContent = await this.git.formatPatch(commit.sha);
998
+ filesOutput = await this.git.exec(["diff-tree", "--no-commit-id", "--name-only", "-r", commit.sha]);
993
999
  } catch {
994
1000
  this.warnings.push(
995
1001
  `Could not generate patch for commit ${commit.sha.slice(0, 7)} \u2014 it may be unreachable in a shallow clone. Skipping.`
996
1002
  );
997
1003
  continue;
998
1004
  }
999
- let contentHash = this.computeContentHash(patchContent);
1000
- if (lock.patches.find((p) => p.content_hash === contentHash) || forgottenHashes.has(contentHash)) {
1001
- continue;
1002
- }
1003
- const filesOutput = await this.git.exec(["diff-tree", "--no-commit-id", "--name-only", "-r", commit.sha]);
1004
1005
  const { files, sensitiveFiles, fernignoredFiles } = filterInfrastructureAndSensitiveFiles(
1005
1006
  filesOutput,
1006
1007
  this.fernignorePatterns
@@ -1015,19 +1016,31 @@ var ReplayDetector = class {
1015
1016
  `.fernignore-protected file(s) excluded from patch for commit ${commit.sha.slice(0, 7)}: ${fernignoredFiles.join(", ")}. These files are managed by .fernignore, not Replay.`
1016
1017
  );
1017
1018
  }
1018
- if ((sensitiveFiles.length > 0 || fernignoredFiles.length > 0) && files.length > 0) {
1019
- const parentSha = parents[0];
1020
- if (parentSha) {
1021
- try {
1022
- patchContent = await this.git.exec(["diff", parentSha, commit.sha, "--", ...files]);
1023
- } catch {
1024
- continue;
1025
- }
1026
- if (!patchContent.trim()) continue;
1027
- contentHash = this.computeContentHash(patchContent);
1019
+ if (files.length === 0) {
1020
+ continue;
1021
+ }
1022
+ const wasFiltered = sensitiveFiles.length > 0 || fernignoredFiles.length > 0;
1023
+ const parentSha = parents[0];
1024
+ let patchContent;
1025
+ if (wasFiltered && parentSha) {
1026
+ try {
1027
+ patchContent = await this.git.exec(["diff", parentSha, commit.sha, "--", ...files]);
1028
+ } catch {
1029
+ continue;
1030
+ }
1031
+ if (!patchContent.trim()) continue;
1032
+ } else {
1033
+ try {
1034
+ patchContent = await this.git.formatPatch(commit.sha);
1035
+ } catch {
1036
+ this.warnings.push(
1037
+ `Could not generate patch for commit ${commit.sha.slice(0, 7)} \u2014 it may be unreachable in a shallow clone. Skipping.`
1038
+ );
1039
+ continue;
1028
1040
  }
1029
1041
  }
1030
- if (files.length === 0) {
1042
+ const contentHash = this.computeContentHash(patchContent);
1043
+ if (lock.patches.find((p) => p.content_hash === contentHash) || forgottenHashes.has(contentHash)) {
1031
1044
  continue;
1032
1045
  }
1033
1046
  const theirsSnapshot = await capturePatchSnapshot(this.git, files, commit.sha);