How can I list all files with NodeGit? (Equivalent of 'git ls-files')

469 Views Asked by At

I currently run the following git command for list of all untracked and modified files:

git ls-files -mo --exclude-standard

Is there any equivalent for it in the NodeGit world?

1

There are 1 best solutions below

0
nitishagar On

This is one of the ways, I got around to satisfy the above requirement:

const Git = require("nodegit");
const _ = require("lodash");


function getDirtyFiles(path) {

    Git.Repository.open(path).then(function (repository) {
        repository.getStatus().then(function(statusFiles) {
            const dirtyFiles = _.chain(statusFiles)
            .filter((statusFile) => (statusFile.isModified() || statusFile.isNew()))
            .flatMap((statusDirtyFile) => statusDirtyFile.path())
            .value();
            
            console.log(dirtyFiles);
        });
    });
};

getDirtyFiles(process.cwd());

The following line helps match -mo params: statusFile.isModified() || statusFile.isNew()