Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit 496153c

Browse files
committed
bug #218 Keep .gitignore files in sync (ogizanagi)
This PR was merged into the 1.0-dev branch. Discussion ---------- Keep .gitignore files in sync This is only a quick fix regarding the issue mentioned in #211 , and the few recent issues related: - #217 - symfony/symfony#16815 Commits ------- 0da1b95 Keep .gitignore files in sync
2 parents 91e8814 + 0da1b95 commit 496153c

File tree

2 files changed

+32
-55
lines changed

2 files changed

+32
-55
lines changed

src/Symfony/Installer/DownloadCommand.php

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -306,50 +306,48 @@ protected function checkSymfonyRequirements()
306306
}
307307

308308
/**
309-
* Creates the appropriate .gitignore file for a Symfony project.
309+
* Creates the appropriate .gitignore file for a Symfony project if it doesn't exist.
310310
*
311311
* @return $this
312312
*/
313313
protected function createGitIgnore()
314314
{
315-
$gitIgnoreEntries = array(
316-
'/app/config/parameters.yml',
317-
'/bin/',
318-
'/build/',
319-
'/composer.phar',
320-
'/vendor/',
321-
'/web/bundles/',
322-
);
323-
if ($this->isSymfony3()) {
324-
$gitIgnoreEntries = array_merge($gitIgnoreEntries, array(
325-
'/var/',
326-
'!var/cache/.gitkeep',
327-
'!var/logs/.gitkeep',
328-
'!var/sessions/.gitkeep',
329-
'/phpunit.xml',
330-
));
331-
} else {
332-
$gitIgnoreEntries = array_merge($gitIgnoreEntries, array(
333-
'/app/bootstrap.php.cache',
334-
'/app/cache/*',
335-
'!app/cache/.gitkeep',
336-
'/app/config/parameters.yml',
337-
'/app/logs/*',
338-
'!app/logs/.gitkeep',
339-
'/app/phpunit.xml',
340-
));
341-
}
342-
343-
try {
344-
$this->fs->dumpFile($this->projectDir.'/.gitignore', implode("\n", $gitIgnoreEntries)."\n");
345-
} catch (\Exception $e) {
346-
// don't throw an exception in case the .gitignore file cannot be created,
347-
// because this is just an enhancement, not something mandatory for the project
315+
if (!is_file($path = $this->projectDir.'/.gitignore')) {
316+
try {
317+
$this->fs->dumpFile($path, @file_get_contents(sprintf(
318+
'https://raw.githubusercontent.com/symfony/symfony-standard/v%s/.gitignore',
319+
$this->getInstalledSymfonyVersion()
320+
)));
321+
} catch (\Exception $e) {
322+
// don't throw an exception in case the .gitignore file cannot be created,
323+
// because this is just an enhancement, not something mandatory for the project
324+
}
348325
}
349326

350327
return $this;
351328
}
352329

330+
/**
331+
* Returns the full Symfony version number of the project by getting
332+
* it from the composer.lock file.
333+
*
334+
* @return string
335+
*/
336+
protected function getInstalledSymfonyVersion()
337+
{
338+
$composer = json_decode(file_get_contents($this->projectDir.'/composer.lock'), true);
339+
340+
foreach ($composer['packages'] as $package) {
341+
if ('symfony/symfony' === $package['name']) {
342+
if ('v' === substr($package['version'], 0, 1)) {
343+
return substr($package['version'], 1);
344+
};
345+
346+
return $package['version'];
347+
}
348+
}
349+
}
350+
353351
/**
354352
* Checks if the installer has enough permissions to create the project.
355353
*/

src/Symfony/Installer/NewCommand.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -361,27 +361,6 @@ protected function updateComposerJson()
361361
return $this;
362362
}
363363

364-
/**
365-
* Returns the full Symfony version number of the project by getting
366-
* it from the composer.lock file.
367-
*
368-
* @return string
369-
*/
370-
protected function getInstalledSymfonyVersion()
371-
{
372-
$composer = json_decode(file_get_contents($this->projectDir.'/composer.lock'), true);
373-
374-
foreach ($composer['packages'] as $package) {
375-
if ('symfony/symfony' === $package['name']) {
376-
if ('v' === substr($package['version'], 0, 1)) {
377-
return substr($package['version'], 1);
378-
};
379-
380-
return $package['version'];
381-
}
382-
}
383-
}
384-
385364
/**
386365
* Generates a good Composer project name based on the application name
387366
* and on the user name.

0 commit comments

Comments
 (0)