changeset 8843:8c7bbe5bd032

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.
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 11 Jan 2021 01:14:07 +0100
parents e40717c471a0
children 3b5657fba7f3
files kallithea/model/scm.py kallithea/templates/admin/settings/settings_mapping.html
diffstat 2 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/model/scm.py	Sun Jan 10 01:28:48 2021 +0100
+++ b/kallithea/model/scm.py	Mon Jan 11 01:14:07 2021 +0100
@@ -704,6 +704,10 @@
                 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__)))
--- a/kallithea/templates/admin/settings/settings_mapping.html	Sun Jan 10 01:28:48 2021 +0100
+++ b/kallithea/templates/admin/settings/settings_mapping.html	Mon Jan 11 01:14:07 2021 +0100
@@ -25,14 +25,14 @@
                             ${_('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>
+                    <span class="help-block">${_("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.")}</span>
                     <div class="checkbox">
                         <label>
                             ${h.checkbox('hooks_overwrite', True)}
-                            ${_('Overwrite existing Git hooks')}
+                            ${_('Install and overwrite 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>
+                    <span class="help-block">${_("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.")}</span>
                 </div>
             </div>