Exemple #1
0
 /**
  * Execute the command.
  *
  * @param  InputInterface  $input
  * @param  OutputInterface  $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->setIo($input, $output);
     /** @var Repository $config */
     $config = $this->container['config'];
     $sourceRepoPath = $config['source.directory'];
     $sourceRepoUrl = $config['source.git.url'];
     $sourceRepoBranch = $config['source.git.branch'];
     $this->checkSourceRepoSettings($sourceRepoPath, $sourceRepoUrl);
     $output->writeln(["<b>steak pull configuration:</b>", " Source repository remote is <path>{$sourceRepoUrl}</path>", " Source repository branch is <path>{$sourceRepoBranch}</path>", " Path to local repository is <path>{$sourceRepoPath}</path>"], OutputInterface::VERBOSITY_VERBOSE);
     if ($this->files->exists($sourceRepoPath)) {
         $workingCopy = $this->git->workingCopy($sourceRepoPath);
         if (!$workingCopy->isCloned()) {
             throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but is not a git repository.");
         }
         if ($workingCopy->getBranches()->head() != $sourceRepoBranch) {
             throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but isn't on the <path>{$sourceRepoBranch}</path> branch.");
         }
         $this->git->streamOutput();
         $workingCopy->pull();
     } else {
         $output->writeln(["The source directory <path>{$sourceRepoPath}</path> does not exist.", "  Attempting clone from {$sourceRepoUrl}"]);
         $this->git->streamOutput();
         $this->git->cloneRepository($sourceRepoUrl, $sourceRepoPath, ['single-branch' => true, 'branch' => $sourceRepoBranch]);
         $output->writeln("<info>Clone complete! Edit your sources in <path>{$sourceRepoPath}</path></info>");
     }
     $output->writeln("Try <comment>steak serve</comment> to fire up the local development server...");
 }
 /**
  * @return void
  */
 public function run()
 {
     $workingDir = $this->gitWrapper->workingCopy($this->workingDir);
     $workingDir->fetch();
     $workingDir->reset('--hard');
     $workingDir->checkout('PRODUCTION');
     $workingDir->pull();
 }
 /**
  * @param  string|null                $tag
  *
  * @return \GitWrapper\GitWorkingCopy
  */
 public function checkout($tag = null)
 {
     $git = $this->gitWrapper->workingCopy($this->getRepositoryDirectory($this));
     if (!$git->isCloned()) {
         $git->clone('git@github.com:' . $this . '.git');
     }
     if ($tag !== null) {
         $git->checkout($tag, ['f' => true]);
     }
     return $git;
 }
Exemple #4
0
 /**
  * Prepare the build directory as a git repository.
  *
  * Maybe there's already a git repo in the build folder, but is it pointing to
  * the correct origin and is it on the correct branch? Instead of checking for
  * things that might be wrong, we'll just start from scratch.
  *
  * @returns GitWorkingCopy
  * @throws RuntimeException
  */
 protected function prepareRepository()
 {
     $config = $this->container['config'];
     $this->builder->clean($config['build.directory']);
     // clear out everything, including .git metadata
     $workingCopy = $this->git->workingCopy($config['build.directory']);
     $this->doGitInit($workingCopy, $config['deploy.git.url'], $config['deploy.git.branch']);
     // start again at last commit
     $this->builder->clean($config['build.directory'], true);
     // clear the old content but keep .git folder
     return $workingCopy;
 }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dependencies = $input->getArgument('dependency');
     $excludes = $input->getOption('exclude');
     $test = $input->getOption('test');
     $wrapper = new GitWrapper();
     $wrapper->streamOutput();
     $projects = Finder::create()->directories()->depth(0)->exclude($excludes)->in(getcwd());
     /** @var SplFileInfo $project */
     foreach ($projects as $project) {
         if (!file_exists($project->getPathname() . '/composer.json')) {
             continue;
         }
         try {
             $this->resetComposer();
             $this->versionParser = null;
             $this->pool = null;
             chdir($project->getPathname());
             $packages = $this->resolveUpdateablePackages($dependencies);
             if (count($packages) > 0) {
                 $output->writeln(sprintf('<comment> Updating project %s with %s</comment>', $project->getFilename(), implode(', ', $packages)));
                 $git = $wrapper->workingCopy($project->getPathname());
                 $stashed = false;
                 if ($git->hasChanges()) {
                     $git->run(['stash']);
                     $stashed = true;
                 }
                 $git->pull();
                 if (!$test) {
                     $exitCode = $this->update($packages);
                     if (0 === $exitCode) {
                         $git->add('composer.json')->add('composer.lock');
                         // Reissue a install for plugins to work. Slows down :/
                         $this->resetComposer();
                         $this->install($output);
                         if ($git->hasChanges()) {
                             $git->commit('Update ' . implode(', ', $packages))->push();
                         }
                     }
                 }
                 if ($stashed) {
                     $git->run(['stash', 'pop']);
                 }
             }
         } catch (\Exception $e) {
             if ($output instanceof ConsoleOutputInterface) {
                 $this->getApplication()->renderException($e, $output->getErrorOutput());
             } else {
                 $this->getApplication()->renderException($e, $output);
             }
         }
     }
 }
Exemple #6
0
 /**
  * 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;
 }
 public function deleteConfig(ConfigCrudEvent $event)
 {
     $config = \Drupal::config('git_config.config');
     $private_key = $config->get('private_key');
     $git_url = $config->get('git_url');
     $active_dir = \Drupal::config('config_files.config')->get('directory');
     if ($active_dir && !empty($private_key) && !empty($git_url)) {
         $wrapper = new GitWrapper();
         $wrapper->setPrivateKey($config->get('private_key'));
         $git = $wrapper->workingCopy($active_dir);
         $object = $event->getConfig();
         $file_name = $object->getName() . '.yml';
         try {
             $user = \Drupal::currentUser();
             $name = $user->getAccount()->getUsername();
             $git->rm($file_name)->commit(t('Removed by @name', array('@name' => $name)))->push();
         } catch (GitException $e) {
             drupal_set_message($e->getMessage(), 'warning');
         }
     }
 }
Exemple #8
0
 // 总数量
 $i = 1;
 // 只要一个仓库新建任务就可以了
 requestAPI::logging('当前用户 ' . $codingUserName . ' 需要执行 ' . $defaultRepositoryTotal . ' 个仓库', 'info');
 foreach ($defaultRepository as $repositoryName => $repositoryUrl) {
     requestAPI::logging('执行第 ' . $i . ' 个仓库', 'info');
     $projectPathName = $repositoryDir . '/' . $repositoryName;
     // 本地没有这个库 就去 git clone 下来
     if (!is_dir($projectPathName)) {
         requestAPI::logging('本地没有此仓库: ' . $repositoryName . ' 开始从 ' . $repositoryUrl . ' Clone ....', 'info');
         $git = $wrapper->cloneRepository($repositoryUrl, $projectPathName);
         if (!$git) {
             requestAPI::logging('Clone 失败 ' . $repositoryName . ' 退出...', 'error', true);
         }
     } else {
         $git = $wrapper->workingCopy($projectPathName);
     }
     //http push 免密码
     $codingUrl = 'https://' . $codingUserName . ':' . $auth[1] . '@git.coding.net/' . $codingUserName . '/' . $repositoryName . '.git';
     requestAPI::logging('当前用户的Coding远程仓库 Url: ' . $codingUrl, 'info');
     $git->remote('show');
     $output = str_replace("\n", '', $git->getOutput());
     if (strpos($output, 'coding') !== false) {
         $git->remote('rm', 'coding');
     }
     $git->remote('add', 'coding', $codingUrl);
     requestAPI::logging('开始从 Github pull ', 'info');
     $git->pull();
     requestAPI::logging('Github pull Successful', 'success');
     requestAPI::logging('Push for Coding ... ', 'info');
     $git->push('coding');
Exemple #9
0
 private function initRepository()
 {
     $gitWrapper = new GitWrapper();
     $this->repository = $gitWrapper->workingCopy($this->config->getPath());
 }
Exemple #10
0
 /**
  * @return \GitWrapper\GitWorkingCopy
  */
 protected function getWorkingCopy()
 {
     $git = new GitWrapper();
     $workingCopy = $git->workingCopy($this->repositoryPath);
     return $workingCopy;
 }
 /**
  * Helper function to convert patch list into numbered list.
  *
  * @param array $patches_to_search
  * @return array
  */
 protected function ensureLatestRepo($repo_dir)
 {
     if (!$this->ensuredLatestRepo) {
         $wrapper = new GitWrapper();
         $git = $wrapper->workingCopy($repo_dir);
         $git->pull();
         $this->ensuredLatestRepo = TRUE;
     }
 }
Exemple #12
0
 /**
  * Get the current branch name of the repository at $dir.
  *
  * @param string $dir
  * @return string
  */
 protected function getBranchName($dir)
 {
     return trim($this->git->workingCopy($dir)->run(['rev-parse', '--abbrev-ref', 'HEAD'])->getOutput());
 }
Exemple #13
0
 /**
  * @param $path
  * @return \GitWrapper\GitWorkingCopy
  */
 public function setWorkingCopy($path)
 {
     return $this->wrapper->workingCopy($path);
 }
Exemple #14
0
 public function initialize($rootDirectory)
 {
     $wrapper = new GitWrapper();
     $this->git = $wrapper->workingCopy($rootDirectory);
 }