Show More
@@ -186,19 +186,25 b' class GitRemote(RemoteBase):' | |||||
186 | region = self._region(wire) |
|
186 | region = self._region(wire) | |
187 |
|
187 | |||
188 | @region.conditional_cache_on_arguments(condition=cache_on) |
|
188 | @region.conditional_cache_on_arguments(condition=cache_on) | |
189 | def _assert_correct_path(_context_uid, _repo_id): |
|
189 | def _assert_correct_path(_context_uid, _repo_id, fast_check): | |
|
190 | if fast_check: | |||
|
191 | path = safe_str(wire['path']) | |||
|
192 | if pygit2.discover_repository(path): | |||
|
193 | return True | |||
|
194 | return False | |||
|
195 | else: | |||
190 | try: |
|
196 | try: | |
191 | repo_init = self._factory.repo_libgit2(wire) |
|
197 | repo_init = self._factory.repo_libgit2(wire) | |
192 |
with repo_init |
|
198 | with repo_init: | |
193 | pass |
|
199 | pass | |
194 | except pygit2.GitError: |
|
200 | except pygit2.GitError: | |
195 | path = wire.get('path') |
|
201 | path = wire.get('path') | |
196 | tb = traceback.format_exc() |
|
202 | tb = traceback.format_exc() | |
197 | log.debug("Invalid Git path `%s`, tb: %s", path, tb) |
|
203 | log.debug("Invalid Git path `%s`, tb: %s", path, tb) | |
198 | return False |
|
204 | return False | |
|
205 | return True | |||
199 |
|
206 | |||
200 | return True |
|
207 | return _assert_correct_path(context_uid, repo_id, True) | |
201 | return _assert_correct_path(context_uid, repo_id) |
|
|||
202 |
|
208 | |||
203 | @reraise_safe_exceptions |
|
209 | @reraise_safe_exceptions | |
204 | def bare(self, wire): |
|
210 | def bare(self, wire): | |
@@ -672,7 +678,7 b' class GitRemote(RemoteBase):' | |||||
672 |
|
678 | |||
673 | @reraise_safe_exceptions |
|
679 | @reraise_safe_exceptions | |
674 | def sync_fetch(self, wire, url, refs=None, all_refs=False): |
|
680 | def sync_fetch(self, wire, url, refs=None, all_refs=False): | |
675 |
|
|
681 | self._factory.repo(wire) | |
676 | if refs and not isinstance(refs, (list, tuple)): |
|
682 | if refs and not isinstance(refs, (list, tuple)): | |
677 | refs = [refs] |
|
683 | refs = [refs] | |
678 |
|
684 | |||
@@ -1315,9 +1321,8 b' class GitRemote(RemoteBase):' | |||||
1315 | bare = self.bare(wire) |
|
1321 | bare = self.bare(wire) | |
1316 | path = wire['path'] |
|
1322 | path = wire['path'] | |
1317 | binary_dir = settings.BINARY_DIR |
|
1323 | binary_dir = settings.BINARY_DIR | |
1318 | executable = None |
|
|||
1319 | if binary_dir: |
|
1324 | if binary_dir: | |
1320 |
|
|
1325 | os.path.join(binary_dir, 'python3') | |
1321 | return install_git_hooks(path, bare, force_create=force) |
|
1326 | return install_git_hooks(path, bare, force_create=force) | |
1322 |
|
1327 | |||
1323 | @reraise_safe_exceptions |
|
1328 | @reraise_safe_exceptions | |
@@ -1334,9 +1339,11 b' class GitRemote(RemoteBase):' | |||||
1334 | @reraise_safe_exceptions |
|
1339 | @reraise_safe_exceptions | |
1335 | def set_head_ref(self, wire, head_name): |
|
1340 | def set_head_ref(self, wire, head_name): | |
1336 | log.debug('Setting refs/head to `%s`', head_name) |
|
1341 | log.debug('Setting refs/head to `%s`', head_name) | |
1337 | cmd = ['symbolic-ref', '"HEAD"', '"refs/heads/%s"' % head_name] |
|
1342 | repo_init = self._factory.repo_libgit2(wire) | |
1338 | output, __ = self.run_git_command(wire, cmd) |
|
1343 | with repo_init as repo: | |
1339 | return [head_name] + output.splitlines() |
|
1344 | repo.set_head(f'refs/heads/{head_name}') | |
|
1345 | ||||
|
1346 | return [head_name] + [f'set HEAD to refs/heads/{head_name}'] | |||
1340 |
|
1347 | |||
1341 | @reraise_safe_exceptions |
|
1348 | @reraise_safe_exceptions | |
1342 | def archive_repo(self, wire, archive_dest_path, kind, mtime, archive_at_path, |
|
1349 | def archive_repo(self, wire, archive_dest_path, kind, mtime, archive_at_path, | |
@@ -1362,14 +1369,14 b' class GitRemote(RemoteBase):' | |||||
1362 | index.read_tree(tree) |
|
1369 | index.read_tree(tree) | |
1363 | file_iter = index |
|
1370 | file_iter = index | |
1364 |
|
1371 | |||
1365 | for fn in file_iter: |
|
1372 | for file_node in file_iter: | |
1366 | file_path = fn.path |
|
1373 | file_path = file_node.path | |
1367 | mode = fn.mode |
|
1374 | mode = file_node.mode | |
1368 | is_link = stat.S_ISLNK(mode) |
|
1375 | is_link = stat.S_ISLNK(mode) | |
1369 | if mode == pygit2.GIT_FILEMODE_COMMIT: |
|
1376 | if mode == pygit2.GIT_FILEMODE_COMMIT: | |
1370 | log.debug('Skipping path %s as a commit node', file_path) |
|
1377 | log.debug('Skipping path %s as a commit node', file_path) | |
1371 | continue |
|
1378 | continue | |
1372 | yield ArchiveNode(file_path, mode, is_link, repo[fn.hex].read_raw) |
|
1379 | yield ArchiveNode(file_path, mode, is_link, repo[file_node.hex].read_raw) | |
1373 |
|
1380 | |||
1374 | return archive_repo(file_walker, archive_dest_path, kind, mtime, archive_at_path, |
|
1381 | return archive_repo(file_walker, archive_dest_path, kind, mtime, archive_at_path, | |
1375 | archive_dir_name, commit_id) |
|
1382 | archive_dir_name, commit_id) |
@@ -115,10 +115,14 b' def test_pull_has_hook_messages(pygrack_' | |||||
115 | '0000', |
|
115 | '0000', | |
116 | '0009done\n', |
|
116 | '0009done\n', | |
117 | ]) |
|
117 | ]) | |
|
118 | ||||
|
119 | pre_pull = 'pre_pull_output' | |||
|
120 | post_pull = 'post_pull_output' | |||
|
121 | ||||
118 | with mock.patch('vcsserver.hooks.git_pre_pull', |
|
122 | with mock.patch('vcsserver.hooks.git_pre_pull', | |
119 |
return_value=hooks.HookResponse(0, |
|
123 | return_value=hooks.HookResponse(0, pre_pull)): | |
120 | with mock.patch('vcsserver.hooks.git_post_pull', |
|
124 | with mock.patch('vcsserver.hooks.git_post_pull', | |
121 |
return_value=hooks.HookResponse(1, |
|
125 | return_value=hooks.HookResponse(1, post_pull)): | |
122 | with mock.patch('vcsserver.subprocessio.SubprocessIOChunker', |
|
126 | with mock.patch('vcsserver.subprocessio.SubprocessIOChunker', | |
123 | return_value=more_itertools.always_iterable([b'0008NAK\n0009subp\n0000'])): |
|
127 | return_value=more_itertools.always_iterable([b'0008NAK\n0009subp\n0000'])): | |
124 | response = pygrack_app.post( |
|
128 | response = pygrack_app.post( | |
@@ -129,7 +133,11 b' def test_pull_has_hook_messages(pygrack_' | |||||
129 | proto = dulwich.protocol.Protocol(data.read, None) |
|
133 | proto = dulwich.protocol.Protocol(data.read, None) | |
130 | packets = list(proto.read_pkt_seq()) |
|
134 | packets = list(proto.read_pkt_seq()) | |
131 |
|
135 | |||
132 |
assert packets == [b'NAK\n', |
|
136 | assert packets == [b'NAK\n', | |
|
137 | # pre-pull only outputs if IT FAILS as in != 0 ret code | |||
|
138 | #b'\x02pre_pull_output', | |||
|
139 | b'subp\n', | |||
|
140 | b'\x02post_pull_output'] | |||
133 |
|
141 | |||
134 |
|
142 | |||
135 | def test_get_want_capabilities(pygrack_instance): |
|
143 | def test_get_want_capabilities(pygrack_instance): |
General Comments 0
You need to be logged in to leave comments.
Login now