Skip to content

Commit 7f26c5d

Browse files
committed
fix: look for modified fiels to commit only if there files matching the globs
1 parent 651224e commit 7f26c5d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/git.js

Lines changed: 6 additions & 4 deletions
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

Lines changed: 10 additions & 0 deletions
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)