Skip to content

Fix [behind-upstream] when dealing with subtrees #2005

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

Merged
merged 2 commits into from
May 23, 2025

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented May 22, 2025

This PR fixes our logic flawed logic for the [behind-upstream] handler, which just looked at the parent commit of the first commit of the branch, which doesn't work in the presence of subtree.

Instead we are using git merge-base, provided by GitHub compare API (example from the issue). This is more robust at it gives us the first common ancestors between the master branch and the pull branch.

(a side bonus is that [behind-upstream] handler is now much less complex)

Fixes #2003

Copy link
Contributor

@xizheyin xizheyin left a comment

Choose a reason for hiding this comment

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

Quite a beautiful solution

);

Some(format!(
r"This PR is based on an upstream commit that is {} days old.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to list the link of base commit to give more adequate hints?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could give similar instructions as when we detect merge commits.

You can start a rebase with the following commands:
```shell-session
$ # rebase
$ git pull --rebase https://github.com/{repository_name}.git {default_branch}
$ git push --force-with-lease
```"

Copy link
Contributor

Choose a reason for hiding this comment

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

We could make upstream commit be a link to the merge base, to show people the old master commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it will be more convenient for the author to check the mistakes. :)

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Shame that GitHub doesn't include this directly in the main PR message. I did a few experiments and tried to think of simpler heuristics, but the merge base seems like it should be robust against various edge cases and issues. Left one nit, but with or without dealing with it feel free to merge.

);

Some(format!(
r"This PR is based on an upstream commit that is {} days old.
Copy link
Contributor

Choose a reason for hiding this comment

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

We could make upstream commit be a link to the merge base, to show people the old master commit.

@Urgau
Copy link
Member Author

Urgau commented May 23, 2025

I may not be avalaible this week-end, I will merge it now, as to fix the false positives, and fix the nits in a follow-up PR.

@Urgau Urgau added this pull request to the merge queue May 23, 2025
Merged via the queue into rust-lang:master with commit c335263 May 23, 2025
3 checks passed
@Urgau Urgau deleted the fix-behind-upstream branch May 23, 2025 10:18
@xizheyin
Copy link
Contributor

I would like to fix the nit if you are not free. I just finished my vocation.

@Urgau
Copy link
Member Author

Urgau commented May 23, 2025

Sure, go ahead.

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.

Incorrect warning about outdated upstream commit
3 participants