Skip to content

Commit

Permalink
Merge pull request #32 from ramsey/specify-diff-algorithm
Browse files Browse the repository at this point in the history
Explicitly specify the diff algorithm to use
  • Loading branch information
sebastianfeldmann authored May 29, 2021
2 parents ca827dc + 74a8c7c commit 406b98e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/Command/Diff/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ public function ignoreSubmodules(bool $bool = true): Compare
*/
protected function getGitCommand(): string
{
return 'diff --no-ext-diff'
return 'diff'
. ' --no-ext-diff'
. ' --diff-algorithm=myers'
. $this->unified
. $this->ignoreWhitespaces
. $this->ignoreSubmodules
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DiffIndex/GetStagedFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ class GetStagedFiles extends Base
*/
protected function getGitCommand(): string
{
return 'diff-index --no-ext-diff --cached --name-status HEAD';
return 'diff-index --diff-algorithm=myers --no-ext-diff --cached --name-status HEAD';
}
}
1 change: 1 addition & 0 deletions src/Command/DiffIndex/GetUnstagedPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function tree(?string $treeId): GetUnstagedPatch
protected function getGitCommand(): string
{
return 'diff-index'
. ' --diff-algorithm=myers'
. ' --ignore-submodules'
. ' --binary'
. ' --exit-code'
Expand Down
8 changes: 7 additions & 1 deletion src/Command/DiffTree/ChangedFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ public function toRevision(string $to): ChangedFiles
*/
protected function getGitCommand(): string
{
return 'diff-tree --no-ext-diff --no-commit-id --name-only -r ' . $this->getVersionsToCompare();
return 'diff-tree'
. ' --diff-algorithm=myers'
. ' --no-ext-diff'
. ' --no-commit-id'
. ' --name-only'
. ' -r'
. ' ' . $this->getVersionsToCompare();
}

/**
Expand Down
49 changes: 38 additions & 11 deletions tests/git/Command/Diff/CompareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public function testCompareRevisions()
$compare = new Compare();
$compare->revisions('1.0.0', '1.1.0');

$this->assertEquals('git diff --no-ext-diff \'1.0.0\' \'1.1.0\' -- ', $compare->getCommand());
$this->assertEquals(
'git diff --no-ext-diff --diff-algorithm=myers \'1.0.0\' \'1.1.0\' -- ',
$compare->getCommand()
);
}

/**
Expand All @@ -43,7 +46,10 @@ public function testCompareStats()
$compare->revisions('1.0.0', '1.1.0');
$compare->statsOnly();

$this->assertEquals('git diff --no-ext-diff --numstat \'1.0.0\' \'1.1.0\' -- ', $compare->getCommand());
$this->assertEquals(
'git diff --no-ext-diff --diff-algorithm=myers --numstat \'1.0.0\' \'1.1.0\' -- ',
$compare->getCommand()
);
}

/**
Expand All @@ -56,7 +62,7 @@ public function testIgnoreWhitespacesAtEndOfLine()
$compare->ignoreWhitespacesAtEndOfLine();

$this->assertEquals(
'git diff --no-ext-diff --ignore-space-at-eol \'1.0.0\' \'1.1.0\' -- ',
'git diff --no-ext-diff --diff-algorithm=myers --ignore-space-at-eol \'1.0.0\' \'1.1.0\' -- ',
$compare->getCommand()
);
}
Expand All @@ -69,7 +75,10 @@ public function testIndexTo()
$compare = new Compare();
$compare->indexTo();

$this->assertEquals('git diff --no-ext-diff --staged \'HEAD\' -- ', $compare->getCommand());
$this->assertEquals(
'git diff --no-ext-diff --diff-algorithm=myers --staged \'HEAD\' -- ',
$compare->getCommand()
);
}

/**
Expand All @@ -81,7 +90,10 @@ public function testContextLines()
$compare->indexTo()->withContextLines(2);


$this->assertEquals('git diff --no-ext-diff --unified=2 --staged \'HEAD\' -- ', $compare->getCommand());
$this->assertEquals(
'git diff --no-ext-diff --diff-algorithm=myers --unified=2 --staged \'HEAD\' -- ',
$compare->getCommand()
);
}

/**
Expand All @@ -93,7 +105,10 @@ public function testIgnoreWhitespaces()
$compare->revisions('1.0.0', '1.1.0');
$compare->ignoreWhitespaces();

$this->assertEquals('git diff --no-ext-diff -w \'1.0.0\' \'1.1.0\' -- ', $compare->getCommand());
$this->assertEquals(
'git diff --no-ext-diff --diff-algorithm=myers -w \'1.0.0\' \'1.1.0\' -- ',
$compare->getCommand()
);
}

/**
Expand All @@ -107,7 +122,7 @@ public function testIgnoreWhitespacesAndEOL()
->ignoreWhitespaces();

$this->assertEquals(
'git diff --no-ext-diff -w --ignore-space-at-eol \'1.0.0\' \'1.1.0\' -- ',
'git diff --no-ext-diff --diff-algorithm=myers -w --ignore-space-at-eol \'1.0.0\' \'1.1.0\' -- ',
$compare->getCommand()
);
}
Expand All @@ -117,30 +132,42 @@ public function testIgnoreSubmodules(): void
$compare = new Compare();
$compare->ignoreSubmodules();

$this->assertEquals('git diff --no-ext-diff --ignore-submodules -- ', $compare->getCommand());
$this->assertEquals(
'git diff --no-ext-diff --diff-algorithm=myers --ignore-submodules -- ',
$compare->getCommand()
);
}

public function testStaged(): void
{
$compare = new Compare();
$compare->staged();

$this->assertEquals('git diff --no-ext-diff --staged -- ', $compare->getCommand());
$this->assertEquals(
'git diff --no-ext-diff --diff-algorithm=myers --staged -- ',
$compare->getCommand()
);
}

public function testToWithDefaultParam(): void
{
$compare = new Compare();
$compare->to();

$this->assertEquals('git diff --no-ext-diff \'HEAD\' -- ', $compare->getCommand());
$this->assertEquals(
'git diff --no-ext-diff --diff-algorithm=myers \'HEAD\' -- ',
$compare->getCommand()
);
}

public function testToWithPassedParam(): void
{
$compare = new Compare();
$compare->to('foobar');

$this->assertEquals('git diff --no-ext-diff \'foobar\' -- ', $compare->getCommand());
$this->assertEquals(
'git diff --no-ext-diff --diff-algorithm=myers \'foobar\' -- ',
$compare->getCommand()
);
}
}
2 changes: 1 addition & 1 deletion tests/git/Command/DiffIndex/GetStagedFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function testGetGitCommand()
$cmd = new GetStagedFiles();
$exe = $cmd->getCommand();

$this->assertEquals('git diff-index --no-ext-diff --cached --name-status HEAD', $exe);
$this->assertEquals('git diff-index --diff-algorithm=myers --no-ext-diff --cached --name-status HEAD', $exe);
}
}
6 changes: 4 additions & 2 deletions tests/git/Command/DiffIndex/GetUnstagedPatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function testGetUnstagedPatchWithoutTree()
$cmd = new GetUnstagedPatch();

$this->assertSame(
'git diff-index --ignore-submodules --binary --exit-code --no-color --no-ext-diff -- ',
'git diff-index --diff-algorithm=myers --ignore-submodules '
. '--binary --exit-code --no-color --no-ext-diff -- ',
$cmd->getCommand()
);
}
Expand All @@ -45,7 +46,8 @@ public function testGetUnstagedPatchWithTree()
$cmd = (new GetUnstagedPatch())->tree('1234567890');

$this->assertSame(
'git diff-index --ignore-submodules --binary --exit-code --no-color --no-ext-diff \'1234567890\' -- ',
'git diff-index --diff-algorithm=myers --ignore-submodules '
. '--binary --exit-code --no-color --no-ext-diff \'1234567890\' -- ',
$cmd->getCommand()
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/git/Command/DiffTree/ChangedFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testChangedFilesByRevisions()
->toRevision('1.1.0');

$this->assertEquals(
'git diff-tree --no-ext-diff --no-commit-id --name-only -r \'1.0.0\' \'1.1.0\'',
'git diff-tree --diff-algorithm=myers --no-ext-diff --no-commit-id --name-only -r \'1.0.0\' \'1.1.0\'',
$changed->getCommand()
);
}
Expand All @@ -48,7 +48,7 @@ public function testChangedFilesBySingleRevision()
$changed->fromRevision('1.0.0');

$this->assertEquals(
'git diff-tree --no-ext-diff --no-commit-id --name-only -r \'1.0.0\'',
'git diff-tree --diff-algorithm=myers --no-ext-diff --no-commit-id --name-only -r \'1.0.0\'',
$changed->getCommand()
);
}
Expand Down

0 comments on commit 406b98e

Please sign in to comment.