summaryrefslogtreecommitdiffstats
path: root/src/GitDeploy
diff options
context:
space:
mode:
Diffstat (limited to 'src/GitDeploy')
-rw-r--r--src/GitDeploy/Console/Application.php24
-rw-r--r--src/GitDeploy/Console/Command/DeployCommand.php40
-rw-r--r--src/GitDeploy/GitDeploy.php60
3 files changed, 124 insertions, 0 deletions
diff --git a/src/GitDeploy/Console/Application.php b/src/GitDeploy/Console/Application.php
new file mode 100644
index 0000000..0ba70c9
--- /dev/null
+++ b/src/GitDeploy/Console/Application.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace GitDeploy\Console;
+
+use Symfony\Component\Console\Application as BaseApplication;
+use GitDeploy\Console\Command\DeployCommand;
+
+class Application extends BaseApplication
+{
+ const NAME = 'Git Deploy';
+ const VERSION = '@package_version@';
+
+ public function __construct()
+ {
+ parent::__construct(static::NAME, static::VERSION);
+ }
+
+ protected function getDefaultCommands()
+ {
+ $defaultCommands = parent::getDefaultCommands();
+ $defaultCommands[] = new DeployCommand();
+ return $defaultCommands;
+ }
+}
diff --git a/src/GitDeploy/Console/Command/DeployCommand.php b/src/GitDeploy/Console/Command/DeployCommand.php
new file mode 100644
index 0000000..b504d4b
--- /dev/null
+++ b/src/GitDeploy/Console/Command/DeployCommand.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace GitDeploy\Console\Command;
+
+use GitDeploy\GitDeploy;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class DeployCommand extends Command
+{
+ protected function configure()
+ {
+ $this
+ ->setName('deploy')
+ ->setDescription('Deploys the list of repositories.')
+ ->addOption(
+ 'file',
+ 'f',
+ InputOption::VALUE_OPTIONAL,
+ 'The configuration file to load.',
+ 'git-deploy.json'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $deploy = GitDeploy::fromFile($input->getOption('file'));
+ $repositories = $deploy->getRepositories();
+ if (empty($repositories)) {
+ $output->writeln('<info>Configuration file empty.</info>');
+ }
+ else {
+ $deploy->update();
+ }
+ }
+}
diff --git a/src/GitDeploy/GitDeploy.php b/src/GitDeploy/GitDeploy.php
new file mode 100644
index 0000000..d1c2cf6
--- /dev/null
+++ b/src/GitDeploy/GitDeploy.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace GitDeploy;
+
+use GitWrapper\GitWrapper;
+use GitWrapper\GitWorkingCopy;
+
+class GitDeploy
+{
+ protected $repositories;
+
+ public function __construct($repositories = array())
+ {
+ $this->repositories = $repositories;
+ }
+
+ public static function fromFile($file = 'git-deploy.json')
+ {
+ $results = array();
+
+ if (is_file($file)) {
+ $contents = file_get_contents($file);
+ $results = json_decode($contents);
+ }
+
+ return new GitDeploy($results);
+ }
+
+ public function update()
+ {
+ // Create the wrapper.
+ $wrapper = new GitWrapper();
+ $wrapper->streamOutput();
+
+ foreach ($this->repositories as $dir => $repo) {
+ // Build our git interface.
+ $git = null;
+ if (!is_dir($dir)) {
+ $git = $wrapper->cloneRepository($repo, $dir);
+ }
+ else {
+ $git = new GitWorkingCopy($wrapper, $dir);
+ }
+
+ // Fetch all the latest.
+ $git->fetch('--all');
+
+ // Reset over to the gh-pages branch.
+ $git->reset('origin/gh-pages', array('hard' => true));
+
+ // Remove any extra files.
+ $git->clean('-d', '-f', '-x');
+ }
+ }
+
+ public function getRepositories()
+ {
+ return $this->repositories;
+ }
+}