【问题标题】:Git Describe NPM not providing Tag informationGit 描述 NPM 不提供标签信息
【发布时间】:2022-02-08 23:48:31
【问题描述】:

我正在尝试Git-Describe npm 包来检索哈希信息和标记,以便稍后附加到我的应用程序中。

我已按照Git describe npm page 中提供的说明进行操作。该脚本运行良好,但标记信息在此处检索为空。我还在本地和远程 git 中添加了一些标签。

我可以使用git tag -l检索所有标签信息

下面是我尝试运行的脚本。

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);
});

节点版本.js

输出是:

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

这里的标签信息带有空值。但是哈希字符串是正确的。 (Git 日志输出)。

commit **f8f7e57e**713b71b0f9d3181c0d19ffd (HEAD -> PF223095_US1834348_ui_gitcommit, tag: r9.0.6, origin/PF223095_US1834348_ui_gitcommit, mastere)

【问题讨论】:

    标签: node.js git npm git-describe


    【解决方案1】:

    看起来默认情况下 git-describe 只跟踪以 v 开头的版本,所以像 v1.0.0 这样的东西有效,1.0.0 失败。

    【讨论】:

      【解决方案2】:

      正如@zxiiro 所说,default behaviour 是寻找以v 开头后跟一个数字(v0.9v2.3-dev)的标签。

      您可以使用匹配选项指定自己的正则表达式,此示例将匹配以数字开头的标签(0.92.3-dev99-luft-balloons

      const gitInfo = gitDescribeSync({match: '[0-9]*'});
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-12-31
        • 1970-01-01
        • 2019-03-19
        • 2011-09-20
        • 1970-01-01
        • 1970-01-01
        • 2022-10-14
        相关资源
        最近更新 更多