Get hash of most recent git commit

Hello,

I want to implement in my application the string of the latest git commit hash. The reason is that I have sometimes to create builds for different customers.

How can I retrieve such a thing in Xojo ? I want to be used if I build on mac or windows.

I use this command to retrieve the latest hash

git rev-parse --short HEAD

Should I use a script in the build settings?

Well I do not know if it’s the best things to do at all or it’s more an issue of managing the project but some features are for a specific customer or some important fixes can not wait a future release for some customers.

Thanks,

Julien

Hi, I would turn the thing upside down.
Use a form for your commits, which holds more than the git onliner.
Create a git commit out of it and push the data into a database.

Other option ; use git log pretty and push the thing into a database.

Benefit : full control , reporting and more.

See also : git commit template .

BR Rainer

BTW : if its ok to you to use subversion instead of git . Have a look at tortoise svn, its using a sqlite db, which u can link to your workflow, or use good ol fossil-scm… old but still good, even fits on a usb stick.

We did exactly this by storing the hash to an App constant in a pre build script. If needed, I can give you the details when I’m at my desk later.

Hi thank you for the answers,

@Rainer_Greim Storing it in the database can be a good idea but I am not using a local database, we are calling an in house API to retrieves our data. And I want the to retrieves the hash even without being connected to our API
We are very used to work with git and do not plan to switch

@Kem_Tekinay Would like to know how you did it !

dim gitRev As String = Trim(DoShellCommand("git --git-dir=""$PROJECT_PATH/../.git"" rev-parse HEAD"))

ConstantValue("App.GitRevision") = gitRev

Edit: In a release-only build script. We store the script externally and call it for all platform builds.

Another edit: @Jeremy_Cowgar wrote that code. It’s his world and we’re just trying to keep up.

1 Like

Thank you I will try it out