You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following script raises an exception iterating the submodules of the repo after a failed creation of a submodule. I'd expect after catching the exception on the create_submodule for sub2, that I could still iterate the successfully added submodule, sub1.
This is a toy example obviously, but it illustrates the problem that a fail in the create_submodule causes.
import git
def list_submodules (repo):
print "List of submodules"
for submodule in repo.submodules:
print "Submodule: " + str(submodule)
main = git.Repo.init ('main')
sub1 = git.Repo.init ('sub1')
sub2 = git.Repo.init ('sub2')
main.index.commit ('Initial Commit to main')
sub1.index.commit ('Initial Commit to sub1')
list_submodules (main)
for m in ['sub1', 'sub2']:
try:
main.create_submodule (name='modules/' + m, path='modules/' + m, url=m)
main.index.add (['.gitmodules'])
print "Added submodule: " + m
except:
print "Fail for: " + m
list_submodules (main)
This is the output:
○ → rm -rf main sub1 sub2 && python sm.py
List of submodules
Added submodule: sub1
Fail for: sub2
List of submodules
Traceback (most recent call last):
File "sm.py", line 24, in <module>
list_submodules (main)
File "sm.py", line 5, in list_submodules
for submodule in repo.submodules:
File "C:\Python27\lib\site-packages\git\repo\base.py", line 290, in submodules
return Submodule.list_items(self)
File "C:\Python27\lib\site-packages\git\util.py", line 932, in list_items
out_list.extend(cls.iter_items(repo, *args, **kwargs))
File "C:\Python27\lib\site-packages\git\objects\submodule\base.py", line 1189, in iter_items
"Gitmodule path %r did not exist in revision of parent commit %s" % (p, parent_commit))
git.exc.InvalidGitRepositoryError: Gitmodule path u'modules/sub2' did not exist in revision of parent commit HEAD
Is there a GitPython equivalent to a git checkout . , which would discard the non-index changes, and might function as a workaround?
Ideally the create_submodule would clean up after itself though.
The text was updated successfully, but these errors were encountered:
Thanks for providing the details to help me reproducing the issue. Implementing atomicity for all GitPython commands would be great, even though it appears out of scope given that GitPython is in maintenance mode.
In an attempt to answer your question: GitPython itself allows to checkout files from the index itself which behaves more like plumbing. Some high-level commands are most easily accessed by using git itself, for example like repo.git.checkout('.').
The following script raises an exception iterating the submodules of the repo after a failed creation of a submodule. I'd expect after catching the exception on the create_submodule for sub2, that I could still iterate the successfully added submodule, sub1.
This is a toy example obviously, but it illustrates the problem that a fail in the create_submodule causes.
This is the output:
Is there a GitPython equivalent to a
git checkout .
, which would discard the non-index changes, and might function as a workaround?Ideally the create_submodule would clean up after itself though.
The text was updated successfully, but these errors were encountered: