I am developing an internal web application for a company I am doing some work for. It is hosted on a private github repository, but most of my development is done on my linux desktop at home, and the web server for this is hosted in the companies office on a small raspberry pi. It is essentially nginx front end proxying the /api url to a nodejs application supported by pm2.
I deploy by git push
ing to the github repository from my home and git pull
ing the production branch in the server. A git hook
post-commit
script runs a npm install in a build directory before temporarily stopping the production api server, copying over the node_modules directory and running a script which in essence does git describe --abbrev=0 --tags
to get and store the version number in a .env
file for the production server to announce its version to clients.
If I run git describe at home it gives version v4.2.2
, but in the clinic I get v4.1.17
and I cannot see why
In the image below the left hand part is the output of gitk --all
on my home repository and with only terminal access in the clinic, you can see from the right hand part pretty much the same graph using git log
– with commits missing that are not relevant to either the master
or production
branch. v4.2.2 is only two commits away, whereas v4.1.17 is at least 10 away.
Why is git describe behaving the way it is?
EDIT: I sort of know the answer – on the server there is a post-commit hook that ended up making a commit on the branch, even though it wasn’t supposed to – it was only supposed to be doing it on the development machine.
2
Answers
answered by @TTT in his comment :
maybe the cause of the problem is that you intended the server local production branch to be the same as your home branch, but it isn’t. So every time it does a pull it’s making a new merge commit. Maybe the server should push out its version (if you want to keep that), or, maybe the server should get the latest with a
git fetch && git reset --hard @{u}
instead of withgit pull
. (If the server shouldn’t be making it’s own commits.)Git 2.40 (Q1 2023), clarifies what you must do for environment variables set when hooks are invoked.
That would help
git describe
to behave as expected in a hook.See commit 772f8ff (09 Jan 2023) by Eric Sunshine (
sunshineco
).(Merged by Junio C Hamano —
gitster
— in commit fc2735f, 21 Jan 2023)githooks
now includes in its man page: