Permalink
Browse files

js/index.php: Retrieve the commitid even when jQM is a git submodule

  • Loading branch information...
1 parent 11f9546 commit 04b656264246ee5a7c39647ba828333c39357bb4 @gabrielschulhof gabrielschulhof committed Dec 19, 2012
Showing with 33 additions and 9 deletions.
  1. +33 −9 js/index.php
View
@@ -68,16 +68,40 @@
'jquery.mobile.init.js'
);
+function getGitHeadPath() {
+ $gitRoot = "../";
+ $gitDir = ".git";
+ $path = $gitRoot . $gitDir;
+
+ if ( is_file( $path ) && is_readable( $path ) ) {
+ $contents = file_get_contents( $path );
+ if ( $contents ) {
+ $contents = explode( " ", $contents );
+ if ( count( $contents ) > 1 ) {
+ $contents = explode( "\n", $contents[ 1 ] );
+ if ( $contents && count( $contents ) > 0 ) {
+ $path = $gitRoot . $contents[ 0 ];
+ }
+ }
+ }
+ }
+
+ return $path . "/logs/HEAD";
+}
+
function getCommitId() {
- $gitHeadPath = "../.git/logs/HEAD";
- $logs = ( is_readable( $gitHeadPath ) ? file_get_contents( $gitHeadPath ) : false );
- if ( $logs ) {
- $logs = explode( "\n", $logs );
- $n_logs = count( $logs );
- if ( $n_logs > 1 ) {
- $log = explode( " ", $logs[ $n_logs - 2 ] );
- if ( count( $log ) > 1 ) {
- return $log[ 1 ];
+ $gitHeadPath = getGitHeadPath();
+
+ if ( $gitHeadPath ) {
+ $logs = ( is_readable( $gitHeadPath ) ? file_get_contents( $gitHeadPath ) : false );
+ if ( $logs ) {
+ $logs = explode( "\n", $logs );
+ $n_logs = count( $logs );
+ if ( $n_logs > 1 ) {
+ $log = explode( " ", $logs[ $n_logs - 2 ] );
+ if ( count( $log ) > 1 ) {
+ return $log[ 1 ];
+ }
}
}
}

0 comments on commit 04b6562

Please sign in to comment.