spr icon indicating copy to clipboard operation
spr copied to clipboard

How to land a stack at once?

Open rvi opened this issue 1 year ago • 10 comments

I have a bunch of PRs that are approved, but when I run git spr merge it merges only the first PR, once it's done it pass the checks on all the other PRs and I can merge the next one once the tests are passed. Is there something I'm missing here on how to land those PRs faster? Ideally everything at once?

Thanks

rvi avatar Aug 16 '22 18:08 rvi

That's very surprising behavior, the default behavior for git spr merge is to merge as much of the stack as possible in a single shot. Are all the check marks green when you run git spr status? That might shed clue into why only a single pr is merged. If you have multiple ready (all green) prs in a stack and you only want to merge a subset, you can use git spr merge --count X to only merge a subset.

ejoffe avatar Aug 16 '22 21:08 ejoffe

Thanks I think it's because the github checks don't run on the other PRs (See screenshot below, my tests didn't run on PR 2 and 3). Only on the first one, the one that is about to be merged in my main branch.

What is stack check? I'm pretty sure everything can be merged. Not sure why we have ❌ everywhere.

 ┌─ github checks pass
 │ ┌── pull request approved
 │ │ ┌─── no merge conflicts
 │ │ │ ┌──── stack check
 │ │ │ │
[❌❌✅❌] https://github.com/company/repo/pull/958 : PR 3
[❌❌✅❌] https://github.com/company/repo/pull/957 :  PR 2
[✅❌✅❌] https://github.com/company/repo/pull/956 : PR 1

In my config file:

requireChecks: true
requireApproval: true

Another thing I don't understand is on PR 2 and 3 I can directly merge them, approval is not required? This is not normal. Do you think it's because those PR are not against my main (protected) branch?

Screen Shot 2022-08-16 at 4 18 55 PM

rvi avatar Aug 16 '22 23:08 rvi

Ok, I think I understand now. For this to work well you should setup a branch protection rule for pr/*/*/* . The rule should run all the checks. This way your checks will run for all your prs, and you'll be able to have multiple requests with checks passed at the same time, then you'll be able to merge them together. Regarding PR2 and PR3, that's exactly right, and you shouldn't merge them in the ui as you'll end up merging PR2 into PR1, it will just add confusion. The best is to merge all the prs using the spr cli. The stack check makes sure that if there is a pr in the stack that doesn't pass all the checks, it will block all prs above it from merging even if they pass all the checks. Hope that helps, let me know if this solves your issue.

ejoffe avatar Aug 16 '22 23:08 ejoffe

Got it thanks for the explanation on the stack check, makes sense now! Maybe we could mention this in the readme? Yeah that's what I thought, those branches should be protected as well in order to run the checks and force being reviewed. Thanks for confirming it!

rvi avatar Aug 17 '22 07:08 rvi

Thanks. I was able to change the settings on my protected branch but now spr can't force push on them. Any idea?

$ git spr update
> git rev-parse --show-toplevel
> git fetch
> git branch --no-color
> git rebase origin/main --autostash
> github fetch pull requests
> git branch --no-color
> git branch --no-color
> git branch --no-color
> git log --no-color origin/main..HEAD
> git status --porcelain --untracked-files=no
> git push --force --atomic origin <commit_hash>:refs/heads/pr/rvi/myBranch/commitID
git error: remote: error: GH006: Protected branch update failed for refs/heads/pr/rvi/myBranch/commitID.        
remote: error: 2 of 2 required status checks are expected. At least 1 approving review is required by reviewers with write access.        
To github.com:company/repo.git
 ! [remote rejected]   <commit_hash> -> pr/rvi/myBranch/commitID (protected branch hook declined)
error: failed to push some refs to 'github.com:company/repo.git'
error: exit status 1

Here are my settings: Screen Shot 2022-08-17 at 12 04 56 PM Screen Shot 2022-08-17 at 12 05 09 PM

rvi avatar Aug 17 '22 19:08 rvi

Uncheck the "Require pull request before merging" and you can check the "Require linear history"

ejoffe avatar Aug 17 '22 19:08 ejoffe

Thanks, I still have the same issue unfortunately :/

 ! [remote rejected] (protected branch hook declined)

rvi avatar Aug 17 '22 20:08 rvi

This is my branch protection rule Screen Shot 2022-08-17 at 1 32 39 PM

ejoffe avatar Aug 17 '22 20:08 ejoffe

@rvi - any luck with this?

ejoffe avatar Aug 19 '22 02:08 ejoffe

Thanks for checking in Eitan!

I play around a lot with it on Wednesday, tested so many configurations but nothing seemed to work. Now it's working with Require Pull Request before merging as well as status check. I'm not entirely sure what changed and why now I can force push but it seems to work since yesterday.

rvi avatar Aug 19 '22 18:08 rvi