Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get tag output like: 3.5.3-18-dirty ? #72

Open
phatpaul opened this issue Mar 22, 2023 · 1 comment
Open

How to get tag output like: 3.5.3-18-dirty ? #72

phatpaul opened this issue Mar 22, 2023 · 1 comment

Comments

@phatpaul
Copy link

I need my version number to be compiled into my app. I want it to reflect the latest tag, the number of commits since that tag, and whether the working copy is dirty.

This is how it is typically done:

git describe --tags --always --dirty
3.5.3-8-geb51d63-dirty

(I don't really care if the hash is there or not, so it could also be 3.5.3-8-dirty. But I need to know if the app was built off the actual commit that the tag is pointing to, or a later commit, which the -8 tells me.).

But when I run:

node
Welcome to Node.js v14.17.3.
Type ".help" for more information.
> var git = require('git-rev-sync');
> console.log(git.tag(true));
3.5.3
undefined

This plugin is only returning the tag name without the expected suffix.
I think the issue may be with the --abbrev=0. The git documentation says: "An of 0 will suppress long format, only showing the closest tag."

git version 2.38.1.windows.1

@phatpaul
Copy link
Author

FYI, I've solved my own problem by removing this plugin and just using a simple 2-liner.

const execSync = require('child_process').execSync;
...
console.log( execSync('git describe --tags --always --dirty').toString('utf8').replace(/^\s+|\s+$/g, '') );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant