repomix
Version:
A tool to pack repository contents to single file for AI consumption
42 lines (41 loc) • 1.22 kB
JavaScript
import { logger } from '../../shared/logger.js';
import { execGitLogFilenames, execGitRevParse, execGitVersion } from './gitCommand.js';
export const getFileChangeCount = async (directory, maxCommits = 100, deps = {
execGitLogFilenames,
}) => {
try {
const filenames = await deps.execGitLogFilenames(directory, maxCommits);
const fileChangeCounts = {};
for (const filename of filenames) {
fileChangeCounts[filename] = (fileChangeCounts[filename] || 0) + 1;
}
return fileChangeCounts;
}
catch (error) {
logger.trace('Failed to get file change counts:', error.message);
return {};
}
};
export const isGitRepository = async (directory, deps = {
execGitRevParse,
}) => {
try {
await deps.execGitRevParse(directory);
return true;
}
catch {
return false;
}
};
export const isGitInstalled = async (deps = {
execGitVersion,
}) => {
try {
const result = await deps.execGitVersion();
return !result.includes('error') && result.includes('git version');
}
catch (error) {
logger.trace('Git is not installed:', error.message);
return false;
}
};