Skip to content

Fix submodules listing error #818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,9 @@ def iter_items(cls, repo, parent_commit='HEAD'):
entry = index.entries[index.entry_key(p, 0)]
sm = Submodule(repo, entry.binsha, entry.mode, entry.path)
except KeyError:
raise InvalidGitRepositoryError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way for this Exception to stay, just as there is a test that expects this behaviour (see the test-failure on travis).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do that, we wouldn't be able to keep listing the submodules here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stsewd I think all that's left before the merge is to fix the now failing test. It could be changed to now expect to no failure and to see a listing of the existing submodules - if you think there is not too much overlap with the test you added.

"Gitmodule path %r did not exist in revision of parent commit %s" % (p, parent_commit))
# The submodule doesn't exist, probably it wasn't
# removed from the .gitmodules file.
continue
# END handle keyerror
# END handle critical error

Expand Down
24 changes: 21 additions & 3 deletions git/test/test_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import os
import shutil
import sys
from unittest import skipIf

Expand Down Expand Up @@ -479,9 +480,8 @@ def test_root_module(self, rwrepo):
with sm.config_writer() as writer:
writer.set_value('path', fp) # change path to something with prefix AFTER url change

# update fails as list_items in such a situations cannot work, as it cannot
# find the entry at the changed path
self.failUnlessRaises(InvalidGitRepositoryError, rm.update, recursive=False)
# update doesn't fail, because list_items ignores the wrong path in such situations.
rm.update(recursive=False)

# move it properly - doesn't work as it its path currently points to an indexentry
# which doesn't exist ( move it to some path, it doesn't matter here )
Expand Down Expand Up @@ -660,6 +660,24 @@ def test_add_empty_repo(self, rwdir):
url=empty_repo_dir, no_checkout=checkout_mode and True or False)
# end for each checkout mode

@with_rw_directory
def test_list_only_valid_submodules(self, rwdir):
repo_path = osp.join(rwdir, 'parent')
repo = git.Repo.init(repo_path)
repo.git.submodule('add', self._small_repo_url(), 'module')
repo.index.commit("add submodule")

assert len(repo.submodules) == 1

# Delete the directory from submodule
submodule_path = osp.join(repo_path, 'module')
shutil.rmtree(submodule_path)
repo.git.add([submodule_path])
repo.index.commit("remove submodule")

repo = git.Repo(repo_path)
assert len(repo.submodules) == 0

@skipIf(HIDE_WINDOWS_KNOWN_ERRORS,
"""FIXME on cygwin: File "C:\\projects\\gitpython\\git\\cmd.py", line 671, in execute
raise GitCommandError(command, status, stderr_value, stdout_value)
Expand Down