Commit fb3c685f authored by Douwe Maan's avatar Douwe Maan Committed by Robert Speicher

Merge branch 'fix-commits-manual-merge' into 'master'

Fix bug where manually merged branches in a MR would end up with an empty diff

This bug manifested in 8.1 with the refactoring of `RefreshService`. Here's what happens:

1. User create a new branch `foo`.
2. User creates a merge request for `foo`.
3. User merges `foo` into `master` by hand.
4. `RefreshService` reloads the merge request. Since `master` is equivalent to `foo`, this results in an empty diff.
5. `RefreshService` then closes the MR.

This wasn't an issue when you use the normal "Accept Merge Request" flow because the act of clicking the button closes the merge request, so step 4 never happens.

Closes #3314

See merge request !1758
parent a76d4d27
Please view this file on the master branch, on stable branches it's out of date.
v 8.2.0 (unreleased)
- Fix bug where manually merged branches in a MR would end up with an empty diff (Stan Hu)
- Force update refs/merge-requests/X/head upon a push to the source branch of a merge request (Stan Hu)
- Improved performance of finding users by one of their Email addresses
- Improved performance of replacing references in comments
- Show last project commit to default branch on project home page
- Highlight comment based on anchor in URL
- Adds ability to remove the forked relationship from project settings screen. (Han Loong Liauw)
- Improved performance of sorting milestone issues
- Allow users to select the Files view as default project view (Cristian Bica)
- Show "Empty Repository Page" for repository without branches (Artem V. Navrotskiy)
- Fix: Inability to reply to code comments in the MR view, if the MR comes from a fork
- Use git follow flag for commits page when retrieve history for file or directory
- Show merge request CI status on merge requests index page
- Extend yml syntax for only and except to support specifying repository path
- Enable shared runners to all new projects
- Fix: 500 error returned if destroy request without HTTP referer (Kazuki Shimizu)
- Remove deprecated CI events from project settings page
- Use issue editor as cross reference comment author when issue is edited with a new mention.
- [API] Add ability to fetch the commit ID of the last commit that actually touched a file
- Add "New file" link to dropdown on project page
- Include commit logs in project search
- Add "added", "modified" and "removed" properties to commit object in webhook
- Rename "Back to" links to "Go to" because its not always a case it point to place user come from
- Allow groups to appear in the search results if the group owner allows it
v 8.1.3
- Force update refs/merge-requests/X/head upon a push to the source branch of a merge request (Stan Hu)
- Spread out runner contacted_at updates
......
......@@ -7,17 +7,17 @@ module MergeRequests
@branch_name = Gitlab::Git.ref_name(ref)
find_new_commits
# Be sure to close outstanding MRs before reloading them to avoid generating an
# empty diff during a manual merge
close_merge_requests
reload_merge_requests
# Leave a system note if a branch was deleted/added
if branch_added? || branch_removed?
comment_mr_branch_presence_changed
comment_mr_with_commits
else
comment_mr_with_commits
close_merge_requests
end
comment_mr_with_commits
execute_mr_web_hooks
true
......
......@@ -62,6 +62,25 @@ describe MergeRequests::RefreshService do
it { expect(@fork_merge_request.notes.last.note).to include('changed to merged') }
end
context 'manual merge of source branch' do
before do
# Merge master -> feature branch
author = { email: 'test@gitlab.com', time: Time.now, name: "Me" }
commit_options = { message: 'Test message', committer: author, author: author }
master_commit = @project.repository.commit('master')
@project.repository.merge(@user, master_commit.id, 'feature', commit_options)
commit = @project.repository.commit('feature')
service.new(@project, @user).execute(@oldrev, commit.id, 'refs/heads/feature')
reload_mrs
end
it { expect(@merge_request.notes.last.note).to include('changed to merged') }
it { expect(@merge_request).to be_merged }
it { expect(@merge_request.diffs.length).to be > 0 }
it { expect(@fork_merge_request).to be_merged }
it { expect(@fork_merge_request.notes.last.note).to include('changed to merged') }
end
context 'push to fork repo source branch' do
let(:refresh_service) { service.new(@fork_project, @user) }
before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment