Skip to content
This repository has been archived by the owner on Jul 30, 2023. It is now read-only.

Commit

Permalink
Don't fail in Diffusion if .gitmodules is missing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
epriestley committed Jul 5, 2012
1 parent bf9cd55 commit 4dd5bcf
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/applications/diffusion/query/browse/DiffusionGitBrowseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,39 @@ protected function executeQuery() {
// 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
// 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',
$commit);

$tmp = new TempFile();
Filesystem::writeFile($tmp, $contents);
list($module_info) = $repository->execxLocalCommand(
'config -l -f %s',
$tmp);

$dict = array();
$lines = explode("\n", trim($module_info));
foreach ($lines as $line) {
list($key, $value) = explode('=', $line, 2);
$parts = explode('.', $key);
$dict[$key] = $value;
}
if (!$err) {
$tmp = new TempFile();
Filesystem::writeFile($tmp, $contents);
list($module_info) = $repository->execxLocalCommand(
'config -l -f %s',
$tmp);

$dict = array();
$lines = explode("\n", trim($module_info));
foreach ($lines as $line) {
list($key, $value) = explode('=', $line, 2);
$parts = explode('.', $key);
$dict[$key] = $value;
}

foreach ($submodules as $path) {
$full_path = $path->getFullPath();
$key = $dict['submodule.'.$full_path.'.url'];
if (isset($dict[$key])) {
$path->setExternalURI($key);
foreach ($submodules as $path) {
$full_path = $path->getFullPath();
$key = 'submodule.'.$full_path.'.url';
if (isset($dict[$key])) {
$path->setExternalURI($dict[$key]);
}
}
}
}
Expand Down

0 comments on commit 4dd5bcf

Please sign in to comment.