Пример #1
0
        public void TestGetInNotEmptyFolderWithBranch()
        {
            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>()) }
                });

                env.CommitIntoRemote("A", "test.txt", "hello");
                env.AddBranch("A", "new_branch");
                env.Checkout("A", "new_branch");
                env.CommitIntoRemote("A", "test.txt", "hello2");

                var localA = Path.Combine(dir, "A");
                Directory.CreateDirectory(localA);
                File.WriteAllText(Path.Combine(localA, "test.txt"), "bye");

                env.Get("A", "new_branch");
                var newText = File.ReadAllText(Path.Combine(localA, "test.txt"));
                Assert.That(newText == "hello2");
            }
        }
Пример #2
0
        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());
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        public void TestModuleWithDep()
        {
            using (var env = new TestEnvironment())
            {
                env.CreateRepo("A", new Dictionary <string, DepsData>
                {
                    { "full-build", new DepsData(null, new List <Dep> {
                            new Dep("B")
                        }) }
                });
                env.CreateRepo("B", new Dictionary <string, DepsData>
                {
                    { "full-build", new DepsData(null, new List <Dep>()) }
                });
                Helper.SetWorkspace(env.RemoteWorkspace);

                CollectionAssert.AreEquivalent(new[] { new Dep("A/full-build"), new Dep("B/full-build") }, GetUpdatedModules(new Dep("A")));
                BuildDeps(new Dep("A/full-build"));
                CollectionAssert.AreEquivalent(new[] { new Dep("A/full-build") }, GetUpdatedModules(new Dep("A")));
                Build(new Dep("A/full-build"));
                Assert.That(GetUpdatedModules(new Dep("A")), Is.Empty);

                //change dep
                env.CommitIntoRemote("B", "1.txt", "changes");
                CollectionAssert.AreEquivalent(new[] { new Dep("A/full-build"), new Dep("B/full-build") }, GetUpdatedModules(new Dep("A")));
                BuildDeps(new Dep("A/full-build"));
                CollectionAssert.AreEquivalent(new[] { new Dep("A/full-build") }, GetUpdatedModules(new Dep("A")));
                Build(new Dep("A/full-build"));
                Assert.That(GetUpdatedModules(new Dep("A")), Is.Empty);

                //change root
                env.CommitIntoRemote("A", "1.txt", "changes");
                CollectionAssert.AreEquivalent(new[] { new Dep("A/full-build") }, GetUpdatedModules(new Dep("A")));
                CollectionAssert.AreEquivalent(new Dep[] { }, GetUpdatedModules(new Dep("B")));
                Build(new Dep("A/full-build"));
                Assert.That(GetUpdatedModules(new Dep("A")), Is.Empty);
            }
        }
Пример #6
0
        public void TestGetDepsOneDepWithPullAnywayFastForwardPullNotAllowedThrowsException()
        {
            using (var env = new TestEnvironment())
            {
                env.CreateRepo("A", new Dictionary <string, DepsContent>
                {
                    { "full-build", new DepsContent(null, new List <Dep> {
                            new Dep("B")
                        }) }
                });
                env.CreateRepo("B");
                env.Get("A");
                env.CommitIntoRemote("B", "file", "text");
                env.MakeLocalChanges("B", "file", "some content");

                Assert.Throws <GitPullException>(() => env.Get("A", localChangesPolicy: LocalChangesPolicy.Pull));
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        private static void TestAddGit(string oldContent, string moduleName, string push, string fetch, string answer)
        {
            using (var env = new TestEnvironment())
            {
                env.CreateRepo("modulesRepo");
                env.CommitIntoRemote("modulesRepo", "modules", oldContent);

                env.AddBranch("modulesRepo", "tmp");
                env.Checkout("modulesRepo", "tmp");
                var package = new Package("test_package", Path.Combine(env.RemoteWorkspace, "modulesRepo"));
                if (ModuleCommand.AddModule(package, moduleName, push, fetch) != 0)
                {
                    throw new CementException("");
                }
                env.Checkout("modulesRepo", "master");

                var path = Path.Combine(env.RemoteWorkspace, "modulesRepo", "modules");
                var text = File.ReadAllText(path);
                text   = Helper.FixLineEndings(text);
                answer = Helper.FixLineEndings(answer);
                Assert.AreEqual(answer, text);
            }
        }