0

I am trying to get previous file versions and the persons who changed that fie by using the Nodegit module. Even though the file is existing in the repository I am getting ** file path "file_name" not existing in the given tree**. This is the function I am calling.

async function getFileCommits(repositoryPath, filePath) {
    try {
        const repository = await NodeGit.Repository.open(repositoryPath);
        const headCommit = await repository.getHeadCommit();
        const walker = repository.createRevWalk();

        // Manually iterate through the commit history
        walker.push(headCommit.id());
        walker.sorting(NodeGit.Revwalk.SORT.TIME);

        const commits = [];
        while (true) {
            const commitId = await walker.next();
            if (!commitId) break;

            const commit = await repository.getCommit(commitId);
            const entry = await commit.getEntry(filePath);

            if (entry) {
                commits.push(commit);
            }
        }

        console.log(`Commits related to ${filePath}:`);
        for (const commit of commits) {
            console.log(`Commit ID: ${commit.sha()}`);
            console.log(`Author: ${commit.author().name()} <${commit.author().email()}>`);
            console.log(`Date: ${commit.date()}`);
            console.log('---');
        }
    } catch (error) {
        console.error('Error retrieving commits:', error);
    }
}

I tried giving the correct repo path and correct file path. I am expecting the exact commits which are related to the specific file. If I can at least have the commit ids for the specific file I can try to get the author's and committer's information. I want to know if there is anything wrong with the function I provided.

Ram
  • 1

0 Answers0