Apply Gerrit Submit-Requirement to Multiple Branches

117 views
Skip to first unread message

Ioana Silas

unread,
Jan 21, 2026, 4:46:37 AMJan 21
to Repo and Gerrit Discussion
Hello,

From what I have seen, defining function = MaxWithBlock is deprecated in the label definition. As a result, we need to use submit-requirements. However, I would want the submit-requirement to apply to the same branches as those defined in the label definition. 
Let's say we have this in the label def:
branch = ^refs/heads/master|refs/heads/(aaa|bbb)/[a-zA-Z0-9_-]+|refs/heads/bbb/(?!exempt[1,3])(?!another_one[1,2,3])

The problem is that the applicableIf block form the submit-requirement does not support the same kind of regex and I have trouble finding an efficient way of defining exempt branches. So far, I came up with this:
applicableIf = -branch:refs/heads/bbb/exempt1 AND -branch:refs/heads/bbb/exempt3 AND -branch:refs/heads/another_one1 AND -branch:refs/heads/bbb/another_one2 AND -branch:refs/heads/bbb/another_one3... (there are a lot of branches).

This does not seem like a viable solution long term, especially if new branches are added. Is there a better alternative?

Thank you.


Nuno Costa

unread,
Mar 20, 2026, 8:48:33 AMMar 20
to Repo and Gerrit Discussion
Try with escaped double quotes like below:

applicableIf =  branch:\"^refs/heads/master|refs/heads/(aaa|bbb)/[a-zA-Z0-9_-]+|refs/heads/bbb/(?!exempt[1,3])(?!another_one[1,2,3])\"

The Label to SR migration tool does this but be aware that it escapes too much, as I reported here >> https://issues.gerritcodereview.com/issues/493952648

Ioana Silas

unread,
Apr 3, 2026, 9:05:26 AM (2 days ago) Apr 3
to Repo and Gerrit Discussion
Hello Nuno,

Thank you for your answer. Escaping double quotes works, but there are some particularities to the allowed syntax.  After some research and testing, we have the following findings:
  • simple regex works without double quotes, but complex regex does not, so we recommend always using double quotes;
  • ?! is not supported; rather it is interpreted literally; instead, we have the ~ operator, which is set complement. We can use it to simulate behavior similar to ?!;
    • example1: applicableIf = -branch:refs/meta/config AND branch:\"^refs/heads/bbb/(?!exempt1)\"
      • expectation: it should apply to every bbb branch except exempt1
      • reality: it interprets ?!exempt1 literally, and there is no branch with that name. It ends up not being applied on any branch.
    • example2applicableIf = -branch:refs/meta/config AND branch:\"^~(refs/heads/bbb/exempt1)\"
      • this applies the submit-requirement to every branch that is not bbb/exempt1, or refs/meta/config.
      • it can be further modified to: applicableIf = branch:\"^~(refs/meta/config|refs/heads/bbb/exempt1)\"
  • both refs/heads/<branch-name> and <branch-name> should be supported (according to the documentation), but we found that refs/heads/<branch-name> does not work in all cases
    • example1: applicableIf = -branch:refs/meta/config AND branch:\"^~(refs/heads/bbb/exempt1.*|2)\"
      • expectation: we expected this to apply to non bbb/exempt1.* branches and non 2 branches.
      • reality: on multiple bbb that fit the bbb/exempt1.* pattern:  bbb/exempt12, bbb/exempt12 , bbb/exempt13  , but not on branch called 2.
      • from this result, we infer that refs/heads/bbb/exempt1.* is being interpreted literally, and since there is no branch called  refs/heads/bbb/exempt1.* , this does not limit the scope of the submit-requirement in any way.
    • example2: applicableIf = -branch:refs/meta/config AND branch:\"^~(bbb/exempt1.*|2)\"
      • if we remove refs/heads, this actually limits the scope of the submit-requirements as we expected the previous example to do.
  • [ ] is supported;
  • global matching is not supported: e.g. applicableIf = branch:^refs/meta/.* works, but applicableIf = branch:refs/meta/* does not;
  • .* can be replaced with @ according to author (maintainer) of dk.brics.automaton.
I hope this information proves to be useful.

Reply all
Reply to author
Forward
0 new messages