I have some C code which writes Ruby code into Git’s post-commit hook. The way this is currently being pulled off is by embedding the Ruby code directly in a C string like so…
char * post_commit_hook = <<Ruby code here>>
It’s then written directly to .git/hooks/post-commit by way of fprintf.
This is somewhat ugly and difficult to maintain IMO, and I was wondering if there was some way to move the Ruby code into its own file. I tried looking for ways to have GNU make to do text replacement on the fly, but somehow that still feels like a hack. Anyone have any ideas?
Put your code into its own file and generate a C header from that via
makeand a scripting language of your choice.For example, the following
makeruletogether with this Perl script
rb2hwill generate a file
hook.hwhich defines the macroPOST_COMMIT_HOOKcontaining your code.