Skip to content

Instantly share code, notes, and snippets.

@neekey
Created August 27, 2014 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neekey/0a1ad02a1cc28e089495 to your computer and use it in GitHub Desktop.
Save neekey/0a1ad02a1cc28e089495 to your computer and use it in GitHub Desktop.
获取当前git仓库信息
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