Skip to content

fix: resolve 4 bugs found during e2e testing#25

Merged
alexandreafj merged 2 commits into
masterfrom
fix/e2e-findings
May 1, 2026
Merged

fix: resolve 4 bugs found during e2e testing#25
alexandreafj merged 2 commits into
masterfrom
fix/e2e-findings

Conversation

@alexandreafj
Copy link
Copy Markdown
Owner

Summary

Fixes 4 bugs discovered during comprehensive e2e testing (PR #24):

  1. Checkout remote-only branches (critical): git checkout failed for branches that only exist on origin because RemoteBranchExists uses ls-remote (which doesn't update local refs). Now fetches the branch first via git fetch origin <branch> before attempting checkout.

  2. Status DIRTY column mislabel: Changed label from "N modified" to "N changed" since the count includes untracked files (??), not just tracked modifications.

  3. repo add alias conflict exits 0: When adding a repo with a duplicate alias (pointing to a different path), the command printed a red error message but exited with code 0. Now correctly returns non-zero. Also handles macOS symlink path resolution (/var/private/var) to avoid false alias collisions.

  4. update/checkout exit 0 on failure: Both commands ignored runner.Run() results and always returned nil. Now check for errors and return appropriate exit codes. Added HasErrors()/ErrorCount() helpers to the runner package.

Changes

  • internal/git/git.go: Add FetchBranch() function
  • internal/cli/checkout.go: Fetch before checkout for remote-only branches; propagate runner errors
  • internal/cli/status.go: Fix label "modified" → "changed"
  • internal/cli/repo.go: Return error on alias conflicts; resolve symlinks before comparing paths
  • internal/cli/update.go: Propagate runner errors
  • internal/runner/parallel.go: Add HasErrors() / ErrorCount() helpers

Testing

  • All 314 tests pass with -race flag
  • New tests: TestFetchBranch, TestFetchBranch_NonExistentBranch, TestRunCheckoutBranch_RemoteOnly, TestRunCheckoutDefault_ReturnsErrorOnFailure, TestRunUpdate_ReturnsErrorOnFailure, TestRepoAddAliasConflictReturnsError, TestRepoAddSamePathIdempotent, TestHasErrors, TestErrorCount
  • Lint passes cleanly

1. Checkout remote-only branches: add git fetch before checkout so git
   can create a local tracking branch from the remote ref (was failing
   silently because ls-remote doesn't update local refs).

2. Status DIRTY column: change label from 'N modified' to 'N changed'
   since the count includes untracked files, not just modifications.

3. Repo add alias conflict: return non-zero exit code when an alias
   collision occurs with a different repo path. Previously exited 0
   with a red message but no error, confusing scripts/CI.

4. Update/checkout exit code: propagate failures from runner.Run so
   commands return non-zero when any repository operation fails.
   Added HasErrors/ErrorCount helpers to the runner package.
Copilot AI review requested due to automatic review settings May 1, 2026 09:52
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

✅ All checks passed (Go 1.26)

Coverage: 68.1%

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes multiple CLI correctness issues uncovered by e2e testing, primarily around git branch checkout behavior, exit codes on failure, and clearer status/add-repo behavior.

Changes:

  • Add git.FetchBranch() and use it to support checking out remote-only branches.
  • Propagate parallel runner failures to command exit codes via new runner.HasErrors() / runner.ErrorCount() helpers.
  • Improve UX/correctness: status “DIRTY” label wording, and repo add alias-collision handling (including symlink-normalized path comparison).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/runner/parallel.go Adds HasErrors() / ErrorCount() helpers for result slices.
internal/runner/parallel_test.go Adds unit tests for new runner helpers.
internal/git/git.go Adds FetchBranch() helper to fetch a single remote branch.
internal/git/git_test.go Adds tests covering fetching remote-only branches and non-existent branches.
internal/cli/checkout.go Fetches remote-only branches before checkout; returns errors when runner results contain failures.
internal/cli/checkout_run_test.go Adds regression tests for remote-only checkout and non-zero on failure.
internal/cli/update.go Returns an error when any repo update fails (based on runner results).
internal/cli/update_run_test.go Adds regression test that update returns an error on repo failures.
internal/cli/status.go Renames dirty label from “modified” to “changed”.
internal/cli/repo.go Returns non-zero on alias conflicts; resolves symlinks when comparing stored vs new paths.
internal/cli/repo_test.go Adds tests for alias conflict error and idempotent re-add of same path.

Comment thread internal/git/git.go Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

✅ All checks passed (Go 1.26)

Coverage: 68.1%

@alexandreafj alexandreafj merged commit 993c200 into master May 1, 2026
1 check passed
@alexandreafj alexandreafj deleted the fix/e2e-findings branch May 1, 2026 10:02
alexandreafj added a commit that referenced this pull request May 1, 2026
- Use filepath.Join for non-existent path test (cross-platform)
- Assert exit codes in AutoDetectWithDepth, remove _ = r1/r2 workaround
- Replace generic "1" with "changed" in DirtyModified check
- Use specific "No files matching" assertion in untrack test
- Assert deterministic non-zero exit for unknown --repo alias
- Assert idempotent behavior for duplicate path add (exit 0 + warning)
- Assert non-zero exit for conflicting alias (fixed in PR #25)
alexandreafj added a commit that referenced this pull request May 1, 2026
* test: add e2e test suite for CLI binary-level testing

Adds 77 automated e2e tests that build the gitm binary and exercise it
as a real user would, using isolated HOME directories and real git repos.

Covers: repo add/list/remove/rename, status, branch create/rename,
checkout, update, track/untrack, commit, discard, stash, reset,
upgrade, help/version.

Key findings documented in test output via t.Log:
- checkout fails for unfetched remote-only branches
- status DIRTY column counts untracked files as 'modified'
- duplicate alias on repo add silently ignored

* fix: resolve golangci-lint issues in e2e tests

- Check os.MkdirAll return values (errcheck)
- Remove unused gitLog and isDirty helper methods (unused)
- Use errors.As instead of type assertion on *exec.ExitError (errorlint)
- Add missing errors import

* fix: address PR review comments on e2e test suite

- Cross-platform: replace /dev/null with os.DevNull, add Windows HOME
  env vars (USERPROFILE/HOMEDRIVE/HOMEPATH), clean up TestMain temp dir
- Stronger assertions: replace t.Log-only tests with real assertions
  for remote-only checkout, diverged update, dirty branch create,
  non-existent branch rename, and stash list empty state
- Broader match fixes: 'No' -> specific messages like 'No dirty
  repositories found', 'No untracked files found'
- Skip TUI-dependent tests that cannot run in non-TTY environments
  (commit protection, reset, track file picker)
- Remove custom contains/findSubstring reimplementing strings.Contains
- Use filepath.Join instead of string concatenation with '/'
- Remove unused dataDir struct field
- Use upgrade --help instead of real network call in TestUpgrade

* fix: address second round of PR review comments

- Use filepath.Join for non-existent path test (cross-platform)
- Assert exit codes in AutoDetectWithDepth, remove _ = r1/r2 workaround
- Replace generic "1" with "changed" in DirtyModified check
- Use specific "No files matching" assertion in untrack test
- Assert deterministic non-zero exit for unknown --repo alias
- Assert idempotent behavior for duplicate path add (exit 0 + warning)
- Assert non-zero exit for conflicting alias (fixed in PR #25)
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.

2 participants