Fix #5203.

Explicitly check if `dir` is not empty before trying
`git add --all` and `git add .`. Needed for git 1.8.5