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

Commit c75c9a7

Browse files
Merge branch 'master' into fixes/reduce-auth-scope
2 parents 2060b8f + f5c3e47 commit c75c9a7

File tree

10 files changed

+83
-22
lines changed

10 files changed

+83
-22
lines changed

src/GitHub.Api/Git/GitStatusEntry.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public struct GitStatusEntry
1414
public GitFileStatus status;
1515
public bool staged;
1616

17-
public GitStatusEntry(string path, string fullPath, string projectPath,
18-
GitFileStatus status,
17+
public GitStatusEntry(string path, string fullPath, string projectPath, GitFileStatus status,
1918
string originalPath = null, bool staged = false)
2019
{
2120
Guard.ArgumentNotNullOrWhiteSpace(path, "path");

src/GitHub.Api/OutputProcessors/StatusOutputProcessor.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private void ReturnStatus()
191191
return;
192192

193193
gitStatus.Entries = gitStatus.Entries
194-
.OrderBy(entry => entry.Path)
194+
.OrderBy(entry => entry.Path, StatusOutputPathComparer.Instance)
195195
.ToList();
196196

197197
RaiseOnEntry(gitStatus);
@@ -214,5 +214,32 @@ private void HandleUnexpected(string line)
214214
{
215215
Logger.Error("Unexpected Input:\"{0}\"", line);
216216
}
217+
218+
class StatusOutputPathComparer : IComparer<string>
219+
{
220+
internal static StatusOutputPathComparer Instance => new StatusOutputPathComparer();
221+
222+
public int Compare(string x, string y)
223+
{
224+
Guard.ArgumentNotNull(x, nameof(x));
225+
Guard.ArgumentNotNull(y, nameof(y));
226+
227+
var meta = ".meta";
228+
var xHasMeta = x.EndsWith(meta);
229+
var yHasMeta = y.EndsWith(meta);
230+
231+
if(!xHasMeta && !yHasMeta) return StringComparer.InvariantCulture.Compare(x, y);
232+
233+
var xPure = xHasMeta ? x.Substring(0, x.Length - meta.Length) : x;
234+
var yPure = yHasMeta ? y.Substring(0, y.Length - meta.Length) : y;
235+
236+
if (xHasMeta)
237+
{
238+
return xPure.Equals(y) ? 1 : StringComparer.InvariantCulture.Compare(xPure, yPure);
239+
}
240+
241+
return yPure.Equals(x) ? -1 : StringComparer.InvariantCulture.Compare(xPure, yPure);
242+
}
243+
}
217244
}
218245
}

src/GitHub.Api/UI/TreeBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Load(IEnumerable<TData> treeDatas)
5454
TNode lastAddedNode = null;
5555

5656
Clear();
57-
AddNode(Title, Title, -1 + displayRootLevel, true, false, false, false, isSelected, false, null, false);
57+
AddNode(Title, Title, -1 + displayRootLevel, true, false, false, false, isSelected, false, null);
5858

5959
foreach (var treeData in treeDatas)
6060
{
@@ -123,8 +123,7 @@ public void Load(IEnumerable<TData> treeDatas)
123123

124124
isSelected = selectedNodePath != null && nodePath == selectedNodePath;
125125

126-
lastAddedNode = AddNode(nodePath, label, level + displayRootLevel + (parentIsPromoted ? 1 : 0), isFolder, isActive, nodeIsHidden,
127-
nodeIsCollapsed, isSelected, isChecked, treeNodeTreeData, false);
126+
lastAddedNode = AddNode(nodePath, label, level + displayRootLevel + (parentIsPromoted ? 1 : 0), isFolder, isActive, nodeIsHidden, nodeIsCollapsed, isSelected, isChecked, treeNodeTreeData);
128127
}
129128
}
130129
}
@@ -204,9 +203,9 @@ public void SetCheckStateOnAll(bool isChecked)
204203
}
205204
}
206205

207-
protected TNode AddNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isSelected, bool isChecked, TData? treeData, bool isContainer)
206+
protected TNode AddNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isSelected, bool isChecked, TData? treeData)
208207
{
209-
var node = CreateTreeNode(path, label, level, isFolder, isActive, isHidden, isCollapsed, isChecked, treeData, isContainer);
208+
var node = CreateTreeNode(path, label, level, isFolder, isActive, isHidden, isCollapsed, isChecked, treeData);
210209

211210
SetNodeIcon(node);
212211
Nodes.Add(node);
@@ -407,7 +406,8 @@ private void ToggleParentFoldersChecked(int idx, TNode node, bool isChecked)
407406
protected abstract IEnumerable<string> GetCollapsedFolders();
408407
protected abstract void RemoveCheckedNode(TNode node);
409408
protected abstract void AddCheckedNode(TNode node);
410-
protected abstract TNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, TData? treeData, bool isContainer);
409+
protected abstract TNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, TData? treeData);
410+
411411
protected abstract void SetNodeIcon(TNode node);
412412

413413
public string SelectedNodePath => SelectedNode?.Path;

src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@
104104
<Compile Include="UI\Subview.cs" />
105105
<Compile Include="UI\Window.cs" />
106106
</ItemGroup>
107-
<Choose>
108-
<When Condition="$(Buildtype) == 'Internal'" />
109-
</Choose>
110107
<ItemGroup>
111108
<ProjectReference Include="..\..\..\..\GitHub.Api\GitHub.Api.csproj">
112109
<Project>{b389adaf-62cc-486e-85b4-2d8b078df763}</Project>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected Texture GetNodeIconBadge(ChangesTreeNode node)
186186
return Styles.GetFileStatusIcon(gitFileStatus, node.IsLocked);
187187
}
188188

189-
protected override ChangesTreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, GitStatusEntryTreeData? treeData, bool isContainer)
189+
protected override ChangesTreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, GitStatusEntryTreeData? treeData)
190190
{
191191
var gitStatusEntry = GitStatusEntry.Default;
192192
var isLocked = false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private static void ContextMenu_Lock()
119119
RunLockUnlock(IsObjectUnlocked, CreateLockObjectTask, Localization.RequestLockActionTitle, "Failed to lock: no permissions");
120120
}
121121

122-
[MenuItem(AssetsMenuReleaseLockForced, false, 10001)]
122+
[MenuItem(AssetsMenuReleaseLock, false, 10001)]
123123
private static void ContextMenu_Unlock()
124124
{
125125
RunLockUnlock(IsObjectLocked, x => CreateUnlockObjectTask(x, false), Localization.ReleaseLockActionTitle, "Failed to unlock: no permissions");

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,13 @@ protected Texture GetNodeIcon(TreeNode node)
660660
return nodeIcon;
661661
}
662662

663-
protected override TreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, GitBranchTreeData? treeData, bool isContainer)
663+
protected override TreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, GitBranchTreeData? treeData)
664664
{
665665
var node = new TreeNode {
666666
Path = path,
667667
Label = label,
668668
Level = level,
669669
IsFolder = isFolder,
670-
IsContainer = isContainer,
671670
IsActive = isActive,
672671
IsHidden = isHidden,
673672
IsCollapsed = isCollapsed,

src/tests/IntegrationTests/IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<Compile Include="Git\GitClientTests.cs" />
7878
<Compile Include="IntegrationTestEnvironment.cs" />
7979
<Compile Include="Installer\GitInstallerTests.cs" />
80-
<Compile Include="Metrics\MetricsTests.cs" />
80+
<Compile Condition="$(Buildtype) == 'Internal'" Include="Metrics\MetricsTests.cs" />
8181
<Compile Include="ProcessManagerExtensions.cs" />
8282
<Compile Include="Process\ProcessManagerIntegrationTests.cs" />
8383
<Compile Include="Properties\AssemblyInfo.cs" />

src/tests/UnitTests/IO/StatusOutputProcessorTests.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,46 @@ public void ShouldParseCleanWorkingTreeTracked()
245245
});
246246
}
247247

248+
[Test]
249+
public void ShouldSortOutputCorrectly()
250+
{
251+
var output = new[]
252+
{
253+
"## master",
254+
"?? Assets/Assets.Test.dll.meta",
255+
"?? Assets/Assets.Test.dll",
256+
"?? Plugins/GitHub.Unity.dll",
257+
"?? Plugins/GitHub.Unity.dll.mdb",
258+
"?? Plugins/GitHub.Unity.dll.mdb.meta",
259+
"?? Plugins/GitHub.Unity2.dll",
260+
"?? Plugins/GitHub.Unity2.dll.mdb",
261+
"?? Plugins/GitHub.Unity2.dll.mdb.meta",
262+
"?? Plugins/GitHub.Unity2.dll.meta",
263+
"?? Plugins/GitHub.Unity.dll.meta",
264+
"?? blah.txt",
265+
null
266+
};
267+
268+
AssertProcessOutput(output, new GitStatus
269+
{
270+
LocalBranch = "master",
271+
Entries = new List<GitStatusEntry>
272+
{
273+
new GitStatusEntry(@"Assets/Assets.Test.dll", TestRootPath + @"\Assets/Assets.Test.dll", null, GitFileStatus.Untracked),
274+
new GitStatusEntry(@"Assets/Assets.Test.dll.meta", TestRootPath + @"\Assets/Assets.Test.dll.meta", null, GitFileStatus.Untracked),
275+
new GitStatusEntry(@"blah.txt", TestRootPath + @"\blah.txt", null, GitFileStatus.Untracked),
276+
new GitStatusEntry(@"Plugins/GitHub.Unity.dll", TestRootPath + @"\Plugins/GitHub.Unity.dll", null, GitFileStatus.Untracked),
277+
new GitStatusEntry(@"Plugins/GitHub.Unity.dll.meta", TestRootPath + @"\Plugins/GitHub.Unity.dll.meta", null, GitFileStatus.Untracked),
278+
new GitStatusEntry(@"Plugins/GitHub.Unity.dll.mdb", TestRootPath + @"\Plugins/GitHub.Unity.dll.mdb", null, GitFileStatus.Untracked),
279+
new GitStatusEntry(@"Plugins/GitHub.Unity.dll.mdb.meta", TestRootPath + @"\Plugins/GitHub.Unity.dll.mdb.meta", null, GitFileStatus.Untracked),
280+
new GitStatusEntry(@"Plugins/GitHub.Unity2.dll", TestRootPath + @"\Plugins/GitHub.Unity2.dll", null, GitFileStatus.Untracked),
281+
new GitStatusEntry(@"Plugins/GitHub.Unity2.dll.meta", TestRootPath + @"\Plugins/GitHub.Unity2.dll.meta", null, GitFileStatus.Untracked),
282+
new GitStatusEntry(@"Plugins/GitHub.Unity2.dll.mdb", TestRootPath + @"\Plugins/GitHub.Unity2.dll.mdb", null, GitFileStatus.Untracked),
283+
new GitStatusEntry(@"Plugins/GitHub.Unity2.dll.mdb.meta", TestRootPath + @"\Plugins/GitHub.Unity2.dll.mdb.meta", null, GitFileStatus.Untracked),
284+
}
285+
});
286+
}
287+
248288
private void AssertProcessOutput(IEnumerable<string> lines, GitStatus expected)
249289
{
250290
var gitObjectFactory = SubstituteFactory.CreateGitObjectFactory(TestRootPath);
@@ -262,4 +302,4 @@ private void AssertProcessOutput(IEnumerable<string> lines, GitStatus expected)
262302
result.Value.AssertEqual(expected);
263303
}
264304
}
265-
}
305+
}

src/tests/UnitTests/UI/TreeBaseTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,13 @@ protected override void AddCheckedNode(TestTreeNode node)
113113
TestTreeListener.AddCheckedNode(node);
114114
}
115115

116-
protected override TestTreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, TestTreeData? treeData, bool isContainer)
116+
protected override TestTreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, TestTreeData? treeData)
117117
{
118118
if (traceLogging)
119119
{
120120
Logger.Trace(
121-
"CreateTreeNode(path: {0}, label: {1}, level: {2}, isFolder: {3}, " +
122-
"isActive: {4}, isHidden: {5}, isCollapsed: {6}, isChecked: {7}, treeData: {8})", path, label,
123-
level, isFolder, isActive, isHidden, isCollapsed, isChecked, treeData?.ToString() ?? "[NULL]");
121+
"CreateTreeNode(path: {0}, label: {1}, level: {2}, isFolder: {3}, isActive: {4}, isHidden: {5}, isCollapsed: {6}, isChecked: {7}, treeData: {8})",
122+
path, label, level, isFolder, isActive, isHidden, isCollapsed, isChecked, treeData?.ToString() ?? "[NULL]");
124123
}
125124

126125
TestTreeListener.CreateTreeNode(path, label, level, isFolder, isActive, isHidden, isCollapsed, isChecked,

0 commit comments

Comments
 (0)