def reinit_plugin(name, upmate: bool=False): # pragma: no cover
"""
Reinitialize gitmate with plugin and upmate, if specified.
"""
app_name = 'gitmate_' + name
app_config_name = 'plugins.{}.apps.{}Config'.format(
app_name, snake_case_to_camel_case(app_name))
if app_config_name in settings.INSTALLED_APPS:
return
settings.GITMATE_PLUGINS += [name]
settings.INSTALLED_APPS += [app_config_name]
# To load the new app let's reset app_configs, the dictionary
# with the configuration of loaded apps
apps.app_configs = OrderedDict()
# set ready to false so that populate will work
apps.ready = False
# re-initialize them all
apps.populate(settings.INSTALLED_APPS)
# migrate the models
management.call_command('migrate', app_name, interactive=False)
# upmate the plugins, if specified
if upmate is True:
management.call_command('upmate', interactive=False)