I have a project hosted on Github, and I would like to set it up such that the project has a version number, and the version number is only updated when the master branch is updated, either directly by a push, or via a merged Pull Request.
Is there any way to let git/Bitbucket update a specific number in a specific file? It is OK if there is just a dedicated file for this purpose, containing a single number. I assume I will be able to write code that upon asking what version my project is using, will simply read that file. My project is a C# Web API project, although I'm not sure that matters much.
Using Git to Create a Version NumberThe git describe command returns the latest tag on the current branch. If additional commits have been made after the tag, the tag name is suffixed with the number of additional commits and the hash of the tip commit.
When you perform the update operation, IntelliJ IDEA fetches changes from all project roots and branches, and merges the tracked remote branches into your local working copy (equivalent to pull).
Is there any way to let git/Bitbucket update a specific number in a specific file?
Not a file tracked in the repo, since it would be part of another commit.
As explained in "How do I enable ident string for Git repos?", that is a task (generating build info) better left to a build system, rather than some kind of hook/content filter.
Any repo hosting services can have webhooks (GitHub, BitBucket) allowing you to attach some kind of process to an event (like a git push), but those process would be executed on the client side (a client listening to the JSON payload generated by said webhook): nothing is executed on GitHub/BitBucket servers (except maybe BitBucket brokers, mainly to communicate with other third-party services).
One way which could work though is a post-commit hook (executed on the client, before pushing) using:
git notes
as described heregit describe
as in this scriptThat way, each commit would update a git notes
on said commit, with the content of a git describe
.
The idea with git notes is they don't change the SHA1 associated to the repo, meaning you can add those after a commit.
You can then push those notes to GitHub and see them.
git push origin refs/notes/*
See more with "Git Notes and GitHub " by Matthew McCullough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With