aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2007-11-15 17:20:39 +0200
committerTommi Virtanen <tv@eagain.net>2007-11-15 17:20:39 +0200
commit8e488ad02f38248753ec2d846e3fc5f7431dced3 (patch)
treeed5c17ac4ecdcd38c0c347d6f5414202e55fe36a
parentMake repository.export pass through environment to git. (diff)
downloadgitosis-gentoo-8e488ad02f38248753ec2d846e3fc5f7431dced3.tar.gz
gitosis-gentoo-8e488ad02f38248753ec2d846e3fc5f7431dced3.tar.bz2
gitosis-gentoo-8e488ad02f38248753ec2d846e3fc5f7431dced3.zip
Make repository.has_initial_commit pass through environment to git.
-rw-r--r--gitosis/repository.py8
-rw-r--r--gitosis/test/test_repository.py38
2 files changed, 44 insertions, 2 deletions
diff --git a/gitosis/repository.py b/gitosis/repository.py
index a97c1aa..17b50b2 100644
--- a/gitosis/repository.py
+++ b/gitosis/repository.py
@@ -143,11 +143,15 @@ class GitRevParseError(GitError):
def has_initial_commit(git_dir):
child = subprocess.Popen(
- args=['git', 'rev-parse', 'HEAD'],
+ args=[
+ 'git',
+ '--git-dir=.',
+ 'rev-parse',
+ 'HEAD',
+ ],
cwd=git_dir,
stdout=subprocess.PIPE,
close_fds=True,
- env=dict(GIT_DIR='.'),
)
got = child.stdout.read()
returncode = child.wait()
diff --git a/gitosis/test/test_repository.py b/gitosis/test/test_repository.py
index 3dbd3f7..4aca6e7 100644
--- a/gitosis/test/test_repository.py
+++ b/gitosis/test/test_repository.py
@@ -269,3 +269,41 @@ def test_has_initial_commit_yes():
got = repository.has_initial_commit(git_dir=tmp)
eq(got, True)
+def test_has_initial_commit_environment():
+ tmp = maketemp()
+ git_dir = 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)
+ repository.init(path=tmp)
+ repository.fast_import(
+ git_dir=tmp,
+ commit_msg='fakecommit',
+ committer='John Doe <jdoe@example.com>',
+ files=[],
+ )
+ 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
+ got = repository.has_initial_commit(git_dir=tmp)
+ finally:
+ os.environ['PATH'] = good_path
+ os.environ.pop('GITOSIS_UNITTEST_COOKIE', None)
+ eq(got, True)
+ got = readFile(os.path.join(tmp, 'cookie'))
+ eq(got, magic_cookie)
+