Exemplo n.º 1
0
        public void TestRename()
        {
            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("Commit all");
                Assert.That(!client.Status().ContainsKey("foo"), "Default commit failed for foo");

                client.Rename("foo", "foo2");
                IDictionary <string, Status> statuses = client.Status();
                statuses = client.Status(new[] { path }, quiet: false);
                Assert.AreEqual(Status.Removed, statuses ["foo"], string.Format("Incorrect status for foo: {0}", statuses ["foo"]));
                Assert.AreEqual(Status.Added, statuses ["foo2"], string.Format("Incorrect status for foo2: {0}", statuses ["foo2"]));

                client.Commit("Commit rename");
                Assert.That(!client.Status().ContainsKey("foo"), "Failed to rename file");
                Assert.That(!client.Status().ContainsKey("foo2"), "Failed to rename file");
                Assert.That(!File.Exists(file));
                Assert.That(File.Exists(Path.Combine(path, "foo2")));
            }
        }
Exemplo n.º 2
0
        public void TestStatus()
        {
            string path        = GetTemporaryPath();
            string file        = Path.Combine(path, "foo");
            string unknownFile = Path.Combine(path, "bar");

            CommandClient.Initialize(path, MercurialPath);
            using (var client = new CommandClient(path, null, null, MercurialPath)) {
                File.WriteAllText(file, string.Empty);
                File.WriteAllText(unknownFile, string.Empty);
                client.Add(file);
                IDictionary <string, Status> statuses = client.Status(path);
                Assert.That(statuses.ContainsKey("foo"), "foo not found in status");
                Assert.That(statuses.ContainsKey("bar"), "bar not found in status");
                Assert.AreEqual(Status.Added, statuses ["foo"], "Incorrect status for foo");
                Assert.AreEqual(statuses ["bar"], Status.Unknown, "Incorrect status for bar");

                statuses = client.Status(new[] { path }, quiet: true);
                Assert.That(statuses.ContainsKey("foo"), "foo not found in status");
                Assert.AreEqual(Status.Added, statuses ["foo"], "Incorrect status for foo");
                Assert.That(!statuses.ContainsKey("bar"), "bar listed in quiet status output");

                statuses = client.Status(new[] { path }, onlyFilesWithThisStatus: Status.Added);
                Assert.That(statuses.ContainsKey("foo"), "foo not found in status");
                Assert.AreEqual(Status.Added, statuses ["foo"], "Incorrect status for foo");
                Assert.That(!statuses.ContainsKey("bar"), "bar listed in added-only status output");
            }
        }
Exemplo n.º 3
0
        public void TestRevert()
        {
            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("Commit all");
                Assert.That(!client.Status().ContainsKey("foo"), "Default commit failed for foo");

                File.WriteAllText(file, "Modified!");
                Assert.That(client.Status().ContainsKey("foo"), "Failed to modify file");
                client.Revert(null, file);
                Assert.That(!client.Status().ContainsKey("foo"), "Revert failed for foo");
            }
        }
Exemplo n.º 4
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");
            }
        }
Exemplo n.º 5
0
        public void TestForget()
        {
            string path = GetTemporaryPath();
            string file = Path.Combine(path, "foo");
            IDictionary <string, Status> statuses = null;

            CommandClient.Initialize(path, MercurialPath);
            using (var client = new CommandClient(path, null, null, MercurialPath)) {
                File.WriteAllText(file, string.Empty);
                client.Add(file);
                statuses = client.Status(null);

                Assert.IsNotNull(statuses);
                Assert.That(statuses.ContainsKey("foo"), "No status received for foo");
                Assert.AreEqual(Status.Added, statuses ["foo"]);

                client.Forget(file);
                statuses = client.Status();
            }
            Assert.That(statuses.ContainsKey("foo"), "foo is no longer known");
            Assert.AreEqual(Status.Unknown, statuses ["foo"], "foo was not forgotten");
        }
Exemplo n.º 6
0
        public void TestParents()
        {
            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("Commit all");
                Assert.That(!client.Status().ContainsKey(file), "Default commit failed for foo");

                IEnumerable <Revision> parents = client.Parents(file, null);
                Assert.AreEqual(1, parents.Count(), "Unexpected number of parents");
            }
        }
Exemplo n.º 7
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.º 8
0
        public void TestCat()
        {
            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, "foo\n");
                client.Add(Path.Combine(path, "foo"));
                client.Commit("Commit all");
                Assert.That(!client.Status().ContainsKey("foo"), "Default commit failed for foo");

                var contents = client.Cat(null, file);
                Assert.AreEqual(1, contents.Count, "Unexpected size of file set");
                Assert.That(contents.ContainsKey(file), "foo not in file set");
                Assert.AreEqual("foo\n", contents [file]);
            }
        }
Exemplo n.º 9
0
        public void TestCatMore()
        {
            string path = GetTemporaryPath();
            string file = Path.Combine(path, "foo");

            Console.WriteLine(Environment.CurrentDirectory);
            CommandClient.Initialize(path, MercurialPath);
            File.Copy("../../../Mercurial/CommandClient.cs", file);
            using (var client = new CommandClient(path, null, null, MercurialPath)) {
                client.Add(file);
                client.Commit("Commit all");
                Assert.That(!client.Status().ContainsKey("foo"), "Default commit failed for foo");

                var contents = client.Cat(null, file);
                Assert.AreEqual(1, contents.Count, "Unexpected size of file set");
                Assert.That(contents.ContainsKey(file), "foo not in file set");
                Assert.AreEqual(File.ReadAllText(file), contents [file]);
            }
        }
Exemplo n.º 10
0
        public void TestAdd()
        {
            string path = GetTemporaryPath();
            IDictionary <string, Status> statuses = null;

            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"), Path.Combine(path, "bar"));
                statuses = client.Status(null);
            }

            Assert.IsNotNull(statuses);
            Assert.That(statuses.ContainsKey("foo"), "No status received for foo");
            Assert.That(statuses.ContainsKey("bar"), "No status received for bar");
            Assert.AreEqual(Status.Added, statuses ["foo"]);
            Assert.AreEqual(Status.Added, statuses ["bar"]);
        }