diff options
author | Saverio Miroddi <saverio.pub2@gmail.com> | 2017-08-10 21:16:49 +0200 |
---|---|---|
committer | Saverio Miroddi <saverio.pub2@gmail.com> | 2017-08-10 21:18:22 +0200 |
commit | 1d6ba597028142511af8c9863f81073278ccd927 (patch) | |
tree | a564f1d60a0ed0cc6407d18d3f198a124b86829b /app | |
parent | 3a9f210b5ce44f1a464e765ff6e95c1eac5363d8 (diff) | |
download | gitlab-ce-1d6ba597028142511af8c9863f81073278ccd927.tar.gz |
Add 'from commit' information to cherry-picked commits
Store the original commit in the commit message. In case of
merge commit, the commits added to the start branch are also
listed.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/commit.rb | 24 | ||||
-rw-r--r-- | app/models/repository.rb | 4 |
2 files changed, 27 insertions, 1 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 638fddc5d3d..24732b6dd29 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -251,6 +251,30 @@ class Commit project.repository.next_branch("cherry-pick-#{short_id}", mild: true) end + def cherry_pick_message(start_branch_name) + message_buffer = message.dup + + if merge_commit? + compare = CompareService.new(project, sha).execute(project, start_branch_name) + + *commits_in_merge, merge_commit = compare.commits + + message_buffer << "\n\ncherry picked from merge #{merge_commit.sha}" + + if commits_in_merge.present? + message_buffer << "; commits:" + + commits_in_merge.each do |commit_in_merge| + message_buffer << "\n- #{commit_in_merge.sha}" + end + end + else + message_buffer << "\ncherry picked from commit #{sha}" + end + + message_buffer + end + def revert_description(user) if merged_merge_request?(user) "This reverts merge request #{merged_merge_request(user).to_reference}" diff --git a/app/models/repository.rb b/app/models/repository.rb index 049bebdbe42..0e876189f63 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -875,7 +875,9 @@ class Repository committer = user_to_committer(user) - create_commit(message: commit.message, + commit_message = commit.cherry_pick_message(start_branch_name) + + create_commit(message: commit_message, author: { email: commit.author_email, name: commit.author_name, |