Skip to content

Commit 9ff6537

Browse files
author
Alexandre Salomé
authored
Merge pull request #113 from neemzy/master
Better directory existence check to avoid empty paths in exception
2 parents b4b9164 + 63472dc commit 9ff6537

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Gitonomy/Git/Repository.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,18 @@ public function __construct($dir, $options = array())
149149
*/
150150
private function initDir($gitDir, $workingDir = null)
151151
{
152-
$gitDir = realpath($gitDir);
152+
$realGitDir = realpath($gitDir);
153153

154-
if (null === $workingDir && is_dir($gitDir.'/.git')) {
155-
$workingDir = $gitDir;
156-
$gitDir = $gitDir.'/.git';
157-
} elseif (!is_dir($gitDir)) {
154+
if (false === $realGitDir) {
158155
throw new InvalidArgumentException(sprintf('Directory "%s" does not exist or is not a directory', $gitDir));
156+
} else if (!is_dir($realGitDir)) {
157+
throw new InvalidArgumentException(sprintf('Directory "%s" does not exist or is not a directory', $realGitDir));
158+
} elseif (null === $workingDir && is_dir($realGitDir.'/.git')) {
159+
$workingDir = $realGitDir;
160+
$realGitDir = $realGitDir.'/.git';
159161
}
160162

161-
$this->gitDir = $gitDir;
163+
$this->gitDir = $realGitDir;
162164
$this->workingDir = $workingDir;
163165
}
164166

0 commit comments

Comments
 (0)