##// END OF EJS Templates
fix(ssh): add pull fix into pre_pull hook
super-admin -
r5303:ff82a853 default
parent child Browse files
Show More
@@ -1,87 +1,88 b''
1 1 # Copyright (C) 2016-2023 RhodeCode GmbH
2 2 #
3 3 # This program is free software: you can redistribute it and/or modify
4 4 # it under the terms of the GNU Affero General Public License, version 3
5 5 # (only), as published by the Free Software Foundation.
6 6 #
7 7 # This program is distributed in the hope that it will be useful,
8 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 # GNU General Public License for more details.
11 11 #
12 12 # You should have received a copy of the GNU Affero General Public License
13 13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 14 #
15 15 # This program is dual-licensed. If you wish to learn more about the
16 16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18 18
19 19 import sys
20 20 import logging
21 21 import subprocess
22 22
23 23 from vcsserver import hooks
24 24 from .base import VcsServer
25 25
26 26 log = logging.getLogger(__name__)
27 27
28 28
29 29 class GitTunnelWrapper(object):
30 30 process = None
31 31
32 32 def __init__(self, server):
33 33 self.server = server
34 34 self.stdin = sys.stdin
35 35 self.stdout = sys.stdout
36 36
37 37 def create_hooks_env(self):
38 38 pass
39 39
40 40 def command(self):
41 41 root = self.server.get_root_store()
42 42 command = "cd {root}; {git_path} {mode} '{root}{repo_name}'".format(
43 43 root=root, git_path=self.server.git_path,
44 44 mode=self.server.repo_mode, repo_name=self.server.repo_name)
45 45 log.debug("Final CMD: %s", command)
46 46 return command
47 47
48 48 def run(self, extras):
49 49 action = "push" if self.server.repo_mode == "receive-pack" else "pull"
50 50 exit_code = self.server._check_permissions(action)
51 51 if exit_code:
52 52 return exit_code
53 53
54 54 scm_extras = self.server.update_environment(action=action, extras=extras)
55 55
56 if action == "pull":
56 57 hook_response = hooks.git_pre_pull(scm_extras)
57 58 pre_pull_messages = hook_response.output
58 59 sys.stdout.write(pre_pull_messages)
59 60
60 61 self.create_hooks_env()
61 62 result = subprocess.run(self.command(), shell=True)
62 63 result = result.returncode
63 64
64 65 # Upload-pack == clone
65 66 if action == "pull":
66 67 hook_response = hooks.git_post_pull(scm_extras)
67 68 post_pull_messages = hook_response.output
68 69 sys.stderr.write(post_pull_messages)
69 70 return result
70 71
71 72
72 73 class GitServer(VcsServer):
73 74 backend = 'git'
74 75 repo_user_agent = 'git'
75 76
76 77 def __init__(self, store, ini_path, repo_name, repo_mode,
77 78 user, user_permissions, config, env):
78 79 super().\
79 80 __init__(user, user_permissions, config, env)
80 81
81 82 self.store = store
82 83 self.ini_path = ini_path
83 84 self.repo_name = repo_name
84 85 self._path = self.git_path = config.get('app:main', 'ssh.executable.git')
85 86
86 87 self.repo_mode = repo_mode
87 88 self.tunnel = GitTunnelWrapper(server=self)
General Comments 0
You need to be logged in to leave comments. Login now