Exemplo n.º 1
0
        public void IsStatusResultAccurate()
        {
            //Due to the cumulative nature of these tests, rather than recreate the same
            // conditions multiple times, all StatusResult testing has been rolled into one test.
            bool bare = false;
            var path = Path.Combine(trash.FullName, "test");
            using (var repo = Repository.Init(path, bare))
            {
                StatusCommand cmd = new StatusCommand();
                Assert.IsNotNull(cmd);
                cmd.Repository = repo;
                Assert.IsNotNull(cmd.Repository);
                //Verify the file has not already been created
                string filename = "newfile.txt";
                StatusResults results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsFalse(results.Contains(filename, StatusState.Untracked));

                //Create the file and verify the file is untracked
                string filepath = Path.Combine(repo.WorkingDirectory, filename);
                File.WriteAllText(filepath, "Just a simple test.");
                //Re-populate the status results
                results.Clear();
                results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsFalse(results.Contains(filename, StatusState.Staged));
                Assert.IsFalse(results.Contains(filename, StatusState.Modified));
                Assert.IsTrue(results.Contains(filename, StatusState.Untracked));

                //Add the file to the index and verify the file is modified
                Index index = new Index(repo);
                index.Add(filepath);
                //Re-populate the status results
                results.Clear();
                results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsTrue(results.Contains(filename, StatusState.Staged));
                Assert.IsFalse(results.Contains(filename, StatusState.Modified));
                Assert.IsFalse(results.Contains(filename, StatusState.Untracked));

                //Change the modified file status to staged and verify the file is staged.
                index.Add(filepath);
                //Re-populate the status results
                results.Clear();
                results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsTrue(results.Contains(filename, StatusState.Staged));
                Assert.IsFalse(results.Contains(filename, StatusState.Modified));
                Assert.IsFalse(results.Contains(filename, StatusState.Untracked));

                // Modify the staged file and verify the file is both modified
                // and staged simultaneously.
                File.AppendAllText(filepath, "Appended a line.");
                //Re-populate the status results
                results.Clear();
                results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsTrue(results.Contains(filename, StatusState.Staged));
                Assert.IsTrue(results.Contains(filename, StatusState.Modified));
                Assert.IsFalse(results.Contains(filename, StatusState.Untracked));

            }
        }
Exemplo n.º 2
0
 public static StatusResults Status(StatusCommand command)
 {
     //Populate the command with the status results
     command.Execute();
     return command.Results;
 }