diff options
author | 2007-11-15 17:02:32 +0200 | |
---|---|---|
committer | 2007-11-15 17:10:25 +0200 | |
commit | a9e37272cd508fe32111ff4d90f7853b6b829b0b (patch) | |
tree | 001c4ad7aaa84eef232f6b8df61929533e7d8506 | |
parent | Missed mkdir in README (diff) | |
download | gitosis-gentoo-a9e37272cd508fe32111ff4d90f7853b6b829b0b.tar.gz gitosis-gentoo-a9e37272cd508fe32111ff4d90f7853b6b829b0b.tar.bz2 gitosis-gentoo-a9e37272cd508fe32111ff4d90f7853b6b829b0b.zip |
Make repository.init pass through environment to git.
-rw-r--r-- | gitosis/repository.py | 7 | ||||
-rw-r--r-- | gitosis/test/test_repository.py | 49 |
2 files changed, 52 insertions, 4 deletions
diff --git a/gitosis/repository.py b/gitosis/repository.py index 4ebbbfd..cfcfb21 100644 --- a/gitosis/repository.py +++ b/gitosis/repository.py @@ -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) diff --git a/gitosis/test/test_repository.py b/gitosis/test/test_repository.py index 9d22d0a..1c21033 100644 --- a/gitosis/test/test_repository.py +++ b/gitosis/test/test_repository.py @@ -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') |