Skip to content

Commit

Permalink
Merge pull request #108 from wp-cli/fix/105-update-files
Browse files Browse the repository at this point in the history
Remove existing files in zip file
  • Loading branch information
swissspidy authored Feb 14, 2025
2 parents ce4774e + 00bc865 commit c4ef681
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
82 changes: 82 additions & 0 deletions features/dist-archive.feature
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,85 @@ Feature: Generate a distribution archive of a project
"""
Success: Created hello-world-dist.zip
"""

Scenario: Removes existing files in the ZIP file
Given an empty directory
And a foo/.distignore file:
"""
"""
And a foo/foo.txt file:
"""
Hello Foo
"""
And a foo/bar.txt file:
"""
Hello Bar
"""

When I try `wp dist-archive foo`
Then the foo.zip file should exist

When I try `zipinfo -1 foo.zip`
Then STDOUT should contain:
"""
foo/bar.txt
"""
And STDOUT should contain:
"""
foo/foo.txt
"""

When I run `echo "foo.txt" > foo/.distignore`
And I try `wp dist-archive foo --force`
Then the foo.zip file should exist

When I try `zipinfo -1 foo.zip`
Then STDOUT should contain:
"""
foo/bar.txt
"""
And STDOUT should not contain:
"""
foo/foo.txt
"""

Scenario: Removes existing files in the tarball
Given an empty directory
And a foo/.distignore file:
"""
"""
And a foo/foo.txt file:
"""
Hello Foo
"""
And a foo/bar.txt file:
"""
Hello Bar
"""

When I try `wp dist-archive foo --format=targz`
Then the foo.tar.gz file should exist

When I try `tar -tf foo.tar.gz`
Then STDOUT should contain:
"""
foo/bar.txt
"""
And STDOUT should contain:
"""
foo/foo.txt
"""

When I run `echo "foo.txt" > foo/.distignore`
And I try `wp dist-archive foo --format=targz --force`
Then the foo.tar.gz file should exist

When I try `tar -tf foo.tar.gz`
Then STDOUT should contain:
"""
foo/bar.txt
"""
And STDOUT should not contain:
"""
foo/foo.txt
"""
2 changes: 1 addition & 1 deletion src/Dist_Archive_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function ( $relative_path ) use ( $source_path ) {
)
)
);
$cmd = "zip -r '{$archive_absolute_filepath}' {$archive_output_dir_name} -i@{$include_list_filepath}";
$cmd = "zip --filesync -r '{$archive_absolute_filepath}' {$archive_output_dir_name} -i@{$include_list_filepath}";
} elseif ( 'targz' === $assoc_args['format'] ) {
$exclude_list_filepath = "{$tmp_dir}/exclude-file-list.txt";
$excludes = array_filter(
Expand Down

0 comments on commit c4ef681

Please sign in to comment.