public void UnstagingFileWithBadParamsThrows()
 {
     using (var repo = new Repository(StandardTestRepoPath))
     {
         Assert.Throws <ArgumentException>(() => repo.Unstage(string.Empty));
         Assert.Throws <ArgumentNullException>(() => repo.Unstage((string)null));
         Assert.Throws <ArgumentException>(() => repo.Unstage(new string[] { }));
         Assert.Throws <ArgumentException>(() => repo.Unstage(new string[] { null }));
     }
 }
Example #2
0
        public void CanMergeIntoOrphanedBranch()
        {
            string path = SandboxMergeTestRepo();

            using (var repo = new Repository(path))
            {
                repo.Refs.Add("HEAD", "refs/heads/orphan", true);

                // Remove entries from the working directory
                foreach (var entry in repo.RetrieveStatus())
                {
                    repo.Unstage(entry.FilePath);
                    repo.Remove(entry.FilePath, true);
                }

                // Assert that we have an empty working directory.
                Assert.False(repo.RetrieveStatus().Any());

                MergeResult result = repo.Merge("master", Constants.Signature);

                Assert.Equal(MergeStatus.FastForward, result.Status);
                Assert.Equal(masterBranchInitialId, result.Commit.Id.Sha);
                Assert.False(repo.RetrieveStatus().Any());
            }
        }
        public void StagingANewVersionOfAFileThenUnstagingItRevertsTheBlobToTheVersionOfHead()
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                int count = repo.Index.Count;

                string       filename           = Path.Combine("1", "branch_file.txt");
                const string posixifiedFileName = "1/branch_file.txt";
                ObjectId     blobId             = repo.Index[posixifiedFileName].Id;

                string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename);

                File.AppendAllText(fullpath, "Is there there anybody out there?");
                repo.Stage(filename);

                Assert.Equal(count, repo.Index.Count);
                Assert.NotEqual((blobId), repo.Index[posixifiedFileName].Id);

                repo.Unstage(posixifiedFileName);

                Assert.Equal(count, repo.Index.Count);
                Assert.Equal(blobId, repo.Index[posixifiedFileName].Id);
            }
        }
        public void CanUnstageUnknownPathsAgainstAnOrphanedHeadWithLaxUnmatchedExplicitPathsValidation(string relativePath, FileStatus currentStatus)
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                repo.Refs.UpdateTarget("HEAD", "refs/heads/orphaned");
                Assert.True(repo.Info.IsHeadUnborn);

                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                Assert.DoesNotThrow(() => repo.Unstage(relativePath));
                Assert.DoesNotThrow(() => repo.Unstage(relativePath, new ExplicitPathsOptions {
                    ShouldFailOnUnmatchedPath = false
                }));
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));
            }
        }
Example #5
0
        public void StagingANewVersionOfAFileThenUnstagingItRevertsTheBlobToTheVersionOfHead()
        {
            string path = SandboxStandardTestRepo();
            using (var repo = new Repository(path))
            {
                int count = repo.Index.Count;

                string filename = Path.Combine("1", "branch_file.txt");
                const string posixifiedFileName = "1/branch_file.txt";
                ObjectId blobId = repo.Index[posixifiedFileName].Id;

                string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename);

                File.AppendAllText(fullpath, "Is there there anybody out there?");
                repo.Stage(filename);

                Assert.Equal(count, repo.Index.Count);
                Assert.NotEqual((blobId), repo.Index[posixifiedFileName].Id);

                repo.Unstage(posixifiedFileName);

                Assert.Equal(count, repo.Index.Count);
                Assert.Equal(blobId, repo.Index[posixifiedFileName].Id);
            }
        }
        public void UnstagingUnknownPathsWithStrictUnmatchedExplicitPathsValidationThrows(string relativePath, FileStatus currentStatus)
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                Assert.Throws <UnmatchedPathException>(() => repo.Unstage(relativePath, new ExplicitPathsOptions()));
            }
        }
        public void CanUnstageUntrackedFileAgainstAnOrphanedHead()
        {
            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                const string relativePath = "a.txt";
                Touch(repo.Info.WorkingDirectory, relativePath, "hello test file\n");

                repo.Stage(relativePath);

                repo.Unstage(relativePath);
                RepositoryStatus status = repo.RetrieveStatus();
                Assert.Equal(0, status.Staged.Count());
                Assert.Equal(1, status.Untracked.Count());

                Assert.Throws <UnmatchedPathException>(() => repo.Unstage("i-dont-exist", new ExplicitPathsOptions()));
            }
        }
Example #8
0
        public void CanUnstageBothSidesOfARename()
        {
            using (var repo = new Repository(CloneStandardTestRepo()))
            {
                repo.Move("branch_file.txt", "renamed_branch_file.txt");
                repo.Unstage(new string[] { "branch_file.txt", "renamed_branch_file.txt" });

                RepositoryStatus status = repo.RetrieveStatus();
                Assert.Equal(FileStatus.Missing, status["branch_file.txt"].State);
                Assert.Equal(FileStatus.Untracked, status["renamed_branch_file.txt"].State);
            }
        }
        public void UnstagingUnknownPathsAgainstAnOrphanedHeadWithStrictUnmatchedExplicitPathsValidationThrows(string relativePath, FileStatus currentStatus)
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                repo.Refs.UpdateTarget("HEAD", "refs/heads/orphaned");
                Assert.True(repo.Info.IsHeadUnborn);

                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                Assert.Throws <UnmatchedPathException>(() => repo.Unstage(relativePath, new ExplicitPathsOptions()));
            }
        }
        public void CanUnstageBothSidesOfARename()
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                repo.Move("branch_file.txt", "renamed_branch_file.txt");
                repo.Unstage(new string[] { "branch_file.txt", "renamed_branch_file.txt" });

                RepositoryStatus status = repo.RetrieveStatus();
                Assert.Equal(FileStatus.Missing, status["branch_file.txt"].State);
                Assert.Equal(FileStatus.Untracked, status["renamed_branch_file.txt"].State);
            }
        }
        public void CanUnstageUnknownPathsWithLaxUnmatchedExplicitPathsValidation(string relativePath, FileStatus currentStatus)
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                Assert.DoesNotThrow(() => repo.Unstage(relativePath, new ExplicitPathsOptions()
                {
                    ShouldFailOnUnmatchedPath = false
                }));
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));
            }
        }
        public void UnstagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows()
        {
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                DirectoryInfo di = Directory.CreateDirectory(scd.DirectoryPath);

                const string filename = "unit_test.txt";
                string       fullPath = Touch(di.FullName, filename, "some contents");

                Assert.Throws <ArgumentException>(() => repo.Unstage(fullPath));
            }
        }
Example #13
0
        public void CanUnstage(
            string relativePath, FileStatus currentStatus, bool doesCurrentlyExistInTheIndex,
            FileStatus expectedStatusOnceStaged, bool doesExistInTheIndexOnceStaged, int expectedIndexCountVariation)
        {
            string path = SandboxStandardTestRepo();
            using (var repo = new Repository(path))
            {
                int count = repo.Index.Count;
                Assert.Equal(doesCurrentlyExistInTheIndex, (repo.Index[relativePath] != null));
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                repo.Unstage(relativePath);

                Assert.Equal(count + expectedIndexCountVariation, repo.Index.Count);
                Assert.Equal(doesExistInTheIndexOnceStaged, (repo.Index[relativePath] != null));
                Assert.Equal(expectedStatusOnceStaged, repo.RetrieveStatus(relativePath));
            }
        }
        public void CanUnstageTargetOfARename()
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                repo.Move("branch_file.txt", "renamed_branch_file.txt");

                RepositoryStatus oldStatus = repo.RetrieveStatus();
                Assert.Equal(1, oldStatus.RenamedInIndex.Count());
                Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);

                repo.Unstage(new string[] { "renamed_branch_file.txt" });

                RepositoryStatus newStatus = repo.RetrieveStatus();
                Assert.Equal(0, newStatus.RenamedInIndex.Count());
                Assert.Equal(FileStatus.Untracked, newStatus["renamed_branch_file.txt"].State);
                Assert.Equal(FileStatus.Removed, newStatus["branch_file.txt"].State);
            }
        }
        public void CanUnstage(
            string relativePath, FileStatus currentStatus, bool doesCurrentlyExistInTheIndex,
            FileStatus expectedStatusOnceStaged, bool doesExistInTheIndexOnceStaged, int expectedIndexCountVariation)
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                int count = repo.Index.Count;
                Assert.Equal(doesCurrentlyExistInTheIndex, (repo.Index[relativePath] != null));
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                repo.Unstage(relativePath);

                Assert.Equal(count + expectedIndexCountVariation, repo.Index.Count);
                Assert.Equal(doesExistInTheIndexOnceStaged, (repo.Index[relativePath] != null));
                Assert.Equal(expectedStatusOnceStaged, repo.RetrieveStatus(relativePath));
            }
        }
        public void CanUnstageSourceOfARename()
        {
            using (var repo = new Repository(CloneStandardTestRepo()))
            {
                repo.Move("branch_file.txt", "renamed_branch_file.txt");

                RepositoryStatus oldStatus = repo.RetrieveStatus();
                Assert.Equal(1, oldStatus.RenamedInIndex.Count());
                Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State);
                Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);

                repo.Unstage(new string[] { "branch_file.txt" });

                RepositoryStatus newStatus = repo.RetrieveStatus();
                Assert.Equal(0, newStatus.RenamedInIndex.Count());
                Assert.Equal(FileStatus.Missing, newStatus["branch_file.txt"].State);
                Assert.Equal(FileStatus.Added, newStatus["renamed_branch_file.txt"].State);
            }
        }
Example #17
0
        public void CanStageAndUnstageAnIgnoredFile()
        {
            string path = SandboxStandardTestRepo();
            using (var repo = new Repository(path))
            {
                Touch(repo.Info.WorkingDirectory, ".gitignore", "*.ign" + Environment.NewLine);

                const string relativePath = "Champa.ign";
                Touch(repo.Info.WorkingDirectory, relativePath, "On stage!" + Environment.NewLine);

                Assert.Equal(FileStatus.Ignored, repo.RetrieveStatus(relativePath));

                repo.Stage(relativePath, new StageOptions { IncludeIgnored = true });
                Assert.Equal(FileStatus.Added, repo.RetrieveStatus(relativePath));

                repo.Unstage(relativePath);
                Assert.Equal(FileStatus.Ignored, repo.RetrieveStatus(relativePath));
            }
        }
        public void CanUnstageTheRemovalOfAFile()
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                int count = repo.Index.Count;

                const string filename = "deleted_staged_file.txt";

                string fullPath = Path.Combine(repo.Info.WorkingDirectory, filename);
                Assert.False(File.Exists(fullPath));

                Assert.Equal(FileStatus.Removed, repo.RetrieveStatus(filename));

                repo.Unstage(filename);
                Assert.Equal(count + 1, repo.Index.Count);

                Assert.Equal(FileStatus.Missing, repo.RetrieveStatus(filename));
            }
        }
        public void CanStageAndUnstageAnIgnoredFile()
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                Touch(repo.Info.WorkingDirectory, ".gitignore", "*.ign" + Environment.NewLine);

                const string relativePath = "Champa.ign";
                Touch(repo.Info.WorkingDirectory, relativePath, "On stage!" + Environment.NewLine);

                Assert.Equal(FileStatus.Ignored, repo.RetrieveStatus(relativePath));

                repo.Stage(relativePath, new StageOptions {
                    IncludeIgnored = true
                });
                Assert.Equal(FileStatus.Added, repo.RetrieveStatus(relativePath));

                repo.Unstage(relativePath);
                Assert.Equal(FileStatus.Ignored, repo.RetrieveStatus(relativePath));
            }
        }
Example #20
0
        public void CanUnstageSourceOfARename()
        {
            using (var repo = new Repository(CloneStandardTestRepo()))
            {
                repo.Move("branch_file.txt", "renamed_branch_file.txt");

                RepositoryStatus oldStatus = repo.RetrieveStatus();
                Assert.Equal(1, oldStatus.RenamedInIndex.Count());
                Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State);
                Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);

                repo.Unstage(new string[] { "branch_file.txt" });

                RepositoryStatus newStatus = repo.RetrieveStatus();
                Assert.Equal(0, newStatus.RenamedInIndex.Count());
                Assert.Equal(FileStatus.Missing, newStatus["branch_file.txt"].State);
                Assert.Equal(FileStatus.Added, newStatus["renamed_branch_file.txt"].State);
            }
        }
Example #21
0
 public static void Unstage(Repository repository, IEnumerable <string> paths)
 {
     repository.Unstage(paths);
 }
Example #22
0
        public void CanUnstageUnknownPathsWithLaxUnmatchedExplicitPathsValidation(string relativePath, FileStatus currentStatus)
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                Assert.DoesNotThrow(() => repo.Unstage(relativePath, new ExplicitPathsOptions() { ShouldFailOnUnmatchedPath = false }));
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));
            }
        }
Example #23
0
        public void CanUnstageTheRemovalOfAFile()
        {
            string path = SandboxStandardTestRepo();
            using (var repo = new Repository(path))
            {
                int count = repo.Index.Count;

                const string filename = "deleted_staged_file.txt";

                string fullPath = Path.Combine(repo.Info.WorkingDirectory, filename);
                Assert.False(File.Exists(fullPath));

                Assert.Equal(FileStatus.Removed, repo.RetrieveStatus(filename));

                repo.Unstage(filename);
                Assert.Equal(count + 1, repo.Index.Count);

                Assert.Equal(FileStatus.Missing, repo.RetrieveStatus(filename));
            }
        }
Example #24
0
        public void CanUnstageUntrackedFileAgainstAnOrphanedHead()
        {
            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                const string relativePath = "a.txt";
                Touch(repo.Info.WorkingDirectory, relativePath, "hello test file\n");

                repo.Stage(relativePath);

                repo.Unstage(relativePath);
                RepositoryStatus status = repo.RetrieveStatus();
                Assert.Equal(0, status.Staged.Count());
                Assert.Equal(1, status.Untracked.Count());

                Assert.Throws<UnmatchedPathException>(() => repo.Unstage("i-dont-exist", new ExplicitPathsOptions()));
            }
        }
Example #25
0
        public void UnstagingUnknownPathsAgainstAnOrphanedHeadWithStrictUnmatchedExplicitPathsValidationThrows(string relativePath, FileStatus currentStatus)
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                repo.Refs.UpdateTarget("HEAD", "refs/heads/orphaned");
                Assert.True(repo.Info.IsHeadUnborn);

                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                Assert.Throws<UnmatchedPathException>(() => repo.Unstage(relativePath, new ExplicitPathsOptions()));
            }
        }
Example #26
0
        public void CanUnstageUnknownPathsAgainstAnOrphanedHeadWithLaxUnmatchedExplicitPathsValidation(string relativePath, FileStatus currentStatus)
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                repo.Refs.UpdateTarget("HEAD", "refs/heads/orphaned");
                Assert.True(repo.Info.IsHeadUnborn);

                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                Assert.DoesNotThrow(() => repo.Unstage(relativePath));
                Assert.DoesNotThrow(() => repo.Unstage(relativePath, new ExplicitPathsOptions { ShouldFailOnUnmatchedPath = false }));
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));
            }
        }
Example #27
0
        public void UnstagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirAgainstAnOrphanedHeadThrows()
        {
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                DirectoryInfo di = Directory.CreateDirectory(scd.DirectoryPath);

                const string filename = "unit_test.txt";
                string fullPath = Touch(di.FullName, filename, "some contents");

                Assert.Throws<ArgumentException>(() => repo.Unstage(fullPath));
            }
        }
Example #28
0
 public void UnstagingFileWithBadParamsThrows()
 {
     var path = SandboxStandardTestRepoGitDir();
     using (var repo = new Repository(path))
     {
         Assert.Throws<ArgumentException>(() => repo.Unstage(string.Empty));
         Assert.Throws<ArgumentNullException>(() => repo.Unstage((string)null));
         Assert.Throws<ArgumentException>(() => repo.Unstage(new string[] { }));
         Assert.Throws<ArgumentException>(() => repo.Unstage(new string[] { null }));
     }
 }
Example #29
0
        public void CanUnstageTargetOfARename()
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                repo.Move("branch_file.txt", "renamed_branch_file.txt");

                RepositoryStatus oldStatus = repo.RetrieveStatus();
                Assert.Equal(1, oldStatus.RenamedInIndex.Count());
                Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);

                repo.Unstage(new string[] { "renamed_branch_file.txt" });

                RepositoryStatus newStatus = repo.RetrieveStatus();
                Assert.Equal(0, newStatus.RenamedInIndex.Count());
                Assert.Equal(FileStatus.Untracked, newStatus["renamed_branch_file.txt"].State);
                Assert.Equal(FileStatus.Removed, newStatus["branch_file.txt"].State);
            }
        }
Example #30
0
        public void UnstagingUnknownPathsWithStrictUnmatchedExplicitPathsValidationThrows(string relativePath, FileStatus currentStatus)
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                Assert.Equal(currentStatus, repo.RetrieveStatus(relativePath));

                Assert.Throws<UnmatchedPathException>(() => repo.Unstage(relativePath, new ExplicitPathsOptions()));
            }
        }
Example #31
0
        public void CanMergeIntoOrphanedBranch()
        {
            string path = SandboxMergeTestRepo();
            using (var repo = new Repository(path))
            {
                repo.Refs.Add("HEAD", "refs/heads/orphan", true);

                // Remove entries from the working directory
                foreach(var entry in repo.RetrieveStatus())
                {
                    repo.Unstage(entry.FilePath);
                    repo.Remove(entry.FilePath, true);
                }

                // Assert that we have an empty working directory.
                Assert.False(repo.RetrieveStatus().Any());

                MergeResult result = repo.Merge("master", Constants.Signature);

                Assert.Equal(MergeStatus.FastForward, result.Status);
                Assert.Equal(masterBranchInitialId, result.Commit.Id.Sha);
                Assert.False(repo.RetrieveStatus().Any());
            }
        }
Example #32
0
        public async void Unstage(FileStatusViewModel change)
        {
            repository.Unstage(change.Path);

            await LoadWorkingDirectoryStatusAsync();
        }
Example #33
0
 public static void Unstage(Repository repository, string[] paths)
 {
     repository.Unstage(paths);
 }