0

I am trying Git-Describe npm package to retrieve hash information and tag to append to my application later.

I have following the instruction that are provided in the Git describe npm page. The script worked well but the tag information is retrieved as null here. Also I have added few tags in the local and my remote git.

I am able to retrieve all the tag information using git tag -l

The below is the script that I was trying to run.

const {gitDescribe, gitDescribeSync} = require('git-describe');
 
// Another example: working directory, use 16 character commit hash abbreviation
const gitInfo = gitDescribeSync({
    customArguments: ['--abbrev=16']
});
 
// Asynchronous with promise
gitDescribe(__dirname)
    .then((gitInfo) => console.dir(gitInfo))
    .catch((err) => console.error(err));
 
// Asynchronous with node-style callback
gitDescribe(__dirname, (err, gitInfo) => {
    if (err)
        return console.error(err);
    console.dir(gitInfo);
});

node version.js

Output is:

{
  dirty: true,
  raw: 'f8f7e57e-dirty',
  hash: 'f8f7e57e',
  distance: null,
  tag: null,
  semver: null,
  suffix: 'f8f7e57e-dirty',
  semverString: null,
  toString: [Function]
}

Here the tag info are coming with null. But the hash string is correct. (Git log output).

commit **f8f7e57e**713b71b0f9d3181c0d19ffd (HEAD -> PF223095_US1834348_ui_gitcommit, tag: r9.0.6, origin/PF223095_US1834348_ui_gitcommit, mastere)
halfer
  • 19,824
  • 17
  • 99
  • 186
Raja
  • 3,477
  • 12
  • 47
  • 89

2 Answers2

0

Looks like by default git-describe only tracks versions that start with v so something like v1.0.0 works and 1.0.0 fails.

zxiiro
  • 92
  • 5
0

As @zxiiro said, the default behaviour is to look for tags starting with v followed by a digit (v0.9, v2.3-dev).

You can specify your own regex with the match option, this example will match tags starting with a digit (0.9, 2.3-dev, 99-luft-balloons)

const gitInfo = gitDescribeSync({match: '[0-9]*'});
Zaq
  • 1,071
  • 2
  • 10
  • 19