コード例 #1
0
 public function setUp()
 {
     $fileSystem = new Filesystem();
     $fileSystem->remove(self::TEST_PATH);
     $fileSystem->mkdir(self::TEST_PATH);
     $git = new GitWrapper();
     $git->init(self::TEST_PATH);
 }
コード例 #2
0
ファイル: GitVersioning.php プロジェクト: kriskbx/wyn
 /**
  * Create directory if it does not exist and init the repository if it's not a repository.
  */
 public function init()
 {
     if (!file_exists($localGitPath = $this->getLocalRepoPath())) {
         mkdir($localGitPath);
     }
     if (!file_exists($localGitPath . '.git')) {
         $git = $this->gitWrapper->init($localGitPath);
         $git->config('user.name', 'backuppipes')->config('user.email', '*****@*****.**');
     } else {
         $git = $this->gitWrapper->workingCopy($localGitPath);
     }
     $this->git = $git;
 }
コード例 #3
0
ファイル: GitMerge.php プロジェクト: bircher/php-merge
 /**
  * Set up the git wrapper and the temporary directory.
  */
 protected function setup()
 {
     // @TODO: Allow setting up in an existing dierectory.
     if (!$this->dir) {
         // Greate a temporary directory.
         $tempfile = tempnam(sys_get_temp_dir(), '');
         mkdir($tempfile . '.git');
         if (file_exists($tempfile)) {
             unlink($tempfile);
         }
         $this->dir = $tempfile . '.git';
         $this->git = $this->wrapper->init($this->dir);
     }
     $this->git->config('user.name', 'GitMerge')->config('user.email', '*****@*****.**')->config('merge.conflictStyle', 'diff3');
     $this->strategy = null;
 }
コード例 #4
0
 /**
  * @param string
  *
  * @return \GitWrapper\GitWorkingCopy
  */
 protected function initRepository($dir)
 {
     return $this->gitWrapper->init($dir);
 }
コード例 #5
0
ファイル: NewCommand.php プロジェクト: cpliakas/drupal-distro
 /**
  * @{inheritdoc}
  *
  * @throws \RuntimeException
  * @throws \Symfony\Component\Filesystem\Exception\IOException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $wrapper = new GitWrapper($input->getOption('git-binary'));
     $profile = $input->getArgument('profile');
     $dir = $input->getArgument('directory') ?: './' . $profile;
     $profileName = $input->getOption('profile-name') ?: $profile;
     $profileDesc = $input->getOption('profile-description') ?: $profile;
     $siteName = $input->getOption('site-name') ?: $profileName;
     $gitUrl = $input->getOption('git-url') ?: 'http://git.drupal.org/project/' . $profile . '.git';
     $coreVersion = $input->getOption('core-version') ?: '7';
     $coreBranch = $coreVersion . '.x';
     if (!is_dir($this->templateDir . '/' . $coreBranch)) {
         throw new \RuntimeException('Core version not valid: ' . $coreVersion);
     }
     if (preg_match('/[^a-zA-Z0-9_]/', $profile)) {
         throw new \RuntimeException('Profile name must only contain letters, numbers, and underscores');
     }
     $replacements = array('{{ drupal.version }}' => $this->getLatestDrupalVersion($coreBranch), '{{ git.url }}' => $gitUrl, '{{ profile }}' => $profile, '{{ profile.name }}' => $profileName, '{{ profile.description }}' => $profileDesc, '{{ site.name }}' => $siteName);
     $filenames = array('.editorconfig', '.gitignore', '.travis.yml', 'build.xml', 'build.properties.dist', 'behat.yml', 'build-example.make', 'test/features/bootstrap/FeatureContext.php', 'test/features/test.feature', 'drupal-org-core.make', 'drupal-org.make');
     if ('7' == $coreVersion) {
         $filenames[] = $coreBranch . '/example.info';
         $filenames[] = $coreBranch . '/example.install';
         $filenames[] = $coreBranch . '/example.profile';
     }
     $this->mkdir($dir . '/' . $coreBranch);
     $this->mkdir($dir . '/test/features/bootstrap');
     $this->mkdir($dir . '/test');
     $this->mkdir($dir . '/test/features');
     $this->mkdir($dir . '/test/features/bootstrap');
     foreach ($filenames as $filename) {
         $this->copyFile($filename, $dir, $replacements);
     }
     $fs = $this->getFilesystem();
     // Rename the build-example.make file.
     $fs->rename($dir . '/build-example.make', $dir . '/build-' . $profile . '.make');
     // Move the profile files and remove the stub dir.
     $flags = \FilesystemIterator::SKIP_DOTS;
     $profileFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir . '/' . $coreBranch, $flags), \RecursiveIteratorIterator::CHILD_FIRST);
     $pattern = '@' . preg_quote($coreBranch, '@') . '/example(\\.[a-z]+)$@';
     $replacement = $profile . '\\1';
     foreach ($profileFiles as $profileOrigin) {
         $profileTarget = preg_replace($pattern, $replacement, $profileOrigin);
         $fs->rename($profileOrigin, $profileTarget);
     }
     $fs->remove($dir . '/' . $coreBranch);
     if (!$input->getOption('no-repo')) {
         $git = $wrapper->init($dir);
         $git->add('*', array('A' => true));
         $git->commit('first commit');
         $git->remote('add', 'origin', $gitUrl);
     }
 }
コード例 #6
0
 /**
  * @inheritDoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $output->writeln([$this->getApplication()->getLongVersion(), '']);
     $question = new Question('<question>Please enter project name in title case:</question> ');
     $name = $helper->ask($input, $output, $question);
     if (empty($name)) {
         $output->writeln(['', '<error>Error: Project name cannot be empty</error>']);
         return 1;
     }
     if (false === ctype_upper($name[0])) {
         $output->writeln(['', '<error>Error: Project name must be title case</error>']);
         return 1;
     }
     $nameCan = Strings\dasherize($name);
     $projectPath = getcwd() . '/' . $nameCan;
     if (file_exists($projectPath) || is_dir($projectPath)) {
         $output->writeln(['', '<error>Error: Project with name "' . $nameCan . '" already exists</error>']);
         return 1;
     }
     $projectTypes = ['Component', 'Tool', 'Bundle', 'Action'];
     $question = new Question('<question>Please enter project type (Component):</question> ', 'Component');
     $question->setAutocompleterValues($projectTypes);
     $projectType = $helper->ask($input, $output, $question);
     if (empty($projectType)) {
         $output->writeln(['', '<error>Error: Project type cannot be empty</error>']);
         return 1;
     }
     if (false === ctype_upper($projectType[0])) {
         $output->writeln(['', '<error>Error: Project type must be title case</error>']);
         return 1;
     }
     $author = rtrim(shell_exec("git config --get user.name"));
     $authorSug = '';
     if (null !== $author) {
         $authorSug = '(' . $author . ')';
     }
     $question = new Question('<question>Please enter author ' . $authorSug . ':</question> ', $author);
     $author = $helper->ask($input, $output, $question);
     if (empty($author)) {
         $output->writeln(['', '<error>Error: Author cannot be empty</error>']);
         return 1;
     }
     $email = rtrim(shell_exec("git config --get user.email"));
     $emailSug = '';
     if (null !== $email) {
         $emailSug = '(' . $email . ')';
     }
     $question = new Question('<question>Please enter email ' . $emailSug . ':</question> ', $email);
     $email = $helper->ask($input, $output, $question);
     if (empty($email)) {
         $output->writeln(['', '<error>Error: Email cannot be empty</error>']);
         return 1;
     }
     $question = new Question('<question>Please enter git repository:</question> ');
     $repo = $helper->ask($input, $output, $question);
     if (empty($email)) {
         $output->writeln(['', '<error>Error: Git repository cannot be empty</error>']);
         return 1;
     }
     $output->writeln(['']);
     $year = date('Y');
     $output->write('<info>Cloning project template: </info>');
     $wrapper = new GitWrapper();
     $wrapper->cloneRepository('git@github.com:ThrusterIO/project-template.git', $projectPath);
     $output->writeln('<comment>Done</comment>');
     $fs = new Filesystem();
     $output->write('<info>Removing .git folder: </info>');
     $fs->remove($projectPath . '/.git');
     $output->writeln('<comment>Done</comment>');
     $output->write('<info>Removing src/.gitkeep file: </info>');
     $fs->remove($projectPath . '/src/.gitkeep');
     $output->writeln('<comment>Done</comment>');
     $output->write('<info>Initialized empty Git repository: </info>');
     $git = $wrapper->init($projectPath);
     $output->writeln('<comment>Done</comment>');
     $finder = new Finder();
     $finder->in($projectPath)->ignoreDotFiles(false)->files();
     $output->writeln(['', '<info>Applying variables to files: </info>']);
     $progress = new ProgressBar($output, count($finder));
     $progress->setFormat('debug');
     $progress->start();
     /** @var SplFileInfo $file */
     foreach ($finder as $file) {
         $searchFor = ['${NAME}$', '${NAME_CAN}$', '${PROJECT_TYPE}$', '${YEAR}$', '${AUTHOR}$', '${EMAIL}$'];
         $replaceWith = [$name, $nameCan, $projectType, $year, $author, $email];
         $progress->setMessage($file->getFilename());
         file_put_contents($file->getRealPath(), str_replace($searchFor, $replaceWith, $file->getContents()));
         $progress->advance();
     }
     $progress->finish();
     $git->remote('add', 'origin', $repo);
     $git->add('./');
     $output->writeln(['', '', '<comment>Finished.</comment>']);
     return 0;
 }
コード例 #7
0
ファイル: Workbench.php プロジェクト: padosoft/workbench
 private function createAndDownloadFromGit(bool $upload)
 {
     try {
         $gitWrapper = new GitWrapper();
         if (substr($this->workbenchSettings->requested["type"]['valore'], -7) != 'package') {
             $gitWorkingCopy = $gitWrapper->init(\Padosoft\Workbench\Parameters\Dir::adjustPath($this->workbenchSettings->requested['dir']['valore'] . $this->workbenchSettings->requested['domain']['valore'] . "/www", []));
         }
         if (substr($this->workbenchSettings->requested["type"]['valore'], -7) == 'package') {
             $gitWorkingCopy = $gitWrapper->init(\Padosoft\Workbench\Parameters\Dir::adjustPath($this->workbenchSettings->requested['dir']['valore'] . $this->workbenchSettings->requested['domain']['valore'], []));
         }
         //$gitWorkingCopy=$gitWrapper->init($this->workbenchSettings->requested['dir']['valore'].$this->workbenchSettings->requested['domain']['valore'],[]);
         $gitWrapper->git("config --global user.name " . $this->workbenchSettings->requested['user']['valore']);
         $gitWrapper->git("config --global user.email " . $this->workbenchSettings->requested['email']['valore']);
         $gitWrapper->git("config --global user.password " . $this->workbenchSettings->requested['password']['valore']);
         $gitWorkingCopy->add('.');
         switch ($this->workbenchSettings->requested['type']['valore']) {
             case Parameters\Type::AGNOSTIC_PACKAGE:
                 $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@github.com/padosoft/" . Config::get('workbench.type_repository.agnostic_package') . ".git");
                 $this->info("Downloading skeleton agnostic package...");
                 break;
             case Parameters\Type::LARAVEL_PACKAGE:
                 $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@github.com/padosoft/" . Config::get('workbench.type_repository.laravel_package') . ".git");
                 $this->info("Downloading skeleton laravel package...");
                 break;
             case Parameters\Type::LARAVEL:
                 $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@github.com/padosoft/" . Config::get('workbench.type_repository.laravel') . ".git");
                 $this->info("Downloading skeleton laravel project...");
                 break;
             case Parameters\Type::NORMAL:
                 $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@github.com/padosoft/" . Config::get('workbench.type_repository.normal') . ".git");
                 //$this->info("Downloading skeleton normal project...");
                 break;
         }
         if ($this->workbenchSettings->requested['gitaction']['valore'] == Parameters\GitAction::PULL) {
             $this->info("Donwloading repo...");
             $gitWorkingCopy->removeRemote('origin');
             $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@" . $this->workbenchSettings->requested["git"]["valore"] . ".com/" . $this->workbenchSettings->requested['organization']['valore'] . "/" . $this->workbenchSettings->requested['packagename']['valore'] . ".git");
         }
         if ($this->workbenchSettings->requested['type']['valore'] != Parameters\Type::NORMAL) {
             $gitWorkingCopy->pull('origin', 'master');
             $this->info("Download complete.");
         }
         if ($upload && $this->workbenchSettings->requested['gitaction']['valore'] == Parameters\GitAction::PUSH) {
             $gitWorkingCopy->removeRemote('origin');
             $extension = $this->workbenchSettings->requested["git"]["valore"] == Parameters\Git::BITBUCKET ? "org" : "com";
             $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@" . $this->workbenchSettings->requested["git"]["valore"] . "." . $extension . "/" . $this->workbenchSettings->requested['organization']['valore'] . "/" . $this->workbenchSettings->requested['packagename']['valore'] . ".git");
             $this->substitute();
             $gitWorkingCopy->add('.');
             $gitWorkingCopy->commit("Substitute");
             $this->info("Uploading repo...");
             $gitWorkingCopy->push('origin', 'master');
             $this->info("Upload complete");
         }
         $dir = \Padosoft\Workbench\Parameters\Dir::adjustPath(__DIR__) . 'config/pre-commit';
         if (!File::exists($dir)) {
             $this->error('File ' . $dir . ' not exist');
             exit;
         }
         if (substr($this->workbenchSettings->requested["type"]['valore'], -7) != 'package') {
             File::copy($dir, \Padosoft\Workbench\Parameters\Dir::adjustPath($this->workbenchSettings->requested["dir"]['valore'] . $this->workbenchSettings->requested["domain"]['valore']) . 'www/.git/hooks/pre-commit');
         }
         if (substr($this->workbenchSettings->requested["type"]['valore'], -7) == 'package') {
             File::copy($dir, \Padosoft\Workbench\Parameters\Dir::adjustPath($this->workbenchSettings->requested["dir"]['valore'] . $this->workbenchSettings->requested["domain"]['valore']) . '.git/hooks/pre-commit');
         }
     } catch (\Exception $ex) {
         $this->error($ex->getMessage());
         exit;
     }
     return true;
 }