##// END OF EJS Templates
git: add option for forcing overwrite of Git hooks when remapping and rescanning the repositories. (Issue #153)...
Branko Majic -
r5452:c3d83238 default
parent child Browse files
Show More
@@ -201,6 +201,31 b' database, using the database string you '
201 If you started out using the branding interoperability approach mentioned
201 If you started out using the branding interoperability approach mentioned
202 above, watch out for stray brand.pyc after removing brand.py.
202 above, watch out for stray brand.pyc after removing brand.py.
203
203
204 Git hooks
205 ~~~~~~~~~
206
207 After switching to Kallithea, it will be necessary to update the Git_ hooks in
208 your repositories. If not, the Git_ hooks from RhodeCode will still be called,
209 which will cause ``git push`` to fail every time.
210
211 If you do not have any custom Git_ hooks deployed, perform the following steps
212 (this may take some time depending on the number and size of repositories you
213 have):
214
215 1. Log-in as an administrator.
216
217 2. Open page *Admin > Settings > Remap and Rescan*.
218
219 3. Turn on the option **Install Git Hooks**.
220
221 4. Turn on the option **Overwrite existing Git hooks**.
222
223 5. Click on the button **Rescan Repositories**.
224
225 If you do have custom hooks, you will need to merge those changes manually. In
226 order to get sample hooks from Kallithea, the easiest way is to create a new Git_
227 repository, and have a look at the hooks deployed there.
228
204
229
205 .. _virtualenv: http://pypi.python.org/pypi/virtualenv
230 .. _virtualenv: http://pypi.python.org/pypi/virtualenv
206 .. _Python: http://www.python.org/
231 .. _Python: http://www.python.org/
@@ -136,5 +136,5 b' def load_environment(global_conf, app_co'
136
136
137 if str2bool(config.get('initial_repo_scan', True)):
137 if str2bool(config.get('initial_repo_scan', True)):
138 repo2db_mapper(ScmModel().repo_scan(repos_path),
138 repo2db_mapper(ScmModel().repo_scan(repos_path),
139 remove_obsolete=False, install_git_hook=False)
139 remove_obsolete=False, install_git_hooks=False)
140 return config
140 return config
@@ -197,9 +197,11 b' class SettingsController(BaseController)'
197 if request.POST:
197 if request.POST:
198 rm_obsolete = request.POST.get('destroy', False)
198 rm_obsolete = request.POST.get('destroy', False)
199 install_git_hooks = request.POST.get('hooks', False)
199 install_git_hooks = request.POST.get('hooks', False)
200 overwrite_git_hooks = request.POST.get('hooks_overwrite', False);
200 invalidate_cache = request.POST.get('invalidate', False)
201 invalidate_cache = request.POST.get('invalidate', False)
201 log.debug('rescanning repo location with destroy obsolete=%s and '
202 log.debug('rescanning repo location with destroy obsolete=%s, '
202 'install git hooks=%s' % (rm_obsolete,install_git_hooks))
203 'install git hooks=%s and '
204 'overwrite git hooks=%s' % (rm_obsolete, install_git_hooks, overwrite_git_hooks))
203
205
204 if invalidate_cache:
206 if invalidate_cache:
205 log.debug('invalidating all repositories cache')
207 log.debug('invalidating all repositories cache')
@@ -208,8 +210,9 b' class SettingsController(BaseController)'
208
210
209 filesystem_repos = ScmModel().repo_scan()
211 filesystem_repos = ScmModel().repo_scan()
210 added, removed = repo2db_mapper(filesystem_repos, rm_obsolete,
212 added, removed = repo2db_mapper(filesystem_repos, rm_obsolete,
211 install_git_hook=install_git_hooks,
213 install_git_hooks=install_git_hooks,
212 user=c.authuser.username)
214 user=c.authuser.username,
215 overwrite_git_hooks=overwrite_git_hooks)
213 h.flash(h.literal(_('Repositories successfully rescanned. Added: %s. Removed: %s.') %
216 h.flash(h.literal(_('Repositories successfully rescanned. Added: %s. Removed: %s.') %
214 (', '.join(h.link_to(safe_unicode(repo_name), h.url('summary_home', repo_name=repo_name))
217 (', '.join(h.link_to(safe_unicode(repo_name), h.url('summary_home', repo_name=repo_name))
215 for repo_name in added) or '-',
218 for repo_name in added) or '-',
@@ -460,7 +460,7 b' def map_groups(path):'
460
460
461
461
462 def repo2db_mapper(initial_repo_list, remove_obsolete=False,
462 def repo2db_mapper(initial_repo_list, remove_obsolete=False,
463 install_git_hook=False, user=None):
463 install_git_hooks=False, user=None, overwrite_git_hooks=False):
464 """
464 """
465 maps all repos given in initial_repo_list, non existing repositories
465 maps all repos given in initial_repo_list, non existing repositories
466 are created, if remove_obsolete is True it also check for db entries
466 are created, if remove_obsolete is True it also check for db entries
@@ -468,8 +468,10 b' def repo2db_mapper(initial_repo_list, re'
468
468
469 :param initial_repo_list: list of repositories found by scanning methods
469 :param initial_repo_list: list of repositories found by scanning methods
470 :param remove_obsolete: check for obsolete entries in database
470 :param remove_obsolete: check for obsolete entries in database
471 :param install_git_hook: if this is True, also check and install githook
471 :param install_git_hooks: if this is True, also check and install git hook
472 for a repo if missing
472 for a repo if missing
473 :param overwrite_git_hooks: if this is True, overwrite any existing git hooks
474 that may be encountered (even if user-deployed)
473 """
475 """
474 from kallithea.model.repo import RepoModel
476 from kallithea.model.repo import RepoModel
475 from kallithea.model.scm import ScmModel
477 from kallithea.model.scm import ScmModel
@@ -515,14 +517,14 b' def repo2db_mapper(initial_repo_list, re'
515 # installed, and updated server info
517 # installed, and updated server info
516 if new_repo.repo_type == 'git':
518 if new_repo.repo_type == 'git':
517 git_repo = new_repo.scm_instance
519 git_repo = new_repo.scm_instance
518 ScmModel().install_git_hook(git_repo)
520 ScmModel().install_git_hooks(git_repo)
519 # update repository server-info
521 # update repository server-info
520 log.debug('Running update server info')
522 log.debug('Running update server info')
521 git_repo._update_server_info()
523 git_repo._update_server_info()
522 new_repo.update_changeset_cache()
524 new_repo.update_changeset_cache()
523 elif install_git_hook:
525 elif install_git_hooks:
524 if db_repo.repo_type == 'git':
526 if db_repo.repo_type == 'git':
525 ScmModel().install_git_hook(db_repo.scm_instance)
527 ScmModel().install_git_hooks(db_repo.scm_instance, force_create=overwrite_git_hooks)
526
528
527 removed = []
529 removed = []
528 # remove from database those repositories that are not in the filesystem
530 # remove from database those repositories that are not in the filesystem
@@ -726,7 +726,7 b' class RepoModel(BaseModel):'
726 elif repo_type == 'git':
726 elif repo_type == 'git':
727 repo = backend(repo_path, create=True, src_url=clone_uri, bare=True)
727 repo = backend(repo_path, create=True, src_url=clone_uri, bare=True)
728 # add kallithea hook into this repo
728 # add kallithea hook into this repo
729 ScmModel().install_git_hook(repo=repo)
729 ScmModel().install_git_hooks(repo=repo)
730 else:
730 else:
731 raise Exception('Not supported repo_type %s expected hg/git' % repo_type)
731 raise Exception('Not supported repo_type %s expected hg/git' % repo_type)
732
732
@@ -835,7 +835,7 b' class ScmModel(BaseModel):'
835
835
836 return choices, hist_l
836 return choices, hist_l
837
837
838 def install_git_hook(self, repo, force_create=False):
838 def install_git_hooks(self, repo, force_create=False):
839 """
839 """
840 Creates a kallithea hook inside a git repository
840 Creates a kallithea hook inside a git repository
841
841
@@ -23,6 +23,11 b''
23 <label for="hooks"> ${_('Install Git hooks')} </label>
23 <label for="hooks"> ${_('Install Git hooks')} </label>
24 </div>
24 </div>
25 <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>
25 <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>
26 <div class="checkbox">
27 ${h.checkbox('hooks_overwrite', True)}
28 <label for="hooks_overwrite"> ${_('Overwrite existing Git hooks')}</label>
29 </div>
30 <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>
26 </div>
31 </div>
27 </div>
32 </div>
28
33
General Comments 0
You need to be logged in to leave comments. Login now