Rectangle 27 0

php phar exclude directories when creating tar archive?


The problem with your regex is that the full path of the file gets matched, not only the directory (basename). Thus you cannot filter out the .git directory itself.

This means you can use positive matches only.

Using a character class negation ([^.][^g][^i][^t]) does also not help because there are parts of the path that do match this regex, so the path matches anyway.

You could use Phar::buildFromIterator and then use RecursiveFilterIterator to filter out the files. There you can define your own matching method that filters correctly.

Note
Rectangle 27 0

php phar exclude directories when creating tar archive?


The problem with your regex is that the full path of the file gets matched, not only the directory (basename). Thus you cannot filter out the .git directory itself.

This means you can use positive matches only.

Using a character class negation ([^.][^g][^i][^t]) does also not help because there are parts of the path that do match this regex, so the path matches anyway.

You could use Phar::buildFromIterator and then use RecursiveFilterIterator to filter out the files. There you can define your own matching method that filters correctly.

Note
Rectangle 27 0

php phar exclude directories when creating tar archive?


$phar->buildFromDirectory(__DIR__, '/^((?!\.git).)*$/');

I've seen the following used to exclude git directories using a negative lookahead:

Note