Skip to content
Versora

Manual

Checks

Push rules

8 min read

On this page

GitLab Premium lets the project require a pattern in commit messages, company emails, Signed-off-by (DCO), signed commits, a pattern for branch names and a maximum file size. When a commit doesn't comply, the server rejects the whole push, and you only find out afterwards. Versora checks the same rules earlier, on commit and on push, and offers the fix.

Without GitLab Premium (or on another server), the team can share the same rules in a file in the repository, and each person can have local rules on their own machine only.

Where the rules come from

SourceWhere it livesWho sees it
GitLab (server)the project's push rules, read through the GitLab Premium APIeveryone, and the server rejects the push
.versora/push-rules.jsona versioned file in the repositorywhoever uses Versora in the repository
local rulesPreferences › Push rules, on this computer onlyonly you

Each source is checked on its own: the commit must meet all of them. Each finding says which sources require it (the "Required by" badge).

To read the server rules, the token registered in Git servers needs the api scope and the Maintainer role on the project. Without that, only the file and the local rules apply.

The rules

RuleKeyWhat it requires
Required messagecommit_message_regexevery commit message must match the expression (multiline mode: ^ and $ apply to each line)
Forbidden messagecommit_message_negative_regexno message may match the expression
Branch namebranch_name_regexthe name of a branch that's new on the remote; the default branch always passes. GitLab also rejects names that start with 40 hexadecimal characters
Author emailauthor_email_regexapplies to both the author and the committer email
Forbidden file namesfile_name_regexnew files whose path matches the expression are rejected
Maximum file sizemax_file_sizeadded or changed files over the limit, in MB (0 = no limit)
Reject unsigned commitsreject_unsigned_commitsevery commit signed (GPG, SSH or X.509)
Require Signed-off-by (DCO)reject_non_dco_commitsevery message with Signed-off-by: Name <email>
Verified committercommit_committer_checkthe committer email is a verified email of your GitLab account
Author name matches the accountcommit_committer_name_checkwhen author and committer share an email, the author name is your GitLab account name
Author is a GitLab usermember_checkGitLab checks that the author is a GitLab user; Versora only warns when the author isn't you
Don't delete tagsdeny_delete_tagdeleting a tag with push is rejected

Expressions use RE2, as in GitLab (no lookahead or backreferences).

When the check runs

  • Before committing: message, identity, signature, Signed-off-by and the staged files.
  • Before pushing: all the commits the remote doesn't have yet (at most the 300 most recent), the name of a new branch and, when you delete a tag on the remote, the tag rule.
  • From the palette (Ctrl+P): "Check push rules" (detail: "What GitLab would reject if the current branch were pushed now").

Push rules run before the other checks: if the server is going to reject it, you find out before deciding anything else. While they're being checked, you see "Checking push rules…".

Before the commit

When the commit doesn't meet a rule, the Before committing: push rules dialog opens, with "This commit breaks the push rules (GitLab): GitLab will reject its push." (or "… the repository push rules (.versora/push-rules.json)."). Each finding comes with a hint for the fix and, when possible, the button that fixes it:

FindingFix in the dialog
"The message is missing the Signed-off-by line (DCO)"Add Signed-off-by (shows the line that goes in) and the Always add it in this repository checkbox
"assets/intro.mp4 is 25 MB, over the 10 MB limit" or a forbidden file nameUnstage the file
"The commit won't be signed (signing is off in this repository)"Set up signing… (opens Preferences › Commit)
author/committer email or nameFix your identity… (opens Preferences › Profile)
message that doesn't match the pattern"Go back and fix the message."

With everything resolved, you see "All good: the commit meets the push rules." and the main button is Commit. Otherwise, Commit anyway. Back cancels the commit.

Before the push

When something doesn't meet the rules, GitLab will reject this push (or Outside the repository push rules) opens, with "From feature/login to origin/feature/login — 3 commits aren't on the remote yet.":

  • Branch name on the remote: feature/login: the name doesn't match the pattern. Rename the branch… opens the Rename feature/login dialog with the required pattern ("The name must match the pattern ^(feature|hotfix)/."), and then "Branch renamed to … Push again."
  • 3 commits break the rules: each commit with the SHA, the summary and what's missing.
  • How to fix, with the fixes:
    • Fix automatically…: rewrites the unpushed commits to add Signed-off-by, sign them again and redo author and committer with your current identity, depending on what's missing. The Fix the commits confirmation says how many commits will be rewritten and what changes (for example, "The 3 most recent commits on feature/login will be rewritten to add Signed-off-by and sign them again. … These commits aren't on the remote yet. You can undo with Ctrl+Z.");
    • Edit in an interactive rebase…: opens the interactive rebase with the commits to fix marked (for messages that don't match the pattern and files to take out); adjust, start the rebase and push again;
    • Fix your identity… and Set up signing…: take you to Preferences.

After the fixes, "All good: the commits meet the push rules." and Push. Otherwise, Push anyway.

What Versora does in git

The automatic fix is a rebase of the commits not pushed yet:

bash
# add Signed-off-by and sign again
git rebase --force-rebase --autostash --signoff --gpg-sign <base>

# redo author and committer with the current identity
git rebase --force-rebase --autostash --exec "git commit --amend --no-edit --no-verify --allow-empty --reset-author" <base>

It only runs on the checked-out branch, with no operation in progress and no merge commits among the commits to fix. Add Signed-off-by, on commit, only changes the message before committing.

How to undo

Ctrl+Z undoes the automatic fix ("Fix commits (push rules)") and the branch rename ("Rename branch"). The fixed commits hadn't gone to the remote yet, so nothing needs a force push.

Deleting a tag with "Don't delete tags"

When you delete a tag on the remote (tag menu › Delete v1.2.0 from remote), if the rules forbid it, Delete tag v1.2.0 on the remote? opens:

  • with the server rule: "The push rules of origin (GitLab) don't allow deleting tags with push: the server will reject it." and "In GitLab, someone with permission can delete the tag from the project's Tags page.";
  • with the file or local rule: "The repository push rules for origin (.versora/push-rules.json) don't allow deleting tags." and "This is a team rule: make sure before going ahead."

Delete anyway continues. See Tags.

Checking from the palette

"Check push rules" checks the current branch against the upstream (or against origin with the same name) and:

  • with problems, opens Push rules check with the list and the fixes;
  • with no problems, says "All good: 3 commits checked for origin/feature/login (GitLab)." or "All good for origin/feature/login: there are no new commits to check, and the branch name is accepted (GitLab).";
  • with no rules, "There are no active push rules in this repository (server, file or local).".

Preferences › Push rules

Where to find it

  • Preferences (Ctrl+,) › Push rules.
  • Palette: "Preferences: Push rules".

What's on the page

GroupWhat it shows
ChecksBefore committing › Check and Before pushing › Check (on by default)
Where the rules come from — appthe server ("3 active rules in project equipe/app on gitlab.exemplo.com.", "Read 5 min. ago"), with Check again; the repository file (or "Doesn't exist…"); the local rules
Active rulesthe table of all the rules in effect, by source
Local rulesthe local rules editor, with the same fields as GitLab, Save to the repository file… and Clear local rules
Signed-off-byAdd to every commit (like git commit -s), only in this repository
Format of .versora/push-rules.jsonthe file format

Sharing the rules with the team

  1. Set the rules in Local rules.
  2. Click Save to the repository file….
  3. In the Save the rules to the repository dialog, leave Clear the local rules after saving checked and click Save. If the file already exists, it's replaced.
  4. Commit .versora/push-rules.json ("Rules saved to .versora/push-rules.json. Commit it so they apply to the team.").

The file format

A JSON object with the same keys as GitLab's push rules API (you can copy the API response). All keys are optional; empty, false or 0 = rule off. In JSON, backslashes are doubled. max_file_size is in MB.

JSON
{
  "commit_message_regex": "^(feat|fix|docs|chore)(\\(.+\\))?: ",
  "commit_message_negative_regex": "(?i)\\bwip\\b",
  "branch_name_regex": "^(feature|bugfix|hotfix|release)/[a-z0-9._-]+$",
  "author_email_regex": "@empresa\\.com\\.br$",
  "file_name_regex": "\\.(exe|dll|jar)$",
  "max_file_size": 10,
  "reject_non_dco_commits": true,
  "deny_delete_tag": true
}

The $schema, description and comment keys can document the file; prevent_secrets is accepted and ignored (secrets are handled by the Secrets check). Other unknown keys are ignored with a warning.

Caveats and messages

  • "This server has no per-project push rules (GitLab Free/CE), or the project wasn't found.": on GitLab Free, use the repository file.
  • "The token isn't allowed to read push rules (the API requires the Maintainer role on the project).": the file and the local rules apply.
  • "The remote is on GitHub, which has no GitLab-style push rules: only the file and local rules apply."
  • "The server didn't answer just now, so the rules read earlier were used. (…)" and "The server didn't answer within 8 seconds, so only the file and local rules were applied. Its answer will be kept for the next check.": the server was slow.
  • "Versora couldn't evaluate the expression … (GitLab): …. GitLab still enforces the rule.": the expression uses something the app doesn't understand; the server keeps checking it.
  • ".versora/push-rules.json has an error and was ignored: Invalid JSON: …": fix the file.
  • "1200 commits aren't on the remote yet; only the 300 most recent were checked."
  • "To fix the commits here, check out feature/login." and "There are merge commits among the commits to fix, and the automatic fix would flatten them: fix them one by one.": the automatic fix doesn't apply; use the interactive rebase.
  • "Rules that compare the committer with the GitLab account couldn't be checked (they need a GitLab server with a token under Git servers)."
  • "Checking the push rules failed: …": the app tells you and goes on.

See also