2
2
3
3
#if UNITY_EDITOR
4
4
using System ;
5
+ using System . Collections . Generic ;
5
6
using System . Diagnostics ;
6
7
using System . Linq ;
7
8
using Debug = UnityEngine . Debug ;
@@ -12,12 +13,18 @@ namespace CandyCoded.GitStatus
12
13
public static class Git
13
14
{
14
15
16
+ #if UNITY_EDITOR_WIN
17
+ public static string GitPath => "C:\\ Program Files\\ Git\\ cmd\\ git.exe" ;
18
+ #else
19
+ public static string GitPath => "/usr/local/bin/git" ;
20
+ #endif
21
+
15
22
public static string Branch ( )
16
23
{
17
24
18
25
var process = Process . Start ( new ProcessStartInfo
19
26
{
20
- FileName = "/usr/local/bin/git" ,
27
+ FileName = GitPath ,
21
28
Arguments = "rev-parse --abbrev-ref HEAD" ,
22
29
UseShellExecute = false ,
23
30
RedirectStandardOutput = true ,
@@ -34,18 +41,24 @@ public static string[] Branches()
34
41
35
42
var process = Process . Start ( new ProcessStartInfo
36
43
{
37
- FileName = "/usr/local/bin/git" ,
44
+ FileName = GitPath ,
38
45
Arguments = "for-each-ref --format='%(refname:short)' refs/heads" ,
39
46
UseShellExecute = false ,
40
47
RedirectStandardOutput = true ,
41
48
RedirectStandardError = true ,
42
49
CreateNoWindow = true
43
50
} ) ;
44
51
45
- return process ? . StandardOutput
46
- . ReadToEnd ( )
47
- . Split ( new [ ] { Environment . NewLine } , StringSplitOptions . RemoveEmptyEntries )
48
- . ToArray ( ) ;
52
+ var branches = new List < string > ( ) ;
53
+
54
+ while ( process ? . StandardOutput . ReadLine ( ) is string line )
55
+ {
56
+
57
+ branches . Add ( line . Trim ( '\' ' ) ) ;
58
+
59
+ }
60
+
61
+ return branches . ToArray ( ) ;
49
62
50
63
}
51
64
@@ -54,7 +67,7 @@ public static void CheckoutBranch(string branch)
54
67
55
68
Process . Start ( new ProcessStartInfo
56
69
{
57
- FileName = "/usr/local/bin/git" ,
70
+ FileName = GitPath ,
58
71
Arguments = $ "checkout { branch } ",
59
72
UseShellExecute = false ,
60
73
RedirectStandardOutput = true ,
@@ -69,7 +82,7 @@ public static string[] AllChanges()
69
82
70
83
var process = Process . Start ( new ProcessStartInfo
71
84
{
72
- FileName = "/usr/local/bin/git" ,
85
+ FileName = GitPath ,
73
86
Arguments = "status --short --untracked-files --porcelain" ,
74
87
UseShellExecute = false ,
75
88
RedirectStandardOutput = true ,
@@ -103,7 +116,7 @@ public static void DiscardChanges(string path)
103
116
104
117
var process = Process . Start ( new ProcessStartInfo
105
118
{
106
- FileName = "/usr/local/bin/git" ,
119
+ FileName = GitPath ,
107
120
Arguments = $ "checkout { path } ",
108
121
UseShellExecute = false ,
109
122
RedirectStandardOutput = true ,
0 commit comments