Allow editing of commit messages on unprotected branches
In epic https://gitlab.com/groups/gitlab-com/gl-infra/-/epics/351 we discuss
implementing changelog generation in GitLab, based on commit titles/messages.
To make this easier for users, we want to extend GitLab to have the ability to
edit commit messages on unprotected branches.
:warning: For this epic we will focus exclusively on editing commit messages.
Changing the wording/template for squashed commits and such is out of the scope
of this epic.
<details>
<summary>Table of contents</summary>
[[_TOC_]]
</details>
## Status
* Status: :hourglass_flowing_sand: in progress
* DRI: @yorickpeterse
## The problem
Editing commit messages can be difficult for those unfamiliar with `git rebase`,
those new to Git, or those who simply don't want to rebase a bunch of merge
request commits just to fix a few typos.
GitLab doesn't provide any tools to help developers in these cases. The closest
we have is the ability to edit merge commits when merging merge requests, but
this leaves the original commits as-is. Using squash on merge in turn can lead
to a loss of valuable history.
If we want to use Git commit messages to generate changelogs, we need to tackle
this problem so it becomes trivial to edit commit messages.
## Prior/related work
* https://gitlab.com/groups/gitlab-org/-/epics/4941
* https://gitlab.com/gitlab-org/gitlab/-/issues/5316
* https://gitlab.com/gitlab-org/gitlab/-/issues/2551
* https://gitlab.com/gitlab-org/gitlab/-/issues/18142
* https://gitlab.com/groups/gitlab-org/-/epics/2894
The comments in https://gitlab.com/gitlab-org/gitlab/-/issues/2551 in particular
show the interest in having this kind of functionality.
## Proposal
When creating a merge request, the author of the merge request can edit the
commit messages in one of two ways:
1. Using the merge request UI
1. By navigating to the individual commit, and editing its message there
When members of the target project are allowed to commit to the merge request,
they too can edit the commit messages.
If the source branch is a protected branch, editing isn't possible. If the merge
request is merged, project members can't edit the commit messages.
When a commit is edited, a system note is created showing the diff of the commit
message changes. The author of the system note will be the user that made the
changes. If a commit is associated with a merge request, the note should be
visible both when viewing the commit and when viewing the merge request.
## Success/exit criteria
Users can edit commit messages through GitLab, removing the need to use `git
rebase` for simple use cases. In addition, we aim for this to make our own
developers more comfortable with the idea of using Git commits to drive our
changelog generation process.
## Technical details
Editing commit messages is to be done using `git rebase` or equivalent, not `git
replace`, as `git replace` is not the right tool for this (see the comments in
https://gitlab.com/gitlab-org/gitlab/-/issues/18142 regarding this).
Gitaly will need to be extended to support some degree of commit rebasing. At
the very least we should be able to give a commit SHA and a new commit message
to use for that commit.
We then need to extend the API to support this functionality, allowing us to use
this in our frontend code.
The frontend changes should ideally just use this API, instead of using a custom
internal API.
For this iteration we will focus on editing one commit at a time, instead of
allowing for bulk edits. Bulk editing is something we may want to add in the
future, but I think it's a step too far at this time.
## Future enhancements
Enhancements we would make in the future include the ability to edit multiple
commit messages in one API call, or to make it possible to submit review
comments for commit messages. These enhancements are out of the scope of this
epic.
epic