public void TestGetDepsOneDepWithTreeishSha1() { using (var env = new TestEnvironment()) { var dir = env.WorkingDirectory.Path; env.CreateRepo("A", new Dictionary <string, DepsContent> { { "full-build", new DepsContent(null, new List <Dep> { new Dep("B") }) } }); env.CreateRepo("B", null, new[] { "new" }); env.Get("A"); var repo = new GitRepository("B", dir, Log); var sha1 = repo.CurrentLocalCommitHash(); env.CommitIntoRemote("B", "newFile", "content"); env.Get("A"); env.CreateRepo("C", new Dictionary <string, DepsContent> { { "full-build", new DepsContent(null, new List <Dep> { new Dep("B", sha1) }) } }); env.Get("C"); Assert.AreEqual(sha1, repo.CurrentLocalCommitHash()); } }
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 void TestGetDepsOneDepWithPullAnywayFastForwardPullAllowed() { using (var env = new TestEnvironment()) { var dir = env.WorkingDirectory.Path; env.CreateRepo("A", new Dictionary <string, DepsContent> { { "full-build", new DepsContent(null, new List <Dep> { new Dep("B") }) } }); env.CreateRepo("B"); env.Get("A"); var bRepo = new GitRepository("B", dir, Log); env.CommitIntoRemote("B", "another_new_file", "text"); var remoteSha = bRepo.RemoteCommitHashAtBranch("master"); env.MakeLocalChanges("B", "file", "some content"); env.Get("A", localChangesPolicy: LocalChangesPolicy.Pull); Assert.AreNotEqual("", bRepo.ShowLocalChanges()); var newSha = bRepo.CurrentLocalCommitHash(); Assert.AreEqual(newSha, remoteSha); } }
public void TestGetDepsOneDepWithResetChangesAndCommit() { using (var env = new TestEnvironment()) { var dir = env.WorkingDirectory.Path; env.CreateRepo("A", new Dictionary <string, DepsContent> { { "full-build", new DepsContent(new[] { "new" }, new List <Dep> { new Dep("B") }) } }); env.CreateRepo("B", null, new[] { "new" }); env.Get("A"); var bRepo = new GitRepository("B", dir, Log); var remoteSha = bRepo.RemoteCommitHashAtBranch("master"); env.CommitIntoLocal("B", "newfile", "content"); env.MakeLocalChanges("B", "file", "some content"); env.Get("A", localChangesPolicy: LocalChangesPolicy.Reset); Assert.AreEqual("", bRepo.ShowLocalChanges()); var newSha = bRepo.CurrentLocalCommitHash(); Assert.AreEqual(newSha, remoteSha); } }
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 TestGitResetModified() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); File.WriteAllText(Path.Combine(tempRepo.Path, "README.txt"), "text"); var repo = new GitRepository(Path.GetFileName(tempRepo.Path), Directory.GetParent(tempRepo.Path).FullName, Log); Helper.SetWorkspace(repo.Workspace); var shaBefore = repo.CurrentLocalCommitHash(); repo.ResetHard(); var shaAfter = repo.CurrentLocalCommitHash(); Assert.AreEqual(shaBefore, shaAfter); Assert.AreEqual("", repo.ShowLocalChanges()); } }
public void TestGitLocalCommitHash40Symbols() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); var repo = new GitRepository(Path.GetFileName(tempRepo.Path), Directory.GetParent(tempRepo.Path).FullName, Log); Assert.AreEqual(40, repo.CurrentLocalCommitHash().Length); } }
public void TestGetOnCommitHashAfterPush() { using (var env = new TestEnvironment()) { var cwd = env.WorkingDirectory.Path; env.CreateRepo("B"); env.CommitIntoRemote("B", "file.txt", "commit 1"); var bRemote = new GitRepository("B", env.RemoteWorkspace, Log); var bHash1 = bRemote.CurrentLocalCommitHash(); env.CreateRepo("A", new Dictionary <string, DepsContent> { { "full-build", new DepsContent(null, new List <Dep> { new Dep("B", bHash1) }) } }); env.Get("A"); Assert.IsTrue(Directory.Exists(Path.Combine(cwd, "A"))); Assert.AreEqual(bHash1, new GitRepository("B", cwd, Log).CurrentLocalTreeish().Value); //push new in b env.CommitIntoRemote("B", "file.txt", "commit 2"); var bHash2 = bRemote.CurrentLocalCommitHash(); Assert.That(bHash1, Is.Not.EqualTo(bHash2)); env.CreateRepo("C", new Dictionary <string, DepsContent> { { "full-build", new DepsContent(null, new List <Dep> { new Dep("B", bHash2) }) } }); env.Get("C"); Assert.IsTrue(Directory.Exists(Path.Combine(cwd, "C"))); Assert.AreEqual(bHash2, new GitRepository("B", cwd, Log).CurrentLocalTreeish().Value); } }
private void PrintHashes(string[] modules) { foreach (var module in modules) { try { var moduleName = Path.GetFileName(module); var workspace = Directory.GetParent(module).FullName; var repo = new GitRepository(moduleName, workspace, Log); if (repo.IsGitRepo) { var hash = repo.CurrentLocalCommitHash(); ConsoleWriter.WriteLine(moduleName + " " + hash); } } catch (Exception) { // ignored } } }
public void TestGetOnCommitHash() { using (var env = new TestEnvironment()) { var dir = env.WorkingDirectory.Path; env.CreateRepo("B"); env.CommitIntoRemote("B", "file.txt", "new commit"); var bRemote = new GitRepository("B", env.RemoteWorkspace, Log); var bHash = bRemote.CurrentLocalCommitHash(); env.CreateRepo("A", new Dictionary <string, DepsContent> { { "full-build", new DepsContent(null, new List <Dep> { new Dep("B", bHash) }) } }); env.Get("A"); Assert.IsTrue(Directory.Exists(Path.Combine(dir, "A"))); Assert.AreEqual(bHash, new GitRepository("B", dir, Log).CurrentLocalTreeish().Value); } }