From 371c57ac24701dfc50066b9734c25ec9742a8659 Mon Sep 17 00:00:00 2001 From: RahulR19 Date: Sun, 4 Aug 2019 23:26:45 +0530 Subject: [PATCH] Renamed git to repo in dvc/scm/git along with changes in some tests. --- dvc/external_repo.py | 4 ++-- dvc/scm/base.py | 3 +++ dvc/scm/git/__init__.py | 3 +++ tests/basic_env.py | 2 +- tests/conftest.py | 2 +- tests/func/test_diff.py | 4 ++-- tests/func/test_install.py | 10 +++++----- tests/func/test_metrics.py | 4 ++-- tests/func/test_repo.py | 2 +- tests/func/test_scm.py | 2 +- tests/func/test_update.py | 2 +- 11 files changed, 22 insertions(+), 16 deletions(-) diff --git a/dvc/external_repo.py b/dvc/external_repo.py index c29863465..cb5f38620 100644 --- a/dvc/external_repo.py +++ b/dvc/external_repo.py @@ -46,7 +46,7 @@ def _clone(cache_dir=None, **kwargs): repo = Repo(_path) cache_config = CacheConfig(repo.config) cache_config.set_dir(cache_dir, level=Config.LEVEL_LOCAL) - repo.scm.git.close() + repo.scm.close() return Repo(_path) @@ -70,7 +70,7 @@ def _clone_git_repo(to_path, url=None, rev=None, rev_lock=None): def _remove(repo): - repo.scm.git.close() + repo.scm.close() if os.name == "nt": # git.exe may hang for a while not permitting to remove temp dir diff --git a/dvc/scm/base.py b/dvc/scm/base.py index e52fafe99..e7cf61fa5 100644 --- a/dvc/scm/base.py +++ b/dvc/scm/base.py @@ -144,3 +144,6 @@ class Base(object): def belongs_to_scm(self, path): """Return boolean whether file belongs to scm""" + + def close(self): + """ Method to close the files """ diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index d4dffda64..290ca5802 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -323,3 +323,6 @@ class Git(Base): def get_rev(self): return self.repo.git.rev_parse("HEAD") + + def close(self): + self.repo.close() diff --git a/tests/basic_env.py b/tests/basic_env.py index 5de08bc0f..5afba2c3c 100644 --- a/tests/basic_env.py +++ b/tests/basic_env.py @@ -166,7 +166,7 @@ class TestDvcGitFixture(TestGitFixture): self.dvc.scm.commit("init dvc") def tearDown(self): - self.dvc.scm.git.close() + self.dvc.scm.close() super(TestDvcGitFixture, self).tearDown() diff --git a/tests/conftest.py b/tests/conftest.py index 8010ff18f..3356a4a0b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -162,7 +162,7 @@ def erepo(repo_dir): repo.dvc.scm.checkout("master") - repo.dvc.scm.git.close() + repo.dvc.scm.close() repo.git.close() os.chdir(repo._saved_dir) diff --git a/tests/func/test_diff.py b/tests/func/test_diff.py index f4b148cfa..92910a3d0 100644 --- a/tests/func/test_diff.py +++ b/tests/func/test_diff.py @@ -96,7 +96,7 @@ class TestDiffDir(TestDvcGit): self.git.index.add([self.DATA_DIR + ".dvc"]) self.git.index.commit("adds data_dir") self.a_ref = self.git.git.rev_parse( - self.dvc.scm.git.head.commit, short=True + self.dvc.scm.repo.head.commit, short=True ) self.old_checksum = _get_checksum(self.dvc, self.DATA_DIR) self.new_file = os.path.join(self.DATA_SUB_DIR, diff.DIFF_NEW_FILE) @@ -154,7 +154,7 @@ class TestDiffDirRepoDeletedFile(TestDiffDir): self.b_ref = self.a_ref self.new_checksum = self.old_checksum - self.a_ref = str(self.dvc.scm.git.head.commit) + self.a_ref = str(self.dvc.scm.repo.head.commit) self.old_checksum = _get_checksum(self.dvc, self.DATA_DIR) def test(self): diff --git a/tests/func/test_install.py b/tests/func/test_install.py index 1e3c7b8ba..140e0b5d5 100644 --- a/tests/func/test_install.py +++ b/tests/func/test_install.py @@ -88,12 +88,12 @@ class TestInstall(object): assert ret == 0 stage_file = repo_dir.FOO + Stage.STAGE_FILE_SUFFIX - dvc_repo.scm.git.index.add([stage_file, ".gitignore"]) - dvc_repo.scm.git.index.commit("commit message") + dvc_repo.scm.repo.index.add([stage_file, ".gitignore"]) + dvc_repo.scm.repo.index.commit("commit message") - dvc_repo.scm.git.clone(git_remote) - dvc_repo.scm.git.create_remote("origin", git_remote) + dvc_repo.scm.repo.clone(git_remote) + dvc_repo.scm.repo.create_remote("origin", git_remote) - dvc_repo.scm.git.git.push("origin", "master") + dvc_repo.scm.repo.git.push("origin", "master") assert os.path.isfile(expected_cache_path) diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index 4159c6461..e7892f506 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -22,7 +22,7 @@ class TestMetricsBase(TestDvcGit): branches = ["foo", "bar", "baz"] for branch in branches: - self.dvc.scm.git.create_head(branch) + self.dvc.scm.repo.create_head(branch) for branch in branches: self.dvc.scm.checkout(branch) @@ -692,7 +692,7 @@ class TestCachedMetrics(TestDvcGit): # TestDvc currently is based on TestGit, so it is safe to use # scm.git for now - self.dvc.scm.git.git.clean("-fd") + self.dvc.scm.repo.git.clean("-fd") self.dvc = DvcRepo(".") diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index 8da5082dd..8184721c6 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -31,7 +31,7 @@ class TestCollect(TestDvcGit): def _check(self, branch, target, with_deps, expected): if branch: - self.dvc.tree = GitTree(self.dvc.scm.git, branch) + self.dvc.tree = GitTree(self.dvc.scm.repo, branch) else: self.dvc.tree = WorkingTree() result = self.dvc.collect(target + ".dvc", with_deps=with_deps) diff --git a/tests/func/test_scm.py b/tests/func/test_scm.py index 8135f6606..ada5b4759 100644 --- a/tests/func/test_scm.py +++ b/tests/func/test_scm.py @@ -42,7 +42,7 @@ class TestSCMGit(TestGit): G.commit("add") self.assertTrue(G.is_tracked(foo)) self.assertTrue(G.is_tracked(self.FOO)) - G.git.index.remove([self.FOO], working_tree=True) + G.repo.index.remove([self.FOO], working_tree=True) self.assertFalse(G.is_tracked(foo)) self.assertFalse(G.is_tracked(self.FOO)) self.assertFalse(G.is_tracked("not-existing-file")) diff --git a/tests/func/test_update.py b/tests/func/test_update.py index 7345627aa..454501504 100644 --- a/tests/func/test_update.py +++ b/tests/func/test_update.py @@ -30,7 +30,7 @@ def test_update_import(dvc_repo, erepo): repo.scm.commit("updated") repo.scm.checkout("master") - repo.scm.git.close() + repo.scm.close() os.chdir(saved_dir)