@@ -10,12 +10,10 @@ namespace Open_Rails_Code_Bot.Git
1010 public class Project
1111 {
1212 string GitPath ;
13- bool Verbose ;
1413
15- public Project ( string gitPath , bool verbose )
14+ public Project ( string gitPath )
1615 {
1716 GitPath = gitPath ;
18- Verbose = verbose ;
1917 }
2018
2119 public void Init ( string repository )
@@ -56,7 +54,7 @@ public void Clean()
5654
5755 public void Merge ( string reference )
5856 {
59- RunCommand ( $ "merge --no-edit --no-ff { reference } ") ;
57+ RunCommand ( $ "merge --quiet -- no-edit --no-ff { reference } ") ;
6058 }
6159
6260 public void Push ( string reference )
@@ -132,40 +130,44 @@ public void SetBranchRef(string branch, string reference)
132130
133131 void RunCommand ( string command )
134132 {
135- foreach ( var line in GetCommandOutput ( command ) )
133+ foreach ( var line in GetCommandOutput ( command , true ) )
136134 {
137135 }
138136 }
139137
140- IEnumerable < string > GetCommandOutput ( string command )
138+ IEnumerable < string > GetCommandOutput ( string command , bool printOutput = false )
141139 {
142140 var args = $ "--no-pager { command } ";
143- if ( Verbose )
141+ if ( printOutput )
142+ Console . WriteLine ( $ " > git { args } ") ;
143+ var git = new Process ( ) ;
144+ git . StartInfo . WorkingDirectory = GitPath ;
145+ git . StartInfo . FileName = "git" ;
146+ git . StartInfo . Arguments = args ;
147+ git . StartInfo . UseShellExecute = false ;
148+ git . StartInfo . RedirectStandardOutput = true ;
149+ git . StartInfo . RedirectStandardError = true ;
150+ git . StartInfo . StandardOutputEncoding = Encoding . UTF8 ;
151+ git . StartInfo . StandardErrorEncoding = Encoding . UTF8 ;
152+ git . ErrorDataReceived += ( sender , e ) =>
144153 {
145- Console . WriteLine ( "```shell" ) ;
146- Console . WriteLine ( $ "{ GitPath } > git { args } ") ;
147- }
148- var git = Process . Start ( new ProcessStartInfo ( )
149- {
150- WorkingDirectory = GitPath ,
151- FileName = "git" ,
152- Arguments = args ,
153- StandardOutputEncoding = Encoding . UTF8 ,
154- RedirectStandardOutput = true ,
155- } ) ;
154+ if ( e . Data ? . Length > 0 )
155+ Console . Error . WriteLine ( $ " ! { e . Data } ") ;
156+ } ;
157+ git . Start ( ) ;
158+ git . BeginErrorReadLine ( ) ;
156159 while ( ! git . StandardOutput . EndOfStream )
157160 {
158- yield return git . StandardOutput . ReadLine ( ) ;
161+ if ( printOutput )
162+ Console . WriteLine ( $ " < { git . StandardOutput . ReadLine ( ) } ") ;
163+ else
164+ yield return git . StandardOutput . ReadLine ( ) ;
159165 }
160166 git . WaitForExit ( ) ;
161167 if ( git . ExitCode != 0 )
162168 {
163169 throw new ApplicationException ( $ "git { command } failed: { git . ExitCode } ") ;
164170 }
165- if ( Verbose )
166- {
167- Console . WriteLine ( "```" ) ;
168- }
169171 }
170172 }
171173}
0 commit comments