Skip to content

fix: allow checkout with non-conflicting dirty tracked files#35

Merged
alexandreafj merged 1 commit into
masterfrom
fix/checkout-allow-non-conflicting-dirty-files
May 19, 2026
Merged

fix: allow checkout with non-conflicting dirty tracked files#35
alexandreafj merged 1 commit into
masterfrom
fix/checkout-allow-non-conflicting-dirty-files

Conversation

@alexandreafj
Copy link
Copy Markdown
Owner

Summary

  • Removed pre-checkout dirty check that unconditionally skipped repos with any modified tracked files
  • Attempts checkout first, then only skips when git reports an actual conflict (Your local changes would be overwritten)
  • Fixes the case where git checkout works (e.g. modified .npmrc identical on both branches) but gitm checkout refused

What changed

Before After
gitm checkout runs git status --porcelain -uno before checkout; any dirty tracked file → skip gitm checkout attempts git checkout directly; only skips on conflict error from git

New helpers:

  • isCheckoutConflict(err) — detects git's "Your local changes would be overwritten" errors
  • checkoutConflictSkip(path, err) — builds the skip reason with dirty file list

Test plan

  • TestRunCheckoutDefault_NonConflictingDirtyFile — dirty file identical on both branches → checkout succeeds
  • TestRunCheckoutDefault_ConflictingDirtyFile — dirty file differs between branches → skip (not error)
  • TestCheckoutBranchInRepo_NonConflictingDirtyFile — same via checkoutBranchInRepo
  • TestCheckoutBranchInRepo_ConflictingDirtyFile — same via checkoutBranchInRepo
  • TestCheckoutInteractive_NonConflictingDirtyFile — interactive mode with non-conflicting dirty
  • TestCheckoutDefault_MultipleReposMixedDirtyState — 3 repos: clean, conflicting, non-conflicting
  • TestIsCheckoutConflict — unit test for conflict detection
  • TestCheckoutConflictSkip_NonConflictError — non-conflict errors pass through
  • E2E: TestCheckout_DirtyRepo_NonConflicting_Succeeds (replaces old TestCheckout_DirtyRepo_Skips)
  • E2E: TestCheckout_DirtyRepo_Conflicting_Skips — new e2e for actual conflicts
  • All 418 tests pass with -race
  • make lint passes

🤖 Generated with Claude Code

gitm checkout was unconditionally skipping repos with any modified tracked
files, even when git itself would allow the branch switch (e.g. a modified
file that is identical on both branches). This made gitm stricter than
native git and blocked common workflows like switching branches with a
locally-modified .npmrc.

Instead of pre-checking dirty state, attempt the checkout and only skip
when git reports an actual conflict ("Your local changes would be
overwritten"). This delegates conflict detection to git's own merge logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 19, 2026 14:32
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

Note

Copilot was unable to run its full agentic suite in this review.

Allows gitm checkout to proceed when dirty tracked files do not conflict with the target branch, matching git checkout semantics. Previously, any dirty tracked file caused an unconditional skip.

Changes:

  • Removed pre-checkout IsDirtyTrackedOnly check from both runCheckoutDefault and checkoutBranchInRepo.
  • Added isCheckoutConflict and checkoutConflictSkip helpers to detect git's "local changes would be overwritten" errors and skip only in that case.
  • Updated/added unit and E2E tests covering conflicting vs. non-conflicting dirty-file scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
internal/cli/checkout.go Replaces dirty-check skip with attempt-then-detect-conflict approach; adds conflict detection helpers; updates command long description.
internal/cli/checkout_run_test.go Adds unit tests for the new behavior across default, interactive, and helper code paths, plus tests for helpers.
internal/e2e/checkout_test.go Replaces TestCheckout_DirtyRepo_Skips with separate non-conflicting (succeeds) and conflicting (skips) E2E tests.

Comment thread internal/cli/checkout.go
Comment thread internal/cli/checkout.go
Comment thread internal/cli/checkout_run_test.go
@github-actions
Copy link
Copy Markdown

✅ All checks passed (Go 1.26)

Coverage: 69.1%

@alexandreafj alexandreafj merged commit 464be04 into master May 19, 2026
1 check passed
@alexandreafj alexandreafj deleted the fix/checkout-allow-non-conflicting-dirty-files branch May 19, 2026 14:44
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