mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-23 08:07:54 -05:00
35 lines
1,017 B
Haxe
35 lines
1,017 B
Haxe
package funkin.util.macro;
|
|
|
|
#if debug
|
|
class GitCommit
|
|
{
|
|
public static macro function getGitCommitHash():haxe.macro.Expr.ExprOf<String>
|
|
{
|
|
#if !display
|
|
// Get the current line number.
|
|
var pos = haxe.macro.Context.currentPos();
|
|
|
|
var process = new sys.io.Process('git', ['rev-parse', 'HEAD']);
|
|
if (process.exitCode() != 0)
|
|
{
|
|
var message = process.stderr.readAll().toString();
|
|
haxe.macro.Context.info('[WARN] Could not determine current git commit; is this a proper Git repository?', pos);
|
|
}
|
|
|
|
// read the output of the process
|
|
var commitHash:String = process.stdout.readLine();
|
|
var commitHashSplice:String = commitHash.substr(0, 7);
|
|
|
|
trace('Git Commit ID ${commitHashSplice}');
|
|
|
|
// Generates a string expression
|
|
return macro $v{commitHashSplice};
|
|
#else
|
|
// `#if display` is used for code completion. In this case returning an
|
|
// empty string is good enough; We don't want to call git on every hint.
|
|
var commitHash:String = "";
|
|
return macro $v{commitHashSplice};
|
|
#end
|
|
}
|
|
}
|
|
#end
|