Merge "Misc follow-ups to I2fc3966e (a161c5e)"
[lhc/web/wiklou.git] / includes / GitInfo.php
index e1b0379..a0a216e 100644 (file)
@@ -5,6 +5,21 @@
  * of anyone working on large branches in git to setup config that show up only
  * when specific branches are currently checked out.
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  */
 
@@ -29,7 +44,15 @@ class GitInfo {
         * @param $dir string The root directory of the repo where the .git dir can be found
         */
        public function __construct( $dir ) {
-               $this->basedir = "{$dir}/.git/";
+               $this->basedir = "{$dir}/.git";
+               if ( is_readable( $this->basedir ) ) {
+                       $GITfile = file_get_contents( $this->basedir );
+                       if ( strlen( $GITfile ) > 8 && substr( $GITfile, 0, 8 ) === 'gitdir: ' ) {
+                               $path = rtrim( substr( $GITfile, 8 ), "\r\n" );
+                               $isAbsolute = $path[0] === '/' || substr( $path, 1, 1 ) === ':';
+                               $this->basedir = $isAbsolute ? $path : "{$dir}/{$path}";
+                       }
+               }
        }
 
        /**
@@ -87,7 +110,7 @@ class GitInfo {
                }
 
                // If not a SHA1 it may be a ref:
-               $REFfile = "{$this->basedir}{$HEAD}";
+               $REFfile = "{$this->basedir}/{$HEAD}";
                if ( !is_readable( $REFfile ) ) {
                        return false;
                }