Skip to content

Commit

Permalink
fix: look for modified fiels to commit only if there files matching t…
Browse files Browse the repository at this point in the history
…he globs
  • Loading branch information
pvdlg committed Dec 19, 2018
1 parent 9e521d9 commit d97c030
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/git.js
Expand Up @@ -10,10 +10,12 @@ const debug = require('debug')('semantic-release:git');
* @return {Array<String>} 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))
: [];
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/git.test.js
Expand Up @@ -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();
Expand Down

0 comments on commit d97c030

Please sign in to comment.