Skip to content

Instantly share code, notes, and snippets.

@standarddeviant
Created June 6, 2019 03:33
Show Gist options
  • Select an option

  • Save standarddeviant/91497c45f5a50ba9c8cf3029e8e00a78 to your computer and use it in GitHub Desktop.

Select an option

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
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