From 839e518d8ab293f410b09c5212532b8bb56b0b3f Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 28 Nov 2017 08:28:56 -0500 Subject: [PATCH 1/2] Removing ChangesetTreeView --- .../Editor/GitHub.Unity/GitHub.Unity.csproj | 1 - .../GitHub.Unity/UI/ChangesetTreeView.cs | 295 ------------------ 2 files changed, 296 deletions(-) delete mode 100644 src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesetTreeView.cs diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj b/src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj index a0b6dd2f1..1cf51301f 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj @@ -96,7 +96,6 @@ - diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesetTreeView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesetTreeView.cs deleted file mode 100644 index 5d787da89..000000000 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesetTreeView.cs +++ /dev/null @@ -1,295 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using UnityEditor; -using UnityEngine; - -namespace GitHub.Unity -{ - [Serializable] - class ChangesetTreeView : Subview - { - private const string BasePathLabel = "{0}"; - private const string NoChangesLabel = "No changes found"; - - [SerializeField] private List entries = new List(); - [SerializeField] private List entryCommitTargets = new List(); - [SerializeField] private List foldedTreeEntries = new List(); - [NonSerialized] private FileTreeNode tree; - - public override void OnGUI() - { - GUILayout.BeginVertical(); - { - // The file tree (when available) - if (tree != null && entries.Any()) - { - // Base path label - if (!string.IsNullOrEmpty(tree.Path)) - { - GUILayout.BeginHorizontal(); - { - var iconRect = GUILayoutUtility.GetRect(Styles.CommitIconSize, Styles.CommitIconSize, GUILayout.ExpandWidth(false)); - iconRect.y += 2; - iconRect.x += 2; - - GUI.DrawTexture(iconRect, Styles.FolderIcon, ScaleMode.ScaleToFit); - - GUILayout.Label(string.Format(BasePathLabel, tree.Path)); - } - GUILayout.EndHorizontal(); - } - - GUILayout.BeginHorizontal(); - { - GUILayout.Space(Styles.TreeIndentation + Styles.TreeRootIndentation); - GUILayout.BeginVertical(); - { - // Root nodes - foreach (var node in tree.Children) - { - TreeNode(node); - } - } - - GUILayout.EndVertical(); - } - - GUILayout.EndHorizontal(); - - // If we have no minimum height calculated, do that now and repaint so it can be used - if (Height == 0f && Event.current.type == EventType.Repaint) - { - Height = GUILayoutUtility.GetLastRect().yMax + Styles.MinCommitTreePadding; - Redraw(); - } - - GUILayout.FlexibleSpace(); - } - else - { - GUILayout.FlexibleSpace(); - GUILayout.BeginHorizontal(); - { - GUILayout.FlexibleSpace(); - GUILayout.Label(NoChangesLabel); - GUILayout.FlexibleSpace(); - } - GUILayout.EndHorizontal(); - GUILayout.FlexibleSpace(); - } - } - - GUILayout.EndVertical(); - } - - public void UpdateEntries(IList newEntries) - { - // Handle the empty list scenario - if (!newEntries.Any()) - { - entries.Clear(); - entryCommitTargets.Clear(); - tree = null; - foldedTreeEntries.Clear(); - - OnCommitTreeChange(); - - return; - } - - tree = TreeBuilder.BuildTreeRoot(newEntries, entries, entryCommitTargets, foldedTreeEntries, AssetDatabase.GetCachedIcon); - - OnCommitTreeChange(); - } - - private void OnCommitTreeChange() - { - Height = 0f; - Redraw(); - } - - private void TreeNode(FileTreeNode node) - { - GUILayout.Space(Styles.TreeVerticalSpacing); - var target = node.Target; - var isFolder = node.Children.Any(); - - var isFolderForMeta = false; - if (node.Children.Count() == 1) - { - var parentLabel = node.Label; - var childLabel = node.Children.First().Label; - isFolderForMeta = childLabel.StartsWith(parentLabel) && childLabel.EndsWith(".meta"); - } - - GUILayout.BeginHorizontal(); - { - if (!Readonly) - { - // Commit inclusion toggle - var state = node.State; - var toggled = state == CommitState.All; - - EditorGUI.BeginChangeCheck(); - { - toggled = GUILayout.Toggle(toggled, "", state == CommitState.Some ? Styles.ToggleMixedStyle : GUI.skin.toggle, - GUILayout.ExpandWidth(false)); - } - if (EditorGUI.EndChangeCheck()) - { - node.State = toggled ? CommitState.All : CommitState.None; - } - } - - // Foldout - if (isFolder) - { - Rect foldoutRect; - - if (Readonly) - { - foldoutRect = GUILayoutUtility.GetRect(1, 1); - foldoutRect.Set(foldoutRect.x - 7f, foldoutRect.y + 3f, 0f, EditorGUIUtility.singleLineHeight); - } - else - { - foldoutRect = GUILayoutUtility.GetLastRect(); - } - - foldoutRect.Set(foldoutRect.x - Styles.FoldoutWidth + Styles.FoldoutIndentation, foldoutRect.y, Styles.FoldoutWidth, - foldoutRect.height); - - EditorGUI.BeginChangeCheck(); - { - node.Open = GUI.Toggle(foldoutRect, node.Open, "", EditorStyles.foldout); - } - if (EditorGUI.EndChangeCheck()) - { - if (!node.Open && !foldedTreeEntries.Contains(node.RepositoryPath)) - { - foldedTreeEntries.Add(node.RepositoryPath); - } - else if (node.Open) - { - foldedTreeEntries.Remove(node.RepositoryPath); - } - - OnCommitTreeChange(); - } - } - - GitFileStatus? status = null; - - // Node icon and label - GUILayout.BeginHorizontal(); - { - GUILayout.Space(Styles.CommitIconHorizontalPadding); - var iconRect = GUILayoutUtility.GetRect(Styles.CommitIconSize, Styles.CommitIconSize, GUILayout.ExpandWidth(false)); - iconRect.y += 2; - iconRect.x -= 2; - - if (Event.current.type == EventType.Repaint) - { - var icon = (Texture) node.Icon; - if (icon == null) - { - if (isFolderForMeta || !isFolder) - { - icon = Styles.DefaultAssetIcon; - } - else - { - icon = Styles.FolderIcon; - } - } - - if (icon != null) - { - GUI.DrawTexture(iconRect, - icon, - ScaleMode.ScaleToFit); - } - } - - var statusRect = new Rect( - iconRect.xMax - 9, - iconRect.yMax - 7, - 9, - 9); - - // Current status (if any) - if (target != null) - { - var idx = entryCommitTargets.IndexOf(target); - if (idx > -1) - { - status = entries[idx].Status; - var statusIcon = Styles.GetFileStatusIcon(entries[idx].Status, false); - if (statusIcon != null) - GUI.DrawTexture(statusRect, statusIcon); - } - } - - GUILayout.Space(Styles.CommitIconHorizontalPadding); - } - GUILayout.EndHorizontal(); - - // Make the text gray and strikethrough if the file is deleted - if (status == GitFileStatus.Deleted) - { - GUILayout.Label(new GUIContent(node.Label, node.RepositoryPath), Styles.DeletedFileLabel, GUILayout.ExpandWidth(true)); - var labelRect = GUILayoutUtility.GetLastRect(); - var strikeRect = new Rect(labelRect.xMin, labelRect.center.y, labelRect.width, 1); - EditorGUI.DrawRect(strikeRect, Color.gray); - } - else - { - GUILayout.Label(new GUIContent(node.Label, node.RepositoryPath), GUILayout.ExpandWidth(true)); - } - GUILayout.FlexibleSpace(); - } - GUILayout.EndHorizontal(); - - GUILayout.BeginHorizontal(); - { - // Render children (if any and folded out) - if (isFolder && node.Open) - { - GUILayout.Space(Styles.TreeIndentation); - GUILayout.BeginVertical(); - { - foreach (var child in node.Children) - { - TreeNode(child); - } - } - - GUILayout.EndVertical(); - } - } - - GUILayout.EndHorizontal(); - } - - public override bool IsBusy - { - get { return false; } - } - - public float Height { get; protected set; } - - public bool Readonly { get; set; } - - public IList Entries - { - get { return entries; } - } - - public IList CommitTargets - { - get { return entryCommitTargets; } - } - } -} From fb29c681878c95ff364bcaded62d55466b63837d Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 30 Nov 2017 10:00:03 -0500 Subject: [PATCH 2/2] Removing more old stuff --- src/GitHub.Api/GitHub.Api.csproj | 3 - src/GitHub.Api/UI/FileTreeNode.cs | 143 ----- src/GitHub.Api/UI/GitCommitTarget.cs | 23 - src/GitHub.Api/UI/TreeBuilder.cs | 146 ----- src/tests/UnitTests/UI/TreeBuilderTests.cs | 692 --------------------- src/tests/UnitTests/UnitTests.csproj | 1 - 6 files changed, 1008 deletions(-) delete mode 100644 src/GitHub.Api/UI/FileTreeNode.cs delete mode 100644 src/GitHub.Api/UI/GitCommitTarget.cs delete mode 100644 src/GitHub.Api/UI/TreeBuilder.cs delete mode 100644 src/tests/UnitTests/UI/TreeBuilderTests.cs diff --git a/src/GitHub.Api/GitHub.Api.csproj b/src/GitHub.Api/GitHub.Api.csproj index 7185423ec..9534e44f1 100644 --- a/src/GitHub.Api/GitHub.Api.csproj +++ b/src/GitHub.Api/GitHub.Api.csproj @@ -234,9 +234,6 @@ - - - diff --git a/src/GitHub.Api/UI/FileTreeNode.cs b/src/GitHub.Api/UI/FileTreeNode.cs deleted file mode 100644 index e3f63e423..000000000 --- a/src/GitHub.Api/UI/FileTreeNode.cs +++ /dev/null @@ -1,143 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace GitHub.Unity -{ - enum CommitState - { - None, - Some, - All - } - - class FileTreeNode - { - private List children; - private string path; - private CommitState state; - - public object Icon; - public string Label; - public bool Open = true; - public string RepositoryPath; - public GitCommitTarget Target { get; set; } - - public FileTreeNode() - { - children = new List(); - } - - public FileTreeNode(string path) - { - this.path = path ?? ""; - Label = this.path; - children = new List(); - } - - public FileTreeNode Add(FileTreeNode child) - { - children.Add(child); - return child; - } - - public CommitState State - { - get - { - if (children == null) - return state; - - var commitState = CommitState.None; - if (Target != null) - { - commitState = Target.All ? CommitState.All : Target.Any ? CommitState.Some : CommitState.None; - if (!children.Any()) - { - state = commitState; - return state; - } - } - - var allCount = children.Count(c => c.State == CommitState.All); - - if (allCount == children.Count && (commitState == CommitState.All || Target == null)) - { - state = CommitState.All; - return state; - } - - if (allCount > 0 || commitState == CommitState.Some) - { - state = CommitState.Some; - return state; - } - - var someCount = children.Count(c => c.State == CommitState.Some); - if (someCount > 0 || commitState == CommitState.Some) - { - state = CommitState.Some; - return state; - } - state = CommitState.None; - return state; - } - - set - { - if (value == state) - { - return; - } - - if (Target != null) - { - if (value == CommitState.None) - { - Target.Clear(); - } - else if (value == CommitState.All) - { - Target.All = true; - } - } - - state = value; - - if (children == null) - { - return; - } - - for (var index = 0; index < children.Count; ++index) - { - children[index].State = value; - } - } - } - - public string Path - { - get { return path; } - } - - public IEnumerable Children - { - get { - if (children == null) - children = new List(); - return children; - } - } - - private ILogging logger; - protected ILogging Logger - { - get - { - if (logger == null) - logger = Logging.GetLogger(GetType()); - return logger; - } - } - } -} \ No newline at end of file diff --git a/src/GitHub.Api/UI/GitCommitTarget.cs b/src/GitHub.Api/UI/GitCommitTarget.cs deleted file mode 100644 index 59c7f9008..000000000 --- a/src/GitHub.Api/UI/GitCommitTarget.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace GitHub.Unity -{ - [Serializable] - class GitCommitTarget - { - public bool All = false; - - public void Clear() - { - All = false; - } - - public bool Any - { - get - { - return All; - } - } - } -} \ No newline at end of file diff --git a/src/GitHub.Api/UI/TreeBuilder.cs b/src/GitHub.Api/UI/TreeBuilder.cs deleted file mode 100644 index 75584e3b1..000000000 --- a/src/GitHub.Api/UI/TreeBuilder.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace GitHub.Unity -{ - static class TreeBuilder - { - internal static void BuildChildNode(FileTreeNode parent, FileTreeNode node, HashSet foldedTreeSet) - { - if (String.IsNullOrEmpty(node.Label)) - { - // TODO: We should probably reassign this target onto the parent? Depends on how we want to handle .meta files for folders - return; - } - - node.RepositoryPath = parent.RepositoryPath.ToNPath().Combine(node.Label); - parent.Open = !foldedTreeSet.Contains(parent.RepositoryPath); - - // Is this node inside a folder? - var nodePath = node.Label.ToNPath(); - if (nodePath.Elements.Count() > 1) - { - // Figure out what the root folder is and chop it from the path - var root = nodePath.Elements.First(); - node.Label = new NPath("").Combine(nodePath.Elements.Skip(1).ToArray()); - - // Look for a branch matching our root in the existing children - var found = false; - foreach (var child in parent.Children) - { - // If we found the branch, continue building from that branch - if (child.Label.Equals(root)) - { - found = true; - BuildChildNode(child, node, foldedTreeSet); - break; - } - } - - // No existing branch - we will have to add a new one to build from - if (!found) - { - var p = parent.RepositoryPath.ToNPath().Combine(root); - BuildChildNode(parent.Add(new FileTreeNode(root) { RepositoryPath = p }), node, foldedTreeSet); - } - } - else if (nodePath.ExtensionWithDot == ".meta") - { - // Look for a branch matching our root in the existing children - var found = false; - var searchLabel = nodePath.Parent.Combine(nodePath.FileNameWithoutExtension); - foreach (var child in parent.Children) - { - // If we found the branch, continue building from that branch - if (child.Label.Equals(searchLabel)) - { - found = true; - BuildChildNode(child, node, foldedTreeSet); - break; - } - } - if (!found) - { - parent.Add(node); - } - } - // Not inside a folder - just add this node right here - else - { - parent.Add(node); - } - } - - internal static FileTreeNode BuildTreeRoot(IList newEntries, List gitStatusEntries, List gitCommitTargets, List foldedTreeEntries, Func iconLoaderFunc = null) - { - Guard.ArgumentNotNullOrEmpty(newEntries, "newEntries"); - - var newEntriesSetByPath = new HashSet(newEntries.Select(entry => entry.Path)); - var gitStatusEntriesSetByPath = new HashSet(gitStatusEntries.Select(entry => entry.Path)); - - // Remove what got nuked - for (var index = 0; index < gitStatusEntries.Count;) - { - if (!newEntriesSetByPath.Contains(gitStatusEntries[index].Path)) - { - gitStatusEntries.RemoveAt(index); - gitCommitTargets.RemoveAt(index); - } - else - { - index++; - } - } - - // Remove folding state of nuked items - for (var index = 0; index < foldedTreeEntries.Count;) - { - if (newEntries.All(e => e.Path.IndexOf(foldedTreeEntries[index], StringComparison.CurrentCulture) != 0)) - { - foldedTreeEntries.RemoveAt(index); - } - else - { - index++; - } - } - - var foldedTreeSet = new HashSet(foldedTreeEntries); - - // Add new stuff - for (var index = 0; index < newEntries.Count; ++index) - { - var entry = newEntries[index]; - if (!gitStatusEntriesSetByPath.Contains(entry.Path)) - { - gitStatusEntries.Add(entry); - gitCommitTargets.Add(new GitCommitTarget()); - } - } - - // TODO: In stead of completely rebuilding the tree structure, figure out a way to migrate open/closed states from the old tree to the new - // Build tree structure - - var tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(gitStatusEntries.Select(e => e.Path))); - tree.RepositoryPath = tree.Path; - - for (var index1 = 0; index1 < gitStatusEntries.Count; index1++) - { - var gitStatusEntry = gitStatusEntries[index1]; - var entryPath = gitStatusEntry.Path.ToNPath(); - if (entryPath.IsChildOf(tree.Path)) entryPath = entryPath.RelativeTo(tree.Path.ToNPath()); - - var node = new FileTreeNode(entryPath) { Target = gitCommitTargets[index1] }; - if (!String.IsNullOrEmpty(gitStatusEntry.ProjectPath)) - { - node.Icon = iconLoaderFunc?.Invoke(gitStatusEntry.ProjectPath); - } - - BuildChildNode(tree, node, foldedTreeSet); - } - - return tree; - } - } -} \ No newline at end of file diff --git a/src/tests/UnitTests/UI/TreeBuilderTests.cs b/src/tests/UnitTests/UI/TreeBuilderTests.cs deleted file mode 100644 index 4a3594564..000000000 --- a/src/tests/UnitTests/UI/TreeBuilderTests.cs +++ /dev/null @@ -1,692 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using GitHub.Unity; -using NCrunch.Framework; -using NSubstitute; -using NUnit.Framework; -using TestUtils; - -namespace UnitTests.UI -{ - - [TestFixture, Isolated] - public class TreeBuilderTests - { - private IEnvironment environment; - private GitObjectFactory gitObjectFactory; - - [Test] - public void CanBuildTreeForSingleItem() - { - InitializeEnvironment(@"c:\Project", @"c:\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(1); - gitCommitTargets.Count.Should().Be(1); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(1); - - gitCommitTargets.Count.Should().Be(1); - - var file1 = treeRootChidren[0]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be("file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - file1.Children.Should().BeEmpty(); - } - - [Test] - public void CanBuildTreeForSingleItemWhenProjectNestedInRepo() - { - InitializeEnvironment(@"c:\Repo", @"c:\Repo\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(1); - gitCommitTargets.Count.Should().Be(1); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(1); - - var file1 = treeRootChidren[0]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be(@"Project\file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - file1.Children.Should().BeEmpty(); - } - - [Test] - public void CanBuildTreeForSingleItemInFolder() - { - InitializeEnvironment(@"c:\Project", @"c:\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry(@"folder\file1.txt", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(1); - gitCommitTargets.Count.Should().Be(1); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(1); - - var file1 = treeRootChidren[0]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be(@"folder\file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - file1.Children.Should().BeEmpty(); - } - - [Test] - public void CanBuildTreeForSingleItemInFolderWhenProjectNestedInRepo() - { - InitializeEnvironment(@"c:\Repo", @"c:\Repo\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry(@"folder\file1.txt", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(1); - gitCommitTargets.Count.Should().Be(1); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(1); - - var file1 = treeRootChidren[0]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be(@"Project\folder\file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - file1.Children.Should().BeEmpty(); - } - - [Test] - public void CanBuildTreeForMultipleSiblings() - { - InitializeEnvironment(@"c:\Project", @"c:\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry("file2.txt", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(2); - gitCommitTargets.Count.Should().Be(2); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(2); - - var file1 = treeRootChidren[0]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be("file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - file1.Children.Should().BeEmpty(); - - var file2 = treeRootChidren[1]; - - file2.Label.Should().Be("file2.txt"); - file2.Open.Should().BeTrue(); - file2.Path.Should().Be("file2.txt"); - file2.RepositoryPath.Should().Be("file2.txt"); - file2.State.Should().Be(CommitState.None); - file2.Target.Should().Be(gitCommitTargets[1]); - - file2.Children.Should().BeEmpty(); - } - - [Test] - public void CanBuildTreeForMultipleSiblingsWhenProjectNestedInRepo() - { - InitializeEnvironment(@"c:\Repo", @"c:\Repo\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry("file2.txt", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(2); - gitCommitTargets.Count.Should().Be(2); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(2); - - var file1 = treeRootChidren[0]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be(@"Project\file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - file1.Children.Should().BeEmpty(); - - var file2 = treeRootChidren[1]; - - file2.Label.Should().Be("file2.txt"); - file2.Open.Should().BeTrue(); - file2.Path.Should().Be("file2.txt"); - file2.RepositoryPath.Should().Be(@"Project\file2.txt"); - file2.State.Should().Be(CommitState.None); - file2.Target.Should().Be(gitCommitTargets[1]); - - file2.Children.Should().BeEmpty(); - } - - [Test] - public void CanBuildTreeForHierarchy() - { - InitializeEnvironment(@"c:\Project", @"c:\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder1\file2.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder1\file3.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder2\file4.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder2\file5.txt", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(5); - gitCommitTargets.Count.Should().Be(5); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(3); - - var file1 = treeRootChidren[0]; - var folder1 = treeRootChidren[1]; - var folder2 = treeRootChidren[2]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be("file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - file1.Children.Should().BeEmpty(); - - folder1.Label.Should().Be("folder1"); - folder1.Open.Should().BeTrue(); - folder1.Path.Should().Be("folder1"); - folder1.RepositoryPath.Should().Be("folder1"); - folder1.State.Should().Be(CommitState.None); - folder1.Target.Should().BeNull(); - - folder2.Label.Should().Be("folder2"); - folder2.Open.Should().BeTrue(); - folder2.Path.Should().Be("folder2"); - folder2.RepositoryPath.Should().Be("folder2"); - folder2.State.Should().Be(CommitState.None); - folder2.Target.Should().BeNull(); - - var folder1Children = folder1.Children.ToArray(); - folder1Children.Length.Should().Be(2); - - var file2 = folder1Children[0]; - var file3 = folder1Children[1]; - - file2.Label.Should().Be("file2.txt"); - file2.Open.Should().BeTrue(); - file2.Path.Should().Be(@"folder1\file2.txt"); - file2.RepositoryPath.Should().Be(@"folder1\file2.txt"); - file2.State.Should().Be(CommitState.None); - file2.Target.Should().Be(gitCommitTargets[1]); - - file2.Children.Should().BeEmpty(); - - file3.Label.Should().Be("file3.txt"); - file3.Open.Should().BeTrue(); - file3.Path.Should().Be(@"folder1\file3.txt"); - file3.RepositoryPath.Should().Be(@"folder1\file3.txt"); - file3.State.Should().Be(CommitState.None); - file3.Target.Should().Be(gitCommitTargets[2]); - - file3.Children.Should().BeEmpty(); - - var folder2Children = folder2.Children.ToArray(); - folder2Children.Length.Should().Be(2); - - var file4 = folder2Children[0]; - var file5 = folder2Children[1]; - - file4.Label.Should().Be("file4.txt"); - file4.Open.Should().BeTrue(); - file4.Path.Should().Be(@"folder2\file4.txt"); - file4.RepositoryPath.Should().Be(@"folder2\file4.txt"); - file4.State.Should().Be(CommitState.None); - file4.Target.Should().Be(gitCommitTargets[3]); - - file4.Children.Should().BeEmpty(); - - file5.Label.Should().Be("file5.txt"); - file5.Open.Should().BeTrue(); - file5.Path.Should().Be(@"folder2\file5.txt"); - file5.RepositoryPath.Should().Be(@"folder2\file5.txt"); - file5.State.Should().Be(CommitState.None); - file5.Target.Should().Be(gitCommitTargets[4]); - - file5.Children.Should().BeEmpty(); - } - - [Test] - public void CanBuildTreeForHierarchyWhenProjectNestedInRepo() - { - InitializeEnvironment(@"c:\Repo", @"c:\Repo\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder\file2.txt", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(2); - gitCommitTargets.Count.Should().Be(2); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(2); - - var file1 = treeRootChidren[0]; - var folder = treeRootChidren[1]; - - file1.Path.Should().Be("file1.txt"); - file1.Label.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be(@"Project\file1.txt"); - file1.Open.Should().BeTrue(); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - file1.Children.Should().BeEmpty(); - - folder.Path.Should().Be("folder"); - folder.Label.Should().Be("folder"); - folder.RepositoryPath.Should().Be(@"Project\folder"); - folder.Open.Should().BeTrue(); - folder.State.Should().Be(CommitState.None); - folder.Target.Should().BeNull(); - - var folderChildren = folder.Children.ToArray(); - folderChildren.Length.Should().Be(1); - - var file2 = folderChildren[0]; - - file2.Label.Should().Be("file2.txt"); - file2.Open.Should().BeTrue(); - file2.Path.Should().Be(@"folder\file2.txt"); - file2.RepositoryPath.Should().Be(@"Project\folder\file2.txt"); - file2.State.Should().Be(CommitState.None); - file2.Target.Should().Be(gitCommitTargets[1]); - - file2.Children.Should().BeEmpty(); - } - - [Test] - public void CanBuildTreeForItemAndMetafile() - { - InitializeEnvironment(@"c:\Project", @"c:\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry("file1.txt.meta", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(2); - gitCommitTargets.Count.Should().Be(2); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(1); - - var file1 = treeRootChidren[0]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be("file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - var fileChildren = file1.Children.ToArray(); - fileChildren.Length.Should().Be(1); - - var file1Meta = fileChildren[0]; - - file1Meta.Label.Should().Be("file1.txt.meta"); - file1Meta.Open.Should().BeTrue(); - file1Meta.Path.Should().Be("file1.txt.meta"); - - //TODO: Understand this as this is unexpected - file1Meta.RepositoryPath.Should().Be(@"file1.txt\file1.txt.meta"); - - file1Meta.State.Should().Be(CommitState.None); - file1Meta.State.Should().Be(CommitState.None); - file1Meta.Target.Should().Be(gitCommitTargets[1]); - - file1Meta.Children.Should().BeEmpty(); - } - - [Test] - public void CanUpdateTreeAndMaintainSelectedState() - { - InitializeEnvironment(@"c:\Project", @"c:\Project"); - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var newGitStatusEntries1 = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry("file2.txt", GitFileStatus.Modified) - }; - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries1, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(2); - gitCommitTargets.Count.Should().Be(2); - foldedTreeEntries.Count.Should().Be(0); - - var treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(2); - - var file1 = treeRootChidren[0]; - var file2 = treeRootChidren[1]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be("file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - file1.Children.Should().BeEmpty(); - - file2.Label.Should().Be("file2.txt"); - file2.Open.Should().BeTrue(); - file2.Path.Should().Be("file2.txt"); - file2.RepositoryPath.Should().Be("file2.txt"); - file2.State.Should().Be(CommitState.None); - file2.Target.Should().Be(gitCommitTargets[1]); - file2.Children.Should().BeEmpty(); - - file1.State = CommitState.All; - file2.State = CommitState.All; - - var newGitStatusEntries2 = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry("file3.txt", GitFileStatus.Modified) - }; - - treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries2, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(2); - - var file3 = treeRootChidren[1]; - - gitStatusEntries.Count.Should().Be(2); - gitCommitTargets.Count.Should().Be(2); - foldedTreeEntries.Count.Should().Be(0); - - treeRootChidren = treeRoot.Children.ToArray(); - treeRootChidren.Length.Should().Be(2); - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be("file1.txt"); - file1.State.Should().Be(CommitState.All); - file1.Target.Should().Be(gitCommitTargets[0]); - file1.Children.Should().BeEmpty(); - - file3.Label.Should().Be("file3.txt"); - file3.Open.Should().BeTrue(); - file3.Path.Should().Be("file3.txt"); - file3.RepositoryPath.Should().Be("file3.txt"); - file3.State.Should().Be(CommitState.None); - file3.Target.Should().Be(gitCommitTargets[1]); - file3.Children.Should().BeEmpty(); - } - - [Test] - public void CanUpdateTreeAndMaintainFoldedState() - { - InitializeEnvironment(@"c:\Project", @"c:\Project"); - - var newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry("file1.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder1\file2.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder1\file3.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder2\file4.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder2\file5.txt", GitFileStatus.Modified) - }; - - var gitStatusEntries = new List(); - var gitCommitTargets = new List(); - var foldedTreeEntries = new List(); - - var treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(5); - gitCommitTargets.Count.Should().Be(5); - foldedTreeEntries.Count.Should().Be(0); - - var children = treeRoot.Children.ToArray(); - children.Length.Should().Be(3); - - var file1 = children[0]; - var folder1 = children[1]; - var folder2 = children[2]; - - file1.Label.Should().Be("file1.txt"); - file1.Open.Should().BeTrue(); - file1.Path.Should().Be("file1.txt"); - file1.RepositoryPath.Should().Be("file1.txt"); - file1.State.Should().Be(CommitState.None); - file1.Target.Should().Be(gitCommitTargets[0]); - - file1.Children.Should().BeEmpty(); - - folder1.Label.Should().Be("folder1"); - folder1.Open.Should().BeTrue(); - folder1.Path.Should().Be("folder1"); - folder1.RepositoryPath.Should().Be("folder1"); - folder1.State.Should().Be(CommitState.None); - folder1.Target.Should().BeNull(); - - folder2.Label.Should().Be("folder2"); - folder2.Open.Should().BeTrue(); - folder2.Path.Should().Be("folder2"); - folder2.RepositoryPath.Should().Be("folder2"); - folder2.State.Should().Be(CommitState.None); - folder2.Target.Should().BeNull(); - - var folder1Children = folder1.Children.ToArray(); - folder1Children.Length.Should().Be(2); - - var file2 = folder1Children[0]; - var file3 = folder1Children[1]; - - file2.Label.Should().Be("file2.txt"); - file2.Open.Should().BeTrue(); - file2.Path.Should().Be(@"folder1\file2.txt"); - file2.RepositoryPath.Should().Be(@"folder1\file2.txt"); - file2.State.Should().Be(CommitState.None); - file2.Target.Should().Be(gitCommitTargets[1]); - - file2.Children.Should().BeEmpty(); - - file3.Label.Should().Be("file3.txt"); - file3.Open.Should().BeTrue(); - file3.Path.Should().Be(@"folder1\file3.txt"); - file3.RepositoryPath.Should().Be(@"folder1\file3.txt"); - file3.State.Should().Be(CommitState.None); - file3.Target.Should().Be(gitCommitTargets[2]); - - file3.Children.Should().BeEmpty(); - - var folder2Children = folder2.Children.ToArray(); - folder2Children.Length.Should().Be(2); - - var file4 = folder2Children[0]; - var file5 = folder2Children[1]; - - file4.Label.Should().Be("file4.txt"); - file4.Open.Should().BeTrue(); - file4.Path.Should().Be(@"folder2\file4.txt"); - file4.RepositoryPath.Should().Be(@"folder2\file4.txt"); - file4.State.Should().Be(CommitState.None); - file4.Target.Should().Be(gitCommitTargets[3]); - - file4.Children.Should().BeEmpty(); - - file5.Label.Should().Be("file5.txt"); - file5.Open.Should().BeTrue(); - file5.Path.Should().Be(@"folder2\file5.txt"); - file5.RepositoryPath.Should().Be(@"folder2\file5.txt"); - file5.State.Should().Be(CommitState.None); - file5.Target.Should().Be(gitCommitTargets[4]); - - file5.Children.Should().BeEmpty(); - - newGitStatusEntries = new List { - gitObjectFactory.CreateGitStatusEntry(@"folder1\file2.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder1\file3.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder3\file6.txt", GitFileStatus.Modified), - gitObjectFactory.CreateGitStatusEntry(@"folder3\file7.txt", GitFileStatus.Modified) - }; - - foldedTreeEntries.Add(folder1.RepositoryPath); - foldedTreeEntries.Add(folder2.RepositoryPath); - - foldedTreeEntries.Count.Should().Be(2); - - treeRoot = TreeBuilder.BuildTreeRoot(newGitStatusEntries, gitStatusEntries, gitCommitTargets, - foldedTreeEntries); - - gitStatusEntries.Count.Should().Be(4); - gitCommitTargets.Count.Should().Be(4); - foldedTreeEntries.Count.Should().Be(1); - } - - - private void InitializeEnvironment(string repositoryPath, string projectPath) - { - var substituteFactory = new SubstituteFactory(); - - var fileSystem = - substituteFactory.CreateFileSystem(new CreateFileSystemOptions { CurrentDirectory = projectPath }); - - NPath.FileSystem = fileSystem; - - environment = substituteFactory.CreateEnvironment(new CreateEnvironmentOptions { - RepositoryPath = repositoryPath, - UnityProjectPath = projectPath.ToNPath(), - Extensionfolder = projectPath.ToNPath().Combine("Assets", "Editor", "GitHub") - }); - - gitObjectFactory = new GitObjectFactory(environment); - } - } -} diff --git a/src/tests/UnitTests/UnitTests.csproj b/src/tests/UnitTests/UnitTests.csproj index f5b4b5ed4..974f55512 100644 --- a/src/tests/UnitTests/UnitTests.csproj +++ b/src/tests/UnitTests/UnitTests.csproj @@ -96,7 +96,6 @@ -