Skip to content

Exclude non-essential files using .gitattributes #6107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Nikita20010
Copy link

Summary

This PR adds a .gitattributes file to exclude development-only and non-essential files from distribution packages. This helps reduce package size and ensures that only relevant files are included when the project is exported or packaged via Composer.

Changes Made

  • Added .gitattributes to exclude:
    • Tests
    • Configuration files
    • Git-related files
    • CI/CD files
    • Docs not required in distribution

Benefits

  • Smaller package size
  • Cleaner distribution for Composer consumers
  • Avoids exposing internal test/config files in production environments

Related References


@Nikita20010 Nikita20010 requested a review from a team as a code owner August 4, 2025 16:07
Copy link

codecov bot commented Aug 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

/features export-ignore
/bin export-ignore
/phpunit.xml.dist export-ignore
/composer.json export-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/composer.json export-ignore

There's an argument in favour of keeping composer.json so people can quickly read it to better understand the package.

WordPress/plugin-check#829

You should also keep and/or link configuration files, as for example, the composer.json file in order to allow others to review, study, and yes, fork this code.

https://developer.wordpress.org/plugins/wordpress-org/common-issues/#included-unneeded-folders

/composer.lock export-ignore
/utils export-ignore
/.phpcs.xml.dist export-ignore
/.editorconfig export-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are also valid to exclude, being only dev related files:

Suggested change
/.editorconfig export-ignore
/.actrc export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.mailmap export-ignore
/.behat.yml export-ignore
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore

/bin export-ignore
/phpunit.xml.dist export-ignore
/composer.json export-ignore
/composer.lock export-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/composer.lock export-ignore

There is no composer.lock in this repository.

composer.lock

/.github export-ignore
/tests export-ignore
/features export-ignore
/bin export-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/bin export-ignore

I think excluding /bin would mean vendor/bin/wp would not work when WP CLI is installed via Composer.

wp-cli/composer.json

Lines 54 to 57 in 03d30d4

"bin": [
"bin/wp",
"bin/wp.bat"
],

@swissspidy swissspidy changed the title chore(distribution): exclude non-essential files using .gitattributes Exclude non-essential files using .gitattributes Aug 5, 2025
@swissspidy
Copy link
Member

If we find this useful, we should (automatically) add this to all our repos. Would save a lot of bandwidth :)

Wonder how this affects https://github.com/wp-cli/wp-cli-dev though

@BrianHenryIE
Copy link
Member

I think composer install --prefer-install=source would be the solution for wp-cli/wp-cli-dev:

{
    "name": "wp-cli/wp-cli-dev",
    "config": {
        "preferred-install": "source"
    }
}

Schema:

"preferred-install": {
  "type": ["string", "object"],
  "description": "The install method Composer will prefer to use, defaults to auto and can be any of source, dist, auto, or an object of {\"pattern\": \"preference\"}.",
  "additionalProperties": {
    "type": ["string"]
  }
},

jq '.config += {"preferred-install": "source"}' composer.json --indent 4 | sponge composer.json

I haven't tested it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants