Skip to content

Commit ad0bbf3

Browse files
authored
Merge pull request #25 from CandyCoded/hotfix/simplify-process-generation
[hotfix] Simplified process generation.
2 parents 8067544 + f636539 commit ad0bbf3

File tree

1 file changed

+16
-49
lines changed
  • Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor

1 file changed

+16
-49
lines changed

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

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,34 @@ public static class Git
1717
public static string GitPath => "/usr/local/bin/git";
1818
#endif
1919

20-
public static string Branch()
20+
public static Process GenerateProcess(string path, string arguments)
2121
{
2222

23-
var process = Process.Start(new ProcessStartInfo
23+
return Process.Start(new ProcessStartInfo
2424
{
25-
FileName = GitPath,
26-
Arguments = "rev-parse --abbrev-ref HEAD",
25+
FileName = path,
26+
Arguments = arguments,
2727
UseShellExecute = false,
2828
RedirectStandardOutput = true,
2929
RedirectStandardError = true,
3030
CreateNoWindow = true
3131
});
3232

33+
}
34+
35+
public static string Branch()
36+
{
37+
38+
var process = GenerateProcess(GitPath, "rev-parse --abbrev-ref HEAD");
39+
3340
return process?.StandardOutput.ReadLine();
3441

3542
}
3643

3744
public static string[] Branches()
3845
{
3946

40-
var process = Process.Start(new ProcessStartInfo
41-
{
42-
FileName = GitPath,
43-
Arguments = "for-each-ref --format='%(refname:short)' refs/heads",
44-
UseShellExecute = false,
45-
RedirectStandardOutput = true,
46-
RedirectStandardError = true,
47-
CreateNoWindow = true
48-
});
47+
var process = GenerateProcess(GitPath, "for-each-ref --format='%(refname:short)' refs/heads");
4948

5049
var branches = new List<string>();
5150

@@ -63,30 +62,14 @@ public static string[] Branches()
6362
public static void CheckoutBranch(string branch)
6463
{
6564

66-
Process.Start(new ProcessStartInfo
67-
{
68-
FileName = GitPath,
69-
Arguments = $"checkout {branch}",
70-
UseShellExecute = false,
71-
RedirectStandardOutput = true,
72-
RedirectStandardError = true,
73-
CreateNoWindow = true
74-
});
65+
GenerateProcess(GitPath, $"checkout {branch}");
7566

7667
}
7768

7869
public static string[] ChangedFiles()
7970
{
8071

81-
var process = Process.Start(new ProcessStartInfo
82-
{
83-
FileName = GitPath,
84-
Arguments = "status --short --untracked-files=no --porcelain",
85-
UseShellExecute = false,
86-
RedirectStandardOutput = true,
87-
RedirectStandardError = true,
88-
CreateNoWindow = true
89-
});
72+
var process = GenerateProcess(GitPath, "status --short --untracked-files=no --porcelain");
9073

9174
var changes = new List<string>();
9275

@@ -104,15 +87,7 @@ public static string[] ChangedFiles()
10487
public static string[] UntrackedFiles()
10588
{
10689

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-
});
90+
var process = GenerateProcess(GitPath, "ls-files --others --exclude-standard");
11691

11792
var changes = new List<string>();
11893

@@ -130,15 +105,7 @@ public static string[] UntrackedFiles()
130105
public static void DiscardChanges(string path)
131106
{
132107

133-
var process = Process.Start(new ProcessStartInfo
134-
{
135-
FileName = GitPath,
136-
Arguments = $@"checkout ""{path}""",
137-
UseShellExecute = false,
138-
RedirectStandardOutput = true,
139-
RedirectStandardError = true,
140-
CreateNoWindow = true
141-
});
108+
var process = GenerateProcess(GitPath, $@"checkout ""{path}""");
142109
143110
if (process?.StandardError.ReadLine() is string line && line.StartsWith("error: pathspec"))
144111
{

0 commit comments

Comments
 (0)