1

Referring to this question How to get the git commit count? is there a way to read the value from somewhere (e.g.: a file) rather than executing a system command?

In my case, I want to be able to see the version (e.g.: send it as an HTTP response) of my node.js application as a simple number of git commit count, and I can't execute system commands, in this case git rev-list --all --count. Is this command a dynamic operation that needs to communicate with the remote repository?

I looked into .git folder but I can't find this specific number.

Community
  • 1
  • 1
Alexandru Irimiea
  • 2,513
  • 4
  • 26
  • 46

1 Answers1

1
  1. You should really be using the git tooling to query git.

  2. This will not need to access the remote repository, it can be done on the local copy.

  3. Since the version only changes when you checkout/deploy, you could run the query command during that step (maybe a git-hook) and write the result to a file for NodeJS to pick up. That way you don't have to query dynamically (and it's faster).

Thilo
  • 257,207
  • 101
  • 511
  • 656