Misleading error message when creating new branch
When creation of a new branch fails because we pass an invalid ref
, then app/services/branches/create_service.rb
always assumes that the branch creation failed because new branch name is invalid:
new_branch = repository.add_branch(current_user, branch_name, ref)
if new_branch
success(new_branch)
else
error("Invalid reference name: #{branch_name}")
end
It would be nice to return correct error message if the branch creation fails because of invalid source reference.
A reproducer is the spec linked from the discussion bellow which uses GraphQL API.
The following discussion from !30388 (merged) should be addressed:
-
@cwoolley-gitlab started a discussion: (+1 comment) This error message seems odd. I didn't dig into the code, but based on the test setup, I would expect the message to be
Invalid reference name: unknown
. That is, it should refer to the target branch or value ofref
, not the source branch (which doesn't even exist yet, so it should be "invalid").