I have been at this for hours now, and although I have a feeling I'm close I can't seem to figure this out.
I'm trying to make a script that takes a git repository, updates a submodule in that repository to a specified version, and commits that change.
What works:
I can find the repository, get the submodule and check out the commit I want.
What doesn't work:
I can't seem to add the updated submodule hash so I can commit it.
My Code:
repos = Repo('path/to/repos')
submodule = repos.submodule('submodule-name')
submodule.module().git.checkout('wanted commit')
diff = repos.index.diff(None)
At this point I can see the submodule-change. If I check sourcetree, I can see the changed submodule in the 'unstaged files'. The thing is, I have no clue how to stage the change so I can commit it.
What I have tried:
- If I commit using
repos.index.commit('')
, it creates an empty commit. - If I try to add the path of the submodule using
repos.index.add([submodule.path])
, all files in the submodule are added to the repository, which is definately not what I want. - If I try to add the submodule itself (which should be possible according to the docs) using
repos.index.add([submodule])
, nothing seems to happen.
repos.index.add([submodule])
but… yeah, nothing happens. A bug maybe? I reported it here: github.com/gitpython-developers/GitPython/issues/335 – Lupercalia