Skip to content

Commit 859cd70

Browse files
authored
Merge pull request #10 from CandyCoded/feature/window-support
[feat] Windows support
2 parents aa69c0e + e07f8f3 commit 859cd70

File tree

1 file changed

+22
-9
lines changed
  • Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor

1 file changed

+22
-9
lines changed

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#if UNITY_EDITOR
44
using System;
5+
using System.Collections.Generic;
56
using System.Diagnostics;
67
using System.Linq;
78
using Debug = UnityEngine.Debug;
@@ -12,12 +13,18 @@ namespace CandyCoded.GitStatus
1213
public static class Git
1314
{
1415

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+
1522
public static string Branch()
1623
{
1724

1825
var process = Process.Start(new ProcessStartInfo
1926
{
20-
FileName = "/usr/local/bin/git",
27+
FileName = GitPath,
2128
Arguments = "rev-parse --abbrev-ref HEAD",
2229
UseShellExecute = false,
2330
RedirectStandardOutput = true,
@@ -34,18 +41,24 @@ public static string[] Branches()
3441

3542
var process = Process.Start(new ProcessStartInfo
3643
{
37-
FileName = "/usr/local/bin/git",
44+
FileName = GitPath,
3845
Arguments = "for-each-ref --format='%(refname:short)' refs/heads",
3946
UseShellExecute = false,
4047
RedirectStandardOutput = true,
4148
RedirectStandardError = true,
4249
CreateNoWindow = true
4350
});
4451

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();
4962

5063
}
5164

@@ -54,7 +67,7 @@ public static void CheckoutBranch(string branch)
5467

5568
Process.Start(new ProcessStartInfo
5669
{
57-
FileName = "/usr/local/bin/git",
70+
FileName = GitPath,
5871
Arguments = $"checkout {branch}",
5972
UseShellExecute = false,
6073
RedirectStandardOutput = true,
@@ -69,7 +82,7 @@ public static string[] AllChanges()
6982

7083
var process = Process.Start(new ProcessStartInfo
7184
{
72-
FileName = "/usr/local/bin/git",
85+
FileName = GitPath,
7386
Arguments = "status --short --untracked-files --porcelain",
7487
UseShellExecute = false,
7588
RedirectStandardOutput = true,
@@ -103,7 +116,7 @@ public static void DiscardChanges(string path)
103116

104117
var process = Process.Start(new ProcessStartInfo
105118
{
106-
FileName = "/usr/local/bin/git",
119+
FileName = GitPath,
107120
Arguments = $"checkout {path}",
108121
UseShellExecute = false,
109122
RedirectStandardOutput = true,

0 commit comments

Comments
 (0)