Skip to content

Commit

Permalink
analytics: fix resolving used scm (#3405)
Browse files Browse the repository at this point in the history
  • Loading branch information
pared authored Feb 26, 2020
1 parent 432e399 commit a9bc65e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dvc/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions tests/func/test_analytics.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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"

0 comments on commit a9bc65e

Please sign in to comment.