From a47ea235614e7ebf366dd0f5b54015f17b25cf91 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Thu, 3 Oct 2019 12:10:52 -0500 Subject: [PATCH] git: use escape method from GitWildMatchPattern --- dvc/scm/git/__init__.py | 10 ++-------- setup.py | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 11b91e339..d9d52fe92 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -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) diff --git a/setup.py b/setup.py index 0da1837cf..a57b84c4c 100644 --- a/setup.py +++ b/setup.py @@ -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",