Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 16 additions & 32 deletions cmd/entire/cli/setup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli

import (
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -457,7 +456,7 @@ func runStatus(w io.Writer) error {
localSettingsPath = EntireSettingsLocalFile
}

// Check if either settings file exists
// Check which settings files exist (for source label)
_, projectErr := os.Stat(settingsPath)
if projectErr != nil && !errors.Is(projectErr, fs.ErrNotExist) {
return fmt.Errorf("cannot access project settings file: %w", projectErr)
Expand All @@ -474,40 +473,25 @@ func runStatus(w io.Writer) error {
return nil
}

// Load and display project settings (if exists)
if projectExists {
data, readErr := os.ReadFile(settingsPath) //nolint:gosec // path is from AbsPath or constant
if readErr != nil {
return fmt.Errorf("failed to read project settings: %w", readErr)
}
projectSettings := &EntireSettings{
Strategy: strategy.DefaultStrategyName,
Enabled: true,
}
if unmarshalErr := json.Unmarshal(data, projectSettings); unmarshalErr != nil {
return fmt.Errorf("failed to parse project settings: %w", unmarshalErr)
}
projectSettings.Strategy = strategy.NormalizeStrategyName(projectSettings.Strategy)
fmt.Fprintln(w, formatSettingsStatus("Project", projectSettings))
// Load merged settings
settings, err := LoadEntireSettings()
if err != nil {
return fmt.Errorf("failed to load settings: %w", err)
}
settings.Strategy = strategy.NormalizeStrategyName(settings.Strategy)

// Load and display local settings (if exists)
if localExists {
data, readErr := os.ReadFile(localSettingsPath) //nolint:gosec // path is from AbsPath or constant
if readErr != nil {
return fmt.Errorf("failed to read local settings: %w", readErr)
}
localSettings := &EntireSettings{
Strategy: strategy.DefaultStrategyName,
Enabled: true,
}
if unmarshalErr := json.Unmarshal(data, localSettings); unmarshalErr != nil {
return fmt.Errorf("failed to parse local settings: %w", unmarshalErr)
}
localSettings.Strategy = strategy.NormalizeStrategyName(localSettings.Strategy)
fmt.Fprintln(w, formatSettingsStatus("Local", localSettings))
// Determine source label
var sourceLabel string
switch {
case projectExists && localExists:
sourceLabel = "Project + Local"
case localExists:
sourceLabel = "Local"
default:
sourceLabel = "Project"
}

fmt.Fprintln(w, formatSettingsStatus(sourceLabel, settings))
return nil
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/entire/cli/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ func TestRunStatus_LocalSettingsOnly(t *testing.T) {

func TestRunStatus_BothProjectAndLocal(t *testing.T) {
setupTestRepo(t)
// Project: enabled=true, strategy=manual-commit
// Local: enabled=false, strategy=auto-commit
// Merged: enabled=false (local overrides), strategy=auto-commit (local overrides)
writeSettings(t, `{"strategy": "manual-commit", "enabled": true}`)
writeLocalSettings(t, `{"strategy": "auto-commit", "enabled": false}`)

Expand All @@ -527,11 +530,9 @@ func TestRunStatus_BothProjectAndLocal(t *testing.T) {
}

output := stdout.String()
if !strings.Contains(output, "Project, enabled (manual-commit)") {
t.Errorf("Expected output to show 'Project, enabled (manual-commit)', got: %s", output)
}
if !strings.Contains(output, "Local, disabled (auto-commit)") {
t.Errorf("Expected output to show 'Local, disabled (auto-commit)', got: %s", output)
// Should show merged settings with "Project + Local" source label
if !strings.Contains(output, "Project + Local, disabled (auto-commit)") {
t.Errorf("Expected output to show 'Project + Local, disabled (auto-commit)', got: %s", output)
}
}

Expand Down