Cannot close issue from commit if related to merge request
<!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "type::bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug and verify the issue you're about to submit isn't a duplicate. ---> ### Summary Using [issue closing patterns](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) to close an issue from a commit is not completely reliable. **I do not know the source of the bug, what follows is a description of what I witnessed (and reproduced)** Basically, if the commit that contains the pattern was created by a validated merge request, it does not work. The bug appeared with an external issue tracker but reproduced with full native Gitlab features. <details><summary>Here is some context to know what we want to achieve</summary> We use a workflow with master/develop/feature branches (basically the git flow), and `release` branches pulled from `develop`, then merged into `master`. During the release process, fixes can be added to the `release` branch, and we would like to automatically close issues related to thoses fixes when they are merged. What we do is merge into release, and then automatically merge back into develop. The instinctive way to do that was to have the `Closes` pattern added to the merge commit body, so that when it goes into develop, the automation closes the issue. We did that, and it did not work. </details> ### Steps to reproduce There's a bunch of steps to see the "normal" and the "anomalous" behaviour, trying to get everything clear here: **Preparation** 1. create `release` branch from default branch (`main` in these steps) 1. push that branch 1. in the project, add description to the MR commit message template (this is done because `${issues}` only works in MRs that target the main branch, which is a bit annoying) ``` Merge branch '%{source_branch}' into '%{target_branch}' %{title} %{description} ``` **Anomalous behaviour** 1. create feature branch from `release` branch 1. make a change, commit and push 1. create a merge request targeted to the `release` branch 1. add `Closes <issue-id>` to the description 1. validate the MR 1. pull the `release` branch locally, the head commit should contain `Closes <issue-id>` in the body 1. the issue should not be closed (so far, so good) 1. merge the `release` branch locally into `main` 1. push the `main` branch (with a commit that says `Closes <issue-XXXX>`) in the body Here, despite the main branch being pushed with an issue closing pattern, **the issue is not closed**. **Normal behaviour** 1. create another feature branch from `release` branch 1. make a change and commit (pushing is not necessary I guess, I did it) 1. merge feature branch into `release` locally, reproducing MR commit message (adding the `Closes <issue-id>` clause manually, I also added some quotes around the branch names because my local git did not) 1. you can push the `release` branch, this is not necessary, I did it 1. merge the `release` branch locally into `main` 1. push the `main` branch (with a commit that says `Closes <issue-id>`) in the body Here, the issue is closed. The commit messages are identical, but one triggered the issue closing, the other did not. ### Example Project <!-- If possible, please create an example project here on GitLab.com that exhibits the problematic behavior, and link to it here in the bug report. If you are using an older version of GitLab, this will also determine whether the bug is fixed in a more recent version. --> Here is a small project that shows the issue: https://gitlab.com/fattybenji/test-indirect-issue-closing It does not contain anything that isn't Gitlab related, no CI, no specific configuration except the MR message template documented above. I did the steps above with two different issues. ### What is the current *bug* behavior? When created by a merge request validation, a commit that contains the default issue closing pattern pushed to the default branch does not close the related issue. ### What is the expected *correct* behavior? Any commit containing a documented issue closing pattern pushed to the default branch should close the issue. ### Relevant logs and/or screenshots <!-- Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise. --> No related logs. I doubt it is relevant, but my git version is `2.30.1`. ### Output of checks <!-- If you are reporting a bug on GitLab.com, write: This bug happens on GitLab.com --> This bug happens on GitLab.com ### Possible fixes <!-- If you can, link to the line of code that might be responsible for the problem. --> N/A
issue