From 99e00856ebb09b8edc9729b7f21a8005aaf02cb3 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Mon, 1 Aug 2016 11:13:47 +0100 Subject: [PATCH] REMOVE THIS COMMIT: allow undoing last resolution --- .../projects/merge_requests_controller.rb | 13 ++++++++++++- config/routes.rb | 1 + .../projects/merge_requests_controller_spec.rb | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 6772672992c..1fbdc73cabe 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -10,7 +10,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController before_action :module_enabled before_action :merge_request, only: [ :edit, :update, :show, :diffs, :commits, :conflicts, :builds, :merge, :merge_check, - :ci_status, :toggle_subscription, :cancel_merge_when_build_succeeds, :remove_wip, :resolve_conflicts + :ci_status, :toggle_subscription, :cancel_merge_when_build_succeeds, :remove_wip, :resolve_conflicts, + :undo_last_resolution ] before_action :validates_merge_request, only: [:show, :diffs, :commits, :builds] before_action :define_show_vars, only: [:show, :diffs, :commits, :conflicts, :builds] @@ -160,6 +161,16 @@ class Projects::MergeRequestsController < Projects::ApplicationController end end + def undo_last_resolution + rugged = @merge_request.project.repository.rugged + ref = Gitlab::Git::BRANCH_REF_PREFIX + @merge_request.source_branch + prev = rugged.ref(ref).target + + rugged.references.update(ref, prev.parents.first.oid) if prev.parents.length == 2 + + head :ok + end + def builds respond_to do |format| format.html do diff --git a/config/routes.rb b/config/routes.rb index 93da084b64a..91d33ea43e9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -729,6 +729,7 @@ Rails.application.routes.draw do post :remove_wip get :diff_for_path post :resolve_conflicts + post :undo_last_resolution end collection do diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index bca5d8c0655..226650399cc 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -638,6 +638,19 @@ describe Projects::MergeRequestsController do it 'redirects to the MR show page' do expect(response).to redirect_to([merge_request_with_conflicts.target_project.namespace.becomes(Namespace), merge_request_with_conflicts.target_project, merge_request_with_conflicts]) end + + context 'undoing the resolution' do + before do + post :undo_last_resolution, + namespace_id: merge_request_with_conflicts.project.namespace.to_param, + project_id: merge_request_with_conflicts.project.to_param, + id: merge_request_with_conflicts.iid + end + + it 'undoes the commit' do + expect(original_head_sha).to eq(merge_request_with_conflicts.source_branch_head.sha) + end + end end context 'when sections are missing' do