Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Index.add fails when certain patterns are entered that could be file system globs #994

Closed
@krcrouse

Description

It looks like add() attempts to glob any string path, which fails when a verbatim filename string matches an invalid glob regular expression. I don't see a way to override the globbing of the filename.

Here is a simple example:


import git 
repo = git.Repo()
repo.index.add('filename [2019-2020].txt')

Result:


Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/git/index/base.py", line 740, in add
 entries_added.extend(self._entries_for_paths(paths, path_rewriter, fprogress, entries))
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/git/util.py", line 68, in wrapper
 return func(self, *args, **kwargs)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/git/index/util.py", line 91, in set_git_working_dir
 return func(self, *args, **kwargs)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/git/index/base.py", line 625, in _entries_for_paths
 for filepath in self._iter_expand_paths(paths):
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/git/index/base.py", line 378, in _iter_expand_paths
 resolved_paths = glob.glob(abs_path)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/glob.py", line 20, in glob
 return list(iglob(pathname, recursive=recursive))
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/glob.py", line 72, in _iglob
 for name in glob_in_dir(dirname, basename, dironly):
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/glob.py", line 83, in _glob1
 return fnmatch.filter(names, pattern)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/fnmatch.py", line 52, in filter
 match = _compile_pattern(pat)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/fnmatch.py", line 46, in _compile_pattern
 return re.compile(res).match
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py", line 234, in compile
 return _compile(pattern, flags)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py", line 286, in _compile
 p = sre_compile.compile(pattern, flags)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sre_compile.py", line 764, in compile
 p = sre_parse.parse(p, flags)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sre_parse.py", line 930, in parse
 p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sre_parse.py", line 426, in _parse_sub
 not nested and not items))
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sre_parse.py", line 816, in _parse
 p = _parse_sub(source, state, sub_verbose, nested + 1)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sre_parse.py", line 426, in _parse_sub
 not nested and not items))
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sre_parse.py", line 580, in _parse
 raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range 9-2 at position 18

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /