Ensure "git init" doesn't write to stdout, and confuse a push.

The repository autocreation functionality ends up sending the
stdout to the client side, and there a very confused git push
can't make any sense of the protocol.
This commit is contained in:
Tommi Virtanen 2007-09-03 22:58:30 -07:00
parent 4d793f6fd4
commit 5df4b0c4f8
2 changed files with 31 additions and 0 deletions

View file

@ -1,6 +1,7 @@
import os import os
import re import re
import subprocess import subprocess
import sys
from gitosis import util from gitosis import util
@ -28,6 +29,7 @@ def init(
returncode = subprocess.call( returncode = subprocess.call(
args=args, args=args,
cwd=path, cwd=path,
stdout=sys.stderr,
close_fds=True, close_fds=True,
env=dict(GIT_DIR='.'), env=dict(GIT_DIR='.'),
) )

View file

@ -189,3 +189,32 @@ def test_push_inits_if_needed_existsWithExtension():
# it.. having HEAD implies serve ran git init, which is supposed # it.. having HEAD implies serve ran git init, which is supposed
# to be unnecessary here # to be unnecessary here
eq(os.listdir(os.path.join(tmp, 'foo.git')), []) eq(os.listdir(os.path.join(tmp, 'foo.git')), [])
def test_push_inits_no_stdout_spam():
# git init has a tendency to spew to stdout, and that confuses
# e.g. a git push
tmp = util.maketemp()
cfg = RawConfigParser()
cfg.add_section('gitosis')
cfg.set('gitosis', 'repositories', tmp)
cfg.add_section('group foo')
cfg.set('group foo', 'members', 'jdoe')
cfg.set('group foo', 'writable', 'foo')
old_stdout = os.dup(1)
try:
new_stdout = os.tmpfile()
os.dup2(new_stdout.fileno(), 1)
serve.serve(
cfg=cfg,
user='jdoe',
command="git-receive-pack 'foo'",
)
finally:
os.dup2(old_stdout, 1)
os.close(old_stdout)
new_stdout.seek(0)
got = new_stdout.read()
new_stdout.close()
eq(got, '')
eq(os.listdir(tmp), ['foo.git'])
assert os.path.isfile(os.path.join(tmp, 'foo.git', 'HEAD'))