Skip to content

Commit

Permalink
Added more assertions for custom gitignore tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk authored Feb 18, 2019
1 parent 552a6eb commit d7b7783
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/ArtefactTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ protected function restoreLocalExclude($path)
*/
protected function removeExcludedFiles($location, $gitignore = '.gitignore')
{
$command = sprintf('ls-files --directory --i --exclude-from=%s %s', $location.DIRECTORY_SEPARATOR.$gitignore, $location);
$command = sprintf('ls-files --directory -i --exclude-from=%s %s', $location.DIRECTORY_SEPARATOR.$gitignore, $location);
$result = $this->gitCommandRun($location, $command, 'Unable to remove excluded files');
$excludedFiles = array_filter(preg_split('/\R/', $result->getMessage()));
foreach ($excludedFiles as $excludedFile) {
Expand Down
38 changes: 22 additions & 16 deletions tests/ForcePushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,43 +91,49 @@ public function testGitignore()

public function testGitignoreCustom()
{
$this->gitCreateFixtureFile($this->src, 'mygitignore', '3.txt');
$this->gitCreateFixtureCommits(2);
$this->gitCreateFixtureFile($this->src, '3.txt');
$this->gitCreateFixtureFile($this->src, 'uncom_ignored_com.txt');

$this->gitCreateFixtureFile($this->src, 'mygitignore', 'uncom_ignored_com.txt');
$this->assertBuildSuccess('--gitignore='.$this->src.DIRECTORY_SEPARATOR.'mygitignore');

$this->assertFixtureCommits(2, $this->dst, 'testbranch', ['Deployment commit']);
$this->gitAssertFilesNotExist($this->dst, '3.txt');
$this->gitAssertFilesNotExist($this->dst, 'uncom_ignored_com.txt');

// Now, remove the .gitignore and push again.
$this->gitRemoveFixtureFile($this->src, 'mygitignore');
$this->gitCommitAll($this->src, 'Commit number 3');
$this->assertBuildSuccess();
$this->assertFixtureCommits(3, $this->dst, 'testbranch', ['Deployment commit']);

$this->assertFixtureCommits(3, $this->dst, 'testbranch', ['Deployment commit'], false);
$this->gitAssertFilesCommitted($this->dst, ['1.txt', '2.txt', 'uncom_ignored_com.txt'], 'testbranch');
$this->gitAssertFilesExist($this->dst, ['1.txt', '2.txt', 'uncom_ignored_com.txt'], 'testbranch');
}

public function testGitignoreCustomRemoveCommittedFiles()
{
$this->gitCreateFixtureFile($this->src, '.gitignore', ['3.txt']);
$this->gitCreateFixtureFile($this->src, '3.txt');
$this->gitCreateFixtureFile($this->src, 'subdir/4.txt');
$this->gitCreateFixtureFile($this->src, 'subdir/5.txt');
$this->gitCreateFixtureFile($this->src, '.gitignore', ['ignored_ignored.txt', 'ignored_com.txt']);

$this->gitCreateFixtureFile($this->src, 'ignored_ignored.txt');
$this->gitCreateFixtureFile($this->src, 'ignored_com.txt');
$this->gitCreateFixtureFile($this->src, 'subdir/com_com.txt');
$this->gitCreateFixtureFile($this->src, 'subdir/com_ignored.txt');
$this->gitCreateFixtureCommits(2);
$this->gitCommitAll($this->src, 'Custom third commit');
$this->gitCreateFixtureFile($this->src, 'uncom_ignored.txt');
$this->gitCreateFixtureFile($this->src, 'uncom_com.txt');
$this->gitAssertFilesCommitted($this->src, ['1.txt', '2.txt', 'subdir/com_com.txt', 'subdir/com_ignored.txt']);
$this->gitAssertNoFilesCommitted($this->src, ['ignored_ignored.txt', 'ignored_com.txt', 'uncom_ignored.txt', 'uncom_com.txt']);

$this->gitAssertFilesCommitted($this->src, ['1.txt', '2.txt', 'subdir/4.txt', 'subdir/5.txt']);
$this->gitAssertNoFilesCommitted($this->src, ['3.txt']);

$this->gitCreateFixtureFile($this->src, 'mygitignore', ['1.txt', '3.txt', '5.txt']);
$this->gitCreateFixtureFile($this->src, 'mygitignore', ['1.txt', 'ignored_ignored.txt', 'com_ignored.txt', 'uncom_ignored.txt']);

$this->assertBuildSuccess('--gitignore='.$this->src.DIRECTORY_SEPARATOR.'mygitignore');

$this->assertFixtureCommits(2, $this->dst, 'testbranch', ['Custom third commit', 'Deployment commit'], false);
$this->gitAssertFilesCommitted($this->dst, ['2.txt', 'subdir/4.txt'], 'testbranch');
$this->gitAssertNoFilesCommitted($this->dst, ['1.txt', '3.txt', 'subdir/5.txt'], 'testbranch');
$this->gitAssertFilesExist($this->dst, ['2.txt', 'subdir/4.txt'], 'testbranch');
$this->gitAssertFilesNotExist($this->dst, ['1.txt', '3.txt', 'subdir/5.txt'], 'testbranch');
$this->gitAssertFilesCommitted($this->dst, ['2.txt', 'ignored_com.txt', 'subdir/com_com.txt', 'uncom_com.txt'], 'testbranch');
$this->gitAssertNoFilesCommitted($this->dst, ['1.txt', 'ignored_ignored.txt', 'subdir/com_ignored.txt', 'uncom_ignored.txt'], 'testbranch');
$this->gitAssertFilesExist($this->dst, ['2.txt', 'ignored_com.txt', 'subdir/com_com.txt', 'uncom_com.txt'], 'testbranch');
$this->gitAssertFilesNotExist($this->dst, ['1.txt', 'ignored_ignored.txt', 'subdir/com_ignored.txt', 'uncom_ignored.txt'], 'testbranch');
}

public function testBuildTag()
Expand Down

0 comments on commit d7b7783

Please sign in to comment.