Commit 72c84785 authored by Patrick Bajao's avatar Patrick Bajao

Fix error when cleaning up MR with no head ref

When `MergeRequests::CleanupRefsService` runs on a merge request
that has no head ref (`refs/merge-requests/:iid/head`), it throws
a `NoMethodError` when getting the commit id.

To fix it, there's ensure that we handle that case.
parent fa79e06f
......@@ -17,7 +17,7 @@ module MergeRequests
@repository = merge_request.project.repository
@ref_path = merge_request.ref_path
@merge_ref_path = merge_request.merge_ref_path
@ref_head_sha = @repository.commit(merge_request.ref_path).id
@ref_head_sha = @repository.commit(merge_request.ref_path)&.id
@merge_ref_sha = merge_request.merge_ref_head&.id
end
......
---
title: Fix error when cleaning up MR with no head ref
merge_request: 45504
author:
type: fixed
......@@ -35,6 +35,17 @@ RSpec.describe MergeRequests::CleanupRefsService do
end
end
context 'when merge request has no head ref' do
before do
# Simulate a merge request with no head ref
merge_request.project.repository.delete_refs(merge_request.ref_path)
end
it 'does not fail' do
expect(result[:status]).to eq(:success)
end
end
context 'when merge request has merge ref' do
before do
MergeRequests::MergeToRefService
......
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