Search code examples
pythongitgit-submodulesgitpython

How to use variables of git submodule foreach in gitpython


Using gitpython, I would like to use repo.git.submodule('foreach', …) and get the variables available such as name, sm_path, displaypath, sha1 and toplevel as defined in the git documentation.

I couldn't find any documentation on gitpython and my understanding of the API is limited.


Solution

  • Thanks to stsewd reply on Github issue, one should write

    repo = git.Repo('foo/bar')
    for sub in repo.submodules:
        pass
    

    and the documentation: https://gitpython.readthedocs.io/en/stable/reference.html#git.repo.base.Repo.submodules