How to get changed files list with isomorphic-git?

Viewed 57

git status can display all changed files in the current folder.

But the filepath is required with isomorphic-git's status command.

How can I get the list of the changed files with isomorphic-git?

Thank you.

1 Answers

There is statusMatrix command for enumerating statuses of many/all files.

An example of enumerating all modified/deleted/added files:

const FILE = 0, HEAD = 1, WORKDIR = 2, STAGE = 3;

const statusMapping = {  
  "003": "added, staged, deleted unstaged",
  "020": "new, untracked",
  "022": "added, staged",
  "023": "added, staged, with unstaged changes",
  "100": "deleted, staged",
  "101": "deleted, unstaged",
  "103": "modified, staged, deleted unstaged",
  "111": "unmodified",
  "121": "modified, unstaged",
  "122": "modified, staged",
  "123": "modified, staged, with unstaged changes"
};

let statusMatrix = (await git.statusMatrix({ fs, dir }))
  .filter(row => row[HEAD] !== row[WORKDIR] || row[HEAD] !== row[STAGE]);

let allUncommitedChanges = statusMatrix.map(row => statusMapping[row.slice(1).join("")] + ": " + row[FILE]);
Related