public void Clone_Private_Repo_With_Authentication_SSH() { var privateKey = @"C:\Users\o2\.ssh\id_rsa"; var publicKey = @"C:\Users\o2\.ssh\id_rsa.pub"; if (privateKey.fileExists().isFalse() || publicKey.fileExists().isFalse()) { Assert.Ignore("Ignoring test because test SSH keys were not found"); } var factory = new CustomConfigSessionFactory(publicKey.fileContents(), privateKey.fileContents()); SshSessionFactory.SetInstance(factory); var repoToClone = "UnitTests_TestRepo_Private"; var repositoryUrl = "[email protected]:o2platform/{0}.git".format(repoToClone); var pathToRepo = tempFolder.pathCombine(repoToClone); var ngit_O2 = new API_NGit_O2Platform(tempFolder); ngit_O2.clone(repositoryUrl, pathToRepo); Assert.IsNull(ngit_O2.Last_Exception); Assert.IsNotEmpty(tempFolder.dirs()); Assert.IsTrue(pathToRepo.dirExists()); Assert.IsTrue(pathToRepo.isGitRepository()); ngit_O2.delete_Repository_And_Files(); Assert.IsFalse(pathToRepo.dirExists()); SshSessionFactory.SetInstance(null); }
} // End Class CustomConfigSessionFactory // http://stackoverflow.com/questions/13764435/ngit-making-a-connection-with-a-private-key-file/ public virtual void CloneWithPrivateKey() { CustomConfigSessionFactory customConfigSessionFactory = new CustomConfigSessionFactory(); customConfigSessionFactory.PrivateKey = "properties.PrivateKey"; // Enter own customConfigSessionFactory.PublicKey = "properties.PublicKey"; // Enter own NGit.Transport.JschConfigSessionFactory.SetInstance(customConfigSessionFactory); NGit.Api.Git git = NGit.Api.Git.CloneRepository() .SetDirectory("properties.OutputPath") .SetURI("properties.SourceUrlPath") .SetBranchesToClone(new System.Collections.ObjectModel.Collection <string>() { "master" }) .Call(); } // End Sub CloneWithPrivateKey