aboutsummaryrefslogtreecommitdiffhomepage
path: root/misc/get_version.php
diff options
context:
space:
mode:
authorwinter2025-01-18 20:37:43 +0000
committerwinter2025-01-18 20:58:31 +0000
commit43933d556499e84094dd9667a5325584ebe5fe43 (patch)
tree7d40fa50842f557f7ef87ab67dc39e8c9d96fe7a /misc/get_version.php
parent66bdcf04f431d615b5fac93e7677e7304888e90c (diff)
git version getter thing
Diffstat (limited to 'misc/get_version.php')
-rw-r--r--misc/get_version.php21
1 files changed, 21 insertions, 0 deletions
diff --git a/misc/get_version.php b/misc/get_version.php
new file mode 100644
index 0000000..8d48b4a
--- /dev/null
+++ b/misc/get_version.php
@@ -0,0 +1,21 @@
+<?php
+// because of the values in .gitattributes, these should get modified according
+// to the current commit (on any checkout) and/or ref (in archive exports)
+// don't touch these yourself even if they look wrong!
+const __GIT_ID_INFO__ = '$Id$';
+const __GIT_REF_INFO__ = '$Format:%D$';
+
+/**
+ * Gets a version identifier for the currently checked out version of the software
+ * @return string
+ */
+function get_version(): string {
+ if (str_contains(__GIT_REF_INFO__, 'tag: ')) {
+ return explode(',', explode('tag: ', __GIT_REF_INFO__, 2)[1], 2)[0];
+ }
+ // have to do this janky string thing to stop git replacing this one as well :3
+ if (__GIT_ID_INFO__ != '$' . 'Id$') {
+ return 'git ' . substr(__GIT_ID_INFO__, 5, 10);
+ }
+ return 'unknown';
+} \ No newline at end of file