Fix for #4535 ('Test settings' button for services gives 500 on empty repo)

Here's a new fix for issue #4535