Commit c8615ffd authored by Rob Petti's avatar Rob Petti Committed by Robert Speicher

Change default squash commit message to MR title

parent 5b18dcdf
......@@ -1317,11 +1317,8 @@ class MergeRequest < ApplicationRecord
message.join("\n\n")
end
# Returns the oldest multi-line commit message, or the MR title if none found
def default_squash_commit_message
strong_memoize(:default_squash_commit_message) do
first_multiline_commit&.safe_message || title
end
title
end
# Returns the oldest multi-line commit
......
......@@ -30,10 +30,7 @@ NOTE:
The squashed commit in this example is followed by a merge commit, because the merge method for this repository uses a merge commit. You can disable merge commits in
**Project Settings > General > Merge requests > Merge method > Fast-forward merge**.
The squashed commit's commit message is either:
- Taken from the first multi-line commit message in the merge.
- The merge request's title if no multi-line commit message is found.
The squashed commit's default commit message is taken from the merge request title.
NOTE:
This only takes effect if there are at least 2 commits. As there is nothing to squash, the commit message does not change if there is only 1 commit.
......
......@@ -186,39 +186,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
let(:multiline_commits) { subject.commits.select(&is_multiline) }
let(:singleline_commits) { subject.commits.reject(&is_multiline) }
context 'when the total number of commits is safe' do
it 'returns the oldest multiline commit message' do
expect(subject.default_squash_commit_message).to eq(multiline_commits.last.message)
end
end
context 'when the total number of commits is big' do
let(:safe_number) { 20 }
before do
stub_const('MergeRequestDiff::COMMITS_SAFE_SIZE', safe_number)
end
it 'returns the oldest multiline commit message from safe number of commits' do
expect(subject.default_squash_commit_message).to eq(
"remove emtpy file.(beacase git ignore empty file)\nadd whitespace test file.\n"
)
end
end
it 'returns the merge request title if there are no multiline commits' do
expect(subject).to receive(:commits).and_return(
CommitCollection.new(project, singleline_commits)
)
expect(subject.default_squash_commit_message).to eq(subject.title)
end
it 'does not return commit messages from multiline merge commits' do
collection = CommitCollection.new(project, multiline_commits).enrich!
expect(collection.commits).to all( receive(:merge_commit?).and_return(true) )
expect(subject).to receive(:commits).and_return(collection)
it 'returns the merge request title' do
expect(subject.default_squash_commit_message).to eq(subject.title)
end
end
......
......@@ -2533,7 +2533,7 @@ RSpec.describe API::MergeRequests do
it "results in a default squash commit message when not set" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: { squash: true }
expect(squash_commit.message).to eq(merge_request.default_squash_commit_message)
expect(squash_commit.message.chomp).to eq(merge_request.default_squash_commit_message.chomp)
end
end
......
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