Commit b5b2055c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-mr-push-range' into 'master'

Fix condensed range in MR push comment.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/1246

In https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/326#note_984907, you see that the compare page doesn't actually have 39 commits because we're using `first_new_commit^`, which is not always the same as `oldrev`. With this MR, we use `oldrev` instead, which will always work.

See merge request !1721
parents d03d6363 ebfc7d05
...@@ -151,7 +151,7 @@ class Note < ActiveRecord::Base ...@@ -151,7 +151,7 @@ class Note < ActiveRecord::Base
) )
end end
def create_new_commits_note(merge_request, project, author, new_commits, existing_commits = []) def create_new_commits_note(merge_request, project, author, new_commits, existing_commits = [], oldrev = nil)
total_count = new_commits.length + existing_commits.length total_count = new_commits.length + existing_commits.length
commits_text = ActionController::Base.helpers.pluralize(total_count, 'commit') commits_text = ActionController::Base.helpers.pluralize(total_count, 'commit')
body = "Added #{commits_text}:\n\n" body = "Added #{commits_text}:\n\n"
...@@ -161,7 +161,11 @@ class Note < ActiveRecord::Base ...@@ -161,7 +161,11 @@ class Note < ActiveRecord::Base
if existing_commits.length == 1 if existing_commits.length == 1
existing_commits.first.short_id existing_commits.first.short_id
else else
"#{existing_commits.first.short_id}..#{existing_commits.last.short_id}" if oldrev
"#{Commit.truncate_sha(oldrev)}...#{existing_commits.last.short_id}"
else
"#{existing_commits.first.short_id}..#{existing_commits.last.short_id}"
end
end end
commits_text = ActionController::Base.helpers.pluralize(existing_commits.length, 'commit') commits_text = ActionController::Base.helpers.pluralize(existing_commits.length, 'commit')
......
...@@ -89,7 +89,7 @@ module MergeRequests ...@@ -89,7 +89,7 @@ module MergeRequests
end end
Note.create_new_commits_note(merge_request, merge_request.project, Note.create_new_commits_note(merge_request, merge_request.project,
@current_user, new_commits, existing_commits) @current_user, new_commits, existing_commits, @oldrev)
end end
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