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 repo.Index.Stage(relFilePath); // Get the repository status RepositoryStatus repoStatus = repo.Index.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()); } }
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()); } }
public void CanDetectedVariousKindsOfRenaming() { string path = InitNewRepository(); using (var repo = new Repository(path)) { Touch(repo.Info.WorkingDirectory, "file.txt", "This is a file with enough data to trigger similarity matching.\r\n" + "This is a file with enough data to trigger similarity matching.\r\n" + "This is a file with enough data to trigger similarity matching.\r\n" + "This is a file with enough data to trigger similarity matching.\r\n"); Commands.Stage(repo, "file.txt"); repo.Commit("Initial commit", Constants.Signature, Constants.Signature); File.Move(Path.Combine(repo.Info.WorkingDirectory, "file.txt"), Path.Combine(repo.Info.WorkingDirectory, "renamed.txt")); var opts = new StatusOptions { DetectRenamesInIndex = true, DetectRenamesInWorkDir = true }; RepositoryStatus status = repo.RetrieveStatus(opts); // This passes as expected Assert.Equal(FileStatus.RenamedInWorkdir, status.Single().State); Commands.Stage(repo, "file.txt"); Commands.Stage(repo, "renamed.txt"); status = repo.RetrieveStatus(opts); Assert.Equal(FileStatus.RenamedInIndex, status.Single().State); File.Move(Path.Combine(repo.Info.WorkingDirectory, "renamed.txt"), Path.Combine(repo.Info.WorkingDirectory, "renamed_again.txt")); status = repo.RetrieveStatus(opts); Assert.Equal(FileStatus.RenamedInWorkdir | FileStatus.RenamedInIndex, status.Single().State); } }