1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Don't fail in Diffusion if .gitmodules is missing

Summary:
See T1448. If this file isn't present, just move on instead of failing, since it's a (sort of) legitimate repository state.

Also fix some silliness a little later that got introduced in refactoring, I think.

Test Plan: Added an external to my test repo and removed ".gitmodules". Verified that the directory is now viewable after this patch.

Reviewers: btrahan, davidreuss, jungejason

Reviewed By: davidreuss

CC: aran

Maniphest Tasks: T1448

Differential Revision: https://secure.phabricator.com/D2922
This commit is contained in:
epriestley 2012-07-05 06:12:35 -07:00
parent bf9cd55577
commit 4dd5bcf1cd

View file

@ -116,29 +116,39 @@ final class DiffusionGitBrowseQuery extends DiffusionBrowseQuery {
// NOTE: We need to read the file out of git and write it to a temporary // NOTE: We need to read the file out of git and write it to a temporary
// location because "git config -f" doesn't accept a "commit:path"-style // location because "git config -f" doesn't accept a "commit:path"-style
// argument. // argument.
list($contents) = $repository->execxLocalCommand(
// NOTE: This file may not exist, e.g. because the commit author removed
// it when they added the submodule. See T1448. If it's not present, just
// show the submodule without enriching it. If ".gitmodules" was removed
// it seems to partially break submodules, but the repository as a whole
// continues to work fine and we've seen at least two cases of this in
// the wild.
list($err, $contents) = $repository->execLocalCommand(
'cat-file blob %s:.gitmodules', 'cat-file blob %s:.gitmodules',
$commit); $commit);
$tmp = new TempFile(); if (!$err) {
Filesystem::writeFile($tmp, $contents); $tmp = new TempFile();
list($module_info) = $repository->execxLocalCommand( Filesystem::writeFile($tmp, $contents);
'config -l -f %s', list($module_info) = $repository->execxLocalCommand(
$tmp); 'config -l -f %s',
$tmp);
$dict = array(); $dict = array();
$lines = explode("\n", trim($module_info)); $lines = explode("\n", trim($module_info));
foreach ($lines as $line) { foreach ($lines as $line) {
list($key, $value) = explode('=', $line, 2); list($key, $value) = explode('=', $line, 2);
$parts = explode('.', $key); $parts = explode('.', $key);
$dict[$key] = $value; $dict[$key] = $value;
} }
foreach ($submodules as $path) { foreach ($submodules as $path) {
$full_path = $path->getFullPath(); $full_path = $path->getFullPath();
$key = $dict['submodule.'.$full_path.'.url']; $key = 'submodule.'.$full_path.'.url';
if (isset($dict[$key])) { if (isset($dict[$key])) {
$path->setExternalURI($key); $path->setExternalURI($dict[$key]);
}
} }
} }
} }