Skip to content

Conversation

@ssestak
Copy link
Contributor

@ssestak ssestak commented Nov 21, 2025

Summary

Add support for detecting all merged branches including nested merges where one feature branch merges into another before merging to main.

Example: Branch B merges into branch A, then A merges into develop

  • Before: Only feature-A detected
  • After: Both feature-A and feature-B detected ✅

Changes

Core Implementation

  • Remove --first-parent flag for branch name detection to see all merge commits
  • Add negative filtering via grep -v "Merge branch '(EXCLUDE_SOURCE_BRANCHES)' into"
  • Keeps --first-parent for changelog messages (intentionally follows main branch history only)

New Features

  • New input: exclude_source_branches (default: "(main|develop|master)")
    • Regex pattern (ERE) to exclude source branches
    • Example: "(release.*|hotfix.*)" for flexible matching
    • Filters out reverse merges (e.g., main→feature for conflict resolution)

Documentation

  • Comprehensive README updates with nested merge detection section
  • Performance considerations documented
  • Inline code comments explaining intentional design decisions

Testing

  • New test file: test_merged-branches.bats with 13 comprehensive tests
  • All 42 tests pass (29 existing + 13 new)
  • Test coverage includes:
    • Nested merges (B→A→develop)
    • Deep nesting (C→B→A→develop)
    • Conflict resolution filtering
    • Parallel merges
    • Custom target branch patterns
    • Edge cases (quotes, special chars, empty outputs, etc.)

Test Results

✅ All 42 tests pass
✅ Nested merge detection works correctly
✅ Reverse merge filtering works correctly
✅ Backward compatible with default settings

Files Changed

  • action.yml - Add exclude_source_branches input
  • generate-changelog.sh - Implement nested merge detection
  • test_merged-branches.bats - New comprehensive test suite (470 lines)
  • README.md - Documentation updates

Total: 4 files changed, +533 lines, -11 lines

Breaking Changes

None - fully backward compatible with existing workflows.

🤖 Generated with Claude Code

Šimon Šesták and others added 3 commits November 21, 2025 11:38
Add support for detecting all merged branches including nested merges
where branch B merges into branch A, and then A merges into main.

Previously, using --first-parent only detected the final merge (A).
Now detects both A and B by removing --first-parent and using negative
filtering to exclude reverse merges (main→feature).

Changes:
- Add target_branch input to action.yml (default: main|develop|master)
- Remove --first-parent flag from git log commands
- Add negative filter: grep -v "Merge branch '(TARGET_BRANCH)' into"
- Create test_merged-branches.bats with 12 comprehensive tests

Filtering logic:
- Excludes: Reverse merges (main→feature) for conflict resolution
- Includes: All forward merges (feature→feature and feature→main)

Test coverage:
- Nested merges (B→A→develop) ✓
- Deep nesting (C→B→A→develop) ✓
- Conflict resolution filtering ✓
- Parallel merges ✓
- Custom target branch patterns ✓

All 41 tests pass (29 existing + 12 new)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Address all recommendations from code review to improve documentation
and test coverage:

1. Performance Impact (Recommendation 1):
   - Add dedicated "Nested Merge Detection" section to README
   - Document performance considerations and tradeoffs
   - Note: Minimal impact for typical workflows, 1-2s for large histories

2. Document Intentional --first-parent (Recommendation 3):
   - Add inline comments explaining why changelog uses --first-parent
   - Clarify that branch detection does NOT use --first-parent
   - Document the intentional separation of concerns

3. Fix Test Documentation (Recommendation 4):
   - Remove confusing "positive filtering" reference
   - Clarify squash-merge vs separate merge commit scenarios

4. Add Default TARGET_BRANCH Test (Recommendation 5):
   - New test verifies default fallback behavior when unset
   - Ensures "(main|develop|master)" default works correctly

5. Document Regex Patterns (Recommendation 6):
   - Update action.yml description with ERE syntax details
   - Add example: "(release.*|hotfix.*)" for flexible matching
   - Explain filtering behavior clearly

Documentation improvements:
- Add nested merge detection to Features section
- Update inputs table with target_branch and use_git_lfs
- Enhance generate-changelog.sh environment variables docs
- Add test_merged-branches.bats to test running instructions
- Expand test coverage list with new scenarios

All 42 tests pass (29 existing + 13 new)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Improve input naming for better clarity:
- Rename: target_branch → exclude_source_branches
- New description: Exclude merged commits of given branches
- More intuitive: Clearly indicates these branches are excluded when
  they are the SOURCE of a merge (e.g., main→feature)

Changes:
- action.yml: Rename input and update description
- generate-changelog.sh: Rename TARGET_BRANCH → EXCLUDE_SOURCE_BRANCHES
- test_merged-branches.bats: Update all test variable names
- README.md: Update documentation with new naming

All 42 tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@ssestak ssestak merged commit 7df78b3 into main Nov 21, 2025
2 checks passed
@ssestak ssestak deleted the feature/detect-nested-merged-branches branch November 21, 2025 12:07
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.

3 participants