<div dir="ltr"><div>Hi Tim,</div><div><br></div><div>Did you intend to submit this patch?</div><div>If so, please clarify the goal and context of this patch more clearly.</div><div><br></div><div>Thanks,</div><div>Thomas<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El mar., 20 oct. 2020 a las 17:51, Tim Ooms (<<a href="mailto:tim.ooms@aeronomie.be">tim.ooms@aeronomie.be</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"># HG changeset patch<br>
# User Tim Ooms <<a href="mailto:tatankat@users.noreply.github.com" target="_blank">tatankat@users.noreply.github.com</a>><br>
# Date 1603201903 -7200<br>
# Tue Oct 20 15:51:43 2020 +0200<br>
# Node ID 672e57b165d0c1774b692b5706a174bf98f42e4c<br>
# Parent b9b53e25a08d3714c54d82641b419e6d01820e12<br>
git: move non-kallithea hooks and execute other hooks<br>
<br>
diff -r b9b53e25a08d -r 672e57b165d0 kallithea/model/scm.py<br>
--- a/kallithea/model/scm.py Mon Oct 19 12:18:28 2020 +0200<br>
+++ b/kallithea/model/scm.py Tue Oct 20 15:51:43 2020 +0200<br>
@@ -25,10 +25,12 @@<br>
:license: GPLv3, see LICENSE.md for more details.<br>
"""<br>
<br>
+import datetime<br>
import logging<br>
import os<br>
import posixpath<br>
import re<br>
+import stat<br>
import sys<br>
import traceback<br>
<br>
@@ -694,7 +696,7 @@<br>
Creates a kallithea hook inside a git repository<br>
<br>
:param repo: Instance of VCS repo<br>
- :param force: Overwrite existing non-Kallithea hooks<br>
+ :param force: Move existing non-Kallithea hooks<br>
"""<br>
<br>
hooks_path = os.path.join(repo.path, 'hooks')<br>
@@ -730,14 +732,46 @@<br>
other_hook = True<br>
<br>
if other_hook and not force:<br>
- log.warning('skipping overwriting hook file %s', hook_file)<br>
+ log.warning('skip moving non-Kallithea hook file %s',<br>
+ hook_file)<br>
else:<br>
+ # if we want to write the hook,<br>
+ # we move the other hook out of the way<br>
+ if other_hook:<br>
+ # existing non-kallithea hook script will be renamed<br>
+ # additional scripts can be named like:<br>
+ # "%s-receive.kallithea-extern.YYYYmmdd.manual<br>
+ # all "%s-receive.kallithea-extern.*.*" hook scripts<br>
+ # will be executed in order<br>
+ moved_hook_file = '%s.kallithea-extern.%s.%s' % (<br>
+ hook_file,<br>
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S%f"),<br>
+ kallithea.__version__)<br>
+ log.warning('moving hook file %s to %s',<br>
+ hook_file, moved_hook_file)<br>
+ # least chances to break an existing script by renaming<br>
+ # moving to a subdir may break scripts due to changed paths<br>
+ os.rename(hook_file, moved_hook_file)<br>
+ # now we can write our hook<br>
log.debug('writing %s hook file !', h_type)<br>
try:<br>
with open(hook_file, 'wb') as f:<br>
tmpl = tmpl.replace(b'_TMPL_', safe_bytes(kallithea.__version__))<br>
f.write(tmpl)<br>
- os.chmod(hook_file, 0o755)<br>
+ try:<br>
+ if not os.path.islink(hook_file):<br>
+ # add permissions we (may) need<br>
+ # other bits are up to umask/inherited permissions<br>
+ os.chmod(<br>
+ hook_file, os.stat(hook_file).st_mode<br>
+ | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR<br>
+ | stat.S_IRGRP | stat.S_IXGRP<br>
+ | stat.S_IROTH | stat.S_IXOTH)<br>
+ # else this will throw a permission error<br>
+ # but someone choose to create a symlink<br>
+ except IOError as e:<br>
+ log.error('error changing permissions on hoook %s: %s',<br>
+ hook_file, e)<br>
except IOError as e:<br>
log.error('error writing hook %s: %s', hook_file, e)<br>
<br>
diff -r b9b53e25a08d -r 672e57b165d0 kallithea/templates/py/git_post_receive_hook.py<br>
--- a/kallithea/templates/py/git_post_receive_hook.py Mon Oct 19 12:18:28 2020 +0200<br>
+++ b/kallithea/templates/py/git_post_receive_hook.py Tue Oct 20 15:51:43 2020 +0200<br>
@@ -9,6 +9,8 @@<br>
"""<br>
<br>
import os<br>
+import pathlib<br>
+import subprocess<br>
import sys<br>
<br>
import kallithea.lib.hooks<br>
@@ -30,6 +32,11 @@<br>
def main():<br>
repo_path = os.path.abspath('.')<br>
git_stdin_lines = sys.stdin.readlines()<br>
+ full_stdin = ''.join(git_stdin_lines)<br>
+<br>
+ for file in sorted(pathlib.Path('hooks').glob('post-receive.kallithea-extern.*.*')):<br>
+ subprocess.run([file], input=full_stdin, universal_newlines=True)<br>
+<br>
sys.exit(kallithea.lib.hooks.handle_git_post_receive(repo_path, git_stdin_lines))<br>
<br>
<br>
diff -r b9b53e25a08d -r 672e57b165d0 kallithea/templates/py/git_pre_receive_hook.py<br>
--- a/kallithea/templates/py/git_pre_receive_hook.py Mon Oct 19 12:18:28 2020 +0200<br>
+++ b/kallithea/templates/py/git_pre_receive_hook.py Tue Oct 20 15:51:43 2020 +0200<br>
@@ -9,6 +9,8 @@<br>
"""<br>
<br>
import os<br>
+import pathlib<br>
+import subprocess<br>
import sys<br>
<br>
import kallithea.lib.hooks<br>
@@ -30,6 +32,11 @@<br>
def main():<br>
repo_path = os.path.abspath('.')<br>
git_stdin_lines = sys.stdin.readlines()<br>
+ full_stdin = ''.join(git_stdin_lines)<br>
+<br>
+ for file in sorted(pathlib.Path('hooks').glob('pre-receive.kallithea-extern.*.*')):<br>
+ subprocess.run([file], input=full_stdin, universal_newlines=True)<br>
+<br>
sys.exit(kallithea.lib.hooks.handle_git_pre_receive(repo_path, git_stdin_lines))<br>
<br>
<br>
<br>
_______________________________________________<br>
kallithea-general mailing list<br>
<a href="mailto:kallithea-general@sfconservancy.org" target="_blank">kallithea-general@sfconservancy.org</a><br>
<a href="https://lists.sfconservancy.org/mailman/listinfo/kallithea-general" rel="noreferrer" target="_blank">https://lists.sfconservancy.org/mailman/listinfo/kallithea-general</a><br>
</blockquote></div>