Merge Result pipeline commits and squash commits create new commits with commit author set to Full Name if commit author is username instead of Full Name
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
When using username as the commit author, any commits created internally by GitLab will have the user's Full Name as the author instead of the username. This affects temporary commits created for Merged Result Pipelines, and commits created by squashing on merging an MR.
Steps to reproduce
- set git config user.name to GitLab username
git config --local --add user.name {your username} - (not sure if required) Set repository merging strategy to Fast-forward merging
- create 2 commits on a branch
- create a Merge Request for said branch
- set
squashon merge - merge the Merge Request. The commit author on the target branch will now be the
Full Nameinstead of the username
Example Project
Example repo, uses Fast-forward merging: https://gitlab.com/casper.schroder/reproduce-username-commit-author-issue/-/commits/main?ref_type=heads casper.schroder/reproduce-username-commit-author-issue!2 (merged)
main git log --pretty=format:"%h%x09%an%x09%ad%x09%s"
0e30fe8 Casper Schroder Tue Mar 12 10:59:50 2024 +0000 Username author squash 2
username-author-squash-2 git log --pretty=format:"%h%x09%an%x09%ad%x09%s"
fcf82a6 casper.schroder Tue Mar 12 11:58:12 2024 +0100 commit 2
665fdca casper.schroder Tue Mar 12 11:57:58 2024 +0100 commit 1
What is the current bug behavior?
On repositories on our self hosted GitLab instance, we use LDAP usernames as commit authors. This generally fares well throughout GitLab as it maps to the correct users and most features work as expected.
However, specifically on commits created internally by GitLab (temporarily for merged result pipelines, or permanently when squash is used on a Merge Request,) this causes problems. The git commit author turns into the user's Full Name, instead of the aforementioned LDAP username.
I've found a part of the code where this happens for squashing: https://gitlab.com/gitlab-org/gitaly/-/blob/master/internal/gitaly/service/operations/squash.go?ref_type=heads#L125
as provided by: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/git/user.rb?ref_type=heads#L40
This part of the code assumes that the commit author name will always be the user's Full Name, even though the rest of the application seems to map the user's username to the user correctly.
What is the expected correct behavior?
Ideally this should either:
- Respect the original commit Author and use the value for the author of squashed and temporary commits
- (as a workaround) Be configurable by the user just like
Commit emailis.
Relevant logs and/or screenshots
see Example Project
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
None required as far as I can tell, it happens on our self hosted and on gitlab.com
Results of GitLab application Check
None required as far as I can tell, it happens on our self hosted and on gitlab.com
Possible fixes
I'm not an expert on the GitLab repos, but I believe it would either consist of changing something regarding the following code: https://gitlab.com/gitlab-org/gitaly/-/blob/master/internal/gitaly/service/operations/squash.go?ref_type=heads#L125 https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/git/user.rb?ref_type=heads#L40 to respect the original commit author. So conditionally use the user's username as the commit author.
Alternatively, this can be made configurable for the user just like Commit email is. See https://gitlab.com/-/user_settings/profile