track_file_versions
Analyze complete version history of a specific file in a git repository, tracking renames and moves to understand its evolution.
Instructions
Track complete version history of a specific file, including renames and moves
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repoPath | Yes | Path to git repository | |
| file | Yes | File to analyze | |
| outputPath | Yes | Path to write analysis output |
Implementation Reference
- src/index.ts:301-321 (handler)The primary handler function for the 'track_file_versions' tool. It fetches the complete Git history and renames for the specified file, generates a summary, writes the analysis as JSON to the output path, and returns a success message.private async handleFileVersions(args: FileVersionArgs) { const history = this.getCompleteFileHistory(args.repoPath, args.file); const renames = this.getFileRenames(args.repoPath, args.file); const analysis = { history, renames, summary: this.generateVersionSummary(history), }; writeFileSync(args.outputPath, JSON.stringify(analysis, null, 2)); return { content: [ { type: 'text', text: `File version analysis written to ${args.outputPath}`, }, ], }; }
- src/index.ts:146-167 (registration)Tool registration in the ListTools handler, including name, description, and input schema definition.{ name: 'track_file_versions', description: 'Track complete version history of a specific file, including renames and moves', inputSchema: { type: 'object', properties: { repoPath: { type: 'string', description: 'Path to git repository', }, file: { type: 'string', description: 'File to analyze', }, outputPath: { type: 'string', description: 'Path to write analysis output', }, }, required: ['repoPath', 'file', 'outputPath'], }, },
- src/index.ts:14-18 (schema)TypeScript interface defining the input parameters for the track_file_versions tool.interface FileVersionArgs { repoPath: string; file: string; outputPath: string; }
- src/index.ts:60-71 (schema)Runtime validation function to check if arguments match FileVersionArgs shape before calling the handler.private isFileVersionArgs(args: unknown): args is FileVersionArgs { return ( typeof args === 'object' && args !== null && 'repoPath' in args && 'file' in args && 'outputPath' in args && typeof (args as FileVersionArgs).repoPath === 'string' && typeof (args as FileVersionArgs).file === 'string' && typeof (args as FileVersionArgs).outputPath === 'string' ); }
- src/index.ts:389-399 (helper)Helper function that executes Git command to retrieve the complete version history of the file, including follow for renames.private getCompleteFileHistory(repoPath: string, file: string) { const output = execSync( `cd "${repoPath}" && git log --follow --format="%H|%aI|%an|%s" -- "${file}"`, { encoding: 'utf8' } ); return output.trim().split('\n').filter(Boolean).map(line => { const [hash, date, author, message] = line.split('|'); return { hash, date, author, message }; }); }