diff options
Diffstat (limited to 'gitosis/repository.py')
-rw-r--r-- | gitosis/repository.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/gitosis/repository.py b/gitosis/repository.py index 092e41d..272c3cb 100644 --- a/gitosis/repository.py +++ b/gitosis/repository.py @@ -1,4 +1,6 @@ -import errno +""" +Gitosis functions for dealing with Git repositories. +""" import os import re import subprocess @@ -19,6 +21,7 @@ def init( path, template=None, _git=None, + mode=0750, ): """ Create a git repository at C{path} (if missing). @@ -32,11 +35,15 @@ def init( @param template: Template directory, to pass to C{git init}. @type template: str + + @param mode: Permissions for the new reposistory + + @type mode: int """ if _git is None: _git = 'git' - util.mkdir(path, 0750) + util.mkdir(path, mode) args = [ _git, '--git-dir=.', @@ -50,7 +57,7 @@ def init( stdout=sys.stderr, close_fds=True, ) - if returncode != 0: + if returncode != 0: #pragma: no cover raise GitInitError('exit status %d' % returncode) @@ -113,7 +120,7 @@ from %(parent)s child.stdin.write('M 100644 :%d %s\n' % (index+1, path)) child.stdin.close() returncode = child.wait() - if returncode != 0: + if returncode != 0: #pragma: no cover raise GitFastImportError( 'git fast-import failed', 'exit status %d' % returncode) @@ -128,13 +135,8 @@ class GitCheckoutIndexError(GitExportError): """git checkout-index failed""" def export(git_dir, path): - try: - os.mkdir(path) - except OSError, e: - if e.errno == errno.EEXIST: - pass - else: - raise + """Export a Git repository to a given path.""" + util.mkdir(path) returncode = subprocess.call( args=[ 'git', @@ -144,7 +146,7 @@ def export(git_dir, path): ], close_fds=True, ) - if returncode != 0: + if returncode != 0: #pragma: no cover raise GitReadTreeError('exit status %d' % returncode) # jumping through hoops to be compatible with git versions # that don't have --work-tree= @@ -163,7 +165,7 @@ def export(git_dir, path): close_fds=True, env=env, ) - if returncode != 0: + if returncode != 0: #pragma: no cover raise GitCheckoutIndexError('exit status %d' % returncode) class GitHasInitialCommitError(GitError): @@ -173,6 +175,7 @@ class GitRevParseError(GitError): """rev-parse failed""" def has_initial_commit(git_dir): + """Check if a Git repo contains at least one commit linked by HEAD.""" child = subprocess.Popen( args=[ 'git', @@ -192,5 +195,5 @@ def has_initial_commit(git_dir): return False elif re.match('^[0-9a-f]{40}\n$', got): return True - else: + else: #pragma: no cover raise GitHasInitialCommitError('Unknown git HEAD: %r' % got) |