I'm counting staged files in git using GitPython.
For modified files, I can use
repo = git.Repo()
modified_files = len(repo.index.diff(None))
But for staged files I can't find the solution.
I know git status --porcelain
but I'm looking for other solution which is better. (I hope using gitpython
not git command, the script will be faster)
len(repo.index.diff("HEAD"))
breaks on a repo with no commits. Is there any way around this? – Stark