Пример #1
0
        public void CanRetrieveTheStatusOfARelativeWorkingDirectory()
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                const string file      = "just_a_dir/other.txt";
                const string otherFile = "just_a_dir/another_dir/other.txt";

                Touch(repo.Info.WorkingDirectory, file);
                Touch(repo.Info.WorkingDirectory, otherFile);

                RepositoryStatus status = repo.RetrieveStatus(new StatusOptions()
                {
                    PathSpec = new[] { "just_a_dir" }
                });
                Assert.Equal(2, status.Count());
                Assert.Equal(2, status.Untracked.Count());

                status = repo.RetrieveStatus(new StatusOptions()
                {
                    PathSpec = new[] { "just_a_dir/another_dir" }
                });
                Assert.Equal(1, status.Count());
                Assert.Equal(1, status.Untracked.Count());
            }
        }
Пример #2
0
        public void RetrievingTheStatusOfARepositoryReturnNativeFilePaths()
        {
            // Build relative path
            string relFilePath = Path.Combine("directory", "Testfile.txt");

            // Open the repository
            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                Touch(repo.Info.WorkingDirectory, relFilePath, "Anybody out there?");

                // Add the file to the index
                Commands.Stage(repo, relFilePath);

                // Get the repository status
                RepositoryStatus repoStatus = repo.RetrieveStatus();

                Assert.Equal(1, repoStatus.Count());
                StatusEntry statusEntry = repoStatus.Single();

                Assert.Equal(relFilePath, statusEntry.FilePath);

                Assert.Equal(statusEntry.FilePath, repoStatus.Added.Select(s => s.FilePath).Single());
            }
        }
Пример #3
0
        public void RetrievingTheStatusOfARepositoryReturnNativeFilePaths()
        {
            // Initialize a new repository
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

            const string directoryName = "directory";
            const string fileName      = "Testfile.txt";

            // Create a file and insert some content
            string directoryPath = Path.Combine(scd.RootedDirectoryPath, directoryName);
            string filePath      = Path.Combine(directoryPath, fileName);

            Directory.CreateDirectory(directoryPath);
            File.WriteAllText(filePath, "Anybody out there?");

            // Open the repository
            using (Repository repo = Repository.Init(scd.DirectoryPath))
            {
                // Add the file to the index
                repo.Index.Stage(filePath);

                // Get the repository status
                RepositoryStatus repoStatus = repo.Index.RetrieveStatus();

                Assert.Equal(1, repoStatus.Count());
                StatusEntry statusEntry = repoStatus.Single();

                Assert.Equal(Path.Combine(directoryName, fileName), statusEntry.FilePath);

                Assert.Equal(statusEntry.FilePath, repoStatus.Added.Single());
            }
        }
Пример #4
0
        public void RetrievingTheStatusOfARepositoryReturnNativeFilePaths()
        {
            // Initialize a new repository
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

            const string directoryName = "directory";
            const string fileName      = "Testfile.txt";

            // Create a file and insert some content
            string directoryPath = Path.Combine(scd.RootedDirectoryPath, directoryName);
            string filePath      = Path.Combine(directoryPath, fileName);

            Directory.CreateDirectory(directoryPath);
            File.WriteAllText(filePath, "Anybody out there?");

            // Open the repository
            using (var repo = Repository.Init(scd.DirectoryPath))
            {
                // Add the file to the index
                repo.Index.Stage(filePath);

                // Get the repository status
                RepositoryStatus repoStatus = repo.Index.RetrieveStatus();

                repoStatus.Count().ShouldEqual(1);
                var statusEntry = repoStatus.Single();

                string expectedPath = string.Format("{0}{1}{2}", directoryName, Path.DirectorySeparatorChar, fileName);
                statusEntry.FilePath.ShouldEqual(expectedPath);

                repoStatus.Added.Single().ShouldEqual(statusEntry.FilePath);
            }
        }
Пример #5
0
        public void CanRetrieveTheStatusOfTheWholeWorkingDirectory(bool includeUnaltered, int unalteredCount)
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                const string file = "modified_staged_file.txt";

                RepositoryStatus status = repo.RetrieveStatus(new StatusOptions()
                {
                    IncludeUnaltered = includeUnaltered
                });

                Assert.Equal(FileStatus.ModifiedInIndex, status[file].State);

                Assert.NotNull(status);
                Assert.Equal(6 + unalteredCount, status.Count());
                Assert.True(status.IsDirty);

                Assert.Equal("new_untracked_file.txt", status.Untracked.Select(s => s.FilePath).Single());
                Assert.Equal("modified_unstaged_file.txt", status.Modified.Select(s => s.FilePath).Single());
                Assert.Equal("deleted_unstaged_file.txt", status.Missing.Select(s => s.FilePath).Single());
                Assert.Equal("new_tracked_file.txt", status.Added.Select(s => s.FilePath).Single());
                Assert.Equal(file, status.Staged.Select(s => s.FilePath).Single());
                Assert.Equal("deleted_staged_file.txt", status.Removed.Select(s => s.FilePath).Single());

                File.AppendAllText(Path.Combine(repo.Info.WorkingDirectory, file),
                                   "Tclem's favorite commit message: boom");

                Assert.Equal(FileStatus.ModifiedInIndex | FileStatus.ModifiedInWorkdir, repo.RetrieveStatus(file));

                RepositoryStatus status2 = repo.RetrieveStatus(new StatusOptions()
                {
                    IncludeUnaltered = includeUnaltered
                });
                Assert.Equal(FileStatus.ModifiedInIndex | FileStatus.ModifiedInWorkdir, status2[file].State);

                Assert.NotNull(status2);
                Assert.Equal(6 + unalteredCount, status2.Count());
                Assert.True(status2.IsDirty);

                Assert.Equal("new_untracked_file.txt", status2.Untracked.Select(s => s.FilePath).Single());
                Assert.Equal(new[] { file, "modified_unstaged_file.txt" }, status2.Modified.Select(s => s.FilePath));
                Assert.Equal("deleted_unstaged_file.txt", status2.Missing.Select(s => s.FilePath).Single());
                Assert.Equal("new_tracked_file.txt", status2.Added.Select(s => s.FilePath).Single());
                Assert.Equal(file, status2.Staged.Select(s => s.FilePath).Single());
                Assert.Equal("deleted_staged_file.txt", status2.Removed.Select(s => s.FilePath).Single());
            }
        }
Пример #6
0
        public void UnalteredFilesDontMarkIndexAsDirty()
        {
            var path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                repo.Reset(ResetMode.Hard);
                repo.RemoveUntrackedFiles();

                RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { IncludeUnaltered = true });

                Assert.False(status.IsDirty);
                Assert.Equal(9, status.Count());
            }
        }
Пример #7
0
        public void RefreshChanges()
        {
            if (_repo == null)
            {
                return;
            }
            RepositoryStatus rs = _repo.RetrieveStatus(new StatusOptions {
                IncludeIgnored = false
            });
            int c = rs.Count();

            labelChanges.Text = $"{c} changes";
            //yeee not gonna deal with merging
            buttonPull.Enabled   = c == 0;
            buttonCommit.Enabled = c != 0;
        }
Пример #8
0
        public void CanRetrieveTheStatusOfANewRepository()
        {
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

            using (var repo = Repository.Init(scd.DirectoryPath))
            {
                RepositoryStatus status = repo.Index.RetrieveStatus();
                status.ShouldNotBeNull();
                status.Count().ShouldEqual(0);
                status.IsDirty.ShouldBeFalse();

                status.Untracked.Count().ShouldEqual(0);
                status.Modified.Count().ShouldEqual(0);
                status.Missing.Count().ShouldEqual(0);
                status.Added.Count().ShouldEqual(0);
                status.Staged.Count().ShouldEqual(0);
                status.Removed.Count().ShouldEqual(0);
            }
        }
Пример #9
0
        public void CanRetrieveTheStatusOfTheWholeWorkingDirectory()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);

            using (var repo = new Repository(path.RepositoryPath))
            {
                const string file = "modified_staged_file.txt";

                RepositoryStatus status = repo.Index.RetrieveStatus();

                IndexEntry indexEntry = repo.Index[file];
                indexEntry.State.ShouldEqual(FileStatus.Staged);

                status.ShouldNotBeNull();
                status.Count().ShouldEqual(6);
                status.IsDirty.ShouldBeTrue();

                status.Untracked.Single().ShouldEqual("new_untracked_file.txt");
                status.Modified.Single().ShouldEqual("modified_unstaged_file.txt");
                status.Missing.Single().ShouldEqual("deleted_unstaged_file.txt");
                status.Added.Single().ShouldEqual("new_tracked_file.txt");
                status.Staged.Single().ShouldEqual(file);
                status.Removed.Single().ShouldEqual("deleted_staged_file.txt");

                File.AppendAllText(Path.Combine(repo.Info.WorkingDirectory, file),
                                   "Tclem's favorite commit message: boom");

                indexEntry.State.ShouldEqual(FileStatus.Staged | FileStatus.Modified);

                RepositoryStatus status2 = repo.Index.RetrieveStatus();

                status2.ShouldNotBeNull();
                status2.Count().ShouldEqual(6);
                status2.IsDirty.ShouldBeTrue();

                status2.Untracked.Single().ShouldEqual("new_untracked_file.txt");
                CollectionAssert.AreEqual(new[] { file, "modified_unstaged_file.txt" }, status2.Modified);
                status2.Missing.Single().ShouldEqual("deleted_unstaged_file.txt");
                status2.Added.Single().ShouldEqual("new_tracked_file.txt");
                status2.Staged.Single().ShouldEqual(file);
                status2.Removed.Single().ShouldEqual("deleted_staged_file.txt");
            }
        }
Пример #10
0
        public void CanRetrieveTheStatusOfANewRepository()
        {
            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                RepositoryStatus status = repo.Index.RetrieveStatus();
                Assert.NotNull(status);
                Assert.Equal(0, status.Count());
                Assert.False(status.IsDirty);

                Assert.Equal(0, status.Untracked.Count());
                Assert.Equal(0, status.Modified.Count());
                Assert.Equal(0, status.Missing.Count());
                Assert.Equal(0, status.Added.Count());
                Assert.Equal(0, status.Staged.Count());
                Assert.Equal(0, status.Removed.Count());
            }
        }
Пример #11
0
        public void CanRetrieveTheStatusOfANewRepository()
        {
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

            using (Repository repo = Repository.Init(scd.DirectoryPath))
            {
                RepositoryStatus status = repo.Index.RetrieveStatus();
                Assert.NotNull(status);
                Assert.Equal(0, status.Count());
                Assert.False(status.IsDirty);

                Assert.Equal(0, status.Untracked.Count());
                Assert.Equal(0, status.Modified.Count());
                Assert.Equal(0, status.Missing.Count());
                Assert.Equal(0, status.Added.Count());
                Assert.Equal(0, status.Staged.Count());
                Assert.Equal(0, status.Removed.Count());
            }
        }
Пример #12
0
        public void CanRetrieveTheStatusOfTheWholeWorkingDirectory()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);

            using (var repo = new Repository(path.RepositoryPath))
            {
                const string file = "modified_staged_file.txt";

                RepositoryStatus status = repo.Index.RetrieveStatus();

                Assert.Equal(FileStatus.Staged, status[file]);

                Assert.NotNull(status);
                Assert.Equal(6, status.Count());
                Assert.True(status.IsDirty);

                Assert.Equal("new_untracked_file.txt", status.Untracked.Single());
                Assert.Equal("modified_unstaged_file.txt", status.Modified.Single());
                Assert.Equal("deleted_unstaged_file.txt", status.Missing.Single());
                Assert.Equal("new_tracked_file.txt", status.Added.Single());
                Assert.Equal(file, status.Staged.Single());
                Assert.Equal("deleted_staged_file.txt", status.Removed.Single());

                File.AppendAllText(Path.Combine(repo.Info.WorkingDirectory, file),
                                   "Tclem's favorite commit message: boom");

                Assert.Equal(FileStatus.Staged | FileStatus.Modified, repo.Index.RetrieveStatus(file));

                RepositoryStatus status2 = repo.Index.RetrieveStatus();
                Assert.Equal(FileStatus.Staged | FileStatus.Modified, status2[file]);

                Assert.NotNull(status2);
                Assert.Equal(6, status2.Count());
                Assert.True(status2.IsDirty);

                Assert.Equal("new_untracked_file.txt", status2.Untracked.Single());
                Assert.Equal(new[] { file, "modified_unstaged_file.txt" }, status2.Modified);
                Assert.Equal("deleted_unstaged_file.txt", status2.Missing.Single());
                Assert.Equal("new_tracked_file.txt", status2.Added.Single());
                Assert.Equal(file, status2.Staged.Single());
                Assert.Equal("deleted_staged_file.txt", status2.Removed.Single());
            }
        }
Пример #13
0
        public void CanRetrieveTheStatusOfANewRepository(bool includeUnaltered)
        {
            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                RepositoryStatus status = repo.RetrieveStatus(new StatusOptions()
                {
                    IncludeUnaltered = includeUnaltered
                });
                Assert.NotNull(status);
                Assert.Equal(0, status.Count());
                Assert.False(status.IsDirty);

                Assert.Equal(0, status.Untracked.Count());
                Assert.Equal(0, status.Modified.Count());
                Assert.Equal(0, status.Missing.Count());
                Assert.Equal(0, status.Added.Count());
                Assert.Equal(0, status.Staged.Count());
                Assert.Equal(0, status.Removed.Count());
            }
        }
Пример #14
0
        public void CanMergeAndNotCommit()
        {
            string path = CloneMergeTestRepo();

            using (var repo = new Repository(path))
            {
                Commit commitToMerge = repo.Branches["normal_merge"].Tip;

                MergeResult result = repo.Merge(commitToMerge, Constants.Signature, new MergeOptions()
                {
                    CommitOnSuccess = false
                });

                Assert.Equal(MergeStatus.NonFastForward, result.Status);
                Assert.Equal(null, result.Commit);

                RepositoryStatus repoStatus = repo.Index.RetrieveStatus();

                // Verify that there is a staged entry.
                Assert.Equal(1, repoStatus.Count());
                Assert.Equal(FileStatus.Staged, repo.Index.RetrieveStatus("b.txt"));
            }
        }
Пример #15
0
        private static void GetFileStatusInfo(RepositoryStatus repoStatus, out string Changes, out string changeString)
        {
            var addedCount      = 0;
            var modifiedCount   = 0;
            var deletedCount    = 0;
            var renamedCount    = 0;
            var typeChangeCount = 0;
            var otherCount      = 0;

            foreach (var item in repoStatus)
            {
                switch (item.State)
                {
                case FileStatus.NewInWorkdir:
                    addedCount++;
                    break;

                case FileStatus.ModifiedInWorkdir:
                    modifiedCount++;
                    break;

                case FileStatus.DeletedFromWorkdir:
                    deletedCount++;
                    break;

                case FileStatus.RenamedInWorkdir:
                    renamedCount++;
                    break;

                case FileStatus.TypeChangeInIndex:
                    typeChangeCount++;
                    break;

                default:
                    otherCount++;
                    break;
                }
            }

            var sl = new List <string>();

            if (addedCount > 0)
            {
                sl.Add($"Added: {addedCount}");
            }

            if (modifiedCount > 0)
            {
                sl.Add($"Modified: {modifiedCount}");
            }

            if (deletedCount > 0)
            {
                sl.Add($"Deleted: {deletedCount}");
            }

            if (renamedCount > 0)
            {
                sl.Add($"Renamed: {renamedCount}");
            }

            if (typeChangeCount > 0)
            {
                sl.Add($"Type changed: {typeChangeCount}");
            }

            if (otherCount > 0)
            {
                sl.Add($"Other: {otherCount}");
            }

            changeString = sl.Count > 0 ? string.Join(" | ", sl) : "No local changes";
            Changes      = repoStatus.Count().ToString();
        }