How to use the isomorphic-git.statusMatrix function in isomorphic-git

To help you get started, weโ€™ve selected a few isomorphic-git examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mizchi / next-editor / src / domain / git / commands / commitAll.ts View on Github external
export async function commitAll(
  root: string,
  message: string,
  author: { name: string; email: string }
): Promise {
  const mat = await git.statusMatrix({ dir: root })
  const modified = Parser.getModifiedFilenames(mat)
  const removable = Parser.getRemovableFilenames(mat)

  for (const filepath of modified) {
    if (removable.includes(filepath)) {
      await git.remove({ dir: root, filepath })
    } else {
      // TODO: Why?????
      if (filepath) {
        await git.add({ dir: root, filepath })
      }
    }
  }

  return git.commit({
    dir: root,
github InventivetalentDev / PluginBlueprint / js / versionControl.js View on Github external
return new Promise((resolve, reject) => {
        git.statusMatrix({dir: projectPath})
            .then((status) => {// https://isomorphic-git.org/docs/en/snippets#git-add-a-
                return Promise.all(
                    status.map(([filepath, , worktreeStatus]) =>
                        // isomorphic-git may report a changed file as unmodified, so always add if not removing
                        worktreeStatus ? git.add({dir: projectPath, filepath: filepath}) : git.remove({dir: projectPath, filepath: filepath})
                    )
                );
            })
            .then(() => {
                return git.commit({
                    dir: projectPath,
                    message: msg || "N/A",
                    author: {
                        name: project.gitUser ? project.gitUser : "PluginBlueprint",
                        email: project.gitUser ? project.gitUser : "git@pluginblueprint.net"
                    }
github adobe / helix-cli / src / git-utils.js View on Github external
static async isDirty(dir, homedir = os.homedir()) {
    // see https://isomorphic-git.org/docs/en/statusMatrix
    const HEAD = 1;
    const WORKDIR = 2;
    const STAGE = 3;
    const matrix = await git.statusMatrix({ dir });
    let modified = matrix
      .filter((row) => !(row[HEAD] === row[WORKDIR] && row[WORKDIR] === row[STAGE]));
    if (modified.length === 0) {
      return false;
    }

    // ignore submodules
    // see https://github.com/adobe/helix-cli/issues/614
    const gitModules = path.resolve(dir, '.gitmodules');
    if (await fse.pathExists(gitModules)) {
      const modules = ini.parse(await fse.readFile(gitModules, 'utf-8'));
      Object.keys(modules).forEach((key) => {
        const module = modules[key];
        if (module.path) {
          modified = modified.filter((row) => !row[0].startsWith(module.path));
        }
github mizchi / next-editor / src / domain / git / queries / updateStatusMatrix.ts View on Github external
export async function updateStatusMatrix(
  projectRoot: string,
  matrix: StatusMatrix,
  patterns: string[]
): Promise {
  // return getStagingStatus(projectRoot)
  if (patterns.length === 0) {
    return git.statusMatrix({ dir: projectRoot })
  }

  const buffer = [...matrix]
  for (const pattern of patterns) {
    const newMat = await git.statusMatrix({
      dir: projectRoot,
      pattern
    })

    for (const newRow of newMat) {
      const [fpath] = newRow
      const bufferIndex = buffer.findIndex(([f]: StatusRow) => {
        return f === fpath
      })

      if (bufferIndex > -1) {
github felipemanga / FemtoIDE / plugins / git.js View on Github external
gitCommitAll(){
            git.statusMatrix({dir})
                .then(matrix=>{
                    return Promise.all(
                        matrix
                            .filter(([file, head, work, stage])=>{
                                return (head != 1 || work != 1 || stage != 1);
                            })
                            .map(([filepath, head, work, stage])=>{
                                if( work == 0 )
                                    return git.remove({dir, filepath});
                                return git.add({dir, filepath});
                            })
                    );
                })
                .then(res=>{
                    if( res.length == 0 ){
                        APP.log("Nothing to commit");