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.
This commit is contained in:
Tommi Virtanen 2007-11-15 19:00:02 +02:00
parent a3fc27143a
commit 810179e4d4

View file

@ -1,3 +1,4 @@
import errno
import os import os
import re import re
import subprocess import subprocess
@ -107,9 +108,13 @@ class GitCheckoutIndexError(GitExportError):
"""git checkout-index failed""" """git checkout-index failed"""
def export(git_dir, path): def export(git_dir, path):
# it's a literal prefix for git, a trailing slash is needed to try:
# extract to the subdirectory os.mkdir(path)
path = os.path.join(path, '') except OSError, e:
if e.errno == errno.EEXIST:
pass
else:
raise
returncode = subprocess.call( returncode = subprocess.call(
args=[ args=[
'git', 'git',
@ -121,6 +126,11 @@ def export(git_dir, path):
) )
if returncode != 0: if returncode != 0:
raise GitReadTreeError('exit status %d' % returncode) 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( returncode = subprocess.call(
args=[ args=[
'git', 'git',
@ -128,9 +138,10 @@ def export(git_dir, path):
'checkout-index', 'checkout-index',
'-a', '-a',
'-f', '-f',
'--prefix=%s' % path,
], ],
cwd=path,
close_fds=True, close_fds=True,
env=env,
) )
if returncode != 0: if returncode != 0:
raise GitCheckoutIndexError('exit status %d' % returncode) raise GitCheckoutIndexError('exit status %d' % returncode)