From 83fd2c679fb4eb0aad0a05f95968603d04b3fab6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Guido=20G=C3=BCnther?= Date: Sat, 22 Oct 2011 13:54:16 +0200 Subject: [PATCH] GitRepository: add commit and commit_all to commit the current state of the index and all changes. --- gbp/git.py | 28 ++++++++++++++++++++++++++++ tests/03_test_gbp_branch.py | 2 +- tests/04_test_gbp_submodules.py | 18 ++++++++---------- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/gbp/git.py b/gbp/git.py index 610a419..aba2dce 100644 --- a/gbp/git.py +++ b/gbp/git.py @@ -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 diff --git a/tests/03_test_gbp_branch.py b/tests/03_test_gbp_branch.py index a99391d..49ba9b7 100644 --- a/tests/03_test_gbp_branch.py +++ b/tests/03_test_gbp_branch.py @@ -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(): diff --git a/tests/04_test_gbp_submodules.py b/tests/04_test_gbp_submodules.py index a6b66bb..aaa1582 100644 --- a/tests/04_test_gbp_submodules.py +++ b/tests/04_test_gbp_submodules.py @@ -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)""" -- 2.7.4