mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
@@ -149,8 +149,9 @@ class Git(Base):
|
||||
|
||||
self.ignored_paths.append(path)
|
||||
|
||||
@staticmethod
|
||||
def _add_entry_to_gitignore(entry, gitignore):
|
||||
def _add_entry_to_gitignore(self, entry, gitignore):
|
||||
entry = self._escape(entry)
|
||||
|
||||
with open(gitignore, "a+", encoding="utf-8") as fobj:
|
||||
fobj.seek(0, os.SEEK_END)
|
||||
if fobj.tell() == 0:
|
||||
@@ -162,6 +163,12 @@ class Git(Base):
|
||||
prefix = "" if last == "\n" else "\n"
|
||||
fobj.write("{}{}\n".format(prefix, entry))
|
||||
|
||||
@staticmethod
|
||||
def _escape(entry):
|
||||
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)
|
||||
|
||||
|
||||
@@ -634,3 +634,14 @@ def test_should_protect_on_repeated_add(link, dvc_repo, repo_dir):
|
||||
dvc_repo.add(repo_dir.FOO)
|
||||
|
||||
assert not os.access(repo_dir.FOO, os.W_OK)
|
||||
|
||||
|
||||
def test_escape_gitignore_entries(git, dvc_repo, repo_dir):
|
||||
fname = "file!with*weird#naming_[1].txt"
|
||||
ignored_fname = r"/file\!with\*weird\#naming_\[1\].txt"
|
||||
|
||||
os.rename(repo_dir.FOO, fname)
|
||||
|
||||
dvc_repo.add(fname)
|
||||
|
||||
assert ignored_fname in get_gitignore_content()
|
||||
|
||||
Reference in New Issue
Block a user