API: Expose git branch in siteinfo
authorAntoine Musso <hashar@free.fr>
Tue, 6 May 2014 19:28:22 +0000 (21:28 +0200)
committerBryanDavis <bdavis@wikimedia.org>
Wed, 7 May 2014 00:25:51 +0000 (00:25 +0000)
For browser testing, I need a reliable way to determine the branch in use
on a target wiki.  One could parse the generator name forged when
querying the siteinfo, but that yields:

 MediaWiki 1.24alpha  instead of master
 MediaWiki 1.24wmf2   instead of wmf/1.24wmf2

I am not really willing to reverse engineer the version to figure out
the branch, instead just expose it over the API.

Bug: 62509
Change-Id: If3db8f480ce0d590522741d40fb8e43b753efb41

includes/api/ApiQuerySiteinfo.php
includes/specials/SpecialVersion.php

index b0e9bd2..636d798 100644 (file)
@@ -180,6 +180,8 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $git = SpecialVersion::getGitHeadSha1( $GLOBALS['IP'] );
                if ( $git ) {
                        $data['git-hash'] = $git;
+                       $data['git-branch'] =
+                               SpecialVersion::getGitCurrentBranch( $GLOBALS['IP'] );
                } else {
                        $svn = SpecialVersion::getSvnRevision( $GLOBALS['IP'] );
                        if ( $svn ) {
index e61d17a..41847dc 100644 (file)
@@ -1113,6 +1113,15 @@ class SpecialVersion extends SpecialPage {
                return $repo->getHeadSHA1();
        }
 
+       /**
+        * @param string $dir Directory of the git checkout
+        * @return bool|string Branch currently checked out
+        */
+       public static function getGitCurrentBranch( $dir ) {
+               $repo = new GitInfo( $dir );
+               return $repo->getCurrentBranch();
+       }
+
        /**
         * Get the list of entry points and their URLs
         * @return string Wikitext