Skip to content
Snippets Groups Projects
Commit d0749f2e authored by Vasilii Iakliushin's avatar Vasilii Iakliushin :two:
Browse files

Fix 500 error for Commits API

Contributes to #360312

**Problem**

We skip the check for the branch name when the repository is empty.

**Solution**

Verify the branch name for the empty repository case too.

Changelog: fixed
parent f856089d
No related branches found
No related tags found
2 merge requests!97251Synchronize ruby3 branch manually due to conflicts,!96768Fix 500 error for Commits API
......@@ -66,7 +66,7 @@ def validate!
validate_on_branch!
validate_branch_existence!
validate_new_branch_name! if different_branch?
validate_new_branch_name! if project.empty_repo? || different_branch?
end
def validate_permissions!
......
......@@ -473,6 +473,26 @@
it_behaves_like "successfully creates the commit"
end
context 'when repository is empty' do
let!(:project) { create(:project, :empty_repo) }
context 'when params are valid' do
before do
post api(url, user), params: valid_c_params
end
it_behaves_like "successfully creates the commit"
end
context 'when branch name is invalid' do
before do
post api(url, user), params: valid_c_params.merge(branch: 'wrong:name')
end
it { expect(response).to have_gitlab_http_status(:bad_request) }
end
end
context 'a new file with utf8 chars in project repo' do
before do
post api(url, user), params: valid_utf8_c_params
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment