public void EnumerateFileSystemInfos_returns_expected_items() { // ARRANGE var files = new[] { "file1.txt", "file2.txt", "dir1/file3.txt", "dir2/dir3/file4.txt" }; foreach (var file in files) { CreateFile(file); } GitAdd(); GitCommit(); using var repository = new Repository(m_WorkingDirectory); // ACT var sut = new GitDirectoryInfo(repository.Head.Tip); var fileSystemInfos = sut.EnumerateFileSystemInfos(); // ASSERT fileSystemInfos .Should().NotBeNull() .And.HaveCount(files.Length); fileSystemInfos .Should().Contain(f => f.FullName == "file1.txt") .And.Contain(x => x.FullName == "file2.txt") .And.Contain(x => x.FullName == "dir1") .And.Contain(x => x.FullName == "dir2"); }
public void GetFile_returns_expected_file(string path, string expectedName, string expectedFullName) { // ARRANGE var files = new[] { "file1.txt", "file2.txt", "dir1/file3.txt", "dir2/dir3/file4.txt" }; foreach (var file in files) { CreateFile(file); } GitAdd(); GitCommit(); using var repository = new Repository(m_WorkingDirectory); // ACT var sut = new GitDirectoryInfo(repository.Head.Tip); // ASSERT sut.GetFile(path) .Should().NotBeNull() .And.Match <FileInfoBase>(dir => dir.FullName == expectedFullName) .And.Match <FileInfoBase>(dir => dir.Name == expectedName); }
public void Constructor_throws_ArgumentException_if_tree_is_null() { using var repository = new Repository(m_WorkingDirectory); var root = new GitDirectoryInfo(repository.Head.Tip); Action act = () => new GitDirectoryInfo(root.Commit, "dir", root, null !); act.Should().Throw <ArgumentNullException>(); }
public void Constructor_throws_ArgumentException_for_invalid_names(string name) { using var repository = new Repository(m_WorkingDirectory); var root = new GitDirectoryInfo(repository.Head.Tip); Action act = () => new GitDirectoryInfo(root.Commit, name, root, repository.Head.Tip.Tree); act.Should().Throw <ArgumentException>(); }
public void EnumerateFileSystemInfos_returns_expected_items_for_empty_repository() { using var repository = new Repository(m_WorkingDirectory); var sut = new GitDirectoryInfo(repository.Head.Tip); sut.EnumerateFileSystemInfos() .Should().NotBeNull() .And.BeEmpty(); }
public void Root_directory_has_empty_path() { using var repository = new Repository(m_WorkingDirectory); var sut = new GitDirectoryInfo(repository.Head.Tip); sut.Name.Should().Be(""); sut.FullName.Should().Be(""); sut.ParentDirectory.Should().BeNull(); }
public void GetFile_returns_null_if_file_does_not_exist(string path) { // ARRANGE using var repository = new Repository(m_WorkingDirectory); var sut = new GitDirectoryInfo(repository.Head.Tip); // ACT var file = sut.GetFile(path); // ASSERT file.Should().BeNull(); }
public void GetDirectory_returns_if_directory_does_not_exist(string path) { // ARRANGE using var repository = new Repository(m_WorkingDirectory); var sut = new GitDirectoryInfo(repository.Head.Tip); // ACT var dir = sut.GetDirectory(path); // ASSERT dir.Should().BeNull(); }
/// <summary> /// Panel view class refresh function /// </summary> public void ViewRefresh() { int mode = Properties.Settings.Default.viewMode; // Set the view mode text (picked up from the indexed menu combo box) viewLabel.Text = dropViewMode.DropDownItems[mode].Text; menuSortFilesByExtension.Enabled = btListView.Enabled = App.Repos.Current != null; treeView.BeginUpdate(); treeView.NodesClear(); if (App.Repos.Current != null) { status = App.Repos.Current.Status; btListView.Checked = !status.Repo.IsTreeView; menuSortFilesByExtension.Checked = status.Repo.SortBy == GitDirectoryInfo.SortBy.Extension; List <string> files = new List <string>(); switch (mode) { case 0: // Git status of all files: status + untracked files = status.GetFiles(); break; case 1: // Git status of files: status - untracked files = status.GetFiles(); // Remove all untracked files files = files.Where(s => status.Xcode(s) != '?').ToList(); break; case 2: // Git view of repo: ls-tree ExecResult result = App.Repos.Current.Run("ls-tree --abbrev -r -z HEAD"); if (result.Success()) { string[] response = result.stdout .Replace('/', Path.DirectorySeparatorChar) // Correct the path slash on Windows .Split(("\0") .ToCharArray(), StringSplitOptions.RemoveEmptyEntries); files.AddRange(response.Select(s => s.Split('\t').Last())); } break; case 3: // Local file view: use local directory list files = GitDirectoryInfo.GetFilesRecursive(App.Repos.Current.Path); // Remove the repo root from the file paths int rootlen = App.Repos.Current.Path.Length; files = files.Select(file => file.Substring(rootlen + 1)).ToList(); break; case 4: // Local files not in repo: untracked only files = status.GetFiles(); // Leave only untracked files files = files.Where(s => status.Xcode(s) == '?').ToList(); break; case 5: // Git view local files not in .gitignore ExecResult result2 = App.Repos.Current.Run("ls-files -z --abbrev --exclude-from=.gitignore -o -c -d -m"); if (result2.Success()) { string[] response2 = result2.stdout .Replace('/', Path.DirectorySeparatorChar) // Correct the path slash on Windows .Split(("\0") .ToCharArray(), StringSplitOptions.RemoveEmptyEntries); files.AddRange(response2.Select(s => s.Split('\t').Last()).Distinct()); } break; } // Build the tree view (or a list view) TreeNode node = new TreeNode(App.Repos.Current.Path) { Tag = String.Empty }; if (status.Repo.IsTreeView) { ClassView.BuildTree(node, files, status.Repo.SortBy); } else { ClassView.BuildFileList(node, files, status.Repo.SortBy); } // Add the resulting tree to the tree view control treeView.Nodes.Add(node); // Assign the icons to the nodes of tree view ClassView.ViewAssignIcon(status, node, false); ClassView.ViewUpdateToolTips(node); // Set the first node (root) image according to the view mode node.ImageIndex = mode == 2 ? (int)ClassView.Img.DatabaseOpened : (int)ClassView.Img.FolderOpened; // Always keep the root node expanded by default node.Expand(); // Finally, expand the rest of the tree to its previous expand state ViewExpand(node); } treeView.ShowNodeToolTips = true; treeView.EndUpdate(); }