Skip to content

Commit 629dfc4

Browse files
pvdlggr2m
authored andcommitted
feat: commit files from assets even if in they are in .gitignore
BREAKING CHANGE: the `.gitignore` file is now ignored when adding files to the release commit Each files matching a glob in `assets` will now be included in the release commit. The `assets` option has now to be configured to match exactly the the files that have to be commited, independently of the `.gitignore` file.
1 parent fede564 commit 629dfc4

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Each entry in the `assets` `Array` is globbed individually. A [glob](https://git
6464

6565
If a directory is configured, all the files under this directory and its children will be included.
6666

67-
If a file has a match in `.gitignore` it will always be excluded.
67+
**Note**: If a file has a match in `assets` it will be included even if it also has a match in `.gitignore`.
6868

6969
##### `assets` examples
7070

lib/git.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ const debug = require('debug')('semantic-release:git');
77
* @return {Array<String>} Array of modified files path.
88
*/
99
async function getModifiedFiles() {
10-
return (await execa.stdout('git', ['ls-files', '-m', '-o', '--exclude-standard']))
10+
return (await execa.stdout('git', ['ls-files', '-m', '-o']))
1111
.split('\n')
1212
.map(tag => tag.trim())
1313
.filter(tag => Boolean(tag));
1414
}
1515

1616
/**
17-
* Add a list of file to the Git index.
18-
* If on of the files is present in the .gitignore it will be silently skipped. Other files will still be added.
17+
* Add a list of file to the Git index. `.gitignore` will be ignored.
1918
*
2019
* @param {Array<String>} files Array of files path to add to the index,
2120
*/
2221
async function add(files) {
23-
const shell = await execa('git', ['add', '--ignore-errors'].concat(files), {reject: false});
22+
const shell = await execa('git', ['add', '--force', '--ignore-errors'].concat(files), {reject: false});
2423
debug('add file to git index', shell);
2524
}
2625

test/git.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test.serial('Add file to index', async t => {
2222
await t.deepEqual(await gitStaged(), ['file1.js']);
2323
});
2424

25-
test.serial('Get the modified files, ignoring files in .gitignore but including untracked ones', async t => {
25+
test.serial('Get the modified files, including files in .gitignore but including untracked ones', async t => {
2626
// Create a git repository, set the current working directory at the root of the repo
2727
await gitRepo();
2828
// Create files
@@ -34,13 +34,14 @@ test.serial('Get the modified files, ignoring files in .gitignore but including
3434
// Add files and commit
3535
await add(['.']);
3636
await commit('Test commit');
37-
// Update file1.js and dir/file2.js
37+
// Update file1.js, dir/file2.js and file3.js
3838
await appendFile('file1.js', 'Test content');
3939
await appendFile('dir/file2.js', 'Test content');
40+
await appendFile('file3.js', 'Test content');
4041
// Add untracked file
4142
await outputFile('file4.js', 'Test content');
4243

43-
await t.deepEqual(await getModifiedFiles(), ['file4.js', 'dir/file2.js', 'file1.js']);
44+
await t.deepEqual((await getModifiedFiles()).sort(), ['file4.js', 'file3.js', 'dir/file2.js', 'file1.js'].sort());
4445
});
4546

4647
test.serial('Returns [] if there is no modified files', async t => {

test/prepare.test.js

+12-22
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,13 @@ test.serial('Commit files matching the patterns in "assets"', async t => {
126126
// Verify file2 and file1 have been commited
127127
// file4.js is excluded as no glob matching
128128
// file3.css is ignored due to the negative glob '!dir/*.css'
129-
// file5.js is ignore because it's in the .gitignore
129+
// file5.js is not ignored even if it's in the .gitignore
130130
// file6.js and file7.css are included because dir2 is expanded
131-
t.deepEqual(await gitCommitedFiles(), ['dir/file2.js', 'dir2/file6.js', 'dir2/file7.css', 'file1.js']);
132-
t.deepEqual(t.context.log.args[0], ['Found %d file(s) to commit', 4]);
131+
t.deepEqual(
132+
(await gitCommitedFiles()).sort(),
133+
['dir/file2.js', 'dir2/file6.js', 'dir2/file7.css', 'file1.js', 'file5.js'].sort()
134+
);
135+
t.deepEqual(t.context.log.args[0], ['Found %d file(s) to commit', 5]);
133136
});
134137

135138
test.serial('Commit files matching the patterns in "assets" as Objects', async t => {
@@ -155,10 +158,13 @@ test.serial('Commit files matching the patterns in "assets" as Objects', async t
155158
// Verify file2 and file1 have been commited
156159
// file4.js is excluded as no glob matching
157160
// file3.css is ignored due to the negative glob '!dir/*.css'
158-
// file5.js is ignore because it's in the .gitignore
161+
// file5.js is not ignored even if it's in the .gitignore
159162
// file6.js and file7.css are included because dir2 is expanded
160-
t.deepEqual(await gitCommitedFiles(), ['dir/file2.js', 'dir2/file6.js', 'dir2/file7.css', 'file1.js']);
161-
t.deepEqual(t.context.log.args[0], ['Found %d file(s) to commit', 4]);
163+
t.deepEqual(
164+
(await gitCommitedFiles()).sort(),
165+
['dir/file2.js', 'dir2/file6.js', 'dir2/file7.css', 'file1.js', 'file5.js'].sort()
166+
);
167+
t.deepEqual(t.context.log.args[0], ['Found %d file(s) to commit', 5]);
162168
});
163169

164170
test.serial('Commit files matching the patterns in "assets" as single glob', async t => {
@@ -237,19 +243,3 @@ test.serial('Skip commit if there is no files to commit', async t => {
237243
t.deepEqual(t.context.log.args[0], ['Creating tag %s', nextRelease.gitTag]);
238244
t.deepEqual(t.context.log.args[1], ['Prepared Git release: %s', nextRelease.gitTag]);
239245
});
240-
241-
test.serial('Skip commit if all the modified files are in .gitignore', async t => {
242-
const pluginConfig = {assets: 'dist'};
243-
const lastRelease = {};
244-
const nextRelease = {version: '2.0.0', gitTag: 'v2.0.0'};
245-
246-
await outputFile('dist/files1.js', 'Test content');
247-
await outputFile('.gitignore', 'dist/**/*');
248-
249-
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
250-
251-
// Verify the files that have been commited
252-
t.deepEqual(await gitCommitedFiles(), []);
253-
t.deepEqual(t.context.log.args[0], ['Creating tag %s', nextRelease.gitTag]);
254-
t.deepEqual(t.context.log.args[1], ['Prepared Git release: %s', nextRelease.gitTag]);
255-
});

0 commit comments

Comments
 (0)