Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function merge($base, $remote, $local)
 {
     // Skip merging if there is nothing to do.
     if ($merged = PhpMergeBase::simpleMerge($base, $remote, $local)) {
         return $merged;
     }
     // Only set up the git wrapper if we really merge something.
     $this->setup();
     $file = tempnam($this->dir, '');
     $base = self::preMergeAlter($base);
     $remote = self::preMergeAlter($remote);
     $local = self::preMergeAlter($local);
     try {
         $merged = $this->mergeFile($file, $base, $remote, $local);
         return self::postMergeAlter($merged);
     } catch (GitException $e) {
         // @TODO: clean up working directory.
         $conflicts = [];
         $merged = [];
         self::getConflicts($file, $base, $remote, $local, $conflicts, $merged);
         $merged = implode("\n", $merged);
         $merged = self::postMergeAlter($merged);
         file_put_contents($file, $merged);
         $this->git->add($file);
         $this->git->commit('Resolve merge conflict.');
         throw new MergeException('A merge conflict has occured.', $conflicts, $merged, 0, $e);
     }
 }
Пример #2
0
 /**
  * @inheritDoc
  */
 public function merge($base, $remote, $local)
 {
     // Skip merging if there is nothing to do.
     if ($merged = PhpMergeBase::simpleMerge($base, $remote, $local)) {
         return $merged;
     }
     $remoteDiff = Line::createArray($this->differ->diffToArray($base, $remote));
     $localDiff = Line::createArray($this->differ->diffToArray($base, $local));
     $baseLines = Line::createArray(array_map(function ($l) {
         return [$l, 0];
     }, explode("\n", $base)));
     $remoteHunks = Hunk::createArray($remoteDiff);
     $localHunks = Hunk::createArray($localDiff);
     $conflicts = [];
     $merged = PhpMerge::mergeHunks($baseLines, $remoteHunks, $localHunks, $conflicts);
     if ($conflicts) {
         throw new MergeException('A merge conflict has occured.', $conflicts, $merged);
     }
     return $merged;
 }