Skip to content

Commit

Permalink
fix: do not write the state or summary files when their paths have be…
Browse files Browse the repository at this point in the history
…en configured as empty #230 (#232)
  • Loading branch information
flelli authored Jun 8, 2023
1 parent 4a3bdad commit df175e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ There are no new features or improvements in this release.
This release:

* fixes a bug in the command line version that does not comply with `.gitignore` ([#219](https://github.com/mooltiverse/nyx/issues/219)). The issue is inherited by [go-git](https://github.com/go-git/go-git) that just [fixed it](https://github.com/go-git/go-git/issues/500)
* fixes a bug in the command line version that does not allow to disable the generation of the state file ([#230](https://github.com/mooltiverse/nyx/issues/230))

## 2.4.3

Expand Down
9 changes: 5 additions & 4 deletions modules/go/nyx/nyx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt" // https://pkg.go.dev/fmt
"os" // https://pkg.go.dev/os
"path/filepath" // https://pkg.go.dev/path/filepath
"strings" // https://pkg.go.dev/strings

log "github.com/sirupsen/logrus" // https://pkg.go.dev/github.com/sirupsen/logrus

Expand Down Expand Up @@ -341,7 +342,7 @@ func (n *Nyx) runCommand(command cmd.Commands, saveStateAndSummary bool) error {
return err
}
// if the file path is relative make it relative to the configured directory
if stateFile != nil && !filepath.IsAbs(*stateFile) {
if stateFile != nil && "" != strings.TrimSpace(*stateFile) && !filepath.IsAbs(*stateFile) {
configuration, err := n.Configuration()
if err != nil {
return err
Expand All @@ -353,7 +354,7 @@ func (n *Nyx) runCommand(command cmd.Commands, saveStateAndSummary bool) error {
stateFileAbsolutePath := filepath.Join(*directory, *stateFile)
stateFile = &stateFileAbsolutePath
}
if saveStateAndSummary && stateFile != nil {
if saveStateAndSummary && stateFile != nil && "" != strings.TrimSpace(*stateFile) {
log.Debugf("storing the state to '%s'", *stateFile)
state, err := n.State()
if err != nil {
Expand All @@ -371,7 +372,7 @@ func (n *Nyx) runCommand(command cmd.Commands, saveStateAndSummary bool) error {
return err
}
// if the file path is relative make it relative to the configured directory
if summaryFile != nil && !filepath.IsAbs(*summaryFile) {
if summaryFile != nil && "" != strings.TrimSpace(*summaryFile) && !filepath.IsAbs(*summaryFile) {
configuration, err := n.Configuration()
if err != nil {
return err
Expand All @@ -383,7 +384,7 @@ func (n *Nyx) runCommand(command cmd.Commands, saveStateAndSummary bool) error {
summaryFileAbsolutePath := filepath.Join(*directory, *summaryFile)
summaryFile = &summaryFileAbsolutePath
}
if saveStateAndSummary && summaryFile != nil {
if saveStateAndSummary && summaryFile != nil && "" != strings.TrimSpace(*summaryFile) {
log.Debugf("storing the summary to '%s'", *summaryFile)
state, err := n.State()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private void runCommand(Commands command, boolean saveStateAndSummary)
logger.debug(MAIN, "Command '{}' finished.", command.toString());

// optionally save the state file
if (saveStateAndSummary && !Objects.isNull(configuration().getStateFile())) {
if (saveStateAndSummary && !Objects.isNull(configuration().getStateFile()) && !configuration().getStateFile().isBlank()) {
File stateFile = new File(configuration().getStateFile());
// if the file path is relative make it relative to the configured directory
if (!stateFile.isAbsolute())
Expand All @@ -289,7 +289,7 @@ private void runCommand(Commands command, boolean saveStateAndSummary)
}

// optionally save the summary file
if (saveStateAndSummary && !Objects.isNull(configuration().getSummaryFile())) {
if (saveStateAndSummary && !Objects.isNull(configuration().getSummaryFile()) && !configuration().getSummaryFile().isBlank()) {
File summaryFile = new File(configuration().getSummaryFile());
// if the file path is relative make it relative to the configured directory
if (!summaryFile.isAbsolute())
Expand Down

0 comments on commit df175e5

Please sign in to comment.