elastic/elasticsearch · error · IllegalStateException

Found the following merge commits which prevent determining

Error message

Found the following merge commits which prevent determining bwc commits: ${mergeCommits}

What it means

Thrown as IllegalStateException by maybeAlignedRefSpec() when bwc.checkout.align is set and git rev-list finds merge commits in the refspec between the current commit's date and now. The deterministic BWC-version alignment uses commit timestamps to pick a stable ref; merge commits can introduce backdated commits, breaking determinism, so the code refuses to proceed rather than produce a non-reproducible checkout.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalBwcGitPlugin.java:229

     * should not matter in practice.
     */
    private String maybeAlignedRefSpec(Logger logger, String defaultRefSpec) {
        if (providerFactory.systemProperty("bwc.checkout.align").isPresent() == false) {
            return defaultRefSpec;
        }

        String timeOfCurrent = execInCheckoutDir(execSpec -> {
            execSpec.commandLine(asList("git", "show", "--no-patch", "--no-notes", "--pretty='%cD'"));
            execSpec.workingDir(buildLayout.getRootDirectory());
        });

        logger.lifecycle("Commit date of current: {}", timeOfCurrent);

        String mergeCommits = execInCheckoutDir(
            spec -> spec.commandLine(asList("git", "rev-list", defaultRefSpec, "--after", timeOfCurrent, "--merges"))
        );
        if (mergeCommits.isEmpty() == false) {
            throw new IllegalStateException("Found the following merge commits which prevent determining bwc commits: " + mergeCommits);
        }
        return execInCheckoutDir(
            spec -> spec.commandLine(asList("git", "rev-list", defaultRefSpec, "-n", "1", "--before", timeOfCurrent, "--date-order"))
        );
    }

    private void writeFile(File file, String content) {
        try {
            file.getParentFile().mkdirs();
            Files.writeString(file.toPath(), content, CREATE, TRUNCATE_EXISTING);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    private String execInCheckoutDir(Action<ExecSpec> execSpecConfig) {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ExecResult exec = execOperations.exec(execSpec -> {

View on GitHub (pinned to db6a809a66)

Solutions

  1. Rebase the branch instead of merging to eliminate merge commits in the window, then re-run.
  2. Unset -Dbwc.checkout.align to skip deterministic alignment and use the default refspec (loses determinism guarantee).
  3. Inspect the listed merge commit SHAs with git log --merges to decide whether to revert or rebase them out.
  4. If the merge commits are intentional and old, advance the current commit date past them so they fall outside the --after window.

Example fix

# before: branch has merge commits, alignment fails
./gradlew bwcTest -Dbwc.checkout.align=true

# after: rebase to linearize, removing merges
git rebase main
./gradlew bwcTest -Dbwc.checkout.align=true

# or skip alignment
./gradlew bwcTest
Defensive patterns

Strategy: validation

Validate before calling

// before enabling align, check for merge commits
Process p = new ProcessBuilder("git", "rev-list", "HEAD", "--merges", "--since=1.month").start();
if (p.getInputStream().readAllBytes().length > 0) {
    System.err.println("Merge commits present; skip -Dbwc.checkout.align");
}

Prevention

When it happens

Trigger: Only fires when -Dbwc.checkout.align is present (line 214). The code runs git rev-list <refspec> --after <currentCommitDate> --merges; any non-empty output throws. Triggered when the branch being aligned contains merge commits dated after the current commit's committer date.

Common situations: A feature branch with merge commits from main is being used for aligned BWC builds; rebases that preserved merge commits; testing locally on a branch with merges; CI on a release branch that received merge-back commits.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/0955b12843373bf1. Report an issue: GitHub.