Skip to content

Commit

Permalink
feat(start-hotfix): support passing in branch directly via cli
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Jun 25, 2019
1 parent d89156c commit 3543fd9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ program

program
.command('start-hotfix')
.arguments('[hotfix-branch]')
.description('Create new hotfix branch')
.action(async () => {
.action(async (hotfixBranch) => {
try {
await git.bailIfNotGitDirectory();
await git.startHotfix();
await git.startHotfix(hotfixBranch);
} catch (e) {
console.log(e.message);
console.log(e.message, e);
}
});

Expand Down
20 changes: 15 additions & 5 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ async function startFeature(config) {
console.log('feature branch created successfully');
}

async function startHotfix() {
async function startHotfix(hotfixBranch) {
if (!await isClean()) {
const {confirm} = await inquirer.confirmStash();
if (confirm) {
Expand All @@ -274,11 +274,21 @@ async function startHotfix() {
throw new Error('Operation aborted.');
}
}
const {hotfix, issueNumber} = await inquirer.askIssueNumberAndHotfix();
const refinedHotfix = toDashCase(hotfix);
await fetchAll();

let targetBranch = hotfixBranch ? `hotfix/${hotfixBranch}` : '';
const shouldAsk = targetBranch === '' || !/^\d+-./.test(hotfixBranch);

if (shouldAsk) {
if (hotfixBranch) {
console.log('invalid hotfix target branch');
}
const {hotfix, issueNumber} = await inquirer.askIssueNumberAndHotfix();
const refinedHotfix = toDashCase(hotfix);
targetBranch = `hotfix/${issueNumber}-${refinedHotfix}`;
}

const baseBranch = 'master';
const targetBranch = `hotfix/${issueNumber}-${refinedHotfix}`;
await fetchAll();
await checkout(baseBranch);
await resetHardToRemoteBranch(`${DEFAULT_REMOTE}/${baseBranch}`);
await createAndCheckoutBranch(targetBranch);
Expand Down

0 comments on commit 3543fd9

Please sign in to comment.