File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -166,9 +166,19 @@ private function initDir($gitDir, $workingDir = null)
166166 throw new InvalidArgumentException (sprintf ('Directory "%s" does not exist or is not a directory ' , $ gitDir ));
167167 } elseif (!is_dir ($ realGitDir )) {
168168 throw new InvalidArgumentException (sprintf ('Directory "%s" does not exist or is not a directory ' , $ realGitDir ));
169- } elseif (null === $ workingDir && is_dir ($ realGitDir .'/.git ' )) {
169+ } elseif (null === $ workingDir && is_file ($ realGitDir . '/.git ' )) {
170+ if (!preg_match ('/^gitdir: ?(.+)$/ ' , file_get_contents ($ realGitDir . '/.git ' ), $ matches )) {
171+ throw new InvalidArgumentException (sprintf ('Directory "%s" contains a .git file, but it is not in the expected format ' , $ realGitDir ));
172+ }
173+ $ foundGitPath = realpath ($ realGitDir . DIRECTORY_SEPARATOR . $ matches [1 ]);
174+ if (!is_dir ($ foundGitPath )) {
175+ throw new InvalidArgumentException (sprintf ('Directory "%s" contains a .git file, but the directory it points to cannot be found ' , $ realGitDir ));
176+ }
177+ $ workingDir = $ realGitDir ;
178+ $ realGitDir = $ foundGitPath ;
179+ } elseif (null === $ workingDir && is_dir ($ realGitDir . '/.git ' )) {
170180 $ workingDir = $ realGitDir ;
171- $ realGitDir = $ realGitDir. '/.git ' ;
181+ $ realGitDir = $ realGitDir . '/.git ' ;
172182 }
173183
174184 $ this ->gitDir = $ realGitDir ;
You can’t perform that action at this time.
0 commit comments