Skip to content

Commit

Permalink
Adding escaping for spaces, umlaut test, refs #36, refs #34
Browse files Browse the repository at this point in the history
  • Loading branch information
philipsorst committed Jun 17, 2016
1 parent 28f2ac3 commit 12392fc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
14 changes: 12 additions & 2 deletions Service/Git/GitService.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected function add(array $paths)
{
$workingCopy = $this->getWorkingCopy();
foreach ($paths as $path) {
$workingCopy->add($path->toRelativeFileSystemString());
$workingCopy->add($this->escapePath($path));
}
}

Expand All @@ -254,7 +254,7 @@ protected function remove(array $paths)
{
$workingCopy = $this->getWorkingCopy();
foreach ($paths as $path) {
$workingCopy->rm($path->toRelativeFileSystemString());
$workingCopy->rm($this->escapePath($path));
}
}

Expand All @@ -268,4 +268,14 @@ protected function addAndCommitFile(GitUserInterface $author, $commitMessage, Fi
$this->add([$path]);
$this->commit($author, $commitMessage);
}

/**
* @param $path
*
* @return mixed
*/
protected function escapePath(Path $path)
{
return str_replace(" ", "\\ ", $path->toRelativeFileSystemString());
}
}
24 changes: 21 additions & 3 deletions Tests/Service/GitServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class GitServiceTest extends GitRepositoryTestCase
public function setUp()
{
parent::setUp();

$this->fileSystemService = new FileSystemService(GitRepositoryTestCase::GIT_REPOSITORY_PATH);
$this->gitService = new GitService($this->fileSystemService);
}
Expand All @@ -33,16 +34,33 @@ public function testAddAndCommit()
{
$user = new TestUser('Tester', 'test@example.com');

$filePath = FilePath::parse('test.txt');
$this->gitService->putAndCommitFile($user, $filePath, 'asdf', 'Added test.txt');
/* Test with spaces */

$filePath = FilePath::parse('A filename with spaces.txt');
$this->gitService->putAndCommitFile($user, $filePath, 'asdf', 'Added A filename with spaces.txt');
$this->assertTrue($this->gitService->exists($filePath));

$history = $this->gitService->getFileHistory($filePath);
$this->assertCount(1, $history);

/** @var CommitMetadata $firstEntry */
$firstEntry = $history[0];
$this->assertEquals('Added A filename with spaces.txt', $firstEntry->getMessage());
$this->assertEquals('test@example.com', $firstEntry->getEmail());
$this->assertEquals('Tester', $firstEntry->getCommitter());

/* Test with umlauts */

$filePath = FilePath::parse('A filename with Ümläuts.txt');
$this->gitService->putAndCommitFile($user, $filePath, 'asdf', 'Added A filename with Ümläuts.txt');
$this->assertTrue($this->gitService->exists($filePath));

$history = $this->gitService->getFileHistory($filePath);
$this->assertCount(1, $history);

/** @var CommitMetadata $firstEntry */
$firstEntry = $history[0];
$this->assertEquals('Added test.txt', $firstEntry->getMessage());
$this->assertEquals('Added A filename with Ümläuts.txt', $firstEntry->getMessage());
$this->assertEquals('test@example.com', $firstEntry->getEmail());
$this->assertEquals('Tester', $firstEntry->getCommitter());
}
Expand Down

0 comments on commit 12392fc

Please sign in to comment.