diff options
author | Tommi Virtanen <tv@eagain.net> | 2007-11-15 17:10:40 +0200 |
---|---|---|
committer | Tommi Virtanen <tv@eagain.net> | 2007-11-15 17:10:40 +0200 |
commit | aa1c0712bed678e39648890eccf4b84fb66fe870 (patch) | |
tree | f06ff5f180022e66e1c9c0c22ccd999565e80fb2 | |
parent | Make repository.init pass through environment to git. (diff) | |
download | gitosis-gentoo-aa1c0712bed678e39648890eccf4b84fb66fe870.tar.gz gitosis-gentoo-aa1c0712bed678e39648890eccf4b84fb66fe870.tar.bz2 gitosis-gentoo-aa1c0712bed678e39648890eccf4b84fb66fe870.zip |
Make repository.fast_import pass through environment to git.
-rw-r--r-- | gitosis/repository.py | 9 | ||||
-rw-r--r-- | gitosis/test/test_repository.py | 45 |
2 files changed, 52 insertions, 2 deletions
diff --git a/gitosis/repository.py b/gitosis/repository.py index cfcfb21..6647408 100644 --- a/gitosis/repository.py +++ b/gitosis/repository.py @@ -55,11 +55,16 @@ def fast_import( """ init(path=git_dir) child = subprocess.Popen( - args=['git', 'fast-import', '--quiet', '--date-format=now'], + args=[ + 'git', + '--git-dir=.', + 'fast-import', + '--quiet', + '--date-format=now', + ], cwd=git_dir, stdin=subprocess.PIPE, close_fds=True, - env=dict(GIT_DIR=git_dir), ) files = list(files) for index, (path, content) in enumerate(files): diff --git a/gitosis/test/test_repository.py b/gitosis/test/test_repository.py index 1c21033..abe1b0c 100644 --- a/gitosis/test/test_repository.py +++ b/gitosis/test/test_repository.py @@ -103,6 +103,51 @@ exec git "$@" got = readFile(os.path.join(tmp, 'cookie')) eq(got, magic_cookie) +def test_fast_import_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.fast_import( + git_dir=path, + commit_msg='foo initial bar', + committer='Mr. Unit Test <unit.test@example.com>', + files=[ + ('foo', 'bar\n'), + ], + ) + 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') |