MCPcopy Index your code
hub / github.com/code-pushup/cli / listChangedFiles

Function listChangedFiles

packages/ci/src/lib/git.ts:39–88  ·  view source on GitHub ↗
(
  refs: {
    base: string;
    head: string;
  },
  git = simpleGit(),
)

Source from the content-addressed store, hash-verified

37}
38
39export async function listChangedFiles(
40 refs: {
41 base: string;
42 head: string;
43 },
44 git = simpleGit(),
45): Promise<ChangedFiles> {
46 const statuses: DiffNameStatus[] = [
47 DiffNameStatus.ADDED,
48 DiffNameStatus.COPIED,
49 DiffNameStatus.MODIFIED,
50 DiffNameStatus.RENAMED,
51 ];
52 const { files } = await git.diffSummary([
53 refs.base,
54 refs.head,
55 `--diff-filter=${statuses.join('')}`,
56 '--find-renames',
57 '--find-copies',
58 ]);
59
60 const entries = await Promise.all(
61 files
62 .filter(({ binary }) => !binary)
63 .map(({ file }) => {
64 const rename = parseFileRename(file);
65 if (rename) {
66 return { file: rename.curr, originalFile: rename.prev };
67 }
68 return { file };
69 })
70 .map(async ({ file, originalFile }) => {
71 const diff = await git.diff([
72 '--unified=0',
73 refs.base,
74 refs.head,
75 '--',
76 file,
77 ...(originalFile ? [originalFile] : []),
78 ]);
79 const lineChanges = parseDiff(diff);
80 return [
81 file,
82 { ...(originalFile && { originalFile }), lineChanges },
83 ] as const;
84 }),
85 );
86
87 return Object.fromEntries(entries);
88}
89
90function parseFileRename(file: string): { prev: string; curr: string } | null {
91 const partialRenameMatch = file.match(/^(.*){(.*) => (.*)}(.*)$/);

Callers 2

findNewIssuesFunction · 0.85
git.int.test.tsFile · 0.85

Calls 2

parseFileRenameFunction · 0.85
parseDiffFunction · 0.85

Tested by

no test coverage detected