Skip to content

Commit 00bc865

Browse files
committed
Remove existing files in zip file
1 parent ce4774e commit 00bc865

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

features/dist-archive.feature

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,85 @@ Feature: Generate a distribution archive of a project
456456
"""
457457
Success: Created hello-world-dist.zip
458458
"""
459+
460+
Scenario: Removes existing files in the ZIP file
461+
Given an empty directory
462+
And a foo/.distignore file:
463+
"""
464+
"""
465+
And a foo/foo.txt file:
466+
"""
467+
Hello Foo
468+
"""
469+
And a foo/bar.txt file:
470+
"""
471+
Hello Bar
472+
"""
473+
474+
When I try `wp dist-archive foo`
475+
Then the foo.zip file should exist
476+
477+
When I try `zipinfo -1 foo.zip`
478+
Then STDOUT should contain:
479+
"""
480+
foo/bar.txt
481+
"""
482+
And STDOUT should contain:
483+
"""
484+
foo/foo.txt
485+
"""
486+
487+
When I run `echo "foo.txt" > foo/.distignore`
488+
And I try `wp dist-archive foo --force`
489+
Then the foo.zip file should exist
490+
491+
When I try `zipinfo -1 foo.zip`
492+
Then STDOUT should contain:
493+
"""
494+
foo/bar.txt
495+
"""
496+
And STDOUT should not contain:
497+
"""
498+
foo/foo.txt
499+
"""
500+
501+
Scenario: Removes existing files in the tarball
502+
Given an empty directory
503+
And a foo/.distignore file:
504+
"""
505+
"""
506+
And a foo/foo.txt file:
507+
"""
508+
Hello Foo
509+
"""
510+
And a foo/bar.txt file:
511+
"""
512+
Hello Bar
513+
"""
514+
515+
When I try `wp dist-archive foo --format=targz`
516+
Then the foo.tar.gz file should exist
517+
518+
When I try `tar -tf foo.tar.gz`
519+
Then STDOUT should contain:
520+
"""
521+
foo/bar.txt
522+
"""
523+
And STDOUT should contain:
524+
"""
525+
foo/foo.txt
526+
"""
527+
528+
When I run `echo "foo.txt" > foo/.distignore`
529+
And I try `wp dist-archive foo --format=targz --force`
530+
Then the foo.tar.gz file should exist
531+
532+
When I try `tar -tf foo.tar.gz`
533+
Then STDOUT should contain:
534+
"""
535+
foo/bar.txt
536+
"""
537+
And STDOUT should not contain:
538+
"""
539+
foo/foo.txt
540+
"""

src/Dist_Archive_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function ( $relative_path ) use ( $source_path ) {
151151
)
152152
)
153153
);
154-
$cmd = "zip -r '{$archive_absolute_filepath}' {$archive_output_dir_name} -i@{$include_list_filepath}";
154+
$cmd = "zip --filesync -r '{$archive_absolute_filepath}' {$archive_output_dir_name} -i@{$include_list_filepath}";
155155
} elseif ( 'targz' === $assoc_args['format'] ) {
156156
$exclude_list_filepath = "{$tmp_dir}/exclude-file-list.txt";
157157
$excludes = array_filter(

0 commit comments

Comments
 (0)