@@ -264,6 +264,8 @@ func (impl ChartTemplateServiceImpl) pushChartToGitRepo(gitOpsRepoName, referenc
264264 }
265265
266266 dir := filepath .Join (clonedDir , referenceTemplate , version )
267+ pushChartToGit := true
268+
267269 //if chart already exists don't overrides it by reference template
268270 if _ , err := os .Stat (dir ); os .IsNotExist (err ) {
269271 err = os .MkdirAll (dir , os .ModePerm )
@@ -287,30 +289,37 @@ func (impl ChartTemplateServiceImpl) pushChartToGitRepo(gitOpsRepoName, referenc
287289 impl .logger .Errorw ("error copying content in auto-healing" , "err" , err )
288290 return err
289291 }
292+ } else {
293+ // chart exists on git, hence not performing first commit
294+ pushChartToGit = false
290295 }
291296 }
292297
293- userEmailId , userName := impl .GetUserEmailIdAndNameForGitOpsCommit (userId )
294- commit , err := impl .gitFactory .gitService .CommitAndPushAllChanges (clonedDir , "first commit" , userName , userEmailId )
295- if err != nil {
296- impl .logger .Errorw ("error in pushing git" , "err" , err )
297- impl .logger .Warn ("re-trying, taking pull and then push again" )
298- err = impl .GitPull (clonedDir , repoUrl , gitOpsRepoName )
299- if err != nil {
300- return err
301- }
302- err = dirCopy .Copy (tempReferenceTemplateDir , dir )
303- if err != nil {
304- impl .logger .Errorw ("error copying dir" , "err" , err )
305- return err
306- }
307- commit , err = impl .gitFactory .gitService .CommitAndPushAllChanges (clonedDir , "first commit" , userName , userEmailId )
298+ // if push needed, then only push
299+ if pushChartToGit {
300+ userEmailId , userName := impl .GetUserEmailIdAndNameForGitOpsCommit (userId )
301+ commit , err := impl .gitFactory .gitService .CommitAndPushAllChanges (clonedDir , "first commit" , userName , userEmailId )
308302 if err != nil {
309303 impl .logger .Errorw ("error in pushing git" , "err" , err )
310- return err
304+ impl .logger .Warn ("re-trying, taking pull and then push again" )
305+ err = impl .GitPull (clonedDir , repoUrl , gitOpsRepoName )
306+ if err != nil {
307+ return err
308+ }
309+ err = dirCopy .Copy (tempReferenceTemplateDir , dir )
310+ if err != nil {
311+ impl .logger .Errorw ("error copying dir" , "err" , err )
312+ return err
313+ }
314+ commit , err = impl .gitFactory .gitService .CommitAndPushAllChanges (clonedDir , "first commit" , userName , userEmailId )
315+ if err != nil {
316+ impl .logger .Errorw ("error in pushing git" , "err" , err )
317+ return err
318+ }
311319 }
320+ impl .logger .Debugw ("template committed" , "url" , repoUrl , "commit" , commit )
312321 }
313- impl . logger . Debugw ( "template committed" , "url" , repoUrl , "commit" , commit )
322+
314323 defer impl .CleanDir (clonedDir )
315324 return nil
316325}
0 commit comments