def test_clone_existing_folder_without_branch(self): tmp = temp_folder() save(os.path.join(tmp, "file"), "dummy contents") git = Git(tmp) with six.assertRaisesRegex(self, ConanException, "specify a branch to checkout"): git.clone("https://github.com/conan-community/conan-zlib.git")
def test_verify_ssl(self): class MyRunner(object): def __init__(self): self.calls = [] def __call__(self, *args, **kwargs): self.calls.append(args[0]) return "" runner = MyRunner() tmp = temp_folder() git = Git(tmp, username="******", password="******", verify_ssl=True, runner=runner, force_english=True) git.clone(url="https://myrepo.git") self.assertIn("git config http.sslVerify true", runner.calls[1]) runner = MyRunner() git = Git(tmp, username="******", password="******", verify_ssl=False, runner=runner, force_english=False) git.clone(url="https://myrepo.git") self.assertIn("git config http.sslVerify false", runner.calls[1])
def test_clone_git_shallow_revision(self): path, revision = create_local_git_repo({"myfile": "contents"}, commits=3, tags=["1.0"], branch="develop") tmp = temp_folder() git = Git(tmp) if Git.get_version() < "2.13": # older Git versions have known bugs with "git fetch origin <sha>": # https://github.com/git/git/blob/master/Documentation/RelNotes/2.13.0.txt # * "git fetch" that requests a commit by object name, when the other # side does not allow such an request, failed without much # explanation. # https://github.com/git/git/blob/master/Documentation/RelNotes/2.14.0.txt # * There is no good reason why "git fetch $there $sha1" should fail # when the $sha1 names an object at the tip of an advertised ref, # even when the other side hasn't enabled allowTipSHA1InWant. with self.assertRaises(subprocess.CalledProcessError): git.clone("file://" + path, branch=revision, shallow=True) else: git.clone("file://" + path, branch=revision, shallow=True) with self.assertRaises(subprocess.CalledProcessError): git.checkout(element="HEAD~1") self.assertTrue(os.path.exists(os.path.join(tmp, "myfile"))) self.assertEqual(git.get_revision(), revision) self.assertEqual(git.run("rev-list --all --count"), "1")
def test_clone_git_shallow(self, element): path, revision = create_local_git_repo({"myfile": "contents"}, commits=3, tags=["1.0"], branch="develop") tmp = temp_folder() git = Git(tmp) git.clone("file://" + path, branch=element, shallow=True) # --depth is ignored in local clones with self.assertRaises(subprocess.CalledProcessError): git.checkout(element="HEAD~1") self.assertTrue(os.path.exists(os.path.join(tmp, "myfile"))) self.assertEqual(git.get_revision(), revision) self.assertEqual(git.run("rev-list --all --count"), "1")
def test_clone_existing_folder_git(self): path, commit = create_local_git_repo({"myfile": "contents"}, branch="my_release") tmp = temp_folder() save(os.path.join(tmp, "file"), "dummy contents") git = Git(tmp) git.clone(path, branch="my_release") self.assertTrue(os.path.exists(os.path.join(tmp, "myfile"))) # Checkout a commit git.checkout(commit) self.assertEqual(git.get_revision(), commit)
def test_clone_git_shallow_with_local(self): path, revision = create_local_git_repo({"repofile": "contents"}, commits=3) tmp = temp_folder() save(os.path.join(tmp, "localfile"), "contents") save(os.path.join(tmp, "indexfile"), "contents") git = Git(tmp) git.run("init") git.run("add indexfile") git.clone("file://" + path, branch="master", shallow=True) # --depth is ignored in local clones self.assertTrue(os.path.exists(os.path.join(tmp, "repofile"))) self.assertTrue(os.path.exists(os.path.join(tmp, "localfile"))) self.assertTrue(os.path.exists(os.path.join(tmp, "indexfile"))) self.assertEqual(git.get_revision(), revision) self.assertEqual(git.run("rev-list --all --count"), "1")
def test_clone_submodule_git(self): subsubmodule, _ = create_local_git_repo({"subsubmodule": "contents"}) submodule, _ = create_local_git_repo({"submodule": "contents"}, submodules=[subsubmodule]) path, commit = create_local_git_repo({"myfile": "contents"}, submodules=[submodule]) def _create_paths(): tmp = temp_folder() submodule_path = os.path.join( tmp, os.path.basename(os.path.normpath(submodule))) subsubmodule_path = os.path.join( submodule_path, os.path.basename(os.path.normpath(subsubmodule))) return tmp, submodule_path, subsubmodule_path # Check old (default) behaviour tmp, submodule_path, _ = _create_paths() git = Git(tmp) git.clone(path) self.assertTrue(os.path.exists(os.path.join(tmp, "myfile"))) self.assertFalse( os.path.exists(os.path.join(submodule_path, "submodule"))) # Check invalid value tmp, submodule_path, _ = _create_paths() git = Git(tmp) git.clone(path) with six.assertRaisesRegex( self, ConanException, "Invalid 'submodule' attribute value in the 'scm'."): git.checkout(commit, submodule="invalid") # Check shallow tmp, submodule_path, subsubmodule_path = _create_paths() git = Git(tmp) git.clone(path) git.checkout(commit, submodule="shallow") self.assertTrue(os.path.exists(os.path.join(tmp, "myfile"))) self.assertTrue( os.path.exists(os.path.join(submodule_path, "submodule"))) self.assertFalse( os.path.exists(os.path.join(subsubmodule_path, "subsubmodule"))) # Check recursive tmp, submodule_path, subsubmodule_path = _create_paths() git = Git(tmp) git.clone(path) git.checkout(commit, submodule="recursive") self.assertTrue(os.path.exists(os.path.join(tmp, "myfile"))) self.assertTrue( os.path.exists(os.path.join(submodule_path, "submodule"))) self.assertTrue( os.path.exists(os.path.join(subsubmodule_path, "subsubmodule")))
def basic_test(self): server = TestServer() servers = {"default": server} # Create a project with git files = { 'conanfile.py': """from conans import ConanFile class MyPkg(ConanFile): name= "package" version = "1.0" scm = { "type": "git", "subfolder": "hello/to/you", "url": "auto", "revision": "auto" } """ } path, _ = create_local_git_repo(files) client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]}) git = Git(client.current_folder) git.clone(path) # Upload to 'remote' client.run("export . lasote/stable") client.run("upload package/1.0@lasote/stable") # Consume the project client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]}) error = client.run("install package/1.0@lasote/stable --build=package") self.assertFalse(error)
def test_clone_git(self): path, _ = create_local_git_repo({"myfile": "contents"}) tmp = temp_folder() git = Git(tmp) git.clone(path) self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
def test_is_local_repository(self): root_path, _ = create_local_git_repo({"myfile": "anything"}) git = Git(temp_folder()) git.clone(root_path) self.assertTrue(git.is_local_repository())