I'd generally prefer not to have the git(1) incantation hanging around in an unrelated function.
Here's the original code from the "git-rev" package: https://github.com/tblobaum/git-rev/blob/master/index.js