Skip to content

index.add() fails with "maximum recursion depth exceeded" #407

Description

@ppietrasa

Here's how it looks:

Traceback (most recent call last):
[...]
File "/go/ems/emsppi/dev/plspu/git_release_import/git_release_import.py", line 914, in import_patch
self.repo.index.add(files_to_add, fprogress=fprogress)
File "/go/ems/emsppi/dev/plspu/git_release_import/ext/git/index/base.py", line 726, in add
entries_added.extend(self._entries_for_paths(paths, path_rewriter, fprogress, entries))
File "/go/ems/emsppi/dev/plspu/git_release_import/ext/git/util.py", line 54, in wrapper
return func(self, _args, *_kwargs)
File "/go/ems/emsppi/dev/plspu/git_release_import/ext/git/index/util.py", line 84, in set_git_working_dir
return func(self, _args, *_kwargs)
File "/go/ems/emsppi/dev/plspu/git_release_import/ext/git/index/base.py", line 611, in _entries_for_paths
for filepath in self._iter_expand_paths(paths):
File "/go/ems/emsppi/dev/plspu/git_release_import/ext/git/index/base.py", line 372, in _iter_expand_paths
for f in self._iter_expand_paths(glob.glob(abs_path)):
[...]
File "/go/ems/emsppi/dev/plspu/git_release_import/ext/git/index/base.py", line 372, in _iter_expand_paths
for f in self._iter_expand_paths(glob.glob(abs_path)):
File "/gow/ems/emsppi/local/lib/python2.7/glob.py", line 27, in glob
return list(iglob(pathname))
File "/gow/ems/emsppi/local/lib/python2.7/glob.py", line 64, in iglob
for name in glob_in_dir(dirname, basename):
File "/gow/ems/emsppi/local/lib/python2.7/glob.py", line 82, in glob1
names = filter(lambda x: x[0] != '.', names)
File "/gow/ems/emsppi/local/lib/python2.7/glob.py", line 82, in
names = filter(lambda x: x[0] != '.', names)
RuntimeError: maximum recursion depth exceeded in cmp

the files being added contained a file "[.exe" amongs them

Amongst the files_to_add there was a file called [.exe which I believe was the cause of the problem.

Below I attach a patch to index/base.py which is a proposal to resolve the issue and which fixed the problem for me.

--- a/git/index/base.py
+++ b/git/index/base.py
@@ -369,9 +369,17 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):

             # resolve globs if possible
             if '?' in path or '*' in path or '[' in path:
-                for f in self._iter_expand_paths(glob.glob(abs_path)):
-                    yield f.replace(rs, '')
-                continue
+                resolved_paths = glob.glob(abs_path)
+                # not abs_path in resolved_paths:
+                #   A glob() resolving to the same path we are feeding it with
+                #   is a glob() that failed to resolve. If we continued calling
+                #   ourselves we'd endlessly recurse. If the condition below
+                #   evaluates to true then we are likely dealing with a file
+                #   whose name contains wildcard characters.
+                if not abs_path in resolved_paths:
+                    for f in self._iter_expand_paths(glob.glob(abs_path)):
+                        yield f.replace(rs, '')
+                    continue
             # END glob handling
             try:
                 for root, dirs, files in os.walk(abs_path, onerror=raise_exc):

I am using GitPython v1.0.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions