In my case I have carefully set up the directory that I'm going to clone into with the correct group ownership and setgid permission, so that the cloned files will also have the correct ownership. This change just checks to see if the directory actually has anything in it before it deletes it.
https://github.com/ArchiveTeam/glowing-computing-machine/tree/git-in-emtpy-directory
I am not entirely happy with this patch, because it seems that if Git.cloned took care to preserve permissions in this case, it could be argued that it should also preserve permissions when the directory already exists but has the wrong content. Or equally well argued that it should not preserve permissions, which might be a leftover from some past unwanted state.
Is that really the best way to do it? You could instead say:
And then you just have to write a recursiveSetGID which would be a generally useful property.
Yea, I guess that's a fair point about the other cases.
It just seems inelegant to go back over all the files and fix up their permissions, when it could just have been set right to begin with.