Browse Source

Add basic commit support to porcelain.

Jelmer Vernooij 11 năm trước cách đây
mục cha
commit
aa2b6b15c8
3 tập tin đã thay đổi với 28 bổ sung8 xóa
  1. 6 7
      bin/dulwich
  2. 12 0
      dulwich/porcelain.py
  3. 10 1
      dulwich/tests/test_porcelain.py

+ 6 - 7
bin/dulwich

@@ -33,7 +33,11 @@ from getopt import getopt
 from dulwich.client import get_transport_and_path
 from dulwich.errors import ApplyDeltaError
 from dulwich.index import Index
-from dulwich.porcelain import archive
+from dulwich.porcelain import (
+    archive,
+    commit,
+    update_server_info,
+    )
 from dulwich.pack import Pack, sha_to_hex
 from dulwich.patch import write_tree_diff
 from dulwich.repo import Repo
@@ -195,12 +199,7 @@ def cmd_clone(args):
 def cmd_commit(args):
     opts, args = getopt(args, "", ["message"])
     opts = dict(opts)
-    r = Repo(".")
-    committer = "%s <%s>" % (os.getenv("GIT_COMMITTER_NAME"), 
-                             os.getenv("GIT_COMMITTER_EMAIL"))
-    author = "%s <%s>" % (os.getenv("GIT_AUTHOR_NAME"), 
-                          os.getenv("GIT_AUTHOR_EMAIL"))
-    r.do_commit(committer=committer, author=author, message=opts["--message"])
+    commit(".", message=opts["--message"])
 
 
 def cmd_update_server_info(args):

+ 12 - 0
dulwich/porcelain.py

@@ -55,3 +55,15 @@ def update_server_info(path="."):
     """
     r = Repo(path)
     server_update_server_info(r)
+
+
+def commit(path=".", message=None):
+    """Create a new commit.
+
+    :param path: Path to repository
+    :param message: Optional commit message
+    """
+    # FIXME: Support --all argument
+    # FIXME: Support --signoff argument
+    r = Repo(path)
+    r.do_commit(message=message)

+ 10 - 1
dulwich/tests/test_porcelain.py

@@ -26,6 +26,7 @@ import tempfile
 
 from dulwich.porcelain import (
     archive,
+    commit,
     update_server_info,
     )
 from dulwich.repo import Repo
@@ -47,7 +48,7 @@ class PorcelainTestCase(TestCase):
         super(TestCase, self).setUp()
         repo_dir = tempfile.mkdtemp()
         self.addCleanup(shutil.rmtree, repo_dir)
-        self.repo = Repo.init_bare(repo_dir)
+        self.repo = Repo.init(repo_dir)
 
 
 class ArchiveTests(PorcelainTestCase):
@@ -72,3 +73,11 @@ class UpdateServerInfoTests(PorcelainTestCase):
         self.repo.refs["refs/heads/foo"] = c3.id
         update_server_info(self.repo.path)
         self.assertTrue(os.path.exists(os.path.join(self.repo.controldir(), 'info', 'refs')))
+
+
+class CommitTests(PorcelainTestCase):
+
+    def test_simple(self):
+        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")