@@ -288,7 +288,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
288288 $ verboseOutput = '+ Scanning directory ' . $ directory . '. ' ;
289289 $ output ->writeln ($ verboseOutput , OutputInterface::VERBOSITY_VERBOSE );
290290
291- // Print deprecation notices for legacy options but do NOT change exit code.
291+ // Print deprecation notices for legacy options but do NOT change the exit code.
292292 if ($ input ->hasOption ('create ' ) && (bool ) $ input ->getOption ('create ' )) {
293293 $ output ->writeln ('<comment>The --create option is deprecated. Please use the dedicated <info>create</info> command.</comment> ' );
294294 }
@@ -306,7 +306,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
306306 $ validateArchive = $ input ->getOption ('validate-git-archive ' );
307307 $ globPattern = $ input ->getOption ('glob-pattern ' );
308308 $ globPatternFile = (string ) $ input ->getOption ('glob-pattern-file ' );
309- $ omitHeader = $ input ->getOption ('omit-header ' );
309+ $ omitHeader = ( boolean ) $ input ->getOption ('omit-header ' );
310310 $ showDifference = $ input ->getOption ('diff ' );
311311 $ reportStaleExportIgnores = $ input ->getOption ('report-stale-export-ignores ' );
312312
@@ -455,24 +455,28 @@ protected function execute(InputInterface $input, OutputInterface $output): int
455455
456456 $ verboseOutput = '+ Checking .gitattribute file existence in ' . $ directory . '. ' ;
457457 $ output ->writeln ($ verboseOutput , OutputInterface::VERBOSITY_VERBOSE );
458+ $ outputContent = '' ;
458459
459460 if (!$ this ->analyser ->hasGitattributesFile ()) {
460- $ warning = 'Warning: There is no .gitattributes file present in '
461- . $ this ->analyser ->getDirectory () . '. ' ;
462- $ outputContent = '<error> ' . $ warning . '</error> ' ;
463-
464- $ expectedGitattributesFileContent = $ this ->analyser
465- ->getExpectedGitattributesContent ();
461+ if ($ createGitattributesFile === false ) {
462+ $ warning = 'Warning: There is no .gitattributes file present in '
463+ . $ this ->analyser ->getDirectory () . '. ' ;
464+ $ outputContent .= '<error> ' . $ warning . '</error> ' ;
465+ }
466466
467467 $ verboseOutput = '+ Getting expected .gitattribute file content. ' ;
468468 $ output ->writeln ($ verboseOutput , OutputInterface::VERBOSITY_VERBOSE );
469469
470+ $ expectedGitattributesFileContent = $ this ->analyser
471+ ->getExpectedGitattributesContent ();
472+
470473 if ($ expectedGitattributesFileContent !== '' ) {
474+
471475 if ($ createGitattributesFile || $ overwriteGitattributesFile ) {
472476 try {
473477 $ outputContent .= $ this ->gitattributesFileRepository ->createGitattributesFile (
474478 $ expectedGitattributesFileContent ,
475- $ omitHeader === false
479+ $ omitHeader === true ? false : true
476480 );
477481
478482 $ output ->writeln ($ outputContent );
@@ -562,17 +566,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
562566 }
563567 $ output ->writeln ($ verboseOutput , OutputInterface::VERBOSITY_VERBOSE );
564568
565- if ($ omitHeader === false ) {
566- if (\str_contains ($ expectedGitattributesFileContent , GitattributesFileRepository::GENERATED_HEADER )) {
567- $ expectedGitattributesFileContent = \str_replace (
568- GitattributesFileRepository::GENERATED_HEADER . PHP_EOL . PHP_EOL ,
569- '' ,
570- $ expectedGitattributesFileContent
571- );
572- }
573- $ expectedGitattributesFileContent = GitattributesFileRepository::MODIFIED_HEADER . PHP_EOL . PHP_EOL . $ expectedGitattributesFileContent ;
574- }
575-
576569 $ outputContent .= $ this ->gitattributesFileRepository ->overwriteGitattributesFile (
577570 $ expectedGitattributesFileContent
578571 );
0 commit comments