# HG changeset patch # User Mads Kiilerich # Date 2021-01-11 01:14:07 # Node ID 8c7bbe5bd03265b84c0754b292a0113815d02fb2 # Parent e40717c471a028cba5bf4a1a6d273fb4887f689e hooks: when overwriting non-Kallithea hooks, move the old hook to .bak Note: This will only happen when actually overwriting an unknown hook. Repeated hook installation will thus not clobber the existing .bak file until a non-Kallithea hook is found again. diff --git a/kallithea/model/scm.py b/kallithea/model/scm.py --- a/kallithea/model/scm.py +++ b/kallithea/model/scm.py @@ -704,6 +704,10 @@ class ScmModel(object): log.warning('skipping overwriting hook file %s', hook_file) else: log.debug('writing hook file %s', hook_file) + if other_hook: + backup_file = hook_file + '.bak' + log.warning('moving existing hook to %s', backup_file) + os.rename(hook_file, backup_file) try: fh, fn = tempfile.mkstemp(prefix=hook_file + '.tmp.') os.write(fh, tmpl.replace(b'_TMPL_', safe_bytes(kallithea.__version__))) 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 @@ -25,14 +25,14 @@ ${h.form(url('admin_settings_mapping'), ${_('Install Git hooks')} - ${_("Verify if Kallithea's Git hooks are installed for each repository. Current hooks will be updated to the latest version.")} + ${_("Install Kallithea's internal hooks for all Git repositories where they are missing or can be upgraded. Existing hooks that don't seem to come from Kallithea will not be touched.")}
- ${_("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!")} + ${_("Install Kallithea's internal hooks for all Git repositories. Existing hooks that don't seem to come from Kallithea will be disabled by renaming to .bak extension.")}