Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve v in tags if latest tag also has a v #64

Merged
merged 2 commits into from
Sep 8, 2021
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@ Available options:

```
-P, --no-push-flag Will not push local changes to remote
-M, --no-merge-flag Will not merge after creating tag if called with -c
-M, --no-merge-flag Will not merge after creating tag
-h, --help output usage information
```
17 changes: 9 additions & 8 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export async function getBranchPrompt(branch, defaultName?) {
return branch;
}

function shouldPrependWithV(tag) {
return fs.existsSync('package.json') || tag.startsWith('v');
}

export async function getTagPrompt(tag, msg, nextRelease?) {
if (!tag) {
const latestTagCommit = exec('git rev-list --tags --max-count=1', { log: false });
Expand All @@ -138,7 +142,7 @@ export async function getTagPrompt(tag, msg, nextRelease?) {
}
({ tagName: tag } = await inquirer.prompt(tagName(tag, msg)));
}
return (fs.existsSync('package.json') ? 'v' : '') + semver.valid(tag);
return (shouldPrependWithV(tag) ? 'v' : '') + semver.valid(tag);
}

export function createTag(tag, branch) {
Expand Down Expand Up @@ -171,19 +175,16 @@ export function createTag(tag, branch) {
revert(`git tag -d ${tag}`);

if (getConfig().CHANGE_VERSIONS_WHEN_TAGGING && fs.existsSync('pom.xml')) {
const nextVersion = `${semver.inc(tag, 'minor')}-SNAPSHOT`;
const nextVersion = `${shouldPrependWithV(tag) ? 'v' : ''}${semver.inc(tag, 'minor')}-SNAPSHOT`;
exec(`mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${nextVersion}`);
const commitMessage = `prepare for next development iteration ${nextVersion}`;
exec(`git commit -am "[oneflow] ${commitMessage}"`);
}

getConfig().RUN_CMD_AFTER_TAG_CREATION &&
exec(
getConfig()
.RUN_CMD_AFTER_TAG_CREATION.replace('${tag}', tag)
.replace('${branch}', branch),
{ interactive: true }
);
exec(getConfig().RUN_CMD_AFTER_TAG_CREATION.replace('${tag}', tag).replace('${branch}', branch), {
interactive: true
});
}

export async function prompt(msg): Promise<boolean> {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ function init() {
.addOption('push', 'Pushes local changes to remote', 'Will not push local changes to remote')
.addOption(
'merge',
'Will merge after creating tag if called with -c',
'Will not merge after creating tag if called with -c'
'Will merge after creating tag',
'Will not merge after creating tag'
)
.action(wrap(releaseClose));

Expand Down
2 changes: 1 addition & 1 deletion src/test/helpers-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe.skip('helpers', function() {
.local('git add . && git commit -m "adding version files"')
.oneflow('release-create master 1.1.0 -p')
.oneflow('release-close 1.1.0 -p')
.assertLocalCommitMsg('[oneflow] prepare for next development iteration 1.2.0-SNAPSHOT')
.assertLocalCommitMsg('[oneflow] prepare for next development iteration v1.2.0-SNAPSHOT')
.assertLocalCommitMsg('[oneflow] v1.1.0', -1);

const { commit: commitOfTag } = this.getCommit('v1.1.0');
Expand Down