Created
June 6, 2019 03:33
-
-
Save standarddeviant/91497c45f5a50ba9c8cf3029e8e00a78 to your computer and use it in GitHub Desktop.
A python script to generate git hooks to dump git version to a C header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| git_version_hook_lines = [ | |
| "#!/bin/sh\n", | |
| "git_version_str=$(printf '#define GIT_VERSION_STRING \"%s\"' $(git rev-parse --short=16 HEAD))\n", | |
| "echo $git_version_str\n", | |
| "echo $git_version_str > ./git_version.h\n", | |
| ] | |
| hooks_dir = os.path.join(os.getcwd(), '.git', 'hooks') | |
| for hook in ('post-merge', 'post-commit', 'post-checkout'): | |
| fpath = os.path.join(hooks_dir, hook) | |
| with open(fpath, 'w') as f: | |
| f.writelines(git_version_hook_lines) | |
| os.chmod(fpath, 0o775) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment