Accidentally pushing to refs/heads/refs/for/master

223 views
Skip to first unread message

Marquis Wong

unread,
Aug 2, 2022, 6:28:49 PM8/2/22
to Repo and Gerrit Discussion

Hello,


It is rare, but we've had cases where a user accidentally pushes to `refs/heads/refs/for/master` or `refs/refs/for/master`. In both cases, this prevents all users from pushing new changes until the offending branch is deleted.

To ssh://gerrit:29418/foo/bar ! [rejected] cfa36d7d5a61c6c45fa37227936c2687e2cdb26c -> refs/for/master (non-fast-forward) error: failed to push some refs to 'ssh://gerrit:29418/foo/bar' hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and integrate the remote changes hint: (e.g. 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

This isn't hard to fix for an admin, but is extremely confusing and disruptive to users. Is there any way to configure Gerrit to prevent users from creating `refs/for/*` branches?

We have Push and Create Reference permissions configured for refs/for/*, since we want people to be able to push feature branches without review.

I can't imagine any valid use case where someone wants to actually create a branch named `refs/for/master`. Maybe it would make sense to just hard-code Gerrit to deny pushes to `refs/heads/refs/for/*` and `refs/refs/for/*`?

(Semi-related, is it possible to allow people to Push to all branches besides refs/for/master?)

Thanks,
Marquis

Björn Pedersen

unread,
Aug 3, 2022, 2:52:01 AM8/3/22
to Repo and Gerrit Discussion


mar...@w-ng.com schrieb am Mittwoch, 3. August 2022 um 00:28:49 UTC+2:

Hello,


We have Push and Create Reference permissions configured for refs/for/*, since we want people to be able to push feature branches without review.


I would never grant create reference on refs/for as these are 'magic' branches.  If you want to allow  feature branches without review grant create refredencec and push on e.g. ref/heads/feature/* (choose a naming pattern to your liking).

Björn

Marquis Wong

unread,
Aug 5, 2022, 9:53:47 AM8/5/22
to Repo and Gerrit Discussion
Hi Björn,

That's a good suggestion, I will do that. Should have thought of that. Thank you.

Regardless, it might be a good idea to forbid creating branches that begin with "refs/for", since they are "magic" branches, so any attempt to make one is *probably* a mistake?

On a side-note and moderately amusing, my repo has the following branches, apparently.

ref/for/master
ref/for/master%submit
refs/for/master
refsf/for/master
resf/for/master

I will definitely go with a more restrictive naming pattern like refs/heads/feature/*.

Thanks,
Marquis
Reply all
Reply to author
Forward
0 new messages