Make repository.init pass through environment to git.

This commit is contained in:
Tommi Virtanen 2007-11-15 17:02:32 +02:00
parent c81daadc79
commit a9e37272cd
2 changed files with 52 additions and 4 deletions

View file

@ -23,7 +23,11 @@ def init(
_git = 'git'
util.mkdir(path, 0750)
args = [_git, 'init']
args = [
_git,
'--git-dir=.',
'init',
]
if template is not None:
args.append('--template=%s' % template)
returncode = subprocess.call(
@ -31,7 +35,6 @@ def init(
cwd=path,
stdout=sys.stderr,
close_fds=True,
env=dict(GIT_DIR='.'),
)
if returncode != 0:
raise GitInitError('exit status %d' % returncode)

View file

@ -2,11 +2,18 @@ from nose.tools import eq_ as eq
import os
import subprocess
import random
from gitosis import repository
from gitosis.test.util import mkdir, maketemp, readFile, check_mode
from gitosis.test.util import assert_raises
from gitosis.test.util import (
mkdir,
maketemp,
readFile,
writeFile,
check_mode,
assert_raises,
)
def check_bare(path):
# we want it to be a bare repository
@ -58,6 +65,44 @@ def test_init_templates():
# standard templates are there, too
assert os.path.isfile(os.path.join(path, 'hooks', 'pre-rebase'))
def test_init_environment():
tmp = maketemp()
path = os.path.join(tmp, 'repo.git')
mockbindir = os.path.join(tmp, 'mockbin')
os.mkdir(mockbindir)
mockgit = os.path.join(mockbindir, 'git')
writeFile(mockgit, '''\
#!/bin/sh
set -e
# git wrapper for gitosis unit tests
printf '%s' "$GITOSIS_UNITTEST_COOKIE" >"$(dirname "$0")/../cookie"
# strip away my special PATH insert so system git will be found
PATH="${PATH#*:}"
exec git "$@"
''')
os.chmod(mockgit, 0755)
magic_cookie = '%d' % random.randint(1, 100000)
good_path = os.environ['PATH']
try:
os.environ['PATH'] = '%s:%s' % (mockbindir, good_path)
os.environ['GITOSIS_UNITTEST_COOKIE'] = magic_cookie
repository.init(path)
finally:
os.environ['PATH'] = good_path
os.environ.pop('GITOSIS_UNITTEST_COOKIE', None)
eq(
sorted(os.listdir(tmp)),
sorted([
'mockbin',
'cookie',
'repo.git',
]),
)
got = readFile(os.path.join(tmp, 'cookie'))
eq(got, magic_cookie)
def test_export_simple():
tmp = maketemp()
git_dir = os.path.join(tmp, 'repo.git')