diff --git a/index.js b/index.js index 477d1dc..7ceef81 100644 --- a/index.js +++ b/index.js @@ -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); } }); diff --git a/lib/git.js b/lib/git.js index b7f53e8..885845d 100644 --- a/lib/git.js +++ b/lib/git.js @@ -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) { @@ -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);