Catch Git::CommandError in Branches::CreateService
What does this MR do?
When creating a branch, one source of failure is when the new branch name matches a component of an existing branches name. For example, feature
and feature/widget
. In this scenario the Gitaly
UserCreateBranch
RPC returns a Gitlab::Git::CommandError
, which is uncaught and results in a 500 error.
The specific reason for the error is the following:
- Gitaly checks if the requested branch name exist by executing a
git for-each-ref <BRANCH_NAME>
- This returns
feature/widget
becausefeature
is a component offeature/widget
. - Gitaly compares this against the requested branch name, finds they don't match, and returns
ErrReferenceAmbiguous
to Rails.
Also, in the inverse situation, e.g. feature
exists and the user is creating feature/widget
, our current Invalid reference name
error gives no indication of what branch was being created.
This is a particular problem for pull mirroring, where the SHA1 of the source branch is used rather than a human-readable name. This requires the user to copy down the SHA and go to the source repo to attempt to understand which branch is causing the failure.
This MR catches Gitlab::Git::CommandError
in this scenario and also expands the general error message to mention the branch being created.
Screenshots
- When creating an invalid branch in the UI:
- Mirroring failure:
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have self-reviewed this MR per code review guidelines. -
I have followed the style guides.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.)