fix corner cases and an undefined behavior
add unit tests for git_buf_join corner cases
Merge pull request #2064 from piki/piki/buffer-corner-cases

Fix a couple of corner cases and an undefined behavior