Changeset - 3b5657fba7f3
[Not reviewed]
default
1 3 0
Mads Kiilerich (mads) - 5 years ago 2021-01-11 14:25:52
mads@kiilerich.com
Grafted from: 7d4e68b4d696
hooks: drop using Git pre-receive hooks - we don't need them
4 files changed with 18 insertions and 61 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/vcs_hooks.py
Show inline comments
 
@@ -129,14 +129,6 @@ def _git_hook_environment(repo_path):
 
    return repo
 

	
 

	
 
def pre_receive(repo_path, git_stdin_lines):
 
    """Called from Git pre-receive hook.
 
    The returned value is used as hook exit code and must be 0.
 
    """
 
    # Currently unused. TODO: remove?
 
    return 0
 

	
 

	
 
def post_receive(repo_path, git_stdin_lines):
 
    """Called from Git post-receive hook.
 
    The returned value is used as hook exit code and must be 0.
kallithea/model/scm.py
Show inline comments
 
@@ -674,12 +674,8 @@ class ScmModel(object):
 
        tmpl_post += pkg_resources.resource_string(
 
            'kallithea', os.path.join('templates', 'py', 'git_post_receive_hook.py')
 
        )
 
        tmpl_pre = b"#!%s\n" % safe_bytes(self._get_git_hook_interpreter())
 
        tmpl_pre += pkg_resources.resource_string(
 
            'kallithea', os.path.join('templates', 'py', 'git_pre_receive_hook.py')
 
        )
 

	
 
        for h_type, tmpl in [('pre-receive', tmpl_pre), ('post-receive', tmpl_post)]:
 
        for h_type, tmpl in [('pre-receive', None), ('post-receive', tmpl_post)]:
 
            hook_file = os.path.join(hooks_path, h_type)
 
            other_hook = False
 
            log.debug('Installing git hook %s in repo %s', h_type, repo.path)
 
@@ -702,7 +698,7 @@ class ScmModel(object):
 
                other_hook = True
 
            if other_hook and not force:
 
                log.warning('skipping overwriting hook file %s', hook_file)
 
            else:
 
            elif h_type == 'post-receive':
 
                log.debug('writing hook file %s', hook_file)
 
                if other_hook:
 
                    backup_file = hook_file + '.bak'
 
@@ -716,6 +712,9 @@ class ScmModel(object):
 
                    os.rename(fn, hook_file)
 
                except (OSError, IOError) as e:
 
                    log.error('error writing hook %s: %s', hook_file, e)
 
            elif h_type == 'pre-receive':  # no longer used, so just remove any existing Kallithea hook
 
                if os.path.lexists(hook_file) and not other_hook:
 
                    os.remove(hook_file)
 

	
 

	
 
def AvailableRepoGroupChoices(repo_group_perm_level, extras=()):
kallithea/templates/py/git_pre_receive_hook.py
Show inline comments
 
deleted file
kallithea/tests/vcs/test_git.py
Show inline comments
 
@@ -780,9 +780,11 @@ class TestGitHooks(object):
 

	
 
        # Create a dictionary where keys are hook names, and values are paths to
 
        # them in the non-bare repo. Deduplicates code in tests a bit.
 
        self.pre_receive = os.path.join(self.repo.path, '.git', 'hooks', "pre-receive")
 
        self.post_receive = os.path.join(self.repo.path, '.git', 'hooks', "post-receive")
 
        self.kallithea_hooks = {
 
            "pre-receive": os.path.join(self.repo.path, '.git', 'hooks', "pre-receive"),
 
            "post-receive": os.path.join(self.repo.path, '.git', 'hooks', "post-receive"),
 
            "pre-receive": self.pre_receive,
 
            "post-receive": self.post_receive,
 
        }
 

	
 
    def test_hooks_created_if_missing(self):
 
@@ -796,8 +798,8 @@ class TestGitHooks(object):
 

	
 
        ScmModel().install_git_hooks(self.repo)
 

	
 
        for hook, hook_path in self.kallithea_hooks.items():
 
            assert os.path.exists(hook_path)
 
        assert not os.path.exists(self.pre_receive)
 
        assert os.path.exists(self.post_receive)
 

	
 
    def test_kallithea_hooks_updated(self):
 
        """
 
@@ -810,9 +812,9 @@ class TestGitHooks(object):
 

	
 
        ScmModel().install_git_hooks(self.repo)
 

	
 
        for hook, hook_path in self.kallithea_hooks.items():
 
            with open(hook_path) as f:
 
                assert "JUST_BOGUS" not in f.read()
 
        assert not os.path.exists(self.pre_receive)
 
        with open(self.post_receive) as f:
 
            assert "JUST_BOGUS" not in f.read()
 

	
 
    def test_custom_hooks_untouched(self):
 
        """
 
@@ -840,6 +842,7 @@ class TestGitHooks(object):
 

	
 
        ScmModel().install_git_hooks(self.repo, force=True)
 

	
 
        for hook, hook_path in self.kallithea_hooks.items():
 
            with open(hook_path) as f:
 
                assert "KALLITHEA_HOOK_VER" in f.read()
 
        with open(self.pre_receive) as f:
 
            assert "KALLITHEA_HOOK_VER" not in f.read()
 
        with open(self.post_receive) as f:
 
            assert "KALLITHEA_HOOK_VER" in f.read()
0 comments (0 inline, 0 general)