Search code examples
pythongitgitpython

How to check if a Git Repo has uncommitted changes by gitpython


I tried

g = git.Repo(r'C:\Users\Administrator\Desktop\testRepo')
print g.untracked_files

But got:

git.exc.GitCommandNotFound: [Error 2]

Is it a bug?


Solution

  • I don't have this error when I do exactly the same.

    Do you have git executable in your ${PATH} variable? If you are using bash you can run export PATH=$PATH:/path/to/your/git/executable

    From exc.py in gitpython:

    class GitCommandNotFound(Exception): """Thrown if we cannot find thegitexecutable in the PATH or at the path given by the GIT_PYTHON_GIT_EXECUTABLE environment variable""" pass one can assume that setting that env variable may also help.

    You can also set env variable directly from python in platform-independent way as greatly described here, instead of modifying your startup script (aka ~/.bash_profile or similar ):

    Python: Platform independent way to modify PATH environment variable