GitRepository: add commit and commit_all
authorGuido Günther <agx@sigxcpu.org>
Sat, 22 Oct 2011 11:54:16 +0000 (13:54 +0200)
committerGuido Günther <agx@sigxcpu.org>
Sun, 23 Oct 2011 14:18:53 +0000 (16:18 +0200)
to commit the current state of the index and all changes.

gbp/git.py
tests/03_test_gbp_branch.py
tests/04_test_gbp_submodules.py

index 610a419..aba2dce 100644 (file)
@@ -716,6 +716,34 @@ class GitRepository(object):
         self._git_command("rm", args + paths)
 
 
+    def _commit(self, msg, args=[], author_info=None):
+        extra_env = author_info.get_author_env() if author_info else None
+        self._git_command("commit", args + ['-q', '-m', msg], extra_env=extra_env)
+
+
+    def commit(self, msg, author_info=None):
+        """
+        Commit currently staged files to the repository
+
+        @param msg: commit message
+        @type msg: string
+        @param author_info: authorship information
+        @type author_info: L{GitModifier}
+        """
+        self._commit(msg=msg, author_info=author_info)
+
+
+    def commit_all(self, msg, author_info=None):
+        """
+        Commit all changes to the repository
+        @param msg: commit message
+        @type msg: string
+        @param author_info: authorship information
+        @type author_info: L{GitModifier}
+        """
+        self._commit(msg=msg, args=['-a'], author_info=author_info)
+
+
     def format_patches(self, start, end, output_dir):
         """
         Output the commits between start and end as patches in output_dir
index a99391d..49ba9b7 100644 (file)
@@ -40,7 +40,7 @@ def test_add_files():
     """Add some dummy data"""
     shutil.copy(".git/HEAD", "testfile")
     repo.add_files('.', force=True)
-    gbp.command_wrappers.GitCommand("commit", ["-mfoo", "-a"])()
+    repo.commit_all(msg="foo")
     assert True
 
 def test_branch_master():
index a6b66bb..aaa1582 100644 (file)
@@ -5,6 +5,7 @@ import shutil
 import tarfile
 import tempfile
 
+import gbp.log
 import gbp.git
 import gbp.command_wrappers
 
@@ -29,6 +30,7 @@ class Submodule(object):
 def setup():
     global repo, repodir, submodules, top, tmpdir
 
+    gbp.log.setup(False, True)
     top = os.path.abspath(os.curdir)
     tmpdir =os.path.join(top,'gbp_%s_repo' % __name__)
     os.mkdir(tmpdir)
@@ -53,15 +55,15 @@ def test_empty_has_submodules():
     assert not repo.has_submodules()
 
 
-def _add_dummy_data(msg):
+def _add_dummy_data(repo, msg):
     shutil.copy(".git/HEAD", testfile_name)
     repo.add_files('.', force=True)
-    gbp.command_wrappers.GitCommand("commit", ["-m%s" % msg, "-a"])()
+    repo.commit_all(msg)
 
 
 def test_add_files():
     """Add some dummy data"""
-    _add_dummy_data("initial commit")
+    _add_dummy_data(repo, "initial commit")
     assert True
 
 
@@ -69,7 +71,7 @@ def test_add_submodule_files():
     """Add some dummy data"""
     for submodule in submodules:
         os.chdir(submodule.dir)
-        _add_dummy_data("initial commit in submodule")
+        _add_dummy_data(submodule.repo, "initial commit in submodule")
         os.chdir(repodir)
     assert True
 
@@ -77,9 +79,7 @@ def test_add_submodule_files():
 def test_add_submodule():
     """Add a submodule"""
     repo.add_submodule(submodules[0].dir)
-    gbp.command_wrappers.GitCommand("commit",
-                                    ["-m 'Added submodule %s'" % submodules[0].dir,
-                                     "-a"])()
+    repo.commit_all(msg='Added submodule %s' % submodules[0].dir)
 
 def test_has_submodules():
     """Check for submodules"""
@@ -123,9 +123,7 @@ def test_check_tarfile():
 def test_add_whitespace_submodule():
     """Add a second submodule with name containing whitespace"""
     repo.add_submodule(submodules[1].dir)
-    gbp.command_wrappers.GitCommand("commit",
-                                    ["-m 'Added submodule %s'" % submodules[0].dir,
-                                     "-a"])()
+    repo.commit_all(msg='Added submodule %s' % submodules[0].dir)
 
 def test_get_more_submodules():
     """Check for submodules list of  (name, hash)"""