MCPcopy Create free account
hub / github.com/EvoMap/evolver / getGitDiffStats

Function getGitDiffStats

src/adapters/scripts/evolver-session-end.js:47–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45}
46
47function getGitDiffStats() {
48 // Use the host-provided workspace root, not process.cwd(): Cursor runs some
49 // hook events with cwd set to the plugin dir, where `git diff` finds nothing.
50 const cwd = resolveProjectDir();
51 // Distinguish "git failed (no HEAD~1, etc.)" from "git succeeded with
52 // empty output (e.g. empty merge)". The previous `||` chain treated
53 // both as falsy and fell through to the working-tree diff, which can
54 // surface unrelated unstaged changes as the session outcome.
55 const statHead1 = runGit(['diff', '--stat', 'HEAD~1'], cwd);
56 const stat = statHead1.ok ? statHead1.out : runGit(['diff', '--stat'], cwd).out;
57 const diffHead1 = runGit(['diff', '--no-color', 'HEAD~1'], cwd);
58 const diffContent = diffHead1.ok ? diffHead1.out : runGit(['diff', '--no-color'], cwd).out;
59 const filesChanged = (stat.match(/\d+ files? changed/) || ['0'])[0];
60 const insertions = (stat.match(/(\d+) insertions?/) || [null, '0'])[1];
61 const deletions = (stat.match(/(\d+) deletions?/) || [null, '0'])[1];
62 // Distinguish "no git repo here" from "repo with no changes" purely for the
63 // skip-log message — the diff commands above can't tell the two apart (both
64 // yield empty output). A single cheap rev-parse settles it.
65 const isRepo = runGit(['rev-parse', '--is-inside-work-tree'], cwd).out === 'true';
66 return {
67 stat,
68 summary: `${filesChanged}, +${insertions}/-${deletions}`,
69 diffSnippet: diffContent.slice(0, 2000),
70 hasChanges: stat.length > 0,
71 isRepo,
72 };
73}
74
75// Detect whether the hook is running inside Cursor.
76//

Callers 1

mainFunction · 0.85

Calls 2

resolveProjectDirFunction · 0.85
runGitFunction · 0.70

Tested by

no test coverage detected