diff options
| -rw-r--r-- | misc/.gitattributes | 1 | ||||
| -rw-r--r-- | misc/get_version.php | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/misc/.gitattributes b/misc/.gitattributes new file mode 100644 index 0000000..e383d5c --- /dev/null +++ b/misc/.gitattributes @@ -0,0 +1 @@ +get_version.php ident export-subst
\ No newline at end of file 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 |
