matteosister / GitElephant

An abstraction layer for git written in PHP
GNU Lesser General Public License v3.0
613 stars 74 forks source link

Get working tree diff #113

Open fsevestre opened 7 years ago

fsevestre commented 7 years ago

Hi guys, I would like to retrieve a diff of the working tree but it's seems it is not possible at the moment (a simple git diff).

At first sight, I thought that the $repository->getDiff() without parameters method would do the trick, but in the end the diff command use sha^..sha as subject which is not what I expected.

I know that would be a huge BC break, but is this the wanted behavior ?

For now, I created my own DiffCommand object which don't call the addCommandSubject method and create myself the Diff object:

    $command = GitDiffCommand::getInstance($repository)->diff($commit);
    $outputLines = $repository->getCaller()->execute($command)->getOutputLines();

    $diffObjects = array();
    $splitArray = Utilities::pregSplitArray($outputLines, '/^diff --git SRC\/(.*) DST\/(.*)$/');
    foreach ($splitArray as $diffObjectLines) {
        $diffObjects[] = new DiffObject($diffObjectLines);
    }

    $diff = new Diff($repository, $diffObjects);

Is there an alternative approach ?

vkryukov76 commented 7 years ago

Does anyone have any thoughts on this?