diff --git a/README.md b/README.md index bf0f3757..a466fd87 100644 --- a/README.md +++ b/README.md @@ -305,7 +305,7 @@ Initializes Tortilla essentials in the provided project. **command:** `tortilla push ` -Push a tutorial based on the provided branch. e.g. given `master` then `master-history`, `master-root`, `master@0.1.0`, etc, will be pushed. Note that everything will be pushed by FORCE and will override existing refs within the remote. +Push a tutorial based on the provided branch. e.g. given `master` then `master-history`, `master-root`, `master@0.1.0`, etc, will be pushed. Note that everything will be pushed by FORCE and will override existing refs within the remote, **even deleted refs**. **command:** `tortilla pull ` @@ -381,6 +381,10 @@ Bumps the current release of the tutorial. This will create some new release tag Reverts release to the most recent one. For example, if we have 2 releases: `master@2.0.0` and `master@1.0.0`, this command will delete `master@2.0.0`, leaving `master@1.0.0`. If no more releases are left, the `history` branch will be deleted. This is useful if we've released something by accident and we would like to fix it. +**command:** `tortilla release list [branch]` + +Prints a list of all releases of the given `branch`. If no `branch` was provided, the active branch will be used by default. + **command:** `tortilla release current` Prints the current release. diff --git a/src/cli/tortilla-release.ts b/src/cli/tortilla-release.ts index 2134c3a6..45d1adb2 100755 --- a/src/cli/tortilla-release.ts +++ b/src/cli/tortilla-release.ts @@ -1,6 +1,7 @@ #!/usr/bin/env node import * as Program from 'commander'; +import { Git } from '../git'; import { localStorage as LocalStorage } from '../local-storage'; import { Release } from '../release'; @@ -25,6 +26,17 @@ Program Release.revert(); }) +Program + .command('list [branch]') + .description('Lists all releases for given branch') + .action((branch = Git.activeBranchName()) => { + LocalStorage.assertTortilla(true); + const releases = Release.all(null, branch) + .map(release => `${branch}@${Release.format(release)}`); + releases[0] += ' -> current release'; + console.log(releases.join('\n')); + }); + Program .command('current') .description('Prints the current release') diff --git a/src/release.ts b/src/release.ts index 17baf1ed..e516c0f2 100644 --- a/src/release.ts +++ b/src/release.ts @@ -651,9 +651,7 @@ function getAllReleasesOfAllBranches(path = null) { } // Gets a list of all the releases represented as JSONs e.g. // [{ major: 0, minor: 1, patch: 0 }] -function getAllReleases(path = null) { - const branch = Git.activeBranchName(path); - +function getAllReleases(path = null, branch = Git.activeBranchName(path)) { return Git(['tag'], path ? { cwd: path } : null) // Put tags into an array .split('\n') diff --git a/tests/release.spec.ts b/tests/release.spec.ts index 4fc91e6b..b7dbbe79 100644 --- a/tests/release.spec.ts +++ b/tests/release.spec.ts @@ -365,7 +365,7 @@ describe('Release', () => { }); }); - describe.only('revert()', () => { + describe('revert()', () => { it('should revert most recent release', () => { context.tortilla(['release', 'bump', 'major', '-m', 'first release']); context.tortilla(['release', 'bump', 'major', '-m', 'second release']); @@ -378,6 +378,40 @@ describe('Release', () => { }); }); + describe('list()', () => { + it('should print all versions of current branch', () => { + context.tortilla(['release', 'bump', 'major', '-m', 'major version test']); + context.tortilla(['release', 'bump', 'next', '-m', 'next version test']); + context.tortilla(['release', 'bump', 'minor', '-m', 'minor version test']); + context.tortilla(['release', 'bump', 'patch', '-m', 'patch version test']); + + const releasesList = context.tortilla(['release', 'list']); + + expect(releasesList).toEqual([ + 'master@1.1.1 -> current release', + 'master@1.1.0', + 'master@1.0.0' + ].join('\n')); + }); + + it('should print all versions of given branch', () => { + context.tortilla(['release', 'bump', 'major', '-m', 'major version test']); + context.tortilla(['release', 'bump', 'next', '-m', 'next version test']); + context.tortilla(['release', 'bump', 'minor', '-m', 'minor version test']); + context.tortilla(['release', 'bump', 'patch', '-m', 'patch version test']); + + context.git(['checkout', '-b', 'test-branch']); + + context.tortilla(['release', 'bump', 'major', '-m', 'major version test']); + + const releasesList = context.tortilla(['release', 'list']); + + expect(releasesList).toEqual([ + 'test-branch@1.0.0 -> current release' + ].join('\n')); + }); + }); + describe('current()', () => { it('should get the current version', () => { context.tortilla(['release', 'bump', 'major', '-m', 'major version test']);