Exemplo n.º 1
0
        public void TestResolve()
        {
            string firstPath  = GetTemporaryPath();
            string secondPath = GetTemporaryPath();
            string file       = Path.Combine(firstPath, "foo");

            CommandClient.Initialize(firstPath, MercurialPath);
            CommandClient firstClient  = null,
                          secondClient = null;

            try {
                // Create repo with one commit
                firstClient = new CommandClient(firstPath, null, null, MercurialPath);
                File.WriteAllText(file, "1\n");
                firstClient.Add(file);
                firstClient.Commit("1");

                // Clone repo
                CommandClient.Clone(source: firstPath, destination: secondPath, mercurialPath: MercurialPath);
                secondClient = new CommandClient(secondPath, null, null, MercurialPath);
                Assert.AreEqual(1, secondClient.Log(null).Count, "Unexpected number of log entries");

                // Add changeset to original repo
                File.WriteAllText(file, "2\n");
                firstClient.Commit("2");

                // Add non-conflicting changeset to child repo
                File.WriteAllText(Path.Combine(secondPath, "foo"), "1\na\n");
                secondClient.Commit("a");

                // Pull from clone
                Assert.IsTrue(secondClient.Pull(null), "Pull unexpectedly resulted in unresolved files");
                Assert.AreEqual(3, secondClient.Log(null).Count, "Unexpected number of log entries");

                Assert.AreEqual(2, secondClient.Heads().Count(), "Unexpected number of heads");

                Assert.IsTrue(secondClient.Merge(null), "Merge unexpectedly resulted in unresolved files");

                IDictionary <string, bool> statuses = secondClient.Resolve(null, true, true, false, false, null, null, null);
                Assert.That(statuses.ContainsKey("foo"), "No merge status for foo");
                Assert.AreEqual(true, statuses ["foo"], "Incorrect merge status for foo");
            } finally {
                if (null != firstClient)
                {
                    firstClient.Dispose();
                }
                if (null != secondClient)
                {
                    secondClient.Dispose();
                }
            }
        }
Exemplo n.º 2
0
        public void TestCloneLocal()
        {
            string firstPath  = GetTemporaryPath();
            string secondPath = GetTemporaryPath();
            string file       = Path.Combine(firstPath, "foo");

            CommandClient.Initialize(firstPath, MercurialPath);

            using (var client = new CommandClient(firstPath, null, null, MercurialPath)) {
                File.WriteAllText(file, "1");
                client.Add(file);
                client.Commit("1");
            }
            try {
                CommandClient.Clone(source: firstPath, destination: secondPath, mercurialPath: MercurialPath);
            } catch (Exception ex) {
                Console.WriteLine(ex);
                Assert.That(false, ex.Message);
            }
            Assert.That(Directory.Exists(Path.Combine(secondPath, ".hg")), string.Format("Repository was not cloned from {0} to {1}", firstPath, secondPath));
            Assert.That(File.Exists(Path.Combine(secondPath, "foo")), "foo doesn't exist in cloned working copy");

            using (var client = new CommandClient(secondPath, null, null, MercurialPath)) {
                IList <Revision> log = client.Log(null);
                Assert.AreEqual(1, log.Count, "Unexpected number of log entries");
            }
        }
Exemplo n.º 3
0
        public void TestRollback()
        {
            string path = GetTemporaryPath();
            string file = Path.Combine(path, "foo");

            CommandClient.Initialize(path, MercurialPath);
            using (var client = new CommandClient(path, null, null, MercurialPath)) {
                File.WriteAllText(file, string.Empty);
                client.Add(file);
                client.Commit(file);
                File.WriteAllText(file, file);
                client.Commit(file);
                Assert.AreEqual(2, client.Log(null).Count, "Unexpected history length");
                Assert.That(client.Rollback());
                Assert.AreEqual(1, client.Log(null).Count, "Unexpected history length after rollback");
                Assert.AreEqual(Mercurial.Status.Modified, client.Status(file) ["foo"], "Unexpected file status after rollback");
            }
        }
Exemplo n.º 4
0
        public void TestPull()
        {
            string firstPath  = GetTemporaryPath();
            string secondPath = GetTemporaryPath();
            string file       = Path.Combine(firstPath, "foo");

            CommandClient.Initialize(firstPath, MercurialPath);
            CommandClient firstClient  = null,
                          secondClient = null;

            try {
                // Create repo with one commit
                firstClient = new CommandClient(firstPath, null, null, MercurialPath);
                File.WriteAllText(file, "1");
                firstClient.Add(file);
                firstClient.Commit("1");

                // Clone repo
                CommandClient.Clone(source: firstPath, destination: secondPath, mercurialPath: MercurialPath);
                secondClient = new CommandClient(secondPath, null, null, MercurialPath);
                Assert.AreEqual(1, secondClient.Log(null).Count, "Unexpected number of log entries");

                // Add changeset to original repo
                File.WriteAllText(file, "2");
                firstClient.Commit("2");

                // Pull from clone
                Assert.IsTrue(secondClient.Pull(null), "Pull unexpectedly resulted in unresolved files");
                Assert.AreEqual(2, secondClient.Log(null).Count, "Unexpected number of log entries");
            } finally {
                if (null != firstClient)
                {
                    firstClient.Dispose();
                }
                if (null != secondClient)
                {
                    secondClient.Dispose();
                }
            }
        }
Exemplo n.º 5
0
        public void TestLog()
        {
            string path = GetTemporaryPath();
            string file = Path.Combine(path, "foo");

            CommandClient.Initialize(path, MercurialPath);

            using (var client = new CommandClient(path, null, null, MercurialPath)) {
                File.WriteAllText(file, "1");
                client.Add(file);
                client.Commit("1");
                File.WriteAllText(file, "2");
                client.Commit("2");
                Assert.AreEqual(2, client.Log(null).Count, "Unexpected revision count");
            }
        }
Exemplo n.º 6
0
        public void TestPush()
        {
            string firstPath  = GetTemporaryPath();
            string secondPath = GetTemporaryPath();
            string file       = Path.Combine(firstPath, "foo");

            CommandClient.Initialize(firstPath, MercurialPath);
            CommandClient firstClient  = null,
                          secondClient = null;

            try {
                // Create repo with one commit
                firstClient = new CommandClient(firstPath, null, null, MercurialPath);
                File.WriteAllText(file, "1\n");
                firstClient.Add(file);
                firstClient.Commit("1");

                // Clone repo
                CommandClient.Clone(source: firstPath, destination: secondPath, mercurialPath: MercurialPath);
                secondClient = new CommandClient(secondPath, null, null, MercurialPath);
                Assert.AreEqual(1, secondClient.Log(null).Count, "Unexpected number of log entries");

                // Add changeset to child repo
                File.WriteAllText(Path.Combine(secondPath, "foo"), "1\na\n");
                secondClient.Commit("a");

                // Push to parent
                Assert.IsTrue(secondClient.Push(firstPath, null), "Nothing to push");

                // Assert that the first repo now has two revisions in the log
                Assert.AreEqual(2, firstClient.Log(null, firstPath).Count, "Known commandserver bug: server is out of sync");
            } finally {
                if (null != firstClient)
                {
                    firstClient.Dispose();
                }
                if (null != secondClient)
                {
                    secondClient.Dispose();
                }
            }
        }
Exemplo n.º 7
0
        public void TestOutgoing()
        {
            string firstPath  = GetTemporaryPath();
            string secondPath = GetTemporaryPath();
            string file       = Path.Combine(firstPath, "foo");

            CommandClient.Initialize(firstPath, MercurialPath);
            CommandClient firstClient  = null,
                          secondClient = null;

            try {
                // Create repo with one commit
                firstClient = new CommandClient(firstPath, null, null, MercurialPath);
                File.WriteAllText(file, "1");
                firstClient.Add(file);
                firstClient.Commit("1");

                // Clone repo
                CommandClient.Clone(source: firstPath, destination: secondPath, mercurialPath: MercurialPath);
                secondClient = new CommandClient(secondPath, null, null, MercurialPath);
                Assert.AreEqual(1, secondClient.Log(null).Count, "Unexpected number of log entries");

                // Add changeset to original repo
                File.WriteAllText(file, "2");
                firstClient.Commit("2");
                File.WriteAllText(file, "3");
                firstClient.Commit("3");

                IList <Revision> outgoing = firstClient.Outgoing(secondPath, null);
                Assert.AreEqual(2, outgoing.Count, "Unexpected number of outgoing changesets");
            } finally {
                if (null != firstClient)
                {
                    firstClient.Dispose();
                }
                if (null != secondClient)
                {
                    secondClient.Dispose();
                }
            }
        }
Exemplo n.º 8
0
        public void TestCommit()
        {
            string path = GetTemporaryPath();

            CommandClient.Initialize(path, MercurialPath);
            using (var client = new CommandClient(path, null, null, MercurialPath)) {
                File.WriteAllText(Path.Combine(path, "foo"), string.Empty);
                File.WriteAllText(Path.Combine(path, "bar"), string.Empty);
                client.Add(Path.Combine(path, "foo"));
                client.Commit("Commit all");
                Assert.That(!client.Status().ContainsKey("foo"), "Default commit failed for foo");

                File.WriteAllText(Path.Combine(path, "foo"), "foo");
                client.Add(Path.Combine(path, "bar"));
                client.Commit("Commit only bar", Path.Combine(path, "bar"));
                Assert.That(!client.Status().ContainsKey("bar"), "Commit failed for bar");
                Assert.That(client.Status().ContainsKey("foo"), "Committed unspecified file!");
                Assert.AreEqual(Mercurial.Status.Modified, client.Status()["foo"], "Committed unspecified file!");
                Assert.AreEqual(2, client.Log(null).Count, "Unexpected revision count");
            }
        }