@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix `--depth N` clones in Git

Summary: Ref T2230. Fixes T4079. As it turns out, this is Git being weird. See comments for some detials about what's going on here.

Test Plan: Created shallow and deep Git clones.

Reviewers: hach-que, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4079, T2230

Differential Revision: https://secure.phabricator.com/D7554

+30
+30
src/applications/diffusion/controller/DiffusionServeController.php
··· 329 329 ->resolve(); 330 330 331 331 if ($err) { 332 + if ($this->isValidGitShallowCloneResponse($stdout, $stderr)) { 333 + // Ignore the error if the response passes this special check for 334 + // validity. 335 + $err = 0; 336 + } 337 + } 338 + 339 + if ($err) { 332 340 return new PhabricatorVCSResponse( 333 341 500, 334 342 pht('Error %d: %s', $err, $stderr)); ··· 512 520 return implode('', $out); 513 521 } 514 522 523 + private function isValidGitShallowCloneResponse($stdout, $stderr) { 524 + // If you execute `git clone --depth N ...`, git sends a request which 525 + // `git-http-backend` responds to by emitting valid output and then exiting 526 + // with a failure code and an error message. If we ignore this error, 527 + // everything works. 528 + 529 + // This is a pretty funky fix: it would be nice to more precisely detect 530 + // that a request is a `--depth N` clone request, but we don't have any code 531 + // to decode protocol frames yet. Instead, look for reasonable evidence 532 + // in the error and output that we're looking at a `--depth` clone. 533 + 534 + // For evidence this isn't completely crazy, see: 535 + // https://github.com/schacon/grack/pull/7 536 + 537 + $stdout_regexp = '(^Content-Type: application/x-git-upload-pack-result)m'; 538 + $stderr_regexp = '(The remote end hung up unexpectedly)'; 539 + 540 + $has_pack = preg_match($stdout_regexp, $stdout); 541 + $is_hangup = preg_match($stderr_regexp, $stderr); 542 + 543 + return $has_pack && $is_hangup; 544 + } 515 545 } 516 546