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.

List files with unstaged changes

See original GitHub issue

I’m trying to figure out how to retrieve a list of files that have been modified, similar to the git status command. My current approach uses git.listFiles to get the list of all files known to the repository, and then calling git.status on every single file. Although this works, it is very slow compared to the native git status implementation, which returns the results much much faster. Plugging in my own file system implementation, I can see that for every git.status call on a file, there is a readFile .git/index, followed by lstat path/to/file/in/repo followed by readFile path/to/file/in/repo.

I think the bottleneck is that every file is read from the filesystem, not sure if that’s a bug, because I can see in the git.status code that it should only read the file if the attributes returned by the lstat command have changed.

Another bottleneck is that the index file is being read with every single git.status request to a file, which could be avoided if the initial index was cached and re-used for subsequent git.status calls.

Are there any plans to add an API for this feature, or any hints on how I can optimise my current routine?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wmhiltoncommented, Aug 16, 2018

See if the new statusMatrix command works for you. I included an example of how to solve for “What files have unstaged changes?” in the docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to show uncommitted changes in Git and some Git diffs in ...
The command you are looking for is git diff . git diff - Show changes between commits, commit and working tree, etc. Here...
Read more >
2.2 Git Basics - Recording Changes to the Repository
Viewing Your Staged and Unstaged Changes ... If the git status command is too vague for you — you want to know exactly...
Read more >
Git Tutorial => Show both staged and unstaged changes
To show all staged and unstaged changes, use: git diff HEAD. NOTE: You can also use the following command: git status -vv.
Read more >
Git - find staged files with unstaged changes
Thus detecting files with staged and non-staged changes can be done with git status -s | awk '/MM / { print $2 }'....
Read more >
How to Programmatically Determine if there are Uncommitted ...
The git status command is used for demonstrating the state of the working directory and the staging area. It allows viewing the staged...
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