release-it 15.6.1 → 15.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/release-it.js +1 -1
- package/config/release-it.json +2 -0
- package/lib/plugin/git/Git.js +4 -4
- package/lib/util.js +5 -1
- package/package.json +1 -1
- package/test/git.init.js +30 -0
- package/test/stub/github.js +1 -1
- package/test/tasks.js +4 -0
- package/test/util/helpers.js +8 -3
package/bin/release-it.js
CHANGED
package/config/release-it.json
CHANGED
package/lib/plugin/git/Git.js
CHANGED
|
@@ -46,8 +46,8 @@ class Git extends GitBase {
|
|
|
46
46
|
if (this.options.requireUpstream && !(await this.hasUpstreamBranch())) {
|
|
47
47
|
throw e(`No upstream configured for current branch.${EOL}Please set an upstream branch.`, docs);
|
|
48
48
|
}
|
|
49
|
-
if (this.options.requireCommits && (await this.getCommitsSinceLatestTag()) === 0) {
|
|
50
|
-
throw e(`There are no commits since the latest tag.`, docs);
|
|
49
|
+
if (this.options.requireCommits && (await this.getCommitsSinceLatestTag(this.options.commitsPath)) === 0) {
|
|
50
|
+
throw e(`There are no commits since the latest tag.`, docs, this.options.requireCommitsFail);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -120,10 +120,10 @@ class Git extends GitBase {
|
|
|
120
120
|
);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
async getCommitsSinceLatestTag() {
|
|
123
|
+
async getCommitsSinceLatestTag(commitsPath = '') {
|
|
124
124
|
const latestTagName = await this.getLatestTagName();
|
|
125
125
|
const ref = latestTagName ? `${latestTagName}..HEAD` : 'HEAD';
|
|
126
|
-
return this.exec(`git rev-list ${ref} --count`, { options }).then(Number);
|
|
126
|
+
return this.exec(`git rev-list ${ref} --count ${commitsPath}`, { options }).then(Number);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
async getUpstreamArgs(pushRepo) {
|
package/lib/util.js
CHANGED
|
@@ -89,7 +89,11 @@ const parseVersion = raw => {
|
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
-
const e = (message, docs
|
|
92
|
+
const e = (message, docs, fail = true) => {
|
|
93
|
+
const error = new Error(docs ? `${message}${EOL}Documentation: ${docs}${EOL}` : message);
|
|
94
|
+
error.code = fail ? 1 : 0;
|
|
95
|
+
return error;
|
|
96
|
+
};
|
|
93
97
|
|
|
94
98
|
export {
|
|
95
99
|
getSystemInfo,
|
package/package.json
CHANGED
package/test/git.init.js
CHANGED
|
@@ -72,6 +72,36 @@ test.serial('should not throw if there are commits', async t => {
|
|
|
72
72
|
await t.notThrowsAsync(gitClient.init());
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
+
test.serial('should fail (exit code 1) if there are no commits', async t => {
|
|
76
|
+
const options = { git: { requireCommits: true } };
|
|
77
|
+
const gitClient = factory(Git, { options });
|
|
78
|
+
sh.exec('git tag 1.0.0');
|
|
79
|
+
await t.throwsAsync(gitClient.init(), { code: 1 });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test.serial('should not fail (exit code 0) if there are no commits', async t => {
|
|
83
|
+
const options = { git: { requireCommits: true, requireCommitsFail: false } };
|
|
84
|
+
const gitClient = factory(Git, { options });
|
|
85
|
+
sh.exec('git tag 1.0.0');
|
|
86
|
+
await t.throwsAsync(gitClient.init(), { code: 0 });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test.serial('should throw if there are no commits in specified path', async t => {
|
|
90
|
+
const options = { git: { requireCommits: true, commitsPath: 'dir' } };
|
|
91
|
+
const gitClient = factory(Git, { options });
|
|
92
|
+
sh.mkdir('dir');
|
|
93
|
+
sh.exec('git tag 1.0.0');
|
|
94
|
+
await t.throwsAsync(gitClient.init(), { message: /^There are no commits since the latest tag/ });
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test.serial('should not throw if there are commits in specified path', async t => {
|
|
98
|
+
const options = { git: { requireCommits: true, commitsPath: 'dir' } };
|
|
99
|
+
const gitClient = factory(Git, { options });
|
|
100
|
+
sh.exec('git tag 1.0.0');
|
|
101
|
+
gitAdd('line', 'dir/file', 'Add file');
|
|
102
|
+
await t.notThrowsAsync(gitClient.init());
|
|
103
|
+
});
|
|
104
|
+
|
|
75
105
|
test.serial('should not throw if there are no tags', async t => {
|
|
76
106
|
const options = { git: { requireCommits: true } };
|
|
77
107
|
const gitClient = factory(Git, { options });
|
package/test/stub/github.js
CHANGED
|
@@ -30,7 +30,7 @@ const interceptListReleases = ({
|
|
|
30
30
|
upload_url: `https://uploads.${host}/repos/${owner}/${project}/releases/1/assets{?name,label}`,
|
|
31
31
|
html_url: `https://${host}/${owner}/${project}/releases/tag/${tag_name}`,
|
|
32
32
|
tag_name,
|
|
33
|
-
target_commitish: '
|
|
33
|
+
target_commitish: 'main',
|
|
34
34
|
name: `Release ${tag_name}`,
|
|
35
35
|
body: 'Description of the release',
|
|
36
36
|
draft: false,
|
package/test/tasks.js
CHANGED
package/test/util/helpers.js
CHANGED
|
@@ -10,9 +10,14 @@ const mkTmpDir = () => {
|
|
|
10
10
|
|
|
11
11
|
const readFile = file => fs.promises.readFile(path.resolve(file), 'utf8');
|
|
12
12
|
|
|
13
|
-
const gitAdd = (content,
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const gitAdd = (content, filePath, message) => {
|
|
14
|
+
const pathSegments = filePath.split('/').filter(Boolean);
|
|
15
|
+
pathSegments.pop();
|
|
16
|
+
if (pathSegments.length) {
|
|
17
|
+
sh.mkdir('-p', pathSegments.join('/'));
|
|
18
|
+
}
|
|
19
|
+
sh.ShellString(content).toEnd(filePath);
|
|
20
|
+
sh.exec(`git add ${filePath}`);
|
|
16
21
|
const { stdout } = sh.exec(`git commit -m "${message}"`);
|
|
17
22
|
const match = stdout.match(/\[.+([a-z0-9]{7})\]/);
|
|
18
23
|
return match ? match[1] : null;
|