@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.cjs CHANGED
@@ -62,6 +62,11 @@ var init_GitClient = __esm({
62
62
  proc.stderr.on("data", (data) => {
63
63
  stderr += data.toString();
64
64
  });
65
+ proc.on("error", (err) => {
66
+ reject(new Error(`git ${args.join(" ")} failed to spawn: ${err.message}`));
67
+ });
68
+ proc.stdin.on("error", () => {
69
+ });
65
70
  proc.on("close", (code) => {
66
71
  if (code === 0) {
67
72
  resolve2(stdout);
@@ -863,7 +868,8 @@ function isBinaryFile(filePath) {
863
868
  var INFRASTRUCTURE_FILES = /* @__PURE__ */ new Set([".fernignore"]);
864
869
  function matchesFernignorePattern(filePath, patterns) {
865
870
  if (patterns.length === 0) return false;
866
- return patterns.some((p) => {
871
+ return patterns.some((rawPattern) => {
872
+ const p = rawPattern.endsWith("/") ? rawPattern.slice(0, -1) : rawPattern;
867
873
  if (filePath === p) return true;
868
874
  if ((0, import_minimatch2.minimatch)(filePath, p)) return true;
869
875
  if (!p.includes("*") && !p.includes("?") && filePath.startsWith(p + "/")) return true;
@@ -1042,20 +1048,15 @@ var ReplayDetector = class {
1042
1048
  continue;
1043
1049
  }
1044
1050
  const parents = await this.git.getCommitParents(commit.sha);
1045
- let patchContent;
1051
+ let filesOutput;
1046
1052
  try {
1047
- patchContent = await this.git.formatPatch(commit.sha);
1053
+ filesOutput = await this.git.exec(["diff-tree", "--no-commit-id", "--name-only", "-r", commit.sha]);
1048
1054
  } catch {
1049
1055
  this.warnings.push(
1050
1056
  `Could not generate patch for commit ${commit.sha.slice(0, 7)} \u2014 it may be unreachable in a shallow clone. Skipping.`
1051
1057
  );
1052
1058
  continue;
1053
1059
  }
1054
- let contentHash = this.computeContentHash(patchContent);
1055
- if (lock.patches.find((p) => p.content_hash === contentHash) || forgottenHashes.has(contentHash)) {
1056
- continue;
1057
- }
1058
- const filesOutput = await this.git.exec(["diff-tree", "--no-commit-id", "--name-only", "-r", commit.sha]);
1059
1060
  const { files, sensitiveFiles, fernignoredFiles } = filterInfrastructureAndSensitiveFiles(
1060
1061
  filesOutput,
1061
1062
  this.fernignorePatterns
@@ -1070,19 +1071,31 @@ var ReplayDetector = class {
1070
1071
  `.fernignore-protected file(s) excluded from patch for commit ${commit.sha.slice(0, 7)}: ${fernignoredFiles.join(", ")}. These files are managed by .fernignore, not Replay.`
1071
1072
  );
1072
1073
  }
1073
- if ((sensitiveFiles.length > 0 || fernignoredFiles.length > 0) && files.length > 0) {
1074
- const parentSha = parents[0];
1075
- if (parentSha) {
1076
- try {
1077
- patchContent = await this.git.exec(["diff", parentSha, commit.sha, "--", ...files]);
1078
- } catch {
1079
- continue;
1080
- }
1081
- if (!patchContent.trim()) continue;
1082
- contentHash = this.computeContentHash(patchContent);
1074
+ if (files.length === 0) {
1075
+ continue;
1076
+ }
1077
+ const wasFiltered = sensitiveFiles.length > 0 || fernignoredFiles.length > 0;
1078
+ const parentSha = parents[0];
1079
+ let patchContent;
1080
+ if (wasFiltered && parentSha) {
1081
+ try {
1082
+ patchContent = await this.git.exec(["diff", parentSha, commit.sha, "--", ...files]);
1083
+ } catch {
1084
+ continue;
1085
+ }
1086
+ if (!patchContent.trim()) continue;
1087
+ } else {
1088
+ try {
1089
+ patchContent = await this.git.formatPatch(commit.sha);
1090
+ } catch {
1091
+ this.warnings.push(
1092
+ `Could not generate patch for commit ${commit.sha.slice(0, 7)} \u2014 it may be unreachable in a shallow clone. Skipping.`
1093
+ );
1094
+ continue;
1083
1095
  }
1084
1096
  }
1085
- if (files.length === 0) {
1097
+ const contentHash = this.computeContentHash(patchContent);
1098
+ if (lock.patches.find((p) => p.content_hash === contentHash) || forgottenHashes.has(contentHash)) {
1086
1099
  continue;
1087
1100
  }
1088
1101
  const theirsSnapshot = await capturePatchSnapshot(this.git, files, commit.sha);