Skip to content
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

[FR] New mergeMethod merge-ff to only merge when un-fast-forwardable, otherwise hard reset #448

Open
Rongronggg9 opened this issue May 31, 2022 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Rongronggg9
Copy link

Rongronggg9 commented May 31, 2022

A nice mix of two current mergeMethod: hardreset and merge. Effectively simulate the default git merge behavior and make the commit history clean.

A use case:
DIYgod/RSSHub has a pull.yml configuration file with mergeMethod: merge to prevent pull[bot] from overriding downstream manipulated forks (DIYgod/RSSHub#9710). In such a case, merge-ff is a better solution.

@wei
Copy link
Owner

wei commented Nov 1, 2022

merge ff isn't a supported merge method on GitHub pull requests. I recommend using a github actions to achieve your specific use-case.

@wei wei closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2022
@Rongronggg9
Copy link
Author

merge ff isn't a supported merge method on GitHub pull requests. I recommend using a github actions to achieve your specific use-case.

Nope. It seems that you misunderstood my words. I did know and didn't mean to use the nonexistent ff-merge method. Instead, if the PR is ff-able, hardreset instead of merge it.

The title is:

[FR] New mergeMethod merge-ff to only merge when un-fast-forwardable, otherwise hard reset

@wei wei reopened this Nov 1, 2022
@wei
Copy link
Owner

wei commented Nov 1, 2022

Thanks for the clarification. Could you help me identify if ff-able status on a PR can be retrieved using GitHub API?

https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request

@Rongronggg9
Copy link
Author

Rongronggg9 commented Nov 1, 2022

Some tricks are needed. It must be a fork of the upstream repo.
Any commits of any forks can be visited from the upstream repo. Thanks to this feature, we can simply compare the branch HEAD between the fork and its upstream repo:

https://api.github.com/repos/{upstream_owner}/{upstream_repo}/compare/{upstream_branch_HEAD}...{fork_branch_HEAD}

https://docs.github.com/en/rest/commits/commits#compare-two-commits

An un-ff-able sample here:

https://api.github.com/repos/DIYgod/RSSHub/compare/0397ca906561bfc760bc2dcf9043dd3121d2294e...eb1a55f5fe356070091b29656af3c3b63ff4b8aa
{
  "status": "diverged",
  "ahead_by": 133, // the fork is ahead upstream by 133 commits
  "behind_by": 1 // the fork is behind upstream by 1 commit
}

An ff-able sample here:

https://api.github.com/repos/DIYgod/RSSHub/compare/0397ca906561bfc760bc2dcf9043dd3121d2294e...ce92931478e6deae9c22cfbad3fcf37e72927cc4
{
  "status": "behind", // ff-able
  "ahead_by": 0,
  "behind_by": 1 // the fork is behind upstream by 1 commit
}

Note: I use a commit SHA for upstream_branch_HEAD to make the result reproducible, but I recommend using its branch name instead, sample here:

https://api.github.com/repos/DIYgod/RSSHub/compare/master...ce92931478e6deae9c22cfbad3fcf37e72927cc4

Alternatively, if it is a fork and does not use a branch name different from upstream, maybe https://docs.github.com/en/rest/branches/branches#sync-a-fork-branch-with-the-upstream-repository? It defaults to ff-merge if ff-able. But the disadvantage is it will create a merge commit automatically if not ff-able and we can't take the control of this behavior.

@wei
Copy link
Owner

wei commented Nov 2, 2022

Thanks for the thorough example! It looks like pull just needs to call the compare endpoint you shared when the mergeMethod: merge-ff is specified. Sounds like a great workaround.

@wei wei added enhancement New feature or request help wanted Extra attention is needed labels Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants