mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
analytics: fix resolving used scm (#3405)
This commit is contained in:
+4
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user