From e951be59c60a70dd442d10acb4f6e1064967e345 Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Sat, 2 Feb 2013 19:11:28 -0500 Subject: [PATCH] Show HEADs for Git 1.7.8+ submodules 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 | 2 ++ includes/GitInfo.php | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 34030beabc..6e811fc71e 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -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. diff --git a/includes/GitInfo.php b/includes/GitInfo.php index c3c307336e..a0a216ee58 100644 --- a/includes/GitInfo.php +++ b/includes/GitInfo.php @@ -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; } -- 2.20.1