Some methods in this class are borrowed from the Doctrine project.
 public function validate($source, $target)
 {
     $validateBranches = count($this->branches) > 1;
     if (self::PRESET_NONE !== $this->preset) {
         $preset = 'preset' . StringUtil::concatWords($this->preset);
         // When the policy is deny-merge for unknown branches
         // the preset is used as primary, if it grants access then branches are not checked,
         // else you would need configure branches for all checks!
         if (true === $this->{$preset}($source, $target)) {
             $validateBranches = self::BRANCH_POLICY_DENY === $this->policy ? false : $validateBranches;
         }
     }
     if ($validateBranches) {
         $this->validateBranches($source, $target, $this->branches, $this->policy);
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Ensures the fetching of notes is configured for the remote.
  *
  * @param string $remote
  */
 public function ensureNotesFetching($remote)
 {
     $fetches = StringUtil::splitLines($this->getGitConfig('remote.' . $remote . '.fetch', 'local', true));
     if (!in_array('+refs/notes/*:refs/notes/*', $fetches, true)) {
         $this->getHelperSet()->get('gush_style')->note(sprintf('Set fetching of notes for remote "%s".', $remote));
         $this->processHelper->runCommand(['git', 'config', '--add', '--local', 'remote.' . $remote . '.fetch', '+refs/notes/*:refs/notes/*']);
     }
 }
Esempio n. 3
0
 /**
  * @param string $base
  * @param string $branchName
  * @param bool   $ignoreMultipleAuthors Ignore there are multiple authors (ake force)
  *
  * @throws WorkingTreeIsNotReady
  * @throws CannotSquashMultipleAuthors
  */
 public function squashCommits($base, $branchName, $ignoreMultipleAuthors = false)
 {
     $this->guardWorkingTreeReady();
     $this->stashBranchName();
     $this->checkout($branchName);
     // Check if there are multiple authors, we only use the e-mail address
     // As the name could have changed (eg. typo's and accents)
     if (!$ignoreMultipleAuthors) {
         $authors = array_unique(StringUtil::splitLines($this->processHelper->runCommand(['git', '--no-pager', 'log', '--oneline', '--no-color', '--format=%ae', $base . '..' . $branchName])));
         if (count($authors) > 1) {
             throw new CannotSquashMultipleAuthors();
         }
     }
     // Get commits only in the branch but not in base (in reverse order)
     // we can't use --max-count here because that is applied before the reversing!
     //
     // using git-log works better then finding the fork-point with git-merge-base
     // because this protects against edge cases were there is no valid fork-point
     $firstCommitHash = StringUtil::splitLines($this->processHelper->runCommand(['git', '--no-pager', 'log', '--oneline', '--no-color', '--format=%H', '--reverse', $base . '..' . $branchName]))[0];
     // 0=author anything higher then 0 is the full body
     $commitData = StringUtil::splitLines($this->processHelper->runCommand(['git', '--no-pager', 'show', '--format=%an <%ae>%n%s%n%n%b', '--no-color', '--no-patch', $firstCommitHash]));
     $author = array_shift($commitData);
     $message = implode("\n", $commitData);
     $this->reset($base);
     $this->commit($message, ['a', '-author' => $author]);
 }