Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating project version number on git push

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.

like image 441
dabs Avatar asked Jun 16 '14 02:06

dabs


People also ask

How do I manage version numbers in git?

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.

What does update project do in git?

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


1 Answers

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 here
  • git describe as in this script

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

like image 144
VonC Avatar answered Oct 02 '22 00:10

VonC