diff --git a/gitops/prer/create_gitops_prs.go b/gitops/prer/create_gitops_prs.go index ee8e0320..adc269ff 100644 --- a/gitops/prer/create_gitops_prs.go +++ b/gitops/prer/create_gitops_prs.go @@ -121,14 +121,12 @@ func getGitStatusDict(workdir *git.Repo, branchName string) map[string]interface return ctx } -func stampFile(fullPath string, workdir *git.Repo, branchName string) { +func stampFile(fullPath string, ctx map[string]interface{}) { template, err := os.ReadFile(fullPath) if err != nil { log.Fatal(err) } - ctx := getGitStatusDict(workdir, branchName) - outf, err := os.OpenFile(fullPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { log.Fatal(err) @@ -228,13 +226,16 @@ func main() { } if *stamp { changedFiles := workdir.GetChangedFiles() - for _, filePath := range changedFiles { - fullPath := gitopsdir + "/" + filePath - if digester.VerifyDigest(fullPath) { - workdir.RestoreFile(fullPath) - } else { - digester.SaveDigest(fullPath) - stampFile(fullPath, workdir, *branchName) + if len(changedFiles) > 0 { + ctx := getGitStatusDict(workdir, *branchName) + for _, filePath := range changedFiles { + fullPath := gitopsdir + "/" + filePath + if digester.VerifyDigest(fullPath) { + workdir.RestoreFile(fullPath) + } else { + digester.SaveDigest(fullPath) + stampFile(fullPath, ctx) + } } } }