Skip to content

Improve error propagation, env/config handling, and lint hygiene#84

Merged
BjoernKarma merged 7 commits intomainfrom
feat/improve
Apr 2, 2026
Merged

Improve error propagation, env/config handling, and lint hygiene#84
BjoernKarma merged 7 commits intomainfrom
feat/improve

Conversation

@BjoernKarma
Copy link
Copy Markdown
Owner

Overview

This PR improves gitctl reliability by fixing error propagation, tightening config/env handling, improving multi-repo failure reporting, updating tests for negative paths, and aligning docs with actual runtime behavior.

It also includes a final lint/format cleanup commit so the branch is test- and lint-clean.

Why

The main goals are to:

  • avoid process-level exits in lower-level config helpers,
  • propagate actionable errors to the CLI layer,
  • make env var overrides work consistently with dotted config keys,
  • return aggregated errors for multi-repo runs instead of losing partial failures,
  • and ensure docs/tests match the actual behavior.

Changes

1) Config + CLI error propagation

  • Refactored config helpers to return errors instead of calling log.Fatalf:

    • config/config.go
    • GitctlWorkingDir() (string, error)
    • GitctlConfigDir() (string, error)
    • HomeDir() (string, error)
  • Updated call sites to propagate/handle those errors:

    • app/cmd/root.go (InitConfig)
    • config/env.go (GetBaseDirs)
    • app/cmd/gitpull.go
    • app/cmd/gitstatus.go

2) Config loading + env overrides

  • Hardened config initialization in app/cmd/root.go:

    • non-ConfigFileNotFoundError from viper.ReadInConfig() now fails command execution,
    • missing config file is still treated as non-fatal (defaults/env continue).
  • Added explicit env support for dotted keys:

    • viper.SetEnvPrefix("GITCTL")
    • viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
    • Enables mappings like:
      • verbosity.verbose -> GITCTL_VERBOSITY_VERBOSE
      • run_mode.local -> GITCTL_RUN_MODE_LOCAL

3) Multi-repo error aggregation

  • Updated gitrepo/gitrepos.go:
    • repository discovery continues across base dirs even if one fails,
    • errors from discovery and per-repo git commands are aggregated via errors.Join(...),
    • caller now receives one summary error capturing partial failures.

4) Tests improved (negative paths + behavior alignment)

Updated tests to cover new behavior and error paths:

  • app/cmd/root_test.go
  • config/config_test.go
  • config/env_test.go
  • config/fork_test.go
  • gitrepo/gitrepo_test.go
  • gitrepo/gitrepos_test.go

Notable additions/adjustments:

  • invalid config parsing returns an execution error,
  • prefixed env var overrides are exercised,
  • invalid home/base-dir scenarios assert returned errors,
  • git command failure propagation is asserted,
  • mixed valid/invalid base dir scans assert aggregate error behavior.

5) Documentation alignment

Updated README.md to reflect actual behavior:

  • config search locations and order,
  • env var naming and mapping (GITCTL_ + dotted key replacement),
  • precedence (flags > env > config > defaults),
  • current CLI flags in help snippet.

6) Lint/format cleanup

Final cleanup to reach lint-clean state:

  • formatting/import order fixes (gofmt / goimports)
  • minor test cleanup for unparam

Files touched in lint commit:

  • app/cmd/root_test.go
  • color/colorPrinter_test.go
  • gitrepo/gitrepos_test.go
  • main.go
  • main_test.go

- Propagate git execution failures instead of swallowing them
- Make config read/parsing errors fail command execution (except config-not-found)
- Enable underscore env vars for dotted Viper keys
- Update/add tests to lock behavior and prevent regressions
- Run full test suite (+ race detector)
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

TestsPassed ❌️SkippedFailed
Test Report (gitctl)0 ran0 passed0 skipped0 failed

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Coverage for gitctl

Download the latest HTML coverage report for gitctl here.

@BjoernKarma BjoernKarma merged commit b9fb1b6 into main Apr 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant