Skip to content

Add configurable skipMergeCommits parameter to Git info command#1381

Open
GabriRuflex wants to merge 2 commits into
apache:masterfrom
GabriRuflex:skip-merge-commits-1327
Open

Add configurable skipMergeCommits parameter to Git info command#1381
GabriRuflex wants to merge 2 commits into
apache:masterfrom
GabriRuflex:skip-merge-commits-1327

Conversation

@GabriRuflex

@GabriRuflex GabriRuflex commented Jul 1, 2026

Copy link
Copy Markdown

What does this PR do?

The Git info command always passed --no-merges to git log, so the reported revision could differ
from the actual HEAD in merge-based release workflows. This surfaced downstream as a regression in
buildnumber-maven-plugin#229 (which
switched from git rev-parse --verify HEAD to git log -1 --no-merges).

As requested in #1327, this makes the behavior configurable via a new
CommandParameter.SCM_SKIP_MERGE_COMMITS parameter ("skipMergeCommits"):

  • Default true — skip merge commits (current behavior, fully backward compatible).
  • Set to false to include merge commits, so the reported revision matches the actual HEAD.

Changes

  • maven-scm-api — new public CommandParameter.SCM_SKIP_MERGE_COMMITS (@since 2.2.2).
  • maven-scm-provider-gitexeGitInfoCommand adds --no-merges only when the flag is true
    (null-safe reader mirroring the existing shortRevisionLength handling, plus a
    DEFAULT_SKIP_MERGE_COMMITS constant).
  • maven-scm-provider-jgitJGitInfoCommand now honors the same flag by applying
    RevFilter.NO_MERGES for both the HEAD and the per-file lookups. Previously the JGit provider
    never filtered merge commits, diverging from gitexe; it is now consistent with it (with the
    default true, JGit skips merge commits as gitexe already did).

Tests

  • GitInfoCommandTest (gitexe): asserts --no-merges is present by default and absent when
    skipMergeCommits=false.
  • New JGitInfoCommandTest: builds a repository whose HEAD is a no-fast-forward merge commit and
    verifies that the merge commit is reported when skipMergeCommits=false and skipped by default.
  • The existing Info command TCK tests (which pass null parameters) keep passing, confirming the
    default behavior is unchanged for both providers.

Notes

This is the enabling change on the maven-scm side. To fully address buildnumber-maven-plugin#229, the
plugin will need to expose an option that sets SCM_SKIP_MERGE_COMMITS = false on the
CommandParameters it passes to ScmProvider#info.


Following this checklist to help incorporate the contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
  • Run mvn verify to make sure basic checks pass.
  • You have run the integration tests successfully (mvn -Prun-its verify).
  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004.
  • In any other case, please file an Apache Individual Contributor License Agreement.

Build note: mvn verify is green for the modules touched by this PR (maven-scm-api,
maven-scm-provider-gitexe, maven-scm-provider-jgit), including Checkstyle, Spotless and
Apache RAT. The only failures observed locally are 5 pre-existing JGit hook-rejection TCK tests
(testPushBranchRejected, JGitCheckIn*#testCommitWithRejectingPreCommitHook, testPushTagRejected,
testPushTagDeletionRejected) that fail identically on a clean master, because git hooks do not
fire in my local Windows environment — unrelated to this change. The integration tests
(-Prun-its) were not run locally.

Fixes #1327

@GabriRuflex GabriRuflex force-pushed the skip-merge-commits-1327 branch from 265d31c to b5d14bc Compare July 1, 2026 18:34
The Git "info" command always passed --no-merges to git log, so the
reported revision could differ from the actual HEAD in merge-based
release workflows (regression surfaced in buildnumber-maven-plugin#229).

Introduce CommandParameter.SCM_SKIP_MERGE_COMMITS (default true, fully
backward compatible) to make this behavior configurable. When set to
false, merge commits are included so the reported revision matches HEAD.

Both providers honor the flag: gitexe adds --no-merges conditionally,
and the JGit provider now applies RevFilter.NO_MERGES (previously it
never filtered merge commits, diverging from gitexe).

Fixes apache#1327
@GabriRuflex GabriRuflex force-pushed the skip-merge-commits-1327 branch from b5d14bc to d12b21d Compare July 1, 2026 18:46
@GabriRuflex GabriRuflex marked this pull request as ready for review July 1, 2026 19:10
@GabriRuflex

Copy link
Copy Markdown
Author

cc @kwin — would you have time to review this small enabling change for #1327 (make --no-merges configurable in the Git info command)? Thanks!

@GabriRuflex

Copy link
Copy Markdown
Author

cc @kwin — would you have time to review this small enabling change for #1327 (make --no-merges configurable in the Git info command)? Thanks!

Hey @slachiewicz could you please take a look to this PR?
Thanks a lot!

@slachiewicz slachiewicz requested a review from Copilot July 8, 2026 08:55
@slachiewicz slachiewicz added the enhancement New feature or request label Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new skipMergeCommits command parameter to make Git info revision selection configurable, addressing cases where always using --no-merges causes the reported revision to differ from HEAD in merge-based workflows.

Changes:

  • Introduces new public CommandParameter.SCM_SKIP_MERGE_COMMITS (defaulting to true for backward compatibility).
  • Updates gitexe GitInfoCommand to conditionally add --no-merges based on the parameter.
  • Updates JGit JGitInfoCommand to apply merge-skipping consistently (including per-path lookups) and adds provider-level tests.

Reviewed changes

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

Show a summary per file
File Description
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/info/JGitInfoCommandTest.java Adds unit tests for default merge-skipping and opt-in merge inclusion behavior.
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/info/JGitInfoCommand.java Adds parameter handling to optionally apply RevFilter.NO_MERGES and align behavior with gitexe.
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommandTest.java Adds assertions verifying --no-merges default and its absence when disabled.
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommand.java Conditionally adds --no-merges based on the new parameter while preserving default behavior.
maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java Adds the new SCM_SKIP_MERGE_COMMITS public parameter definition (@since 2.2.2).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GabriRuflex

Copy link
Copy Markdown
Author

All fixed and tested

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flag to enable/disable skipMergeCommits behavior for Git CLI and JGit

3 participants