from dulwich.porcelain import (
archive,
commit,
+ init,
update_server_info,
)
from dulwich.pack import Pack, sha_to_hex
else:
path = args[0]
- if not os.path.exists(path):
- os.mkdir(path)
-
- if "--bare" in opts:
- Repo.init_bare(path)
- else:
- Repo.init(path)
+ init(path, bare=("--bare" in opts))
def cmd_clone(args):
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
+import os
import sys
from dulwich.client import get_transport_and_path
# FIXME: Support --signoff argument
r = Repo(path)
r.do_commit(message=message)
+
+
+def init(path=".", bare=False):
+ """Create a new git repository.
+
+ :param path: Path to repository.
+ :param bare: Whether to create a bare repository.
+ """
+ if not os.path.exists(path):
+ os.mkdir(path)
+
+ if bare:
+ Repo.init_bare(path)
+ else:
+ Repo.init(path)
from dulwich.porcelain import (
archive,
commit,
+ init,
update_server_info,
)
from dulwich.repo import Repo
c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
self.repo.refs["refs/heads/foo"] = c3.id
commit(self.repo.path, message="Some message")
+
+
+class CommitTests(TestCase):
+
+ def test_non_bare(self):
+ repo_dir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, repo_dir)
+ init(repo_dir)
+
+ def test_bare(self):
+ repo_dir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, repo_dir)
+ init(repo_dir, bare=True)