import errno
import os
-import stat
from dulwich.errors import (
MissingCommitError,
if refname in peeled_refs:
f.write('^%s\n' % peeled_refs[refname])
+
class BaseRepo(object):
"""Base class for a git repository.
"""
raise NotImplementedError(self.get_named_file)
+ def put_named_file(self, relpath, contents):
+ """Write a file in the control directory with specified name and
+ contents.
+
+ Although the filename should be interpreted as a filename relative to
+ the control dir in a disk-baked Repo, the object returned need not be
+ pointing to a file in that location.
+
+ :param path: The path to the file, relative to the control dir.
+ :param contents: Contents of the new file
+ """
+ raise NotImplementedError(self.put_named_file)
+
def fetch(self, target, determine_wants=None, progress=None):
"""Fetch objects into another repository.
"""Return the path of the control directory."""
return self._controldir
+ def put_named_file(self, path, contents):
+ """Write a file from the control dir with a specific name and contents.
+ """
+ f = GitFile(os.path.join(self.controldir(), path, 'config'), 'wb')
+ try:
+ f.write(contents)
+ finally:
+ f.close()
+
def get_named_file(self, path):
"""Get a file from the control dir with a specific name.
os.mkdir(os.path.join(path, *d))
ret = cls(path)
ret.refs.set_ref("HEAD", "refs/heads/master")
- f = GitFile(os.path.join(path, 'description'), 'wb')
- try:
- f.write("Unnamed repository")
- finally:
- f.close()
-
- f = GitFile(os.path.join(path, 'config'), 'wb')
- try:
- f.write("""[core]
+ ret.put_named_file('description', "Unnamed repository")
+ ret.put_named_file('config', """[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
""")
- finally:
- f.close()
-
- f = GitFile(os.path.join(path, 'info', 'excludes'), 'wb')
- f.close()
+ ret.put_named_file(os.path.join('info', 'excludes'), '')
return ret
create = init_bare