Do not read /.git if it is a directory
authorumherirrender <umherirrender_de.wp@web.de>
Wed, 27 Feb 2013 18:36:25 +0000 (19:36 +0100)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 27 Feb 2013 18:43:57 +0000 (18:43 +0000)
On my windows under eclipse with EGit there is a directory named .git,
but that gives warning, when read with file_get_contents:
Warning: file_get_contents(/.git) [function.file-get-contents]: failed
to open stream: Permission denied in \includes\GitInfo.php on line 49

Follow up Ieb79c0b4

Change-Id: I7c3ba323460a2fd3739d3912ee6420aa29311f4f

includes/GitInfo.php

index a0a216e..0867cd9 100644 (file)
@@ -45,7 +45,7 @@ class GitInfo {
         */
        public function __construct( $dir ) {
                $this->basedir = "{$dir}/.git";
-               if ( is_readable( $this->basedir ) ) {
+               if ( is_readable( $this->basedir ) && !is_dir( $this->basedir ) ) {
                        $GITfile = file_get_contents( $this->basedir );
                        if ( strlen( $GITfile ) > 8 && substr( $GITfile, 0, 8 ) === 'gitdir: ' ) {
                                $path = rtrim( substr( $GITfile, 8 ), "\r\n" );