diff --git a/README.rst b/README.rst --- a/README.rst +++ b/README.rst @@ -201,6 +201,31 @@ database, using the database string you If you started out using the branding interoperability approach mentioned above, watch out for stray brand.pyc after removing brand.py. +Git hooks +~~~~~~~~~ + +After switching to Kallithea, it will be necessary to update the Git_ hooks in +your repositories. If not, the Git_ hooks from RhodeCode will still be called, +which will cause ``git push`` to fail every time. + +If you do not have any custom Git_ hooks deployed, perform the following steps +(this may take some time depending on the number and size of repositories you +have): + +1. Log-in as an administrator. + +2. Open page *Admin > Settings > Remap and Rescan*. + +3. Turn on the option **Install Git Hooks**. + +4. Turn on the option **Overwrite existing Git hooks**. + +5. Click on the button **Rescan Repositories**. + +If you do have custom hooks, you will need to merge those changes manually. In +order to get sample hooks from Kallithea, the easiest way is to create a new Git_ +repository, and have a look at the hooks deployed there. + .. _virtualenv: http://pypi.python.org/pypi/virtualenv .. _Python: http://www.python.org/ diff --git a/kallithea/config/environment.py b/kallithea/config/environment.py --- a/kallithea/config/environment.py +++ b/kallithea/config/environment.py @@ -136,5 +136,5 @@ def load_environment(global_conf, app_co if str2bool(config.get('initial_repo_scan', True)): repo2db_mapper(ScmModel().repo_scan(repos_path), - remove_obsolete=False, install_git_hook=False) + remove_obsolete=False, install_git_hooks=False) return config diff --git a/kallithea/controllers/admin/settings.py b/kallithea/controllers/admin/settings.py --- a/kallithea/controllers/admin/settings.py +++ b/kallithea/controllers/admin/settings.py @@ -197,9 +197,11 @@ class SettingsController(BaseController) if request.POST: rm_obsolete = request.POST.get('destroy', False) install_git_hooks = request.POST.get('hooks', False) + overwrite_git_hooks = request.POST.get('hooks_overwrite', False); invalidate_cache = request.POST.get('invalidate', False) - log.debug('rescanning repo location with destroy obsolete=%s and ' - 'install git hooks=%s' % (rm_obsolete,install_git_hooks)) + log.debug('rescanning repo location with destroy obsolete=%s, ' + 'install git hooks=%s and ' + 'overwrite git hooks=%s' % (rm_obsolete, install_git_hooks, overwrite_git_hooks)) if invalidate_cache: log.debug('invalidating all repositories cache') @@ -208,8 +210,9 @@ class SettingsController(BaseController) filesystem_repos = ScmModel().repo_scan() added, removed = repo2db_mapper(filesystem_repos, rm_obsolete, - install_git_hook=install_git_hooks, - user=c.authuser.username) + install_git_hooks=install_git_hooks, + user=c.authuser.username, + overwrite_git_hooks=overwrite_git_hooks) h.flash(h.literal(_('Repositories successfully rescanned. Added: %s. Removed: %s.') % (', '.join(h.link_to(safe_unicode(repo_name), h.url('summary_home', repo_name=repo_name)) for repo_name in added) or '-', diff --git a/kallithea/lib/utils.py b/kallithea/lib/utils.py --- a/kallithea/lib/utils.py +++ b/kallithea/lib/utils.py @@ -460,7 +460,7 @@ def map_groups(path): def repo2db_mapper(initial_repo_list, remove_obsolete=False, - install_git_hook=False, user=None): + install_git_hooks=False, user=None, overwrite_git_hooks=False): """ maps all repos given in initial_repo_list, non existing repositories are created, if remove_obsolete is True it also check for db entries @@ -468,8 +468,10 @@ def repo2db_mapper(initial_repo_list, re :param initial_repo_list: list of repositories found by scanning methods :param remove_obsolete: check for obsolete entries in database - :param install_git_hook: if this is True, also check and install githook + :param install_git_hooks: if this is True, also check and install git hook for a repo if missing + :param overwrite_git_hooks: if this is True, overwrite any existing git hooks + that may be encountered (even if user-deployed) """ from kallithea.model.repo import RepoModel from kallithea.model.scm import ScmModel @@ -515,14 +517,14 @@ def repo2db_mapper(initial_repo_list, re # installed, and updated server info if new_repo.repo_type == 'git': git_repo = new_repo.scm_instance - ScmModel().install_git_hook(git_repo) + ScmModel().install_git_hooks(git_repo) # update repository server-info log.debug('Running update server info') git_repo._update_server_info() new_repo.update_changeset_cache() - elif install_git_hook: + elif install_git_hooks: if db_repo.repo_type == 'git': - ScmModel().install_git_hook(db_repo.scm_instance) + ScmModel().install_git_hooks(db_repo.scm_instance, force_create=overwrite_git_hooks) removed = [] # remove from database those repositories that are not in the filesystem diff --git a/kallithea/model/repo.py b/kallithea/model/repo.py --- a/kallithea/model/repo.py +++ b/kallithea/model/repo.py @@ -726,7 +726,7 @@ class RepoModel(BaseModel): elif repo_type == 'git': repo = backend(repo_path, create=True, src_url=clone_uri, bare=True) # add kallithea hook into this repo - ScmModel().install_git_hook(repo=repo) + ScmModel().install_git_hooks(repo=repo) else: raise Exception('Not supported repo_type %s expected hg/git' % repo_type) diff --git a/kallithea/model/scm.py b/kallithea/model/scm.py --- a/kallithea/model/scm.py +++ b/kallithea/model/scm.py @@ -835,7 +835,7 @@ class ScmModel(BaseModel): return choices, hist_l - def install_git_hook(self, repo, force_create=False): + def install_git_hooks(self, repo, force_create=False): """ Creates a kallithea hook inside a git repository diff --git a/kallithea/templates/admin/settings/settings_mapping.html b/kallithea/templates/admin/settings/settings_mapping.html --- a/kallithea/templates/admin/settings/settings_mapping.html +++ b/kallithea/templates/admin/settings/settings_mapping.html @@ -23,6 +23,11 @@ ${h.form(url('admin_settings_mapping'), ${_("Verify if Kallithea's Git hooks are installed for each repository. Current hooks will be updated to the latest version.")} +
+ ${h.checkbox('hooks_overwrite', True)} + +
+ ${_("If installing Git hooks, overwrite any existing hooks, even if they do not seem to come from Kallithea. WARNING: This operation will destroy any custom git hooks you may have deployed by hand!")}