Skip to content

feat: detect polluted branch history and guide manual cleanup#35

Merged
javoire merged 5 commits intomainfrom
feat/smart-rebase-detection
Dec 10, 2025
Merged

feat: detect polluted branch history and guide manual cleanup#35
javoire merged 5 commits intomainfrom
feat/smart-rebase-detection

Conversation

@javoire
Copy link
Copy Markdown
Owner

@javoire javoire commented Dec 9, 2025

Problem

When parent branches are rebased, child branches can end up with "polluted" history containing duplicate commits with different SHAs. This causes complex rebase conflicts and can lead to data loss if the tool tries to automatically fix the issue.

Solution

This PR adds intelligent detection of polluted branch history and guides users through manual cleanup instead of attempting automatic fixes that could be destructive.

Key Changes

  1. Patch-based comparison using git cherry to detect duplicate commits by content, not just SHA
  2. Polluted history detection - identifies when a branch has many commits but few unique patches
  3. Clear manual cleanup instructions - provides step-by-step cherry-pick commands instead of auto-fixing
  4. Enhanced abort support - detects both rebase and cherry-pick in progress
  5. Simplified logic - removed complex base branch filtering that could cause data loss

Example Output

When polluted history is detected:

⚠ Detected polluted branch history:
  - 8 commits in branch history
  - Only 1 unique patch(es)

Recommended: Rebuild branch manually with cherry-pick:
  1. git checkout parent-branch
  2. git checkout -b my-branch-clean
  3. git cherry-pick abc1234
  4. git branch -D my-branch
  5. git branch -m my-branch
  6. git push --force-with-lease

Safety

  • No automatic destructive operations
  • Users maintain full control over branch cleanup
  • Clear, actionable error messages

Fixes issues with rebased parent branches causing complex conflicts.

- Add patch-based comparison using git cherry to detect duplicate commits
- Detect when branch history diverged from parent (many commits but few unique patches)
- Provide clear manual cleanup instructions instead of automatic destructive operations
- Add IsRebaseInProgress() and IsCherryPickInProgress() to detect git state
- Add AbortCherryPick() support for stack sync --abort
- Simplify rebase logic by removing complex base branch filtering

This prevents data loss when branches have diverged history and provides
users with safe, actionable steps to rebuild branches manually.
Add mock implementations for:
- GetUniqueCommits
- GetUniqueCommitsByPatch
- CherryPick
- ResetHard
- IsRebaseInProgress
- IsCherryPickInProgress
- AbortCherryPick
Update sync tests with mock expectations for:
- GetUniqueCommitsByPatch
- GetMergeBase
- GetCommitHash (for parent comparison)
@javoire javoire enabled auto-merge December 10, 2025 15:55
@javoire javoire merged commit eafc89d into main Dec 10, 2025
1 check passed
@javoire javoire deleted the feat/smart-rebase-detection branch December 10, 2025 16:29
@javoire
Copy link
Copy Markdown
Owner Author

javoire commented Dec 10, 2025

🎉 This PR is included in version 1.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant