Detect if your local Git has been modified and display it.

This commit is contained in:
EliteMasterEric 2024-05-01 13:29:54 -04:00
parent afdd28dbe2
commit 73baabfa82
3 changed files with 31 additions and 2 deletions
source/funkin/util

View file

@ -46,7 +46,7 @@ class Constants
#if (debug || FORCE_DEBUG_VERSION)
static function get_VERSION():String
{
return 'v${Application.current.meta.get('version')} (${GIT_BRANCH} : ${GIT_HASH})' + VERSION_SUFFIX;
return 'v${Application.current.meta.get('version')} (${GIT_BRANCH} : ${GIT_HASH}${GIT_HAS_LOCAL_CHANGES ? ' : MODIFIED' : ''})' + VERSION_SUFFIX;
}
#else
static function get_VERSION():String
@ -100,6 +100,8 @@ class Constants
*/
public static final GIT_HASH:String = funkin.util.macro.GitCommit.getGitCommitHash();
public static final GIT_HAS_LOCAL_CHANGES:Bool = funkin.util.macro.GitCommit.getGitHasLocalChanges();
/**
* The current library versions, as provided by hmm.
*/

View file

@ -120,7 +120,7 @@ class CrashHandler
fullContents += '\n';
fullContents += 'Generated by: ${Constants.GENERATED_BY}\n';
fullContents += ' Git hash: ${Constants.GIT_HASH}\n';
fullContents += ' Git hash: ${Constants.GIT_HASH} (${Constants.GIT_HAS_LOCAL_CHANGES ? 'MODIFIED' : 'CLEAN'})\n';
fullContents += 'System timestamp: ${DateUtil.generateTimestamp()}\n';
var driverInfo = FlxG?.stage?.context3D?.driverInfo ?? 'N/A';
fullContents += 'Driver info: ${driverInfo}\n';

View file

@ -63,5 +63,32 @@ class GitCommit
return macro $v{branchName};
#end
}
/**
* Get whether the local Git repository is dirty or not.
*/
public static macro function getGitHasLocalChanges():haxe.macro.Expr.ExprOf<Bool>
{
#if !display
// Get the current line number.
var pos = haxe.macro.Context.currentPos();
var branchProcess = new sys.io.Process('git', ['status', '--porcelain']);
if (branchProcess.exitCode() != 0)
{
var message = branchProcess.stderr.readAll().toString();
haxe.macro.Context.info('[WARN] Could not determine current git commit; is this a proper Git repository?', pos);
}
var output:String = branchProcess.stdout.readLine();
trace('Git Status Output: ${output}');
// Generates a string expression
return macro $v{output.length > 0};
#else
// `#if display` is used for code completion. In this case we just assume true.
return macro $v{true};
#end
}
}
#end