Show HEADs for Git 1.7.8+ submodules
authorKevin Israel <pleasestand@live.com>
Sun, 3 Feb 2013 00:11:28 +0000 (19:11 -0500)
committerChad Horohoe <chadh@wikimedia.org>
Wed, 20 Feb 2013 16:14:52 +0000 (11:14 -0500)
I implemented "the gitfile mechanism" in the GitInfo class so it
can access gitdirs for submodules again.

Bug: 44599
Change-Id: Ieb79c0b401a6bb0f5ca8bff98bb382a8c6ffbb01

RELEASE-NOTES-1.21
includes/GitInfo.php

index 34030be..6e811fc 100644 (file)
@@ -173,6 +173,8 @@ production.
   URL without address
 * (bug 45012) Creating an account by e-mail can no longer show a
   "password mismatch" error.
+* (bug 44599) On Special:Version, HEADs for submodule checkouts (e.g. for
+  extensions) performed using Git 1.7.8+ should now appear.
 
 === API changes in 1.21 ===
 * prop=revisions can now report the contentmodel and contentformat.
index c3c3073..a0a216e 100644 (file)
@@ -44,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}";
+                       }
+               }
        }
 
        /**
@@ -102,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;
                }