question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reconsider git.add supporting multiple files

See original GitHub issue

Hi there!

Firstly let me thank you for this project - It has been very useful to us in implementing the git functions we want to support!

That said I am now looking into some key performance issues and am finding the git.add to be a pain point for us.

I am wondering if you would reconsider implementing multi file support for git.add … I am asking because it appears to be very slow to add lots of files in a loop for specific git repositories.

On average it is taking 46ms for each call to await git.add and we are looking to want to add 50-100 files at a time. Even on faster repositories its averaging around 30ms

perhaps something like this? await git.add(file1.txt folder/file2.txt file3.txt file4.txt file5.txt)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
crutchcorncommented, Sep 3, 2020

I’d like to implement this feature @wmhilton. For my usage, I’d like to see an aggregate of errors rather than failing on first step. I think we could throw an array of Errors? What do you think?

0reactions
linonetwocommented, May 2, 2021

I think I need add .

But will this work?

  const allFiles = await git.listFiles({ fs, dir: wikiFolderPath });
  await Promise.all(allFiles.map((filepath) => git.add({ fs, dir: wikiFolderPath, filepath })));

I’m confused because git.listFiles({ fs, dir: '/tutorial' }) will return all files, not just non-added files.

I can see faq have a similar snippet https://isomorphic-git.org/docs/en/faq#how-to-add-all-untracked-files-with-gitadd

const globby = require('globby');
const paths = await globby(['./**', './**/.*'], { gitignore: true });
for (const filepath of paths) {
    await git.add({ fs, dir, filepath });
}

I think both globby(['./**', './**/.*'], { gitignore: true }) and git.listFiles({ fs, dir: '/tutorial' }) will return all files. Which might make git.add run on many files that don’t need to be added?


Maybe I should follow https://isomorphic-git.org/docs/en/statusMatrix#q-what-files-have-unstaged-changes

To use:

  const unstagedFilePaths = (await git.statusMatrix({ dir, fs })).filter((row) => row[2] !== row[3]).map((row) => row[0]);
  await Promise.all(unstagedFilePaths.map((filepath) => git.add({ fs, dir, filepath })));
Read more comments on GitHub >

github_iconTop Results From Across the Web

git add multiple files at once - Stack Overflow
How to add multiple files with different extensions to git all at one time... You can add to git by explicitly listing each...
Read more >
Learn Git Basics - Nulab
You can modify the most recent commit in the same branch by running git commit –amend. This command is convenient for adding new...
Read more >
Introducing git-revise - NIKA:\>
git -revise uses a custom merge backend, which doesn't attempt to handle file renames or copies. For changes which need to be merged...
Read more >
git-revise(1) – Efficiently update, split, and rearrange git commits
git revise is a git(1) subcommand to efficiently update, split, and rearrange commits. It is heavily inspired by git-rebase(1), however tries to be...
Read more >
git-add Documentation - Git
This command can be performed multiple times before a commit. It only adds the content of the specified file(s) at the time the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found