How can I stop brew prune and brew upgrade from fighting? I am running Homebrew on 10.13.6, with the prefix /usr/local.  

When I run brew upgrade, two directories are created in /usr/local/share.  These are: /usr/local/share/man/man2, and /usr/local/share/man/man6.  There are no files in these directories.

Meanwhile, whenever I run brew prune --verbose, I get the output:

rmdir /usr/local/share/man/man6
rmdir /usr/local/share/man/man2
Pruned 0 symbolic links and 2 directories from /usr/local


Whenever brew upgrade, these two troublesome directories are then re-created! The cycle continues, on and on and on.  I have repeatedly run brew update, brew cleanup, and brew doctor.  I have even reinstalled Homebrew and all my packages.  Yet, the eternal battle between brew upgrade and brew prune continues.

How can I get them to stop fighting?
There is an inelegant solution to this bug/inconsistency in the two functions of the tools: put any file in the directories in question.

Then  brew prune will stop removing them because they will no longer be empty.  If brew prune is no longer removing them, brew upgrade won't create them.  If you're concerned about space, you could even put an alias file in the directories.

In the grand scheme of things, having these empty folders create and then removed is a harmless side effect and doesn’t really break anything functionally.