@@ -84,6 +84,13 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
8484 $ output ->writeln ( '<fg=green>✓</> Updating version files...Complete. ' );
8585
8686 $ output ->writeln ( '<fg=gray>- Synchronizing files to zip directory...</> ' );
87+
88+ $ distfiles = $ this ->getDistfilesLines ( $ this ->getSourceDir ( $ root ) );
89+ if ( ! empty ( $ distfiles ) ) {
90+ $ distfiles_message = '>>> Your project has a <fg=yellow>.distfiles</> file, so <fg=yellow>.distignore</> and pup \'s default ignore rules will not be used. ' ;
91+ $ output ->writeln ( "<fg=gray> {$ distfiles_message }</> " );
92+ }
93+
8794 $ pup_zip_dir = $ config ->getZipDir ();
8895
8996 DirectoryUtils::rmdir ( $ pup_zip_dir );
@@ -201,6 +208,22 @@ protected function createZip( string $dir_to_zip, string $zip_filename, string $
201208 return 0 ;
202209 }
203210
211+ /**
212+ * Get the default things to exclude from sync.
213+ *
214+ * @return array<int, string>
215+ */
216+ public function getDefaultIgnoreLines (): array {
217+ $ working_dir = App::getConfig ()->getWorkingDir ();
218+ $ zip_dir = str_replace ( $ working_dir , '' , App::getConfig ()->getZipDir () );
219+
220+ return [
221+ '.puprc ' ,
222+ '.pup-* ' ,
223+ $ zip_dir ,
224+ ];
225+ }
226+
204227 /**
205228 * Get the files to exclude from sync.
206229 *
@@ -230,33 +253,54 @@ public function getIgnoreLines( string $source ): array {
230253 }
231254
232255 /**
233- * Get the files to include in sync.
256+ * Get the distfiles lines to include in sync.
234257 *
235258 * @param string $source
236259 *
237260 * @return array<int, string>
238261 */
239- public function getIncludeLines ( string $ source ): array {
240- $ include = [];
241- $ include_files = [
242- '.pup-distinclude ' ,
243- '.pup-distfiles ' ,
244- ];
262+ public function getDistfilesLines ( string $ source ): array {
263+ $ include = [];
264+ $ include_file = '.pup-distfiles ' ;
245265
246- foreach ( $ include_files as $ include_file ) {
247- if ( ! file_exists ( $ source . $ include_file ) ) {
248- continue ;
249- }
266+ if ( ! file_exists ( $ source . $ include_file ) ) {
267+ return [];
268+ }
250269
251- $ lines = file ( $ source . $ include_file , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
270+ $ lines = file ( $ source . $ include_file , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
252271
253- if ( ! $ lines ) {
254- continue ;
255- }
272+ if ( ! $ lines ) {
273+ return [];
274+ }
275+
276+ $ include = array_merge ( $ include , $ lines );
277+
278+ return $ include ;
279+ }
280+
281+ /**
282+ * Get the distinclude lines to include in sync.
283+ *
284+ * @param string $source
285+ *
286+ * @return array<int, string>
287+ */
288+ public function getDistincludeLines ( string $ source ): array {
289+ $ include = [];
290+ $ include_file = '.pup-include ' ;
291+
292+ if ( ! file_exists ( $ source . $ include_file ) ) {
293+ return [];
294+ }
295+
296+ $ lines = file ( $ source . $ include_file , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
256297
257- $ include = array_merge ( $ include , $ lines );
298+ if ( ! $ lines ) {
299+ return [];
258300 }
259301
302+ $ include = array_merge ( $ include , $ lines );
303+
260304 return $ include ;
261305 }
262306
@@ -392,8 +436,17 @@ protected function syncFiles( string $root, string $destination ): int {
392436
393437 $ this ->buildSyncFiles ( $ source );
394438
395- $ include = $ this ->getIncludeLines ( $ source );
396- $ ignore = $ this ->getIgnoreLines ( $ source );
439+ $ distfiles = $ this ->getDistfilesLines ( $ source );
440+ $ distinclude = $ this ->getDistincludeLines ( $ source );
441+ $ include = array_merge ( $ distfiles , $ distinclude );
442+
443+ $ ignore = $ this ->getDefaultIgnoreLines ();
444+
445+ // We only observe .distignore if there is no .distfiles files.
446+ if ( empty ( $ distfiles ) ) {
447+ $ ignore = array_merge ( $ ignore , $ this ->getIgnoreLines ( $ source ) );
448+ }
449+
397450 $ results = $ this ->migrateNegatedLines ( $ include , $ ignore );
398451 $ include = $ results ['include ' ];
399452 $ ignore = $ results ['ignore ' ];
0 commit comments