Skip to content

Add parentBranch configuration to support CI environments with detached HEAD #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tinder-ravitejabonagiri

Add Support for Explicit Parent Branch in ForkCommit

Problem

When running in CI environments where repositories are cloned with detached HEAD (common in PR builds), the ForkCommit provider's automatic parent branch detection can fail. This is because git show-branch -a might not show correct branch information in detached HEAD state, leading to "Parent branch not found" errors.

Solution

Added the ability to explicitly specify a parent branch in the ForkCommit provider through configuration. This makes the tool more reliable in CI environments by removing the dependency on automatic branch detection.

Changes

  1. Added parentBranch field to CommitShaProviderConfiguration
  2. Added parentBranch configuration option to AffectedModuleConfiguration
  3. Modified ForkCommit to use provided parent branch if available, falling back to auto-detection if not provided

Configuration Example

affectedModuleDetector {
    compareFrom = "ForkCommit"
    parentBranch = "main"  // Explicitly specify the parent branch
}

Usage in CI

Instead of relying on automatic detection which might fail:

# This might fail in detached HEAD state
./gradlew test -Paffected_module_detector.enable

You can now explicitly specify the parent branch:

# This works reliably even in detached HEAD state
./gradlew test -Paffected_module_detector.enable -Paffected_module_detector.parentBranch=main

Benefits

  1. Reliability: Works consistently in CI environments with detached HEAD
  2. Flexibility: Users can explicitly specify which branch to compare against
  3. Backward Compatible: Falls back to existing auto-detection if no parent branch is provided
  4. CI/CD Friendly: Makes it easier to configure in CI/CD pipelines where branch information might be limited

Documentation

Updated README.md to include:

  • New parentBranch configuration option
  • Example usage in CI environments
  • Explanation of when to use explicit parent branch configuration

Breaking Changes

None. This is a backward-compatible enhancement that maintains existing behavior when parentBranch is not specified.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@tinder-ravitejabonagiri
Copy link
Author

tinder-ravitejabonagiri commented May 12, 2025

@joshafeinberg, I would appreciate your review on these changes.

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