From 76d69bd178caf625df37d8ed7af05f217c33ada2 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Wed, 24 Sep 2025 19:16:20 -0400 Subject: [PATCH] allow --match to take an array of matches --- README.md | 2 +- lib/git-describe.js | 4 ++++ test/git-describe.js | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4be5666..d720002 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ Option | Default | Description `long` | `true` | Always adds commit distance and hash to `raw`, `suffix` and `.toString()` (matches the behaviour of git describe's `--long`) `longSemver` | `false` | Always adds commit distance and hash to `semverString` (similar to git describe's `--long`, but for semver). `requireAnnotated` | `false` | Uses `--tags` if false, so that simple git tags are allowed. -`match` | `'v[0-9]*'` | Uses `--match` to filter tag names. By default only tags resembling a version number are considered. +`match` | `'v[0-9]*'` | Uses `--match` to filter tag names. By default only tags resembling a version number are considered. Can be an array to use many `--match`. `customArguments` | `[]` | Array of additional arguments to pass to `git describe`. Not all arguments are useful and some may even break the library, but things like `--abbrev` and `--candidates` should be safe to add. [1]: https://git-scm.com/docs/git-describe diff --git a/lib/git-describe.js b/lib/git-describe.js index e907adb..90c3136 100644 --- a/lib/git-describe.js +++ b/lib/git-describe.js @@ -59,6 +59,10 @@ function createExecArgs(directory, options) { execArgs.push('--tags'); if (_.isString(options.match)) execArgs = execArgs.concat(['--match', options.match]); + if (_.isArray(options.match)) + options.match.forEach( match => + execArgs = execArgs.concat(['--match', match]) + ); if (_.isArray(options.customArguments)) execArgs = execArgs.concat(options.customArguments); return execArgs; diff --git a/test/git-describe.js b/test/git-describe.js index 204b77a..da8bc6a 100644 --- a/test/git-describe.js +++ b/test/git-describe.js @@ -111,6 +111,13 @@ describe('gitDescribe', function() { }); }); + it('should accept an array for match', function() { + return gitDescribe(repoDir, {match: [ '*3' ] }) + .then(function(gitInfo) { + gitInfo.tag.should.equal('v1.2.3'); + }); + }); + it('should recognize dirty state', function() { repo.changeData(); return gitDescribe(repoDir)