Commit committer name check with the commit author_name

What does this MR do and why?

Related to issue #375339 (closed) Related to MR !101909 (merged)

In this issue, the user wants a push rule to align the commit author in the git log with the user's account name in GitLab. In this MR, we use commiter_name to compare with GitLab account name, if so, the user can still push commit with author of another name.

But to prevent some cherry-pick or rebase commit from being blocked by validation, Now the logic is changed to compare committer's email and author's email first, and if they're the same, then compare the author's name with the GitLab user's name, and throw an error if the user names don't match. If the committer's email differs from the author's email, it is not checked. This avoids checking for a commit from cherry-pick or rebase.

/cc @prajnamas

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

  1. Enable feature flag Feature.enable(:commit_committer_name_check_ff)
  2. Get the output of git config user.name, let's say its output is A.
  3. Get the output of git config user.email, let's say its output is a@gitlab.com.
  4. Project > Settings > Repository > Push rules, check the Reject inconsistent user name option. https://docs.gitlab.com/ee/user/project/repository/push_rules.html#override-global-push-rules-per-project
  5. Edit the Full Name of the current user to be different from the output of 1, for example, B.
  6. Edit the email of the current user to be different from the output of 2, for example, a@gitlab.com.
  7. Make some changes and push it to the current project.
  8. Since the git config user.name is inconsistent with the Full Name of the current user, this push will be rejected.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Harsimar Sandhu

Merge request reports

Loading