Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 534d867

Browse files
Adding several unit tests
1 parent 698a603 commit 534d867

File tree

5 files changed

+327
-48
lines changed

5 files changed

+327
-48
lines changed

src/GitHub.Api/Git/GitObjectFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public GitObjectFactory(IEnvironment environment)
1414

1515
public GitStatusEntry CreateGitStatusEntry(string path, GitFileStatus status, string originalPath = null, bool staged = false)
1616
{
17-
var npath = new NPath(path).MakeAbsolute();
18-
var relativePath = npath.RelativeTo(environment.RepositoryPath);
19-
var projectPath = npath.RelativeTo(environment.UnityProjectPath);
17+
var absolutePath = new NPath(path).MakeAbsolute();
18+
var relativePath = absolutePath.RelativeTo(environment.RepositoryPath);
19+
var projectPath = absolutePath.RelativeTo(environment.UnityProjectPath);
2020

21-
return new GitStatusEntry(relativePath, npath, projectPath, status, originalPath?.ToNPath(), staged);
21+
return new GitStatusEntry(relativePath, absolutePath, projectPath, status, originalPath?.ToNPath(), staged);
2222
}
2323

2424
public GitLock CreateGitLock(string path, string user, int id)

src/GitHub.Api/UI/TreeBuilder.cs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using System.Linq;
44
using GitHub.Unity;
55

6-
static internal class TreeBuilder
6+
static class TreeBuilder
77
{
8-
internal static void BuildTree(FileTreeNode parent, FileTreeNode node, List<string> foldedTreeEntries1, Action<FileTreeNode> stateChangeCallback1)
8+
internal static void BuildChildNode(FileTreeNode parent, FileTreeNode node, List<string> foldedTreeEntries1, Action<FileTreeNode> stateChangeCallback1)
99
{
1010
if (String.IsNullOrEmpty(node.Label))
1111
{
@@ -32,7 +32,7 @@ internal static void BuildTree(FileTreeNode parent, FileTreeNode node, List<stri
3232
if (child.Label.Equals(root))
3333
{
3434
found = true;
35-
BuildTree(child, node, foldedTreeEntries1, stateChangeCallback1);
35+
BuildChildNode(child, node, foldedTreeEntries1, stateChangeCallback1);
3636
break;
3737
}
3838
}
@@ -41,7 +41,7 @@ internal static void BuildTree(FileTreeNode parent, FileTreeNode node, List<stri
4141
if (!found)
4242
{
4343
var p = parent.RepositoryPath.ToNPath().Combine(root);
44-
BuildTree(parent.Add(new FileTreeNode(root, stateChangeCallback1) { RepositoryPath = p }), node, foldedTreeEntries1, stateChangeCallback1);
44+
BuildChildNode(parent.Add(new FileTreeNode(root, stateChangeCallback1) { RepositoryPath = p }), node, foldedTreeEntries1, stateChangeCallback1);
4545
}
4646
}
4747
else if (nodePath.ExtensionWithDot == ".meta")
@@ -54,7 +54,7 @@ internal static void BuildTree(FileTreeNode parent, FileTreeNode node, List<stri
5454
if (child.Label.Equals(nodePath.Parent.Combine(nodePath.FileNameWithoutExtension)))
5555
{
5656
found = true;
57-
BuildTree(child, node, foldedTreeEntries1, stateChangeCallback1);
57+
BuildChildNode(child, node, foldedTreeEntries1, stateChangeCallback1);
5858
break;
5959
}
6060
}
@@ -70,35 +70,10 @@ internal static void BuildTree(FileTreeNode parent, FileTreeNode node, List<stri
7070
}
7171
}
7272

73-
internal static FileTreeNode BuildTree3(List<GitStatusEntry> gitStatusEntries, Action<FileTreeNode> stateChangeCallback1, List<GitCommitTarget> entryCommitTargets, List<string> foldedTreeEntries1)
73+
internal static FileTreeNode BuildTreeRoot(IList<GitStatusEntry> newEntries, List<GitStatusEntry> gitStatusEntries, List<GitCommitTarget> gitCommitTargets, List<string> foldedTreeEntries, Action<FileTreeNode> stateChangeCallback)
7474
{
75-
// TODO: Filter .meta files - consider adding them as children of the asset or folder they're supporting
76-
// 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
77-
// Build tree structure
78-
79-
var tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(gitStatusEntries.Select(e => e.Path)), stateChangeCallback1);
80-
tree.RepositoryPath = tree.Path;
81-
82-
for (var index = 0; index < gitStatusEntries.Count; index++)
83-
{
84-
GitStatusEntry gitStatusEntry = gitStatusEntries[index];
85-
var entryPath = gitStatusEntry.Path.ToNPath();
86-
if (entryPath.IsChildOf(tree.Path)) entryPath = entryPath.RelativeTo(tree.Path.ToNPath());
87-
88-
var node = new FileTreeNode(entryPath, stateChangeCallback1) { Target = entryCommitTargets[index] };
89-
if (!String.IsNullOrEmpty(gitStatusEntry.ProjectPath))
90-
{
91-
//node.Icon = AssetDatabase.GetCachedIcon(gitStatusEntry.ProjectPath);
92-
}
93-
94-
TreeBuilder.BuildTree(tree, node, foldedTreeEntries1, stateChangeCallback1);
95-
}
96-
97-
return tree;
98-
}
75+
Guard.ArgumentNotNullOrEmpty(newEntries, "newEntries");
9976

100-
internal static FileTreeNode BuildTree4(IList<GitStatusEntry> newEntries, List<GitStatusEntry> gitStatusEntries, List<GitCommitTarget> gitCommitTargets, List<string> foldedTreeEntries1, Action<FileTreeNode> stateChangeCallback1)
101-
{
10277
// Remove what got nuked
10378
for (var index = 0; index < gitStatusEntries.Count;)
10479
{
@@ -114,11 +89,11 @@ internal static FileTreeNode BuildTree4(IList<GitStatusEntry> newEntries, List<G
11489
}
11590

11691
// Remove folding state of nuked items
117-
for (var index = 0; index < foldedTreeEntries1.Count;)
92+
for (var index = 0; index < foldedTreeEntries.Count;)
11893
{
119-
if (!newEntries.Any(e => e.Path.IndexOf(foldedTreeEntries1[index]) == 0))
94+
if (!newEntries.Any(e => e.Path.IndexOf(foldedTreeEntries[index]) == 0))
12095
{
121-
foldedTreeEntries1.RemoveAt(index);
96+
foldedTreeEntries.RemoveAt(index);
12297
}
12398
else
12499
{
@@ -137,6 +112,28 @@ internal static FileTreeNode BuildTree4(IList<GitStatusEntry> newEntries, List<G
137112
}
138113
}
139114

140-
return TreeBuilder.BuildTree3(gitStatusEntries, stateChangeCallback1, gitCommitTargets, foldedTreeEntries1);
115+
// TODO: Filter .meta files - consider adding them as children of the asset or folder they're supporting
116+
// 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
117+
// Build tree structure
118+
119+
var tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(gitStatusEntries.Select(e => e.Path)), stateChangeCallback);
120+
tree.RepositoryPath = tree.Path;
121+
122+
for (var index1 = 0; index1 < gitStatusEntries.Count; index1++)
123+
{
124+
GitStatusEntry gitStatusEntry = gitStatusEntries[index1];
125+
var entryPath = gitStatusEntry.Path.ToNPath();
126+
if (entryPath.IsChildOf(tree.Path)) entryPath = entryPath.RelativeTo(tree.Path.ToNPath());
127+
128+
var node = new FileTreeNode(entryPath, stateChangeCallback) { Target = gitCommitTargets[index1] };
129+
if (!String.IsNullOrEmpty(gitStatusEntry.ProjectPath))
130+
{
131+
//node.Icon = AssetDatabase.GetCachedIcon(gitStatusEntry.ProjectPath);
132+
}
133+
134+
TreeBuilder.BuildChildNode(tree, node, foldedTreeEntries, stateChangeCallback);
135+
}
136+
137+
return tree;
141138
}
142139
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesetTreeView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void UpdateEntries(IList<GitStatusEntry> newEntries)
109109
return;
110110
}
111111

112-
tree = TreeBuilder.BuildTree4(newEntries, entries, entryCommitTargets, foldedTreeEntries, stateChangeCallback);
112+
tree = TreeBuilder.BuildTreeRoot(newEntries, entries, entryCommitTargets, foldedTreeEntries, stateChangeCallback);
113113

114114
OnCommitTreeChange();
115115
}

src/tests/UnitTests/SetUpFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void SetUp()
1212
{
1313
Logging.TracingEnabled = true;
1414

15-
Logging.LogAdapter = new MultipleLogAdapter(new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-unit-tests.log"));
15+
Logging.LogAdapter = new MultipleLogAdapter(new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-unit-tests.log"), new ConsoleLogAdapter());
1616
}
1717
}
1818
}

0 commit comments

Comments
 (0)