Merge pull request #2552 from mroutis/fix-2043

git: escape filename before ignoring it
This commit is contained in:
Ruslan Kuprieiev
2019-10-04 11:33:48 +03:00
committed by GitHub
4 changed files with 25 additions and 3 deletions
+4 -2
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, cast_bytes_py2
@@ -162,8 +163,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 = GitWildMatchPattern.escape(entry)
with open(gitignore, "a+", encoding="utf-8") as fobj:
fobj.seek(0, os.SEEK_END)
if fobj.tell() == 0:
+3
View File
@@ -88,6 +88,9 @@ install_dependencies()
gem install --no-document fpm
print_info "Uprgading pip..."
pip install --upgrade pip
print_info "Installing requirements..."
pip install .[all] psutil
+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>=0.6.0",
"shortuuid>=0.5.0",
"tqdm>=4.35.0",
"packaging>=19.0",
+17
View File
@@ -634,3 +634,20 @@ 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].t?t"
ignored_fname = r"/file\!with\*weird\#naming_\[1\].t\?t"
if os.name == "nt":
# Some characters are not supported by Windows in the filename
# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
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()