Created
August 27, 2014 02:21
-
-
Save neekey/0a1ad02a1cc28e089495 to your computer and use it in GitHub Desktop.
获取当前git仓库信息
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRepoInfo(){ | |
var gitPath = PATH.resolve( process.cwd(), '.git' ); | |
console.log( gitPath ); | |
if( FS.existsSync( gitPath ) ){ | |
var HEAD = FS.readFileSync( PATH.resolve( gitPath, 'HEAD' )).toString(); | |
var CONFIG = FS.readFileSync( PATH.resolve( gitPath, 'config' )).toString(); | |
var result = {}; | |
console.log( HEAD, CONFIG ); | |
try { | |
console.log( 'try' ); | |
result.version = /ref\:\s+refs\/heads\/daily\/([\d\.]+)/g.exec( HEAD )[1]; | |
var repoRet = /gitlab\.alibaba-inc\.com[\/\:]{1}(\w+)\/(\w+)/g.exec( CONFIG ); | |
result.group = repoRet[1]; | |
result.name = repoRet[2]; | |
} | |
catch(e){ | |
console.log( 'error', e ); | |
getRepoInfo = function(){ | |
return null; | |
}; | |
return null; | |
} | |
getRepoInfo = function(){ | |
return result; | |
}; | |
return result; | |
} | |
else { | |
getRepoInfo = function(){ | |
return null; | |
}; | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment