diff --git a/src/IDF/Diff.php b/src/IDF/Diff.php index 28139a6..a088d4f 100644 --- a/src/IDF/Diff.php +++ b/src/IDF/Diff.php @@ -110,6 +110,12 @@ class IDF_Diff $lline++; continue; } + if ($line == '') { + $files[$current_file]['chunks'][$current_chunk-1][] = array($lline, $rline, $line); + $rline++; + $lline++; + continue; + } } $this->files = $files; return $files; @@ -243,7 +249,8 @@ class IDF_Diff for ($lc=$spans[$i][0];$lc<$chunk[0][0];$lc++) { $exists = false; foreach ($chunk_lines as $line) { - if ($lc == $line[0] or ($chunk[0][1]-$chunk[0][0]+$lc) == $line[1]) { + if ($lc == $line[0] + or ($chunk[0][1]-$chunk[0][0]+$lc) == $line[1]) { $exists = true; break; } diff --git a/src/IDF/Tests/TestDiff.php b/src/IDF/Tests/TestDiff.php index 97e4107..00f579f 100644 --- a/src/IDF/Tests/TestDiff.php +++ b/src/IDF/Tests/TestDiff.php @@ -79,4 +79,15 @@ class IDF_Tests_TestDiff extends UnitTestCase $this->assertEqual(2, count($diff->files)); $this->assertEqual(12, count($diff->files['src/IDF/conf/idf.php-dist']['chunks'][0])); } + + public function testDiffRemoveOneLine() + { + $diff_content = file_get_contents(dirname(__FILE__).'/test-diff-remove-oneline.diff'); + $diff = new IDF_Diff($diff_content); + $diff->parse(); + $this->assertEqual(2, count($diff->files)); + $this->assertEqual(array(280, 288, ''), + $diff->files['src/IDF/Scm/Git.php']['chunks'][1][2]); + $this->assertEqual(7, count($diff->files['src/IDF/Scm/Git.php']['chunks'][1])); + } } \ No newline at end of file diff --git a/src/IDF/Tests/test-diff-remove-oneline.diff b/src/IDF/Tests/test-diff-remove-oneline.diff new file mode 100644 index 0000000..3fb279c --- /dev/null +++ b/src/IDF/Tests/test-diff-remove-oneline.diff @@ -0,0 +1,53 @@ +diff --git a/src/IDF/Scm/Git.php b/src/IDF/Scm/Git.php +index 5f35e0b..ebe0530 100644 +--- a/src/IDF/Scm/Git.php ++++ b/src/IDF/Scm/Git.php +@@ -250,14 +250,22 @@ class IDF_Scm_Git + * Get commit details. + * + * @param string Commit ('HEAD'). ++ * @param bool Get commit diff (false). + * @return array Changes. + */ +- public function getCommit($commit='HEAD') ++ public function getCommit($commit='HEAD', $getdiff=false) + { +- $cmd = sprintf('GIT_DIR=%s git show --date=iso --pretty=format:%s %s', +- escapeshellarg($this->repo), +- "'".$this->mediumtree_fmt."'", +- escapeshellarg($commit)); ++ if ($getdiff) { ++ $cmd = sprintf('GIT_DIR=%s git show --date=iso --pretty=format:%s %s', ++ escapeshellarg($this->repo), ++ "'".$this->mediumtree_fmt."'", ++ escapeshellarg($commit)); ++ } else { ++ $cmd = sprintf('GIT_DIR=%s git log -1 --date=iso --pretty=format:%s %s', ++ escapeshellarg($this->repo), ++ "'".$this->mediumtree_fmt."'", ++ escapeshellarg($commit)); ++ } + $out = array(); + IDF_Scm::exec($cmd, $out); + $log = array(); +@@ -278,7 +286,6 @@ class IDF_Scm_Git + return $out[0]; + } + +- + /** + * Get latest changes. + * +diff --git a/src/IDF/Views/Source.php b/src/IDF/Views/Source.php +index ad24ed6..e5b4f1b 100644 +--- a/src/IDF/Views/Source.php ++++ b/src/IDF/Views/Source.php +@@ -216,7 +216,7 @@ class IDF_Views_Source + } + $title = sprintf(__('%s Commit Details'), (string) $request->project); + $page_title = sprintf(__('%s Commit Details - %s'), (string) $request->project, $commit); +- $cobject = $scm->getCommit($commit); ++ $cobject = $scm->getCommit($commit, true); + $rcommit = IDF_Commit::getOrAdd($cobject, $request->project); + $diff = new IDF_Diff($cobject->changes); + $diff->parse();