Updated on 2023-08-07 GMT+08:00

Commit Rules

To configure commit rules, you can choose Settings > Policy Settings > Commit Rules on the repository details page.

On the Commit Rules page, you can establish a series of code commit verification and restriction rules to ensure code quality. The settings take effect only for the configured repository.

Only the repository administrators and owners can view this tab page and configure code commit rules.

Table 1 Parameters on the Commit Rules page

Parameter

Description

Reject unsigned commits

Only signed commits can be pushed to the repository.

CodeArts Repo signature mode:

When performing online commit in CodeArts Repo, use the following format to compile and submit information:

commit message             # Enter the customized submission information.
                           # This is a blank line.
Signed-off-by: User-defined signature   # Enter the user-defined signature after Signed-off-by:

Git client signature mode:

When running the commit command on the Git client, you need to add the -s parameter.

git commit -s -m "<your commit message>"

You need to configure the signature and email address on the client in advance.

Tags cannot be deleted

After this option is selected, tags cannot be deleted on the page or by running commands on the client.

Prevent committing secrets

Confidential files include ssh_server_rsa, id_rsa, and id_dsa. For details, see Description of Confidential Files.

Prevent git push -f

Indicates whether users can run the git push -f command on the client to push code.

git push -f indicates that the current local code repository is pushed to and overwrites the code in CodeArts Repo.

In general cases, you are not advised to use this command.

Creating a Commit Rule

The repository administrator and repository owner can create a commit rule for a branch of the repository. Only one commit rule can be set for each branch.

Table 2 Parameters

Parameter

Description

Rule Name

This parameter is mandatory. The value contains a maximum of 200 characters.

Branch

This parameter is mandatory. Select a branch from the drop-down list or create a regular expression. This field supports a maximum of 500 characters.

Commit rules

Parameters in this area are optional.

  • Commit Message: This parameter is left empty by default, indicating that the commit message is not verified, and any parameter can be committed. This field supports a maximum of 500 characters.

    For example, you can set the format rule of the commit message as follows:

    TraceNo:((REQ[0-9]{1,9})|(DTS[0-9]{13}))(.|\n|.\n)Author:.*(.|\n|.\n)Description:.*

    The following is a commit message that complies with the rule:

    TraceNo:DTS20220801156688 Author:cwx1094057 Description:testpushfile

    The following is a commit message that does not comply with the rule:

    new files
  • Negative Match: This parameter is left empty by default, indicating that the commit information is not verified, and any parameter can be committed. This field supports a maximum of 500 characters.

    For example, you can set the format rule of the commit message as follows:

    TraceNo:((REQ[0-9]{1,9})|(DTS[0-9]{13}))(.|\n|.\n)Author:.*(.|\n|.\n)Description:.*
  • Commit author: This parameter is left empty by default, indicating that the commit author is not verified, and any parameter can be committed. This field supports a maximum of 200 characters.

    The commit author can run the git config -l command to view the value of user.name and run the git config --global user.name command to set the value of user.name.

    Example:

    Rules for setting the commit author: ([a-z][A-Z]{3})([0-9]{1,9})
  • Commit author's email: This parameter is left empty by default, indicating that the commit author email is not verified, and any parameter can be committed. This field supports a maximum of 200 characters.

    The commit author can run the git config -l command to view the value of user.email and run the git config --global user.email command to set the email address.

    Example:

    Rules for setting the email of the commit author: @huawei.com$

Basic Attributes

Parameters in this area are optional.

  • File Name That Cannot Be Committed: This parameter is left empty by default, indicating that the file name is not verified, and any file can be committed. You are advised to use standard regular expressions to match the file name. By default, the file path is verified based on the file name rule. This field supports a maximum of 2000 characters.

    Example:

    Set  File Name That Cannot Be Committed: (\.jar|\.exe)$
  • Each File Size (MB): The default value is 50, indicating that the push is rejected if the size of the added or updated file exceeds 50 MB. The administrator can change the value from 0 to 200.
NOTE:

When a repository is created, the maximum size of a single file in the default submission rule (default) is 200 MB. When a repository is created, the recommended maximum size of a single file in the default submission rule is 50 MB.

Binary Rules

Parameters in this area are optional.

These parameters are not set by default, indicating that binary files can be uploaded. The size of a single file cannot exceed the upper limit. Allow changes to binary files, Repo File Whitelist, and Privileged User take effect only when Do not allow new binary files is selected. If you select Allow changes to binary files, binary files in modifiable state are not intercepted and can be directly uploaded. Binary files can be deleted without binary check.

  • Do not allow new binary files (privileged users excepted)
  • Allow changes to binary files (privileged users excepted)
  • Binary file trustlist (files that can be directly imported to the database. This field supports a maximum of 2000 characters.)
  • Privileged users (privileged users can directly push all binary files to the database. This field supports a maximum of 2000 characters.)

Effective Date

This parameter is optional.

Before being pushed, all commitments created after the date specified by this parameter must match the hook settings. If this parameter is left empty, all commitments are checked regardless of the committing date.

You are not advised to store binary files in CodeArts Repo. Otherwise, the performance and stability of the code repository will be affected.