From 74a8c7c908f0a28b415919707c249bca60256b1b Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Fri, 28 May 2021 23:15:17 -0500 Subject: [PATCH] Explicitly specify the diff algorithm to use --- src/Command/Diff/Compare.php | 4 +- src/Command/DiffIndex/GetStagedFiles.php | 2 +- src/Command/DiffIndex/GetUnstagedPatch.php | 1 + src/Command/DiffTree/ChangedFiles.php | 8 ++- tests/git/Command/Diff/CompareTest.php | 49 ++++++++++++++----- .../Command/DiffIndex/GetStagedFilesTest.php | 2 +- .../DiffIndex/GetUnstagedPatchTest.php | 6 ++- .../git/Command/DiffTree/ChangedFilesTest.php | 4 +- 8 files changed, 57 insertions(+), 19 deletions(-) diff --git a/src/Command/Diff/Compare.php b/src/Command/Diff/Compare.php index 3c8a7af..6559ee6 100644 --- a/src/Command/Diff/Compare.php +++ b/src/Command/Diff/Compare.php @@ -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 diff --git a/src/Command/DiffIndex/GetStagedFiles.php b/src/Command/DiffIndex/GetStagedFiles.php index e8a0018..16e70c7 100644 --- a/src/Command/DiffIndex/GetStagedFiles.php +++ b/src/Command/DiffIndex/GetStagedFiles.php @@ -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'; } } diff --git a/src/Command/DiffIndex/GetUnstagedPatch.php b/src/Command/DiffIndex/GetUnstagedPatch.php index 4c615bb..c6d30ca 100644 --- a/src/Command/DiffIndex/GetUnstagedPatch.php +++ b/src/Command/DiffIndex/GetUnstagedPatch.php @@ -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' diff --git a/src/Command/DiffTree/ChangedFiles.php b/src/Command/DiffTree/ChangedFiles.php index a3b8720..bdcd95d 100644 --- a/src/Command/DiffTree/ChangedFiles.php +++ b/src/Command/DiffTree/ChangedFiles.php @@ -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(); } /** diff --git a/tests/git/Command/Diff/CompareTest.php b/tests/git/Command/Diff/CompareTest.php index 93020d2..934f7c7 100644 --- a/tests/git/Command/Diff/CompareTest.php +++ b/tests/git/Command/Diff/CompareTest.php @@ -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() + ); } /** @@ -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() + ); } /** @@ -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() ); } @@ -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() + ); } /** @@ -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() + ); } /** @@ -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() + ); } /** @@ -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() ); } @@ -117,7 +132,10 @@ 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 @@ -125,7 +143,10 @@ 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 @@ -133,7 +154,10 @@ 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 @@ -141,6 +165,9 @@ 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() + ); } } diff --git a/tests/git/Command/DiffIndex/GetStagedFilesTest.php b/tests/git/Command/DiffIndex/GetStagedFilesTest.php index 8b27a36..78f6cb8 100644 --- a/tests/git/Command/DiffIndex/GetStagedFilesTest.php +++ b/tests/git/Command/DiffIndex/GetStagedFilesTest.php @@ -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); } } diff --git a/tests/git/Command/DiffIndex/GetUnstagedPatchTest.php b/tests/git/Command/DiffIndex/GetUnstagedPatchTest.php index 1a9e909..e9e5b7e 100644 --- a/tests/git/Command/DiffIndex/GetUnstagedPatchTest.php +++ b/tests/git/Command/DiffIndex/GetUnstagedPatchTest.php @@ -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() ); } @@ -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() ); } diff --git a/tests/git/Command/DiffTree/ChangedFilesTest.php b/tests/git/Command/DiffTree/ChangedFilesTest.php index 90d86e9..bf61310 100644 --- a/tests/git/Command/DiffTree/ChangedFilesTest.php +++ b/tests/git/Command/DiffTree/ChangedFilesTest.php @@ -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() ); } @@ -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() ); }