refactor: isolate expensive IsDirty() call
Some checks failed
continuous-integration/drone/push Build is failing

See #689
This commit is contained in:
2025-10-03 20:35:09 +02:00
parent 2460dd9438
commit d0ccb805c6
4 changed files with 14 additions and 14 deletions

View File

@ -644,6 +644,9 @@ func (a App) WriteRecipeVersion(version string, dryRun bool) error {
scanner = bufio.NewScanner(file)
)
// NOTE(d1): don't care at this point if there is a git failure
isDirty, _ := a.Recipe.IsDirty()
for scanner.Scan() {
line := scanner.Text()
if !strings.HasPrefix(line, "RECIPE=") && !strings.HasPrefix(line, "TYPE=") {
@ -656,7 +659,7 @@ func (a App) WriteRecipeVersion(version string, dryRun bool) error {
continue
}
if strings.Contains(line, version) && !a.Recipe.Dirty && !strings.HasSuffix(line, config.DIRTY_DEFAULT) {
if strings.Contains(line, version) && !isDirty && !strings.HasSuffix(line, config.DIRTY_DEFAULT) {
skipped = true
lines = append(lines, line)
continue
@ -669,16 +672,16 @@ func (a App) WriteRecipeVersion(version string, dryRun bool) error {
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
return err
}
if a.Recipe.Dirty && dirtyVersion != "" {
if isDirty && dirtyVersion != "" {
version = dirtyVersion
}
if !dryRun {
if err := os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm); err != nil {
log.Fatal(err)
return err
}
} else {
log.Debug(i18n.G("skipping writing version %s because dry run", version))