@@ -165,6 +165,30 @@ func (s *Service) Init() error {
165165 fullPath := filepath .Join (s .rootDir , file .Name ())
166166 closer := s .gitRepoInitializer (fullPath )
167167 if repo , err := gogit .PlainOpen (fullPath ); err == nil {
168+ indexFile := filepath .Join (fullPath , ".git" , "index" )
169+ indexLockFile := filepath .Join (fullPath , ".git" , "index.lock" )
170+ if _ , err = os .Stat (indexLockFile ); err == nil {
171+ log .Warnf ("Lock file present in git repository %s, removing it" , fullPath )
172+ if err = os .Remove (indexLockFile ); err != nil {
173+ log .Errorf ("Failed to remove lock file %s: %v" , indexLockFile , err )
174+ }
175+ if err = os .Remove (indexFile ); err != nil {
176+ log .Errorf ("Failed to remove index file %s: %v" , indexFile , err )
177+ }
178+
179+ if err == nil {
180+ wt , _ := repo .Worktree ()
181+ headRef , _ := repo .Head ()
182+ err = wt .Reset (& gogit.ResetOptions {
183+ Mode : gogit .MixedReset ,
184+ Commit : headRef .Hash (),
185+ })
186+ }
187+
188+ if err != nil {
189+ log .Errorf ("Failed to reset git repo %s: %v" , fullPath , err )
190+ }
191+ }
168192 if remotes , err := repo .Remotes (); err == nil && len (remotes ) > 0 && len (remotes [0 ].Config ().URLs ) > 0 {
169193 s .gitRepoPaths .Add (git .NormalizeGitURL (remotes [0 ].Config ().URLs [0 ]), fullPath )
170194 }
0 commit comments