git: use escape method from GitWildMatchPattern

This commit is contained in:
Mr. Outis
2019-10-03 12:10:52 -05:00
parent 9496f34f45
commit a47ea23561
2 changed files with 3 additions and 9 deletions
+2 -8
View File
@@ -6,6 +6,7 @@ import os
import logging
from funcy import cached_property
from pathspec.patterns import GitWildMatchPattern
from dvc.exceptions import GitHookAlreadyExistsError
from dvc.utils.compat import str, open
@@ -150,7 +151,7 @@ class Git(Base):
self.ignored_paths.append(path)
def _add_entry_to_gitignore(self, entry, gitignore):
entry = self._escape(entry)
entry = GitWildMatchPattern.escape(entry)
with open(gitignore, "a+", encoding="utf-8") as fobj:
fobj.seek(0, os.SEEK_END)
@@ -163,13 +164,6 @@ class Git(Base):
prefix = "" if last == "\n" else "\n"
fobj.write("{}{}\n".format(prefix, entry))
@staticmethod
def _escape(entry):
# Reference: https://git-scm.com/docs/gitignore#_pattern_format
meta_characters = r"[]!*#?"
return "".join("\\" + x if x in meta_characters else x for x in entry)
def ignore_remove(self, path):
entry, gitignore = self._get_gitignore(path)
+1 -1
View File
@@ -63,7 +63,7 @@ install_requires = [
"humanize>=0.5.1",
"ruamel.yaml>=0.16.1",
"funcy>=1.12",
"pathspec>=0.5.9",
"pathspec@git+https://github.com/cpburnz/python-path-specification@master",
"shortuuid>=0.5.0",
"tqdm>=4.35.0",
"packaging>=19.0",