diff --git a/dvc/analytics.py b/dvc/analytics.py index f6d404179e..eb7f99a12b 100644 --- a/dvc/analytics.py +++ b/dvc/analytics.py @@ -15,7 +15,8 @@ from dvc.exceptions import NotDvcRepoError from dvc.lock import Lock, LockError from dvc.repo import Repo -from dvc.scm import SCM +from dvc.scm import SCM, NoSCM +from dvc.scm.base import SCMError from dvc.utils import env2bool, is_binary from dvc.utils.fs import makedirs @@ -85,6 +86,8 @@ def _scm_in_use(): try: scm = SCM(root_dir=Repo.find_root()) return type(scm).__name__ + except SCMError: + return NoSCM.__name__ except NotDvcRepoError: pass diff --git a/tests/func/test_analytics.py b/tests/func/test_analytics.py index 2e0a184980..b2294b8cb3 100644 --- a/tests/func/test_analytics.py +++ b/tests/func/test_analytics.py @@ -1,7 +1,9 @@ import mock +from dvc.analytics import _scm_in_use from dvc.main import main from dvc.compat import fspath +from dvc.repo import Repo @mock.patch("dvc.analytics.send") @@ -19,3 +21,24 @@ def test_main_analytics(mock_is_enabled, mock_report, tmp_dir, dvc): assert 0 == main(["add", "foo"]) assert mock_is_enabled.called assert mock_report.called + + +def test_scm_dvc_only(tmp_dir, dvc): + scm = _scm_in_use() + assert scm == "NoSCM" + + +def test_scm_git(tmp_dir, scm, dvc): + scm = _scm_in_use() + assert scm == "Git" + + +def test_scm_subrepo(tmp_dir, scm): + subdir = tmp_dir / "subdir" + subdir.mkdir() + + with subdir.chdir(): + Repo.init(subdir=True) + scm = _scm_in_use() + + assert scm == "Git"