Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions test/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down