def test_git_ssh(tmp_dir, scm, server): from dulwich.repo import Repo as DulwichRepo from sshfs import SSHFileSystem from dvc.utils.fs import remove from tests.remotes.ssh import TEST_SSH_KEY_PATH, TEST_SSH_USER fs = SSHFileSystem( host=server.host, port=server.port, username=TEST_SSH_USER, client_keys=[TEST_SSH_KEY_PATH], ) server._ssh.execute("git init --bare test-repo.git") url = f"ssh://{TEST_SSH_USER}@{server.host}:{server.port}/~/test-repo.git" tmp_dir.scm_gen("foo", "foo", commit="init") rev = scm.get_rev() scm.push_refspec( url, "refs/heads/master", "refs/heads/master", force=True, key_filename=TEST_SSH_KEY_PATH, ) assert ( rev.encode("ascii") == fs.open("test-repo.git/refs/heads/master").read().strip() ) remove(tmp_dir / ".git") remove(tmp_dir / "foo") DulwichRepo.init(str(tmp_dir)) scm.fetch_refspecs( url, ["refs/heads/master"], force=True, key_filename=TEST_SSH_KEY_PATH, ) assert rev == scm.get_ref("refs/heads/master") scm.checkout("master") assert "foo" == (tmp_dir / "foo").read_text()
def _ssh(self): from sshfs import SSHFileSystem return SSHFileSystem( host=self.host, port=self.port, username=TEST_SSH_USER, client_keys=[TEST_SSH_KEY_PATH], )
def ssh_connection(ssh_server): from sshfs import SSHFileSystem yield SSHFileSystem( host=ssh_server["host"], port=ssh_server["port"], username=TEST_SSH_USER, client_files=[TEST_SSH_KEY_PATH], )
def get_fs(): return SSHFileSystem( **conn_info, username=TEST_SSH_USER, client_keys=[TEST_SSH_KEY_PATH], )