Commit 68bf0baf authored by Sean McGivern's avatar Sean McGivern

Set default squash message to MR title

The last commit is a bad default to use, because if you want to squash
commits, the last commit message will often be of the type 'fix
specs'. Instead, use the MR title and author as the commit's author.
parent 5c572335
......@@ -40,9 +40,12 @@ module MergeRequests
)
run_git_command(
%W(commit -C #{merge_request.diff_head_sha}),
%W(commit -m #{merge_request.title}),
tree_path,
git_env.merge('GIT_COMMITTER_NAME' => current_user.name, 'GIT_COMMITTER_EMAIL' => current_user.email),
git_env.merge('GIT_COMMITTER_NAME' => current_user.name,
'GIT_COMMITTER_EMAIL' => current_user.email,
'GIT_AUTHOR_NAME' => merge_request.author.name,
'GIT_AUTHOR_EMAIL' => merge_request.author.email),
'commit squashed changes'
)
......
......@@ -35,8 +35,8 @@ This can then be overridden at the time of accepting the merge request:
The squashed commit has the following metadata:
* Message: taken from the last commit in the source branch.
* Author: taken from the last commit in the source branch.
* Message: the title of the merge request.
* Author: the author of the merge request.
* Committer: the user who initiated the squash.
## Squashing and [fast-forward merge][ff-merge]
......
......@@ -12,11 +12,10 @@ feature 'Squashing merge requests', js: true, feature: true do
shared_examples 'squash' do
it 'squashes the commits into a single commit, and adds a merge commit' do
latest_master_commits = project.repository.commits_between(original_head.sha, 'master').map(&:raw)
last_mr_commit = project.repository.commit(source_branch)
squash_commit = an_object_having_attributes(sha: a_string_matching(/\h{40}/),
message: "#{last_mr_commit.message}\n",
author_name: last_mr_commit.author_name,
message: "Csv\n",
author_name: user.name,
committer_name: user.name)
merge_commit = an_object_having_attributes(sha: a_string_matching(/\h{40}/),
......
......@@ -54,14 +54,12 @@ describe MergeRequests::SquashService do
let(:squash_sha) { service.execute(merge_request)[:squash_sha] }
let(:squash_commit) { project.repository.commit(squash_sha) }
it 'copies the author info and message from the last commit in the source branch' do
diff_head_commit = merge_request.diff_head_commit
it 'copies the author info and message from the merge request' do
expect(squash_commit.author_name).to eq(merge_request.author.name)
expect(squash_commit.author_email).to eq(merge_request.author.email)
expect(squash_commit.author_name).to eq(diff_head_commit.author_name)
expect(squash_commit.author_email).to eq(diff_head_commit.author_email)
# The commit message on the 'real' commit doesn't have a trailing newline
expect(squash_commit.message.chomp).to eq(diff_head_commit.message)
# Commit messages have a trailing newline, but titles don't.
expect(squash_commit.message.chomp).to eq(merge_request.title)
end
it 'sets the current user as the committer' 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