Skip to content

Commit 957ab57

Browse files
authored
Merge pull request #14 from CandyCoded/hotfix/simplify-git-class
[hotfix] Simplified git class
2 parents 4e15a83 + 796ac6e commit 957ab57

File tree

1 file changed

+29
-13
lines changed
  • Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor

1 file changed

+29
-13
lines changed

Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/Git.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information.
22

33
#if UNITY_EDITOR
4-
using System;
54
using System.Collections.Generic;
65
using System.Diagnostics;
7-
using System.Linq;
86
using Debug = UnityEngine.Debug;
97

108
namespace CandyCoded.GitStatus
@@ -77,37 +75,55 @@ public static void CheckoutBranch(string branch)
7775

7876
}
7977

80-
public static string[] AllChanges()
78+
public static string[] ChangedFiles()
8179
{
8280

8381
var process = Process.Start(new ProcessStartInfo
8482
{
8583
FileName = GitPath,
86-
Arguments = "status --short --untracked-files --porcelain",
84+
Arguments = "status --short --untracked-files=no --porcelain",
8785
UseShellExecute = false,
8886
RedirectStandardOutput = true,
8987
RedirectStandardError = true,
9088
CreateNoWindow = true
9189
});
9290

93-
return process?.StandardOutput
94-
.ReadToEnd()
95-
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
96-
.ToArray();
91+
var changes = new List<string>();
9792

98-
}
93+
while (process?.StandardOutput.ReadLine() is string line)
94+
{
9995

100-
public static string[] ChangedFiles()
101-
{
96+
changes.Add(line.Trim().TrimStart('M', ' '));
10297

103-
return AllChanges().Except(UntrackedFiles()).ToArray();
98+
}
99+
100+
return changes.ToArray();
104101

105102
}
106103

107104
public static string[] UntrackedFiles()
108105
{
109106

110-
return AllChanges().Where(file => file.StartsWith("??")).ToArray();
107+
var process = Process.Start(new ProcessStartInfo
108+
{
109+
FileName = GitPath,
110+
Arguments = "ls-files --others --exclude-standard",
111+
UseShellExecute = false,
112+
RedirectStandardOutput = true,
113+
RedirectStandardError = true,
114+
CreateNoWindow = true
115+
});
116+
117+
var changes = new List<string>();
118+
119+
while (process?.StandardOutput.ReadLine() is string line)
120+
{
121+
122+
changes.Add(line.Trim());
123+
124+
}
125+
126+
return changes.ToArray();
111127

112128
}
113129

0 commit comments

Comments
 (0)