-
Notifications
You must be signed in to change notification settings - Fork 1.3k
dvc: more explict error during init when .dvc is ignored by git #4978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ neatlynx/__pycache__ | |
| *.pyc | ||
| .env/ | ||
| .env2.7/ | ||
| .python-version | ||
|
|
||
| .dvc.conf.lock | ||
| .DS_Store | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,19 +45,22 @@ def init(root_dir=os.curdir, no_scm=False, force=False, subdir=False): | |
| scm = SCM(root_dir, search_parent_directories=subdir, no_scm=no_scm) | ||
| except SCMError: | ||
| raise InitError( | ||
| "{repo} is not tracked by any supported SCM tool (e.g. Git). " | ||
| f"{root_dir} is not tracked by any supported SCM tool (e.g. Git). " | ||
| "Use `--no-scm` if you don't want to use any SCM or " | ||
| "`--subdir` if initializing inside a subdirectory of a parent SCM " | ||
| "repository.".format(repo=root_dir) | ||
| "repository." | ||
| ) | ||
|
|
||
| if scm.is_ignored(dvc_dir): | ||
| raise InitError( | ||
| f"{dvc_dir} is ignored by your SCM tool. \n" | ||
| "Make sure that it's tracked, " | ||
| "for example, by adding '!.dvc' to .gitignore." | ||
|
Comment on lines
+56
to
+58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks fot this update! BTW what do you guys think about just saying "Git" for 2.x +? I don't know of any plans to support other SCMs soon anyway... Docs already only ever mention Git. |
||
| ) | ||
|
|
||
| if os.path.isdir(dvc_dir): | ||
| if not force: | ||
| raise InitError( | ||
| "'{repo}' exists. Use `-f` to force.".format( | ||
| repo=relpath(dvc_dir) | ||
| ) | ||
| ) | ||
| raise InitError(f"'{relpath(dvc_dir)}' exists. Use `-f` to force.") | ||
|
|
||
| remove(dvc_dir) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,7 +183,7 @@ def _get_gitignore(self, path): | |
|
|
||
| return entry, gitignore | ||
|
|
||
| def _ignored(self, path): | ||
| def is_ignored(self, path): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed it because it's used as a public method in the PR. |
||
| from dulwich import ignore | ||
| from dulwich.repo import Repo | ||
|
|
||
|
|
@@ -194,7 +194,7 @@ def _ignored(self, path): | |
| def ignore(self, path): | ||
| entry, gitignore = self._get_gitignore(path) | ||
|
|
||
| if self._ignored(path): | ||
| if self.is_ignored(path): | ||
| return | ||
|
|
||
| msg = "Adding '{}' to '{}'.".format(relpath(path), relpath(gitignore)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,3 +111,17 @@ def test_gen_dvcignore(tmp_dir): | |
| "# https://dvc.org/doc/user-guide/dvcignore\n" | ||
| ) | ||
| assert text == (tmp_dir / ".dvcignore").read_text() | ||
|
|
||
|
|
||
| def test_init_when_ignored_by_git(tmp_dir, scm, caplog): | ||
| # https://github.com/iterative/dvc/issues/3738 | ||
| tmp_dir.gen({".gitignore": ".*"}) | ||
| with caplog.at_level(logging.ERROR, logger="dvc"): | ||
| assert main(["init"]) == 1 | ||
|
Comment on lines
+119
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be better to test So something like with pytest.raises(InitError):
# test using DvcRepo.init() instead of main()
...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be better to leave testing with In issues the users did not see a clear message about the issue. Even though the exception when calling the |
||
| assert ( | ||
| "{dvc_dir} is ignored by your SCM tool. \n" | ||
| "Make sure that it's tracked, " | ||
| "for example, by adding '!.dvc' to .gitignore.".format( | ||
| dvc_dir=tmp_dir / DvcRepo.DVC_DIR | ||
| ) | ||
| ) in caplog.text | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pyenv file, right? I'm not a pyenv user (and we recommend using virtualenvs for anyone doing development on DVC), is it normal to gitignore this?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
.python-versionis used bypyenv. It's typical to ignore it in projects intended to be ran in multiple environments:https://github.com/github/gitignore/blob/master/Python.gitignore#L88
Note that
pyenvwithpyenv-virtualenvplugin is just a convenience wrapper on top ofvirtualenv. This is a very common way to use it, sovirtualenvis still being used..python-versionis a convenient feature that switches local shell env to what's mentioned in that file. It's typically a single line of text there.