Repository: iterative/dvc

Issue:
Analytics errors out on SCM creation
After https://github.com/iterative/dvc/pull/3257

`dvc init --no-scm` throws errors which seem to be related to the analytics module.

Discussion:

Patch:
diff --git a/dvc/analytics.py b/dvc/analytics.py
index f6d404179..eb7f99a12 100644
--- a/dvc/analytics.py
+++ b/dvc/analytics.py
@@ -15,7 +15,8 @@ from dvc.daemon import daemon
 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
 


Test patch:
diff --git a/tests/func/test_analytics.py b/tests/func/test_analytics.py
index 2e0a18498..b2294b8cb 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"