GitElephant
GitElephant copied to clipboard
Get working tree diff
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 ?
Does anyone have any thoughts on this?