From 5df4b0c4f869fd4c057127264e747a79a450f221 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Mon, 3 Sep 2007 22:58:30 -0700 Subject: 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. --- gitosis/repository.py | 2 ++ gitosis/test/test_serve.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/gitosis/repository.py b/gitosis/repository.py index 9558494..4ebbbfd 100644 --- a/gitosis/repository.py +++ b/gitosis/repository.py @@ -1,6 +1,7 @@ import os import re import subprocess +import sys from gitosis import util @@ -28,6 +29,7 @@ def init( returncode = subprocess.call( args=args, cwd=path, + stdout=sys.stderr, close_fds=True, env=dict(GIT_DIR='.'), ) diff --git a/gitosis/test/test_serve.py b/gitosis/test/test_serve.py index ec757a4..08a4e67 100644 --- a/gitosis/test/test_serve.py +++ b/gitosis/test/test_serve.py @@ -189,3 +189,32 @@ def test_push_inits_if_needed_existsWithExtension(): # it.. having HEAD implies serve ran git init, which is supposed # to be unnecessary here 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')) -- cgit v1.2.3