From d487f85a161413d759c853039125f5363e85bef3 Mon Sep 17 00:00:00 2001 From: Alan Wynn Date: Fri, 19 Mar 2021 20:47:35 +0000 Subject: [PATCH] Add the ability to change the branch name from "main" --- src/NewCommand.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/NewCommand.php b/src/NewCommand.php index d951f76a..f8821421 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -27,6 +27,7 @@ protected function configure() ->addArgument('name', InputArgument::REQUIRED) ->addOption('dev', null, InputOption::VALUE_NONE, 'Installs the latest "development" release') ->addOption('git', null, InputOption::VALUE_NONE, 'Initialize a Git repository') + ->addOption('branch', null, InputOption::VALUE_REQUIRED, 'Set your branch name, defaults to "main"') ->addOption('github', null, InputOption::VALUE_OPTIONAL, 'Create a new repository on GitHub', false) ->addOption('organization', null, InputOption::VALUE_REQUIRED, 'The GitHub organization to create the new repository for') ->addOption('jet', null, InputOption::VALUE_NONE, 'Installs the Laravel Jetstream scaffolding') @@ -207,8 +208,10 @@ protected function createRepository(string $directory, InputInterface $input, Ou { chdir($directory); + $branch = $input->getOption('branch') ?: 'main'; + $commands = [ - 'git init -q -b main .', + "git init -q -b $branch .", 'git add .', 'git commit -q -m "Set up a fresh Laravel app"', ]; @@ -267,9 +270,11 @@ protected function pushToGitHub(string $name, string $directory, InputInterface $flags = $input->getOption('github') ?: '--private'; + $branch = $input->getOption('branch') ?: 'main'; + $commands = [ "gh repo create $name -y $flags", - "git -c credential.helper= -c credential.helper='!gh auth git-credential' push -q -u origin main", + "git -c credential.helper= -c credential.helper='!gh auth git-credential' push -q -u origin $branch", ]; $this->runCommands($commands, $input, $output, ['GIT_TERMINAL_PROMPT' => 0]);