public void TestGitPull() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); CreateNewBranchInTempRepo(tempRepo, "newbranch"); var remoteRepo = new GitRepository(Path.GetFileName(tempRepo.Path), Directory.GetParent(tempRepo.Path).FullName, Log); { using (var localRepo = new TempDirectory()) { var repo = new GitRepository(Path.GetFileName(localRepo.Path), Directory.GetParent(localRepo.Path).FullName, Log); { repo.Clone(tempRepo.Path.Replace("\\", "/")); CommitIntoTempRepo(tempRepo, "newbranch"); var remoteSha = remoteRepo.CurrentLocalCommitHash(); repo.Pull("newbranch"); var localSha = repo.CurrentLocalCommitHash(); Assert.AreEqual(remoteSha, localSha); } } } } }
public static int ChangeModule(Package package, string moduleName, string pushUrl, string fetchUrl) { using (var tempDir = new TempDirectory()) { var repo = new GitRepository("modules_git", tempDir.Path, Log); repo.Clone(package.Url); var toChange = FindModule(repo, moduleName); if (toChange == null) { ConsoleWriter.WriteError("Unable to find module " + moduleName + " in package " + package.Name); return(-1); } if (toChange.Url == fetchUrl && toChange.Pushurl == pushUrl) { ConsoleWriter.WriteInfo("Your changes were already made"); return(0); } ChangeModuleDescription(repo, toChange, new Module(moduleName, fetchUrl, pushUrl)); var message = "(!)cement comment: changed module '" + moduleName + "'"; repo.Commit(new[] { "-am", message }); repo.Push("master"); } ConsoleWriter.WriteOk("Success changed " + moduleName + " in " + package.Name); return(0); }
public static int AddModule(Package package, string moduleName, string pushUrl, string fetchUrl) { if (fetchUrl.StartsWith("https://git.skbkontur.ru/")) { throw new CementException("HTTPS url not allowed for gitlab. You should use SSH url."); } using (var tempDir = new TempDirectory()) { var repo = new GitRepository("modules_git", tempDir.Path, Log); repo.Clone(package.Url); if (FindModule(repo, moduleName) != null) { ConsoleWriter.WriteError("Module " + moduleName + " already exists in " + package.Name); return(-1); } WriteModuleDescription(moduleName, pushUrl, fetchUrl, repo); var message = "(!)cement comment: added module '" + moduleName + "'"; repo.Commit(new[] { "-am", message }); repo.Push("master"); } ConsoleWriter.WriteOk("Success added " + moduleName + " to " + package.Name); return(0); }
Clone(string parentPath, GitUrl url) { using (LogicalOperation.Start($"Cloning {url}")) { GitRepository.Clone(parentPath, url); } }
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 TestGitLocalCommitHashEqualsRemote() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); var remoteRepo = new GitRepository( Path.GetFileName(tempRepo.Path), Directory.GetParent(tempRepo.Path).FullName, Log); { var remoteCommit = remoteRepo.CurrentLocalCommitHash(); using (var localRepo = new TempDirectory()) { var repo = new GitRepository( Path.GetFileName(localRepo.Path), Directory.GetParent(localRepo.Path).FullName, Log); { repo.Clone(tempRepo.Path); var localCommit = repo.RemoteCommitHashAtBranch("master"); Assert.AreEqual(localCommit, remoteCommit); Assert.AreEqual(localCommit, repo.RemoteCommitHashAtTreeish("master")); } } } } }
public void TestGitCloneUnexistingRepo() { using (var tempDirectory = new TempDirectory()) { var repo = new GitRepository("unexisting_directory", tempDirectory.Path, Log); Assert.Throws <GitCloneException>(() => repo.Clone("SOME/REPO")); } }
public void TestInitialize() { if (Directory.Exists(wrkroot)) { Directory.Delete(wrkroot, true); } Directory.CreateDirectory(wrkroot); wrkRepoA = GitRepository.Clone(wrkroot, srcUrlA); }
public void TestGitCloneUnexistingBranch() { using (var url = new TempDirectory()) { CreateTempRepo(url); using (var tempDirectory = new TempDirectory()) { var repo = new GitRepository("unexisting_directory", tempDirectory.Path, Log); Assert.Throws <GitCloneException>(() => repo.Clone(url.Path, "unexisting_branch")); } } }
public void TestGitClone() { using (var url = new TempDirectory()) { CreateTempRepo(url); using (var tempDirectory = new TempDirectory()) { var repo = new GitRepository("unexisting_directory", tempDirectory.Path, Log); repo.Clone(url.Path); Assert.IsTrue(Directory.Exists(Path.Combine(tempDirectory.Path, "unexisting_directory"))); } } }
public void TestGitHasUnExistingTreeishOnRemote() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); using (var localRepo = new TempDirectory()) { var repo = new GitRepository(Path.GetFileName(localRepo.Path), Directory.GetParent(localRepo.Path).FullName, Log); repo.Clone(tempRepo.Path); } } }
public void TestGitCloneToNotEmptyFolder() { using (var url = new TempDirectory()) { CreateTempRepo(url); using (var tempDirectory = new TempDirectory()) { Directory.CreateDirectory(Path.Combine(tempDirectory.Path, "unexisting_directory")); File.WriteAllText(Path.Combine(tempDirectory.Path, "unexisting_directory", "README.txt"), "README"); var repo = new GitRepository("unexisting_directory", tempDirectory.Path, Log); Assert.Throws <GitCloneException>(() => repo.Clone(url.Path)); } } }
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 TestGitRemoteCommitHash40Symbols() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); using (var localRepo = new TempDirectory()) { var repo = new GitRepository(Path.GetFileName(localRepo.Path), Directory.GetParent(localRepo.Path).FullName, Log); repo.Clone(tempRepo.Path); Assert.AreEqual(40, repo.RemoteCommitHashAtBranch("master").Length); } } }
public void TestGitIsKnownRemoteBranch() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); CreateNewBranchInTempRepo(tempRepo, "newbranch"); using (var localRepo = new TempDirectory()) { var repo = new GitRepository(Path.GetFileName(localRepo.Path), Directory.GetParent(localRepo.Path).FullName, Log); { repo.Clone(tempRepo.Path); Assert.True(repo.IsKnownRemoteBranch("newbranch")); } } } }