Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

Commit

Permalink
Merge pull request #67 from adrian-martinez-interactiv4/patch-1
Browse files Browse the repository at this point in the history
Fix 'File must begin with <?php or #!/usr/bin/env php' error when renaming file
  • Loading branch information
sjparkinson authored Nov 28, 2017
2 parents ff4871d + 5345e79 commit 5720c8d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/VersionControl/GitVersionControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function getStagedFiles()
$files = new FileCollection();

foreach ($this->getFiles() as $file) {
list($status, $relativePath) = explode("\t", $file);
$fileData = explode("\t", $file);
$status = reset($fileData);
$relativePath = end($fileData);

$fullPath = rtrim($base . DIRECTORY_SEPARATOR . $relativePath);

Expand Down
59 changes: 59 additions & 0 deletions tests/functional/VersionControl/GitVersionControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,63 @@ public function testGetStagedFilesWithPartiallyStagedFile()

$this->assertSame('test', trim($process->getOutput()));
}

public function testGetStagedFilesWithMovedUnrenamedFile()
{
$testFolderName = 'test_folder';

$cmd = 'touch ' . $this->testFileName;
$cmd .= ' && echo \'test\' > ' . $this->testFileName;
$cmd .= ' && git init';
$cmd .= ' && git add ' . $this->testFileName;
$cmd .= ' && git commit -m \'test\'';
$cmd .= ' && mkdir ' . $testFolderName;
$cmd .= ' && mv ' . $this->testFileName . ' ' . $testFolderName;
$cmd .= ' && git add ' . $this->testFileName;
$cmd .= ' && git add ' . $testFolderName;

$process = new Process($cmd);
$process->run();

$git = new GitVersionControl();
$collection = $git->getStagedFiles();

$this->assertInstanceOf('StaticReview\Collection\FileCollection', $collection);
$this->assertCount(1, $collection);

$file = $collection->current();

$this->assertSame(basename($this->testFileName), $file->getFileName());
$this->assertStringStartsWith('R', $file->getStatus());
}

public function testGetStagedFilesWithMovedRenamedFile()
{
$testFolderName = 'test_folder';
$newTestFileName = 'test_new.txt';

$cmd = 'touch ' . $this->testFileName;
$cmd .= ' && echo \'test\' > ' . $this->testFileName;
$cmd .= ' && git init';
$cmd .= ' && git add ' . $this->testFileName;
$cmd .= ' && git commit -m \'test\'';
$cmd .= ' && mkdir ' . $testFolderName;
$cmd .= ' && mv ' . $this->testFileName . ' ' . $testFolderName . DIRECTORY_SEPARATOR . $newTestFileName;
$cmd .= ' && git add ' . $this->testFileName;
$cmd .= ' && git add ' . $testFolderName;

$process = new Process($cmd);
$process->run();

$git = new GitVersionControl();
$collection = $git->getStagedFiles();

$this->assertInstanceOf('StaticReview\Collection\FileCollection', $collection);
$this->assertCount(1, $collection);

$file = $collection->current();

$this->assertSame(basename($newTestFileName), $file->getFileName());
$this->assertStringStartsWith('R', $file->getStatus());
}
}

0 comments on commit 5720c8d

Please sign in to comment.