How to use the isomorphic-git.add 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 / setupInitialRepository.ts View on Github external
try {
    await pify(fs.mkdir)("/repo")
  } catch (e) {
    // repo exists
  }

  // ensure git
  if (await existsPath(j(projectRoot, ".git"))) {
    // Pass
  } else {
    await git.init({ dir: projectRoot })
    await git.add({
      dir: "/playground",
      filepath: "README.md"
    })
    await git.add({
      dir: "/playground",
      filepath: ".gitignore"
    })
    await git.add({
      dir: "/playground",
      filepath: "scratch.md"
    })
    await git.commit({
      author: {
        email: "dummy",
        name: "system"
      },
      dir: "/playground",
      message: "Init"
    })
  }
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,
    message,
    author
  })
}
github telstra / openapi-platform / packages / git-util / src / index.ts View on Github external
dir: repoDir,
      // Could use mz/fs but I don't trust it guarentees compatibility with isomorphic git
      fs: oldFs,
      url: gitInfo.repoUrl,
      singleBranch: true,
      depth: 1,
      ...gitInfo.auth,
    });

    await migrateSdkIntoLocalRepo(repoDir, remoteSdkUrl, options);
    const addedPaths = await getAllStageableFilepathsInRepo(repoDir);
    logger.verbose(`Staging ${addedPaths.length} paths`);
    for (const addedPath of addedPaths) {
      const relativeFilePath = relative(repoDir, addedPath);
      // TODO: Got a lot of "oldFs: fs", maybe make some sort of wrapper to avoid this?
      await add({
        fs: oldFs,
        dir: repoDir,
        filepath: relativeFilePath,
      });
    }
    logger.verbose(`Committing changes...`);
    await commit({
      fs: oldFs,
      dir: repoDir,
      // TODO: This should be configurable
      author: {
        name: 'Swagger Platform',
        email: 'N/A',
      },
      // TODO: Could have a better message
      message: 'Updated SDK',
github mizchi / next-editor / src / domain / git / __testHelpers__ / helpers.ts View on Github external
export async function batchUpdateFiles(
  projectRoot: string,
  files: Array<[string, string]>,
  message: string = "Update"
): Promise {
  for (const [filename, content] of files) {
    await fs.promises.writeFile(path.join(projectRoot, filename), content)
    await git.add({ dir: projectRoot, filepath: filename })
  }
  return git.commit({
    dir: projectRoot,
    message,
    author: { name: "test", email: "test" }
  })
}
github DubstepJS / core / src / utils / git-commit.js View on Github external
export const gitCommit = async (message: string) => {
  const paths = await globby(['./**', './**/.*'], {gitignore: true});
  for (const filepath of paths) {
    await git.add({fs, dir: '.', filepath}).catch(() => {});
  }

  const {user = {name: 'dubstep', email: 'dubstep'}} = await getGlobalConfig();
  const name = (await get('user.name')) || user.name;
  const email = (await get('user.email')) || user.email;
  await git.commit({fs, dir: '.', author: {name, email}, message});
};
github mizchi / next-editor / src / domain / git / commands / createProject.ts View on Github external
export async function createProject(newProjectRoot: string): Promise {
  await mkdir(newProjectRoot)
  await git.init({ dir: newProjectRoot })
  const outpath = path.join(newProjectRoot, "README.md")
  await writeFile(outpath, "# New Project")
  await git.add({ dir: newProjectRoot, filepath: "README.md" })
  await git.commit({
    dir: newProjectRoot,
    author: { name: "system", email: "dummy" },
    message: "Init"
  })
}
github nteract / nteract / applications / desktop / src / notebook / epics / git.js View on Github external
actions.gitAddFailed({
            error: new Error("no notebook loaded to add"),
            contentRef: action.payload.contentRef
          })
        );
      }
      const filepath = content.filepath;
      const repo = {
        fs,
        dir: filepath.substring(0, filepath.lastIndexOf("/"))
      };
      const notebookdir = filepath.split("/");
      const notebook = notebookdir[notebookdir.length - 1];
      const notificationSystem = selectors.notificationSystem(state);

      return from(git.add({ ...repo, filepath: notebook })).pipe(
        map(
          () =>
            actions.gitAddSuccessful({ contentRef: action.payload.contentRef }),
          notificationSystem.addNotification({
            title: "Changes Staged",
            message: `Changes to the notebook have been staged.`,
            dismissible: true,
            position: "tr",
            level: "success"
          })
        ),
        catchError(err => {
          actions.gitAddFailed(err);
        })
      );
    })
github mizchi / next-editor / src / domain / git / commands / addFile.ts View on Github external
export function addFile(projectRoot: string, relpath: string): Promise {
  return git.add({ dir: projectRoot, filepath: relpath })
}
github casual-simulation / aux / WebClient / GitManager.ts View on Github external
private async _add(path: string) {
        this._index.push(path);
        await add({
            dir: this.projectDir,
            filepath: path
        });
    }
}
github mizchi / next-editor / src / lib / repository.ts View on Github external
export function addFileInRepository(
  projectRoot: string,
  relpath: string
): Promise {
  return git.add({ fs, dir: projectRoot, filepath: relpath })
}