From 810179e4d4665d608488cabbb22ea7be2d5dd95e Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Thu, 15 Nov 2007 19:00:02 +0200 Subject: [PATCH] Make repository.export work with newer git. gitosis-init and the post-update hook used to fail with GitCheckoutIndexError, when run with git >=1.5.3, which made checkout-index require GIT_WORK_TREE, jump through hoops to provide it, but still be backwards compatible with older git. Thanks to Garry Dolley for hunting the bug. --- gitosis/repository.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gitosis/repository.py b/gitosis/repository.py index 17b50b2..8746144 100644 --- a/gitosis/repository.py +++ b/gitosis/repository.py @@ -1,3 +1,4 @@ +import errno import os import re import subprocess @@ -107,9 +108,13 @@ class GitCheckoutIndexError(GitExportError): """git checkout-index failed""" def export(git_dir, path): - # it's a literal prefix for git, a trailing slash is needed to - # extract to the subdirectory - path = os.path.join(path, '') + try: + os.mkdir(path) + except OSError, e: + if e.errno == errno.EEXIST: + pass + else: + raise returncode = subprocess.call( args=[ 'git', @@ -121,6 +126,11 @@ def export(git_dir, path): ) if returncode != 0: raise GitReadTreeError('exit status %d' % returncode) + # jumping through hoops to be compatible with git versions + # that don't have --work-tree= + env = {} + env.update(os.environ) + env['GIT_WORK_TREE'] = '.' returncode = subprocess.call( args=[ 'git', @@ -128,9 +138,10 @@ def export(git_dir, path): 'checkout-index', '-a', '-f', - '--prefix=%s' % path, ], + cwd=path, close_fds=True, + env=env, ) if returncode != 0: raise GitCheckoutIndexError('exit status %d' % returncode)