Changeset - c3d83238afa1
[Not reviewed]
default
0 7 0
Branko Majic (branko) - 10 years ago 2015-09-01 21:46:03
branko@majic.rs
git: add option for forcing overwrite of Git hooks when remapping and rescanning the repositories. (Issue #153)

README file was updated to include some information on updating Git hooks after migrating to Kallithea.
7 files changed with 47 insertions and 12 deletions:
0 comments (0 inline, 0 general)
README.rst
Show inline comments
 
@@ -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/
kallithea/config/environment.py
Show inline comments
 
@@ -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
kallithea/controllers/admin/settings.py
Show inline comments
 
@@ -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 '-',
kallithea/lib/utils.py
Show inline comments
 
@@ -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
kallithea/model/repo.py
Show inline comments
 
@@ -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)
 

	
kallithea/model/scm.py
Show inline comments
 
@@ -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
 

	
kallithea/templates/admin/settings/settings_mapping.html
Show inline comments
 
@@ -23,6 +23,11 @@ ${h.form(url('admin_settings_mapping'), 
 
                        <label for="hooks"> ${_('Install Git hooks')} </label>
 
                    </div>
 
                    <span class="help-block">${_("Verify if Kallithea's Git hooks are installed for each repository. Current hooks will be updated to the latest version.")}</span>
 
                    <div class="checkbox">
 
                        ${h.checkbox('hooks_overwrite', True)}
 
                        <label for="hooks_overwrite"> ${_('Overwrite existing Git hooks')}</label>
 
                    </div>
 
                    <span class="help-block">${_("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!")}</span>
 
                </div>
 
            </div>
 

	
0 comments (0 inline, 0 general)