How can I embed info such as Git hash/branch/tag info into a Delphi app?

I want to be able to display the git branch, tag, and/or commit hash (bonus points for dirty working directory) in my Delphi app, so it can be displayed for the usual sanity checks.

I've done this in Linux, but don't know Windows well enough, nor how to integrate it into Delphi. I'm guessing a pre-build step in the project's options.

  • You could use a script to populate. Maybe have a template unit with some consts defined. Then have a shell script that gets the info from git and replaces const placeholders with the appropriate values.



    unit gitinfo;


    const GIT_BRANCH = ':git_branch:'; // do a search and replace on :git_branch:

    // ...




    using cygwin, you can use the linux scripting you are familiar with. e.g. script could be something like:



    branch=`git rev-parse --abbrev-ref HEAD`

    sed -i .bak  "s/:git_branch:/${branch}/g" gitinfo.pas

    rm -f gitinfo.pas.bak


    I'd normally let the consts have some value like 'DEV'... and let continuous integration run the script when a build takes place.