MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getGitDiffSize

Function getGitDiffSize

src/utils/commitAttribution.ts:751–788  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

749 * For deleted files, returns the size of the deleted content.
750 */
751export async function getGitDiffSize(filePath: string): Promise<number> {
752 const cwd = getAttributionRepoRoot()
753
754 try {
755 // Use git diff --stat to get a summary of changes
756 const result = await execFileNoThrowWithCwd(
757 gitExe(),
758 ['diff', '--cached', '--stat', '--', filePath],
759 { cwd, timeout: 5000 },
760 )
761
762 if (result.code !== 0 || !result.stdout) {
763 return 0
764 }
765
766 // Parse the stat output to extract additions and deletions
767 // Format: " file | 5 ++---" or " file | 10 +"
768 const lines = result.stdout.split('\n').filter(Boolean)
769 let totalChanges = 0
770
771 for (const line of lines) {
772 // Skip the summary line (e.g., "1 file changed, 3 insertions(+), 2 deletions(-)")
773 if (line.includes('file changed') || line.includes('files changed')) {
774 const insertMatch = line.match(/(\d+) insertions?/)
775 const deleteMatch = line.match(/(\d+) deletions?/)
776
777 // Use line-based changes and approximate chars per line (~40 chars average)
778 const insertions = insertMatch ? parseInt(insertMatch[1]!, 10) : 0
779 const deletions = deleteMatch ? parseInt(deleteMatch[1]!, 10) : 0
780 totalChanges += (insertions + deletions) * 40
781 }
782 }
783
784 return totalChanges
785 } catch {
786 return 0
787 }
788}
789
790/**
791 * Check if a file was deleted in the staged changes.

Callers 1

Calls 2

getAttributionRepoRootFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85

Tested by

no test coverage detected