diff --git a/lib/prepare.js b/lib/prepare.js index cbac855e..b331cc9c 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -32,29 +32,32 @@ module.exports = async (pluginConfig, context) => { const modifiedFiles = await getModifiedFiles({env, cwd}); - const filesToCommit = uniq( - await pReduce( - assets.map((asset) => (!isArray(asset) && isPlainObject(asset) ? asset.path : asset)), - async (result, asset) => { - const glob = castArray(asset); - let nonegate; - // Skip solo negated pattern (avoid to include every non js file with `!**/*.js`) - if (glob.length <= 1 && glob[0].startsWith('!')) { - nonegate = true; - debug( - 'skipping the negated glob %o as its alone in its group and would retrieve a large amount of files ', - glob[0] - ); - } + const filesToCommit = + assets && assets.length > 0 + ? uniq( + await pReduce( + assets.map((asset) => (!isArray(asset) && isPlainObject(asset) ? asset.path : asset)), + async (result, asset) => { + const glob = castArray(asset); + let nonegate; + // Skip solo negated pattern (avoid to include every non js file with `!**/*.js`) + if (glob.length <= 1 && glob[0].startsWith('!')) { + nonegate = true; + debug( + 'skipping the negated glob %o as its alone in its group and would retrieve a large amount of files ', + glob[0] + ); + } - return [ - ...result, - ...micromatch(modifiedFiles, await dirGlob(glob, {cwd}), {dot: true, nonegate, cwd, expand: true}), - ]; - }, - [] - ) - ); + return [ + ...result, + ...micromatch(modifiedFiles, await dirGlob(glob, {cwd}), {dot: true, nonegate, cwd, expand: true}), + ]; + }, + [] + ) + ) + : []; if (filesToCommit.length > 0) { logger.log('Found %d file(s) to commit', filesToCommit.length); diff --git a/test/prepare.test.js b/test/prepare.test.js index 8e7d97a1..82110ff8 100644 --- a/test/prepare.test.js +++ b/test/prepare.test.js @@ -123,6 +123,22 @@ test('Commit files matching the patterns in "assets"', async (t) => { t.deepEqual(t.context.log.args[0], ['Found %d file(s) to commit', 5]); }); +test('Commit no files when "assets" is false', async (t) => { + const {cwd, repositoryUrl} = await gitRepo(true); + const pluginConfig = { + assets: false, + }; + const branch = {name: 'master'}; + const options = {repositoryUrl}; + const env = {}; + const lastRelease = {}; + const nextRelease = {version: '2.0.0', gitTag: 'v2.0.0'}; + + await prepare(pluginConfig, {cwd, env, options, branch, lastRelease, nextRelease, logger: t.context.logger}); + + t.deepEqual((await gitCommitedFiles('HEAD', {cwd, env})).sort(), []); +}); + test('Commit files matching the patterns in "assets" as Objects', async (t) => { const {cwd, repositoryUrl} = await gitRepo(true); const pluginConfig = {