MCPcopy Index your code
hub / github.com/remix-run/react-router / findVersionIntroductionCommit

Function findVersionIntroductionCommit

scripts/utils/git.ts:34–84  ·  view source on GitHub ↗
(
  packageJsonPath: string,
  version: string,
)

Source from the content-addressed store, hash-verified

32 * Returns null when the version can't be found in the available git history.
33 */
34export function findVersionIntroductionCommit(
35 packageJsonPath: string,
36 version: string,
37): string | null {
38 let normalizedPath = packageJsonPath.replaceAll("\\", "/");
39
40 let output: string;
41 try {
42 output = execGit(["log", "--format=%H", "--", normalizedPath]);
43 } catch {
44 return null;
45 }
46
47 if (output.length === 0) {
48 return null;
49 }
50
51 let commits = output.split("\n").filter((line) => line.length > 0);
52
53 for (let commit of commits) {
54 let commitVersion = getPackageVersionAtRef(commit, normalizedPath);
55 if (commitVersion !== version) {
56 continue;
57 }
58
59 let parentLine = execGit(["rev-list", "--parents", "-n", "1", commit]);
60 // eslint-disable-next-line @typescript-eslint/no-unused-vars
61 let [_commit, ...parents] = parentLine
62 .split(" ")
63 .filter((line) => line.length > 0);
64
65 if (parents.length === 0) {
66 return commit;
67 }
68
69 let introducedInCommit = false;
70 for (let parent of parents) {
71 let parentVersion = getPackageVersionAtRef(parent, normalizedPath);
72 if (parentVersion !== version) {
73 introducedInCommit = true;
74 break;
75 }
76 }
77
78 if (introducedInCommit) {
79 return commit;
80 }
81 }
82
83 return null;
84}
85
86/**
87 * Gets the local commit target for a tag.

Callers

nothing calls this directly

Calls 2

execGitFunction · 0.85
getPackageVersionAtRefFunction · 0.85

Tested by

no test coverage detected