static void Main(string[] args) { string gitBranch = ConfigurationManager.AppSettings["GitBranch"].ToString(); string localPath = ConfigurationManager.AppSettings["LocalRepoPath"].ToString(); GitRepository repo = new GitRepository(ConfigurationManager.AppSettings["GithubRepoUrl"].ToString(), localPath, ConfigurationManager.AppSettings["GithubToken"].ToString()); if (!Directory.Exists(Path.GetFullPath(localPath))) { Directory.CreateDirectory(Path.GetFullPath(localPath)); } try { repo.Clone(); } catch (Exception ex) { //System.Console.WriteLine(ex); } if (!string.Equals(repo.CurrentBranch(), gitBranch)) { repo.Checkout(gitBranch); } var result = repo.Pull(); if (!result.Equals("UpToDate")) { System.Console.WriteLine("Invalidate cloudfront distribution."); } }
public void TestGitCheckoutUnexistingBranch() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); var repo = new GitRepository(Path.GetFileName(tempRepo.Path), Directory.GetParent(tempRepo.Path).FullName, Log); Assert.Throws <GitCheckoutException>(() => repo.Checkout("unexisting_branch")); } }
public void TestGitCheckoutExistingBranch() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); CreateNewBranchInTempRepo(tempRepo, "new_branch"); var repo = new GitRepository(Path.GetFileName(tempRepo.Path), Directory.GetParent(tempRepo.Path).FullName, Log); repo.Checkout("new_branch"); Assert.AreEqual("new_branch", repo.CurrentLocalTreeish().Value); Assert.AreEqual(TreeishType.Branch, repo.CurrentLocalTreeish().Type); } }
public void TestPullForRealRepo() { using (var tempRepo = new TempDirectory()) { var repo = new GitRepository(Path.GetFileName(tempRepo.Path), Directory.GetParent(tempRepo.Path).FullName, Log); { repo.Clone("https://github.com/skbkontur/cement", "master"); repo.Fetch("master"); repo.HasRemoteBranch("master"); repo.Checkout("master"); } } }
public void TestGitRecursiveCloneFailsAndDoesntCrash() { var toCheckout = new GitRepository { Url = "git://github.com/xamarin/xamarin-android.git", }; var directory = FileService.CreateTempDirectory(); try { toCheckout.Checkout(directory, true, new ProgressMonitor()); } catch (VersionControlException e) { Assert.That(e.InnerException, Is.InstanceOf <LibGit2Sharp.NotFoundException> ()); return; } finally { Directory.Delete(directory, true); } Assert.Fail("Repository is not reporting loose object cannot be found. Consider removing test."); }
public void TestGitRecursiveCloneFailsAndDoesntCrash() { var toCheckout = new GitRepository { Url = "git://github.com/xamarin/xamarin-android.git", }; var monitor = new ProgressMonitor(); var directory = FileService.CreateTempDirectory(); try { Task.Run(() => toCheckout.Checkout(directory, true, monitor)).Wait(); } catch (AggregateException e) { var exception = e.FlattenAggregate().InnerException; // libgit2 < 0.26 will throw NotFoundException (result -3) // libgit2 >= 0.26 will throw generic LibGit2SharpException (result -1), assert the expected message Assert.That(exception.InnerException, Is.InstanceOf <LibGit2Sharp.NotFoundException> ().Or.Message.EqualTo("reference 'refs/heads/master' not found")); return; } finally { toCheckout.Dispose(); Directory.Delete(directory, true); } Assert.Fail("Repository is not reporting loose object cannot be found. Consider removing test."); }