Skip to content

Explain how to limit mutation testing to a PR or MR - #5

Open
theofidry wants to merge 4 commits into
mainfrom
fix/git-base
Open

theofidry wants to merge 4 commits into
mainfrom
fix/git-base

Conversation

@theofidry

@theofidry theofidry commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

🤖 Disclaimer: the content of the PR has been generated entirely with Codex.

Document the changes from:

@theofidry
theofidry marked this pull request as draft October 28, 2026 18:47
Supposed to be used only with [`--git-diff-filter`](/guide/command-line-options.html#git-diff-filter) option. Configures the base branch for `git diff` command.
Sets the branch reference or commit SHA used with [`--git-diff-filter`](#git-diff-filter) or [`--git-diff-lines`](#git-diff-lines).

<span class="version-since">Automatic CI base selection: unreleased (after Infection 0.35.10)</span>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

to be updated

Comment thread guide/how-to.md
<span class="version-since">Automatic CI base selection: unreleased (after Infection 0.35.10)</span>

<!-- Preserve links to the removed Travis example. -->
<span id="Example-for-Travis-CI"></span>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

to double check

Comment thread guide/using-with-ci.md
- vendor/bin/infection --git-diff-lines #...
```

[![Infection MSI](https://badge.stryker-mutator.io/github.com/infection/infection/master)](https://infection.github.io)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not sure why this was there but the link is broken and the badge is the next page so removed it

@theofidry
theofidry marked this pull request as ready for review November 13, 2026 11:21
| GitHub Actions, merge queue | `merge_group.base_sha` from the event payload at `GITHUB_EVENT_PATH` |
| GitLab CI, merge request | `CI_MERGE_REQUEST_DIFF_BASE_SHA`, including detached, merged results, and merge train pipelines |

When CI metadata does not provide a base, Infection resolves the local symbolic reference `refs/remotes/origin/HEAD`, which normally identifies `origin`'s default branch. If it cannot resolve that reference, it falls back to `origin/master`. A missing or unreadable GitHub event file, or invalid JSON, also causes Infection to use the repository default lookup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
When CI metadata does not provide a base, Infection resolves the local symbolic reference `refs/remotes/origin/HEAD`, which normally identifies `origin`'s default branch. If it cannot resolve that reference, it falls back to `origin/master`. A missing or unreadable GitHub event file, or invalid JSON, also causes Infection to use the repository default lookup.
When CI metadata does not provide a base, Infection resolves the local symbolic reference `refs/remotes/origin/HEAD`, which normally identifies `origin`'s default branch. If it cannot resolve that reference, it falls back to `origin/main`. A missing or unreadable GitHub event file, or invalid JSON, also causes Infection to use the repository default lookup.

I think main is the current default branch name.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it is... but not in our code... Maybe worth changing that now though as it is the default for any new project for a few years already.


When CI metadata does not provide a base, Infection resolves the local symbolic reference `refs/remotes/origin/HEAD`, which normally identifies `origin`'s default branch. If it cannot resolve that reference, it falls back to `origin/master`. A missing or unreadable GitHub event file, or invalid JSON, also causes Infection to use the repository default lookup.

Infection finds the merge base of the supplied reference and `HEAD`, then compares the checked-out files with that ancestor. This excludes changes made only on the target branch since the branches diverged. Both commits and enough history to find their common ancestor must be available locally. If Git cannot find a merge base, Infection falls back to a direct diff against the supplied reference, which can include changes outside the pull request.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds like this explains what Git does by default, or what do I miss?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we're explaining that we're doing git diff indeed, but as noted here, there are a few subtleties for it to work, 1) getting the right base and 2) having the necessary git history

git fetch --depth=1 origin $GITHUB_BASE_REF

infection.phar --logger-github --git-diff-filter=A
infection.phar --logger-github=true --git-diff-filter=A

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

BC break?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hmm I didn't add it in "using with CI" because I thought it was enabled automatically, it is not, so I should add it there and likewise for GitLab.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no it is actually equivalent in this case so I suppose I should not change it more than necessary.

--logger-github: will autodetect whether should be enabled
--logger-github=true: force the reporter, even if not actually on GA
--logger-github=false: disables it

git fetch --depth=1 origin $GITHUB_BASE_REF

infection.phar --logger-github --git-diff-filter=A
infection.phar --logger-github=true --git-diff-filter=A

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

actually I notice here we've been using the PHAR form so I should update the other examples added to use it too.

This branch has not been deployed

No deployments
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