Special dir warning #3436 (#4229)

* add special folder warning

* add special folder warning

* remove special folder warning, start working on default dvcignore

* add default .dvcignote and templates

* remove dvcignore templates

* change text and add tests

* refactor

* dvcignore: ignore comments

* adjust tests

Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Anatoly
2020-08-13 01:03:34 +03:00
committed by GitHub
co-authored by Ruslan Kuprieiev
parent 64f038fda8
commit 5cb36fc983
5 changed files with 42 additions and 2 deletions
+16 -1
View File
@@ -64,7 +64,7 @@ class DvcIgnorePatterns(DvcIgnore):
for line_no, line in enumerate( for line_no, line in enumerate(
map(str.strip, fobj.readlines()) map(str.strip, fobj.readlines())
) )
if line if line and not (line.strip().startswith("#"))
] ]
return cls(path_spec_lines, dirname) return cls(path_spec_lines, dirname)
@@ -325,3 +325,18 @@ class DvcIgnoreFilter:
if matches: if matches:
return CheckIgnoreResult(target, True, matches) return CheckIgnoreResult(target, True, matches)
return CheckIgnoreResult(target, False, ["::"]) return CheckIgnoreResult(target, False, ["::"])
def init(path):
dvcignore = os.path.join(path, DvcIgnore.DVCIGNORE_FILE)
if os.path.exists(dvcignore):
return dvcignore
with open(dvcignore, "w") as fobj:
fobj.write(
"# Add patterns of files dvc should ignore, which could improve\n"
"# the performance. Learn more at\n"
"# https://dvc.org/doc/user-guide/dvcignore\n"
)
return dvcignore
+6 -1
View File
@@ -6,6 +6,7 @@ import colorama
from dvc import analytics from dvc import analytics
from dvc.config import Config from dvc.config import Config
from dvc.exceptions import InitError, InvalidArgumentError from dvc.exceptions import InitError, InvalidArgumentError
from dvc.ignore import init as init_dvcignore
from dvc.repo import Repo from dvc.repo import Repo
from dvc.scm import SCM from dvc.scm import SCM
from dvc.scm.base import SCMError from dvc.scm.base import SCMError
@@ -99,9 +100,13 @@ def init(root_dir=os.curdir, no_scm=False, force=False, subdir=False):
with config.edit() as conf: with config.edit() as conf:
conf["core"]["no_scm"] = True conf["core"]["no_scm"] = True
dvcignore = init_dvcignore(root_dir)
proj = Repo(root_dir) proj = Repo(root_dir)
scm.add([config.files["repo"], proj.plot_templates.templates_dir]) scm.add(
[config.files["repo"], dvcignore, proj.plot_templates.templates_dir]
)
if scm.ignore_file: if scm.ignore_file:
scm.add([os.path.join(dvc_dir, scm.ignore_file)]) scm.add([os.path.join(dvc_dir, scm.ignore_file)])
+1
View File
@@ -132,6 +132,7 @@ def test_ignore_on_branch(tmp_dir, scm, dvc):
assert set(dvc.tree.walk_files(path)) == { assert set(dvc.tree.walk_files(path)) == {
path / "foo", path / "foo",
path / "bar", path / "bar",
path / ".dvcignore",
} }
dvc.tree = scm.get_tree("branch", use_dvcignore=True) dvc.tree = scm.get_tree("branch", use_dvcignore=True)
+10
View File
@@ -101,3 +101,13 @@ def test_subdir_init_no_option(tmp_dir, scm, monkeypatch, caplog):
"`--subdir` if initializing inside a subdirectory of a parent SCM " "`--subdir` if initializing inside a subdirectory of a parent SCM "
"repository.".format(os.fspath(tmp_dir / "subdir")) "repository.".format(os.fspath(tmp_dir / "subdir"))
) in caplog.text ) in caplog.text
def test_gen_dvcignore(tmp_dir):
DvcRepo.init(no_scm=True)
text = (
"# Add patterns of files dvc should ignore, which could improve\n"
"# the performance. Learn more at\n"
"# https://dvc.org/doc/user-guide/dvcignore\n"
)
assert text == (tmp_dir / ".dvcignore").read_text()
+9
View File
@@ -61,6 +61,7 @@ def test_ls_repo(tmp_dir, dvc, scm):
match_files( match_files(
files, files,
( (
((".dvcignore",), False),
((".gitignore",), False), ((".gitignore",), False),
(("README.md",), False), (("README.md",), False),
(("structure.xml.dvc",), False), (("structure.xml.dvc",), False),
@@ -89,6 +90,7 @@ def test_ls_repo_with_color(tmp_dir, dvc, scm, mocker, monkeypatch, caplog):
assert caplog.records[-1].msg == "\n".join( assert caplog.records[-1].msg == "\n".join(
[ [
".dvcignore",
".gitignore", ".gitignore",
"README.md", "README.md",
"\x1b[01;34mdata\x1b[0m", "\x1b[01;34mdata\x1b[0m",
@@ -107,6 +109,7 @@ def test_ls_repo_recursive(tmp_dir, dvc, scm):
match_files( match_files(
files, files,
( (
((".dvcignore",), False),
((".gitignore",), False), ((".gitignore",), False),
(("README.md",), False), (("README.md",), False),
(("structure.xml.dvc",), False), (("structure.xml.dvc",), False),
@@ -258,6 +261,7 @@ def test_ls_repo_with_removed_dvc_dir(tmp_dir, dvc, scm):
(("out.dvc",), False), (("out.dvc",), False),
(("dep",), True), (("dep",), True),
(("out",), False), (("out",), False),
((".dvcignore",), False),
((".gitignore",), False), ((".gitignore",), False),
), ),
) )
@@ -275,6 +279,7 @@ def test_ls_repo_with_removed_dvc_dir_recursive(tmp_dir, dvc, scm):
(("out.dvc",), False), (("out.dvc",), False),
(("dep",), True), (("dep",), True),
(("out", "file"), True), (("out", "file"), True),
((".dvcignore",), False),
((".gitignore",), False), ((".gitignore",), False),
), ),
) )
@@ -306,6 +311,7 @@ def test_ls_remote_repo(erepo_dir):
match_files( match_files(
files, files,
( (
((".dvcignore",), False),
((".gitignore",), False), ((".gitignore",), False),
(("README.md",), False), (("README.md",), False),
(("structure.xml.dvc",), False), (("structure.xml.dvc",), False),
@@ -326,6 +332,7 @@ def test_ls_remote_repo_recursive(erepo_dir):
match_files( match_files(
files, files,
( (
((".dvcignore",), False),
((".gitignore",), False), ((".gitignore",), False),
(("README.md",), False), (("README.md",), False),
(("structure.xml.dvc",), False), (("structure.xml.dvc",), False),
@@ -393,6 +400,7 @@ def test_ls_remote_repo_with_rev(erepo_dir):
match_files( match_files(
files, files,
( (
((".dvcignore",), False),
((".gitignore",), False), ((".gitignore",), False),
(("README.md",), False), (("README.md",), False),
(("model",), False), (("model",), False),
@@ -422,6 +430,7 @@ def test_ls_remote_repo_with_rev_recursive(erepo_dir):
(("model", "people.csv"), True), (("model", "people.csv"), True),
(("model", ".gitignore"), False), (("model", ".gitignore"), False),
(("structure.xml",), True), (("structure.xml",), True),
((".dvcignore",), False),
((".gitignore",), False), ((".gitignore",), False),
), ),
) )