Show More
@@ -186,19 +186,25 b' class GitRemote(RemoteBase):' | |||
|
186 | 186 | region = self._region(wire) |
|
187 | 187 | |
|
188 | 188 | @region.conditional_cache_on_arguments(condition=cache_on) |
|
189 | def _assert_correct_path(_context_uid, _repo_id): | |
|
190 |
|
|
|
191 |
|
|
|
192 | with repo_init as repo: | |
|
193 |
|
|
|
194 | except pygit2.GitError: | |
|
195 | path = wire.get('path') | |
|
196 | tb = traceback.format_exc() | |
|
197 | log.debug("Invalid Git path `%s`, tb: %s", path, tb) | |
|
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 | |
|
198 | 194 | return False |
|
195 | else: | |
|
196 | try: | |
|
197 | repo_init = self._factory.repo_libgit2(wire) | |
|
198 | with repo_init: | |
|
199 | pass | |
|
200 | except pygit2.GitError: | |
|
201 | path = wire.get('path') | |
|
202 | tb = traceback.format_exc() | |
|
203 | log.debug("Invalid Git path `%s`, tb: %s", path, tb) | |
|
204 | return False | |
|
205 | return True | |
|
199 | 206 | |
|
200 | return True | |
|
201 | return _assert_correct_path(context_uid, repo_id) | |
|
207 | return _assert_correct_path(context_uid, repo_id, True) | |
|
202 | 208 | |
|
203 | 209 | @reraise_safe_exceptions |
|
204 | 210 | def bare(self, wire): |
@@ -672,7 +678,7 b' class GitRemote(RemoteBase):' | |||
|
672 | 678 | |
|
673 | 679 | @reraise_safe_exceptions |
|
674 | 680 | def sync_fetch(self, wire, url, refs=None, all_refs=False): |
|
675 |
|
|
|
681 | self._factory.repo(wire) | |
|
676 | 682 | if refs and not isinstance(refs, (list, tuple)): |
|
677 | 683 | refs = [refs] |
|
678 | 684 | |
@@ -1266,7 +1272,7 b' class GitRemote(RemoteBase):' | |||
|
1266 | 1272 | _copts = [] |
|
1267 | 1273 | del opts['_bare'] |
|
1268 | 1274 | else: |
|
1269 |
_copts = ['-c', 'core.quotepath=false', |
|
|
1275 | _copts = ['-c', 'core.quotepath=false',] | |
|
1270 | 1276 | safe_call = False |
|
1271 | 1277 | if '_safe' in opts: |
|
1272 | 1278 | # no exc on failure |
@@ -1315,9 +1321,8 b' class GitRemote(RemoteBase):' | |||
|
1315 | 1321 | bare = self.bare(wire) |
|
1316 | 1322 | path = wire['path'] |
|
1317 | 1323 | binary_dir = settings.BINARY_DIR |
|
1318 | executable = None | |
|
1319 | 1324 | if binary_dir: |
|
1320 |
|
|
|
1325 | os.path.join(binary_dir, 'python3') | |
|
1321 | 1326 | return install_git_hooks(path, bare, force_create=force) |
|
1322 | 1327 | |
|
1323 | 1328 | @reraise_safe_exceptions |
@@ -1334,9 +1339,11 b' class GitRemote(RemoteBase):' | |||
|
1334 | 1339 | @reraise_safe_exceptions |
|
1335 | 1340 | def set_head_ref(self, wire, head_name): |
|
1336 | 1341 | log.debug('Setting refs/head to `%s`', head_name) |
|
1337 | cmd = ['symbolic-ref', '"HEAD"', '"refs/heads/%s"' % head_name] | |
|
1338 | output, __ = self.run_git_command(wire, cmd) | |
|
1339 | return [head_name] + output.splitlines() | |
|
1342 | repo_init = self._factory.repo_libgit2(wire) | |
|
1343 | with repo_init as repo: | |
|
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 | 1348 | @reraise_safe_exceptions |
|
1342 | 1349 | def archive_repo(self, wire, archive_dest_path, kind, mtime, archive_at_path, |
@@ -1362,14 +1369,14 b' class GitRemote(RemoteBase):' | |||
|
1362 | 1369 | index.read_tree(tree) |
|
1363 | 1370 | file_iter = index |
|
1364 | 1371 | |
|
1365 | for fn in file_iter: | |
|
1366 | file_path = fn.path | |
|
1367 | mode = fn.mode | |
|
1372 | for file_node in file_iter: | |
|
1373 | file_path = file_node.path | |
|
1374 | mode = file_node.mode | |
|
1368 | 1375 | is_link = stat.S_ISLNK(mode) |
|
1369 | 1376 | if mode == pygit2.GIT_FILEMODE_COMMIT: |
|
1370 | 1377 | log.debug('Skipping path %s as a commit node', file_path) |
|
1371 | 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 | 1381 | return archive_repo(file_walker, archive_dest_path, kind, mtime, archive_at_path, |
|
1375 | 1382 | archive_dir_name, commit_id) |
@@ -115,10 +115,14 b' def test_pull_has_hook_messages(pygrack_' | |||
|
115 | 115 | '0000', |
|
116 | 116 | '0009done\n', |
|
117 | 117 | ]) |
|
118 | ||
|
119 | pre_pull = 'pre_pull_output' | |
|
120 | post_pull = 'post_pull_output' | |
|
121 | ||
|
118 | 122 | with mock.patch('vcsserver.hooks.git_pre_pull', |
|
119 |
return_value=hooks.HookResponse(0, |
|
|
123 | return_value=hooks.HookResponse(0, pre_pull)): | |
|
120 | 124 | with mock.patch('vcsserver.hooks.git_post_pull', |
|
121 |
return_value=hooks.HookResponse(1, |
|
|
125 | return_value=hooks.HookResponse(1, post_pull)): | |
|
122 | 126 | with mock.patch('vcsserver.subprocessio.SubprocessIOChunker', |
|
123 | 127 | return_value=more_itertools.always_iterable([b'0008NAK\n0009subp\n0000'])): |
|
124 | 128 | response = pygrack_app.post( |
@@ -129,7 +133,11 b' def test_pull_has_hook_messages(pygrack_' | |||
|
129 | 133 | proto = dulwich.protocol.Protocol(data.read, None) |
|
130 | 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 | 143 | def test_get_want_capabilities(pygrack_instance): |
General Comments 0
You need to be logged in to leave comments.
Login now