Skip to content

Commit d97c030

Browse files
committedDec 19, 2018
fix: look for modified fiels to commit only if there files matching the globs
1 parent 9e521d9 commit d97c030

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed
 

‎lib/git.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ const debug = require('debug')('semantic-release:git');
1010
* @return {Array<String>} Array of modified files path.
1111
*/
1212
async function filterModifiedFiles(files, execaOpts) {
13-
return (await execa.stdout('git', ['ls-files', '-m', '-o', ...files], execaOpts))
14-
.split('\n')
15-
.map(file => file.trim())
16-
.filter(file => Boolean(file));
13+
return files.length > 0
14+
? (await execa.stdout('git', ['ls-files', '-m', '-o', ...files], execaOpts))
15+
.split('\n')
16+
.map(file => file.trim())
17+
.filter(file => Boolean(file))
18+
: [];
1719
}
1820

1921
/**

‎test/git.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ test('Returns [] if there is no modified files', async t => {
4747
await t.deepEqual(await filterModifiedFiles(['file1.js', 'file2.js'], {cwd}), []);
4848
});
4949

50+
test('Returns [] if there is no files for which to check modification', async t => {
51+
// Create a git repository, set the current working directory at the root of the repo
52+
const {cwd} = await gitRepo();
53+
// Create files
54+
await outputFile(path.resolve(cwd, 'file1.js'), '');
55+
await outputFile(path.resolve(cwd, 'dir/file2.js'), '');
56+
57+
await t.deepEqual(await filterModifiedFiles([], {cwd}), []);
58+
});
59+
5060
test('Commit added files', async t => {
5161
// Create a git repository, set the current working directory at the root of the repo
5262
const {cwd} = await gitRepo();

0 commit comments

Comments
 (0)
Please sign in to comment.