changeset 5452:c3d83238afa1

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.
author Branko Majic <branko@majic.rs>
date Tue, 01 Sep 2015 21:46:03 +0200
parents c9bb2d6186ba
children ebfab577da16
files README.rst kallithea/config/environment.py kallithea/controllers/admin/settings.py kallithea/lib/utils.py kallithea/model/repo.py kallithea/model/scm.py kallithea/templates/admin/settings/settings_mapping.html
diffstat 7 files changed, 47 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/README.rst	Wed Aug 26 17:28:59 2015 +0200
+++ b/README.rst	Tue Sep 01 21:46:03 2015 +0200
@@ -201,6 +201,31 @@
    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/
--- a/kallithea/config/environment.py	Wed Aug 26 17:28:59 2015 +0200
+++ b/kallithea/config/environment.py	Tue Sep 01 21:46:03 2015 +0200
@@ -136,5 +136,5 @@
 
     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
--- a/kallithea/controllers/admin/settings.py	Wed Aug 26 17:28:59 2015 +0200
+++ b/kallithea/controllers/admin/settings.py	Tue Sep 01 21:46:03 2015 +0200
@@ -197,9 +197,11 @@
         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 @@
 
             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 '-',
--- a/kallithea/lib/utils.py	Wed Aug 26 17:28:59 2015 +0200
+++ b/kallithea/lib/utils.py	Tue Sep 01 21:46:03 2015 +0200
@@ -460,7 +460,7 @@
 
 
 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 @@
 
     :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 @@
             # 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
--- a/kallithea/model/repo.py	Wed Aug 26 17:28:59 2015 +0200
+++ b/kallithea/model/repo.py	Tue Sep 01 21:46:03 2015 +0200
@@ -726,7 +726,7 @@
         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)
 
--- a/kallithea/model/scm.py	Wed Aug 26 17:28:59 2015 +0200
+++ b/kallithea/model/scm.py	Tue Sep 01 21:46:03 2015 +0200
@@ -835,7 +835,7 @@
 
         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
 
--- a/kallithea/templates/admin/settings/settings_mapping.html	Wed Aug 26 17:28:59 2015 +0200
+++ b/kallithea/templates/admin/settings/settings_mapping.html	Tue Sep 01 21:46:03 2015 +0200
@@ -23,6 +23,11 @@
                         <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>