Updated on 2024-07-05 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.

All repository members can view this page. For details about whether a repository member has repository setting permissions, refer to the Permissions page.

Table 1 Parameters on the Commit Rules page

Parameter

Description

Reject non-signed-off-by commits

Only signed-off-by commits are 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.

Reject commits not signed by GPG

Only GPG-signed commits are pushed to the repository.

Configure a GPG key:

git config --global user.signingkey "your GPG private key"

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"

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

git tag -s -m "Your tag 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 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 using 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.

Priority matching mechanism of commit rules:

1. The target branch preferentially matches the configured commit rules.

2. If no rule is exactly matched, the first rule fuzzily match is used.

3. If no rule is fuzzily matched, the default rule is used.

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})(.|\n|.\n)Author:.*(.|\n|.\n)Description:.*

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

    TraceNo:REQ1234567 Author:**** 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})(.|\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 Changed: 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 2,000 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)
  • Repo File Whitelist (files that can be directly imported to the database. This field supports a maximum of 2,000 characters.)
  • Privileged User (Privileged users can directly push all binary files to the repository. Max. 50 privileged users.)
NOTE:

Repository members with the push permission can be privileged users.

Effective Date

Parameters in this area are 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 storing binary files in CodeArts Repo. Otherwise, the performance and stability of the code repository will be affected.

Table 3 Examples of common regular expressions

Rule

Examples

Single a, b, or c

[abc]

Characters other than a, b, or c

[^abc]

Lowercase letters ranging from a to z

[a-z]

Characters other than the range of a to z

[^a-z]

Uppercase and lowercase letters in the range of a to z or A to Z

[a-zA-Z]

Any single character

.

Either a or b

a|b

Any blank character

\s

Non-blank character

\S

Arabic numeral character

\d

Non-Arabic numeral characters

\D

Letters, digits, or underscores (_)

\w

Characters other than letters, digits, or underscores (_)

\W

Match the content in parentheses (not capture)

(?:...)

Match and capture the content in parentheses

(...)

No or one a

a?

No or more a's

a*

One or more a's

a+

Three a's

a{3}

More than three a's

a{3,}

3 to 6 a's

a{3,6}

Beginning of text

^

End of text

$

Word boundary

\b

Non-word boundary

\B

Line breaker

\n

Carriage return character

\r

Tab key

\t

Null string

\0