# Selected base commit when PR is based on an older commit of the target branch

**URL:** <https://community.codecov.com/t/selected-base-commit-when-pr-is-based-on-an-older-commit-of-the-target-branch/4101>\
**Category:** Support\
**Created:** [February 2, 2023, 8:14pm UTC](https://community.codecov.com/t/selected-base-commit-when-pr-is-based-on-an-older-commit-of-the-target-branch/4101 "2023-02-02T20:14:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmw](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/bmw/32/393_2.png) [@bmw](https://community.codecov.com/u/bmw)\
**Post date:** [February 2, 2023, 8:14pm UTC](https://community.codecov.com/t/selected-base-commit-when-pr-is-based-on-an-older-commit-of-the-target-branch/4101/1 "2023-02-02T20:14:43Z")

</div>

## Before submitting a topic, please confirm the following

I have searched for similar issues before creating this topic.  
 I have verified that my repository is using the [Codecov GitHub app](https://github.com/apps/codecov), if using GitHub  
 I have [validated](https://docs.codecov.com/docs/codecov-yaml#validate-your-repository-yaml) my `codecov.yaml` configuration file.  
 I have filled out the below sections to the best of my ability.

### Description

Say your main branch is on commit A and then two things happen. First, commit B lands in your main branch in a way that affects its coverage data. Coverage data for both commits is uploaded to codecov. Second, a PR is opened against main, but the first common commit between the PR and main is the commit A. In other words, the PR isn’t up-to-date with its target branch.

In this case, for a PR build, most CI systems would fetch `pull/<PR num>/merge` from GitHub which is the result of merging that PR into the current state of its target branch. In this case, it would merge the PR into main at commit B and pick up the coverage changes from that commit.

### CI/CD URL

I set up this scenario in a dummy repo at [change something by bmw · Pull Request #3 · bmw/codecov-test · GitHub](https://github.com/bmw/codecov-test/pull/3).

### Expected Results

In the codecov report for the pull request, I’d expect only coverage changes that would take place as a result of that pull request to be reported.

### Actual Results

When codecov computes coverage changes, it selects commit A as the base commit since it’s the first common commit between main and the PR branch. As a result, codecov will report that the PR will cause the change in coverage caused by commit B despite the PR having nothing to do with commit B.

### Additional Information

It seems to me like codecov’s uploader should report that main was on commit B when CI ran and then compare the coverage change between the PR and commit B.

Assuming that’s not going to happen anytime soon, what’s the best way to solve this? Is it to manually set the `--parent` option on the codecov uploader? Is it to force all PRs to be up-to-date with the target branch?

---

<div class="post-metadata">

**Author:** ![tom](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/tom/32/8_2.png) [@tom](https://community.codecov.com/u/tom)\
**Post date:** [February 3, 2023, 4:54am UTC](https://community.codecov.com/t/selected-base-commit-when-pr-is-based-on-an-older-commit-of-the-target-branch/4101/2 "2023-02-03T04:54:04Z")

</div>

@bmw, we use `commit A` in all of these cases because we cannot always make assumptions on the merge of PR and `commit B`. It is possible to use the `--parent` option to spoof it, but honestly, I think it’s more of a pain to handle, and will cause you headaches down the road if you’re not careful.

---

<div class="post-metadata">

**Author:** ![bmw](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/bmw/32/393_2.png) [@bmw](https://community.codecov.com/u/bmw)\
**Post date:** [February 3, 2023, 8:01pm UTC](https://community.codecov.com/t/selected-base-commit-when-pr-is-based-on-an-older-commit-of-the-target-branch/4101/3 "2023-02-03T20:01:40Z")

</div>

Thanks for the quick response!

Can you tell or link me to more info about the kind of problems I may have if I set `--parent`?

Alternatively, can you tell me another way to solve the problem of unrelated coverage changes being reported in PRs like this? Is the best option to force PRs to be up-to-date with the target branch? Is there anything else?

---

<div class="post-metadata">

**Author:** ![tom](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/tom/32/8_2.png) [@tom](https://community.codecov.com/u/tom)\
**Post date:** [February 7, 2023, 2:29pm UTC](https://community.codecov.com/t/selected-base-commit-when-pr-is-based-on-an-older-commit-of-the-target-branch/4101/4 "2023-02-07T14:29:30Z")

</div>

@bmw, I don’t have a resource or page to point you at, this is just a behavior that we don’t necessarily encourage and won’t cleanly solve your problem. To be clear, we will always use the first commit before a branching that has coverage as the BASE. As an example,

```auto
---A---B (main)
    \
     ----C (feature)

```

We will never use `B` as the base commit to compare against `C`. You will need to keep the PR up to date with `B` if you want to use that as the BASE commit.

---

<div class="post-metadata">

**Author:** ![bmw](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/bmw/32/393_2.png) [@bmw](https://community.codecov.com/u/bmw)\
**Post date:** [February 10, 2023, 4:06pm UTC](https://community.codecov.com/t/selected-base-commit-when-pr-is-based-on-an-older-commit-of-the-target-branch/4101/5 "2023-02-10T16:06:13Z")

</div>

Got it. Thanks.

Sorry for continuing to push this issue, but can you help me understand what kind of problems can occur if `--parent` is set to the latest commit on the target branch? In the past, my team and I weren’t enthusiastic about requiring all PRs to be up-to-date so understanding the pitfalls here would help us.

---

<div class="post-metadata">

**Author:** ![tom](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/tom/32/8_2.png) [@tom](https://community.codecov.com/u/tom)\
**Post date:** [February 10, 2023, 10:50pm UTC](https://community.codecov.com/t/selected-base-commit-when-pr-is-based-on-an-older-commit-of-the-target-branch/4101/6 "2023-02-10T22:50:00Z")

</div>

It is likely to really mess with your commit tree (because we take `--parent` as the correct one going forward) further down the road. If you do not upload coverage for every commit, you will probably see wildly inaccurate coverage for some commits.

This is really a, yes, we support `--parent` as a feature, but you’re on your own in knowing your codebase the best.
