From d97c03082b948f1189fdc22d639505fa0395f711 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 19 Dec 2018 12:09:42 -0500 Subject: [PATCH] fix: look for modified fiels to commit only if there files matching the globs --- lib/git.js | 10 ++++++---- test/git.test.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/git.js b/lib/git.js index 3f02846e..43e143aa 100644 --- a/lib/git.js +++ b/lib/git.js @@ -10,10 +10,12 @@ const debug = require('debug')('semantic-release:git'); * @return {Array} Array of modified files path. */ async function filterModifiedFiles(files, execaOpts) { - return (await execa.stdout('git', ['ls-files', '-m', '-o', ...files], execaOpts)) - .split('\n') - .map(file => file.trim()) - .filter(file => Boolean(file)); + return files.length > 0 + ? (await execa.stdout('git', ['ls-files', '-m', '-o', ...files], execaOpts)) + .split('\n') + .map(file => file.trim()) + .filter(file => Boolean(file)) + : []; } /** diff --git a/test/git.test.js b/test/git.test.js index 4bb2f520..277ea2af 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -47,6 +47,16 @@ test('Returns [] if there is no modified files', async t => { await t.deepEqual(await filterModifiedFiles(['file1.js', 'file2.js'], {cwd}), []); }); +test('Returns [] if there is no files for which to check modification', async t => { + // Create a git repository, set the current working directory at the root of the repo + const {cwd} = await gitRepo(); + // Create files + await outputFile(path.resolve(cwd, 'file1.js'), ''); + await outputFile(path.resolve(cwd, 'dir/file2.js'), ''); + + await t.deepEqual(await filterModifiedFiles([], {cwd}), []); +}); + test('Commit added files', async t => { // Create a git repository, set the current working directory at the root of the repo const {cwd} = await gitRepo();