@@ -17,35 +17,34 @@ public static class Git
17
17
public static string GitPath => "/usr/local/bin/git" ;
18
18
#endif
19
19
20
- public static string Branch ( )
20
+ public static Process GenerateProcess ( string path , string arguments )
21
21
{
22
22
23
- var process = Process . Start ( new ProcessStartInfo
23
+ return Process . Start ( new ProcessStartInfo
24
24
{
25
- FileName = GitPath ,
26
- Arguments = "rev-parse --abbrev-ref HEAD" ,
25
+ FileName = path ,
26
+ Arguments = arguments ,
27
27
UseShellExecute = false ,
28
28
RedirectStandardOutput = true ,
29
29
RedirectStandardError = true ,
30
30
CreateNoWindow = true
31
31
} ) ;
32
32
33
+ }
34
+
35
+ public static string Branch ( )
36
+ {
37
+
38
+ var process = GenerateProcess ( GitPath , "rev-parse --abbrev-ref HEAD" ) ;
39
+
33
40
return process ? . StandardOutput . ReadLine ( ) ;
34
41
35
42
}
36
43
37
44
public static string [ ] Branches ( )
38
45
{
39
46
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" ) ;
49
48
50
49
var branches = new List < string > ( ) ;
51
50
@@ -63,30 +62,14 @@ public static string[] Branches()
63
62
public static void CheckoutBranch ( string branch )
64
63
{
65
64
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 } ") ;
75
66
76
67
}
77
68
78
69
public static string [ ] ChangedFiles ( )
79
70
{
80
71
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" ) ;
90
73
91
74
var changes = new List < string > ( ) ;
92
75
@@ -104,15 +87,7 @@ public static string[] ChangedFiles()
104
87
public static string [ ] UntrackedFiles ( )
105
88
{
106
89
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" ) ;
116
91
117
92
var changes = new List < string > ( ) ;
118
93
@@ -130,15 +105,7 @@ public static string[] UntrackedFiles()
130
105
public static void DiscardChanges ( string path )
131
106
{
132
107
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 } """);
142
109
143
110
if (process?.StandardError.ReadLine() is string line && line.StartsWith(" error: pathspec") )
144
111
{
0 commit comments