66 "fmt"
77 "os"
88 "os/exec"
9+ "path/filepath"
910 "strconv"
1011 "strings"
1112 "syscall"
@@ -183,13 +184,29 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
183184 args := strings .Join (cmd .Args , " " )
184185 logCtx .WithFields (logrus.Fields {"dir" : cmd .Dir }).Info (redactor (args ))
185186
187+ // Helper: debug whether HEAD.lock exists under the current working directory
188+ logHeadLockStatus := func (where string ) {
189+ if cmd .Dir == "" {
190+ return
191+ }
192+ lockPath := filepath .Join (cmd .Dir , ".git" , "HEAD.lock" )
193+ _ , statErr := os .Stat (lockPath )
194+ exists := statErr == nil
195+ logCtx .WithFields (logrus.Fields {
196+ "headLockPath" : lockPath ,
197+ "headLockExists" : exists ,
198+ "where" : where ,
199+ }).Info ("HEAD.lock status " + execId )
200+ }
201+
186202 var stdout bytes.Buffer
187203 var stderr bytes.Buffer
188204 cmd .Stdout = & stdout
189205 cmd .Stderr = & stderr
190206
191207 start := time .Now ()
192208 err = cmd .Start ()
209+ logCtx .Info ("*************************************** EXEC COMMAND STARTED *************************************** " + execId )
193210 if err != nil {
194211 return "" , err
195212 }
@@ -228,13 +245,16 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
228245 select {
229246 // noinspection ALL
230247 case <- timoutCh :
248+ logCtx .Info ("*************************************** EXEC TIMEOUT HAPPENED *************************************** " + execId )
231249 // send timeout signal
232250 _ = cmd .Process .Signal (timeoutBehavior .Signal )
233251 // wait on timeout signal and fallback to fatal timeout signal
234252 if timeoutBehavior .ShouldWait {
253+ logCtx .Info ("*************************************** EXEC WAIT HAPPENED *************************************** " + execId )
235254 select {
236255 case <- done :
237256 case <- fatalTimeoutCh :
257+ logCtx .Info ("*************************************** EXEC FATAL TIMEOUT HAPPENED *************************************** " + execId )
238258 // upgrades to SIGKILL if cmd does not respect SIGTERM
239259 _ = cmd .Process .Signal (fatalTimeoutBehaviour )
240260 // now original cmd should exit immediately after SIGKILL
@@ -245,6 +265,7 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
245265 output += stderr .String ()
246266 }
247267 logCtx .WithFields (logrus.Fields {"duration" : time .Since (start )}).Debug (redactor (output ))
268+ logHeadLockStatus ("fatal-timeout" )
248269 err = newCmdError (redactor (args ), fmt .Errorf ("fatal timeout after %v" , timeout + fatalTimeout ), "" )
249270 logCtx .Error (err .Error ())
250271 return strings .TrimSuffix (output , "\n " ), err
@@ -256,11 +277,14 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
256277 output += stderr .String ()
257278 }
258279 logCtx .WithFields (logrus.Fields {"duration" : time .Since (start )}).Debug (redactor (output ))
280+ logHeadLockStatus ("timeout" )
259281 err = newCmdError (redactor (args ), fmt .Errorf ("timeout after %v" , timeout ), "" )
260282 logCtx .Error (err .Error ())
261283 return strings .TrimSuffix (output , "\n " ), err
262284 case err := <- done :
285+ logCtx .Info ("*************************************** FINISHED ON TIME *************************************** " + execId )
263286 if err != nil {
287+ logCtx .Error ("*************************************** FINISHED ON TIME EXEC FAILED *************************************** " + execId )
264288 output := stdout .String ()
265289 if opts .CaptureStderr {
266290 output += stderr .String ()
@@ -270,6 +294,7 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
270294 if ! opts .SkipErrorLogging {
271295 logCtx .Error (err .Error ())
272296 }
297+ logHeadLockStatus ("done-error" )
273298 return strings .TrimSuffix (output , "\n " ), err
274299 }
275300 }
@@ -278,6 +303,7 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
278303 output += stderr .String ()
279304 }
280305 logCtx .WithFields (logrus.Fields {"duration" : time .Since (start )}).Debug (redactor (output ))
306+ logHeadLockStatus ("done-success" )
281307
282308 return strings .TrimSuffix (output , "\n " ), nil
283309}
0 commit comments