diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/merge_request.rb | 4 | ||||
-rw-r--r-- | app/services/files/base_service.rb | 2 | ||||
-rw-r--r-- | app/services/merge_requests/auto_merge_service.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/satellite/merge_action.rb | 2 |
5 files changed, 16 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG index 7ddddac014f..c6c5bc0aac4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ v 7.14.0 (unreleased) - Expire Rails cache entries after two weeks to prevent endless Redis growth - Add support for destroying project milestones (Stan Hu) - Add fetch command to the MR page. + - Fix bug causing "Remove source-branch" option not to work for merge requests from the same project. v 7.13.1 - Revert issue caching diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 53b3fc10ccb..1ef76d16700 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -235,6 +235,10 @@ class MergeRequest < ActiveRecord::Base execute(self, commit_message) end + def remove_source_branch? + self.should_remove_source_branch && !self.source_project.root_ref?(self.source_branch) && !self.for_fork? + end + def open? opened? || reopened? end diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index f587ee266da..646784f2d9d 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -39,7 +39,7 @@ module Files def after_commit(sha, branch) commit = repository.commit(sha) - full_ref = 'refs/heads/' + branch + full_ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch}" old_sha = commit.parent_id || Gitlab::Git::BLANK_SHA GitPushService.new.execute(project, current_user, old_sha, sha, full_ref) end diff --git a/app/services/merge_requests/auto_merge_service.rb b/app/services/merge_requests/auto_merge_service.rb index df793fc997d..db824d452d0 100644 --- a/app/services/merge_requests/auto_merge_service.rb +++ b/app/services/merge_requests/auto_merge_service.rb @@ -37,6 +37,14 @@ module MergeRequests # Merge local branches using rugged instead of satellites if sha = commit after_commit(sha, merge_request.target_branch) + + if merge_request.remove_source_branch? + DeleteBranchService.new(merge_request.source_project, current_user).execute(merge_request.source_branch) + end + + true + else + false end end end @@ -55,7 +63,7 @@ module MergeRequests def after_commit(sha, branch) commit = repository.commit(sha) - full_ref = 'refs/heads/' + branch + full_ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch}" old_sha = commit.parent_id || Gitlab::Git::BLANK_SHA GitPushService.new.execute(project, current_user, old_sha, sha, full_ref) end diff --git a/lib/gitlab/satellite/merge_action.rb b/lib/gitlab/satellite/merge_action.rb index 1f2e5f82dd5..f9bf286697e 100644 --- a/lib/gitlab/satellite/merge_action.rb +++ b/lib/gitlab/satellite/merge_action.rb @@ -33,7 +33,7 @@ module Gitlab merge_repo.git.push(default_options, :origin, merge_request.target_branch) # remove source branch - if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch) && !merge_request.for_fork? + if merge_request.remove_source_branch? # will raise CommandFailed when push fails merge_repo.git.push(default_options, :origin, ":#{merge_request.source_branch}") end |