Create a User-defined Repository Category

You can add your own categories, if you have access to the TeamForgeGerritMappings.xml file.

To add a new user-defined repository category, follow these steps:

  1. Create an empty Git repository, say test-git-repo.
    • git init `test-git-repo`
  2. Download the commits, files, and refs from the remote repository to your local repository.
    • git fetch ssh://admin@<your_domain>:29418/TF-Projects refs/meta/config:meta-config
  3. Check out the TeamForgeGerritMappings.xml file.
    • git checkout meta-config
  4. Open the TeamForgeGerritMappings.xml file in the editor.
    • vim TeamForgeGerritMappings.xml

    Add a new repository category, say "pull_request_new" to it.

    <RepoCategory name="pull_request_new" keepRightsAddedInGerrit="false">
         <ScmAdmin>
             <GerritRead value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritCodeReview upperRange="2" lowerRange="-2" refPattern="refs/*" exclusive="false"/>
             <GerritVerify upperRange="1" lowerRange="-1" refPattern="refs/*" exclusive="false"/>
             <GerritSubmit value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritPush forcePush="true" value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritCreateReference value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritForgeAuthorIdentity value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritForgeCommitterIdentity value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritForgeServerIdentity value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritOwner value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritAbandon value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritPushMerges value="ALLOW" refPattern="refs/for/refs/*" exclusive="false"/>
             <GerritPush forcePush="false" value="ALLOW" refPattern="refs/for/refs/*" exclusive="false"/>
             <GerritRebase value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritPushAnnotatedTag forcePush="false" value="ALLOW" refPattern="refs/tags/*" exclusive="false"/>
             <GerritPushSignedTag value="ALLOW" refPattern="refs/tags/*" exclusive="false"/>
             <!-- protected branches-->
             <GerritPush forcePush="true" value="ALLOW" refPattern="refs/heads/{RepoParams/@protectedBranches}" exclusive="true"/>
             <GerritSubmit value="ALLOW" refPattern="refs/for/refs/heads/{RepoParams/@protectedBranches}" exclusive="true"/>
         </ScmAdmin>
         <ScmDeleteView>
             <GerritRead value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritCodeReview upperRange="2" lowerRange="-2" refPattern="refs/*" exclusive="false"/>
             <GerritVerify upperRange="1" lowerRange="-1" refPattern="refs/*" exclusive="false"/>
             <GerritSubmit value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritPush forcePush="true" value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritCreateReference value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritForgeAuthorIdentity value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritForgeCommitterIdentity value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritPushMerges value="ALLOW" refPattern="refs/for/refs/*" exclusive="false"/>
             <GerritPush forcePush="false" value="ALLOW" refPattern="refs/for/refs/*" exclusive="false"/>
             <GerritRebase value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritPushAnnotatedTag forcePush="false" value="ALLOW" refPattern="refs/tags/*" exclusive="false"/>
             <GerritPushSignedTag value="ALLOW" refPattern="refs/tags/*" exclusive="false"/>
             <!-- protected branches-->
             <GerritPush forcePush="false" value="DENY" refPattern="refs/heads/{RepoParams/@protectedBranches}" exclusive="true"/>
             <GerritSubmit value="DENY" refPattern="refs/for/refs/heads/{RepoParams/@protectedBranches}" exclusive="true"/>
         </ScmDeleteView>
         <ScmCommitView>
             <GerritRead value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritCodeReview upperRange="2" lowerRange="-2" refPattern="refs/*" exclusive="false"/>
             <GerritVerify upperRange="1" lowerRange="-1" refPattern="refs/*" exclusive="false"/>
             <GerritSubmit value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritPush forcePush="false" value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritCreateReference value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritPush forcePush="false" value="ALLOW" refPattern="refs/for/refs/*" exclusive="false"/>
             <GerritRebase value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritPushAnnotatedTag forcePush="false" value="ALLOW" refPattern="refs/tags/*" exclusive="false"/>
             <GerritPushSignedTag value="ALLOW" refPattern="refs/tags/*" exclusive="false"/>
             <GerritPushMerges value="ALLOW" refPattern="refs/for/refs/*" exclusive="false"/>
             <!-- protected branches-->
             <GerritPush forcePush="false" value="DENY" refPattern="refs/heads/{RepoParams/@protectedBranches}" exclusive="true"/>
             <GerritSubmit value="DENY" refPattern="refs/for/refs/heads/{RepoParams/@protectedBranches}" exclusive="true"/>
         </ScmCommitView>
         <ScmViewOnly>
             <GerritRead value="ALLOW" refPattern="refs/*" exclusive="false"/>
             <GerritCodeReview upperRange="1" lowerRange="-1" refPattern="refs/*" exclusive="false"/>
             <GerritPushMerges value="ALLOW" refPattern="refs/for/refs/*" exclusive="false"/>
             <GerritPush forcePush="false" value="ALLOW" refPattern="refs/for/refs/*" exclusive="false"/>
             <GerritRebase value="ALLOW" refPattern="refs/*" exclusive="false"/>
         </ScmViewOnly>
     </RepoCategory>
  5. Run this command to add the changes to your local directory.
    • git add TeamForgeGerritMappings.xml
  6. Commit the changes.
    • git commit -m "add user-defined repo type 'pull_request_new'
  7. Check-in the changes to your remote repository
    • git push ssh/admin@<your-domain>:29418/TF-Projects meta-config:refs/meta/config

    Now the user-defined category Pull Request New is added successfully.

    The master branch becomes the default protect branch for repositories that belong to the user-defined repository category, provided that its name is prefixed with "Pull Request".
    Once the repository is created, the master branch becomes a protected branch of the repository by default.