Skip to content

Commit

Permalink
Merge pull request #93 from gnutix/create-git-options
Browse files Browse the repository at this point in the history
Add an --options argument to provide options to 'git clone' and 'git submodule add'
  • Loading branch information
franzliedke committed Jun 2, 2019
2 parents ee4f9a1 + 4c7e233 commit 27e2c5c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -117,6 +117,20 @@ This will include things like configuration for testing tools, Travis CI, and au

This will clone the given Git repository to the `bar` directory and install its dependencies.

#### create --submodule: Manage existing packages by loading a Git repository as submodule

$ studio create bar --submodule git@github.com:me/myrepo.git

This will load the given Git repository to the `bar` directory as a submodule and install its dependencies.

#### create --options: Provide specific options to Git when loading the repository

$ studio create bar --git git@github.com:me/myrepo.git --options="--single-branch --branch=mybranch"
$ studio create bar --submodule git@github.com:me/myrepo.git --options="-b mybranch"

This will load the given Git repository and checkout a specific branch.
To have an overview of all the options available to you, check `git clone --help` and `git submodule add --help`.

#### load: Make all packages from the given local path available to Composer

$ studio load baz
Expand Down
22 changes: 15 additions & 7 deletions src/Console/CreateCommand.php
Expand Up @@ -50,6 +50,12 @@ protected function configure()
'gs',
InputOption::VALUE_REQUIRED,
'If set, this will download the given Git repository (as submodule) instead of creating a new one.'
)
->addOption(
'options',
'go',
InputOption::VALUE_REQUIRED,
'If set, this will provide options to Git when fetching the repository or submodule.'
);
}

Expand Down Expand Up @@ -87,14 +93,16 @@ protected function makeCreator(InputInterface $input)
$path = $input->getArgument('path');

if ($input->getOption('git')) {
return new GitRepoCreator($input->getOption('git'), $path);
} elseif ($input->getOption('submodule')) {
return new GitSubmoduleCreator($input->getOption('submodule'), $path);
} else {
$creator = new SkeletonCreator($path);
$this->installParts($creator);
return $creator;
return new GitRepoCreator($input->getOption('git'), $path, $input->getOption('options'));
}

if ($input->getOption('submodule')) {
return new GitSubmoduleCreator($input->getOption('submodule'), $path, $input->getOption('options'));
}

$creator = new SkeletonCreator($path);
$this->installParts($creator);
return $creator;
}

protected function installParts(SkeletonCreator $creator)
Expand Down
7 changes: 5 additions & 2 deletions src/Creator/GitRepoCreator.php
Expand Up @@ -11,11 +11,14 @@ class GitRepoCreator implements CreatorInterface

protected $path;

protected $options;

public function __construct($repo, $path)

public function __construct($repo, $path, $options = '')
{
$this->repo = $repo;
$this->path = $path;
$this->options = $options;
}

/**
Expand All @@ -32,6 +35,6 @@ public function create()

protected function cloneRepository()
{
Shell::run("git clone $this->repo $this->path");
Shell::run("git clone $this->options $this->repo $this->path");
}
}
2 changes: 1 addition & 1 deletion src/Creator/GitSubmoduleCreator.php
Expand Up @@ -8,7 +8,7 @@ class GitSubmoduleCreator extends GitRepoCreator
{
protected function cloneRepository()
{
Shell::run("git submodule add $this->repo $this->path");
Shell::run("git submodule add $this->options $this->repo $this->path");
Shell::run("git submodule init");
}
}

0 comments on commit 27e2c5c

Please sign in to comment.