Skip to content

Commit

Permalink
Add git checkout and composer install commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonpugh committed Sep 17, 2024
1 parent 847761a commit 3b6cbec
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Drupal\commands\Plugin\Command;
namespace Drupal\site_hosting\Plugin\Command;

use Drupal\commands\CommandPluginBase;
use Drupal\Core\Form\FormStateInterface;
Expand Down
61 changes: 61 additions & 0 deletions src/Drupal/Modules/site_hosting/src/Plugin/Command/GitCheckout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Drupal\site_hosting\Plugin\Command;

use Drupal\commands\CommandPluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\Entity\User;

/**
* Clones and checks out code.
*
* @Command(
* id = "git_checkout",
* label = @Translation("Git Checkout"),
* description = @Translation("Clone a git repository and checkout the desired git reference."),
* command = {
* "git clone [git_remote] [git_root]",
* "cd [git_root]",
* "git fetch",
* "git checkout [git_reference]",
* }
* )
*/
class GitCheckout extends CommandPluginBase {

// public function command($params = []) {
// $command = <<<CMD
//git clone $git_remote $git_root
//cd $git_root
//git fetch
//git checkout $git_reference
//CMD;
// return $command;
//
// }

/**
* Show a form on the "Run command" form.
* @return void
*/
public function form($form, FormStateInterface $form_state) {
$form['parameters']['git_remote'] = [
'#type' => 'textfield',
'#title' => t('Git Remote'),
'#description'=> t('The remote URL of the repository to clone.'),
];
$form['parameters']['git_root'] = [
'#type' => 'textfield',
'#title' => t('Git Root'),
'#description'=> t('The absolute path to the root of the repository.'),
];
$form['parameters']['git_reference'] = [
'#type' => 'textfield',
'#title' => t('Git Reference'),
'#description'=> t('The git reference to checkout.'),
];

// @TODO: Reset working_directory to detected composer root.
return $form;
}
}
Empty file.

0 comments on commit 3b6cbec

Please sign in to comment.