Description
Repository archives generated with the archive()
method will be corrupted if git archive
prints anything to stderr.
When I run git archive commands on the command line, sometimes stuff gets printed to stderr, while the archive itself is output to stdout:
$ git archive --remote=ssh://git@my.git.server/my_git_repo.git master > my_git_repo.tar
X11 forwarding request failed on channel 0
$ file my_git_repo.tar
archive.tar: POSIX tar archive
However, I found that the line X11 forwarding request failed on channel 0
was getting prepended to my archives generated when using ruby-git's archive()
method, resulting in a corrupted archive (note that "X1 archive" is not a valid archive type):
$ head -n 1 my_git_repo | strings
X11 forwarding request failed on channel 0
$ file my_git_repo
my_git_repo: X1 archive data
This appears to be because command()
indiscriminately redirects stderr to stdout and archive()
calls command()
while redirecting stdout into the archive file. The upshot is that if git archive
prints anything to stderr, the resulting archive will be corrupted.