From 17e6d72c9727d501b73df5dafa05f40f0593fe34 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Thu, 5 Jun 2014 16:37:25 +0300 Subject: [PATCH] rpm-ch: implement --commit option Signed-off-by: Markus Lehtonen --- docs/manpages/gbp-rpm-ch.sgml | 25 +++++++++++++++++++------ gbp/scripts/rpm_ch.py | 19 ++++++++++++------- tests/component/rpm/test_rpm_ch.py | 22 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/docs/manpages/gbp-rpm-ch.sgml b/docs/manpages/gbp-rpm-ch.sgml index 9f6ae99..37a4272 100644 --- a/docs/manpages/gbp-rpm-ch.sgml +++ b/docs/manpages/gbp-rpm-ch.sgml @@ -41,6 +41,7 @@ GIT-LOG-OPTIONS EDITOR + @@ -273,16 +274,28 @@ + + + + + Commit changes to git after modifying changelog. Importantly, in + addition to the changelog modifications all other staged changes are + committed, too, making it possible to update other files in the same + commit. + + + + - Commit the changes and create a packaging (release) tag. All - changelog modifications (and importantly, all other staged changes) - are committed to git before creating the tag. This option makes it - possible to create a release and correctly document the the tag name - in the rpm changelog (by using %(tagname)s in the - string). + Commit the changes and create a packaging (release) tag. Similarly to + , all staged changes are committed to git + before creating the tag. This option makes it possible to create a + release and correctly document the the tag name in the rpm changelog + (by using %(tagname)s in the + string). diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py index 09586d0..b509bd3 100755 --- a/gbp/scripts/rpm_ch.py +++ b/gbp/scripts/rpm_ch.py @@ -131,7 +131,7 @@ def check_repo_state(repo, options): raise GbpError("Use --ignore-branch to ignore or " "--packaging-branch to set the branch name.") # Check unstaged changes - if options.tag: + if options.commit: unstaged = [] status = repo.status() for group, files in status.iteritems(): @@ -141,7 +141,7 @@ def check_repo_state(repo, options): gbp.log.error("Unstaged changes in:\n %s" % '\n '.join(unstaged)) raise GbpError("Please commit or stage your changes before using " - "the --tag option") + "the --commit or --tag option") def parse_spec_file(repo, options): @@ -325,7 +325,7 @@ def update_changelog(changelog, entries, repo, spec, options): rev_str_fields = dict(spec.version, version=RpmPkgPolicy.compose_full_version(spec.version), vendor=options.vendor) - if options.tag: + if options.commit: # Get fake information for the to-be-created git commit commit_info = {'author': GitModifier(date=now), 'committer': GitModifier(date=now)} @@ -444,6 +444,8 @@ def parse_args(argv): help="text to use as new changelog entries - git commit " "messages and the --since are ignored in this case") # Commit/tag group options + commit_grp.add_option("-c", "--commit", action="store_true", + help="commit changes") commit_grp.add_option("--tag", action="store_true", help="commit the changes and create a packaging/release" "tag") @@ -454,6 +456,8 @@ def parse_args(argv): commit_grp.add_config_file_option(option_name="keyid", dest="keyid") options, args = parser.parse_args(argv[1:]) + if options.tag: + options.commit = True if not options.changelog_revision: options.changelog_revision = RpmPkgPolicy.Changelog.header_rev_format @@ -492,12 +496,13 @@ def main(argv): if editor_cmd and not options.message: gbpc.Command(editor_cmd, [ch_file.path])() - if options.tag: - if options.retag and repo.has_tag(tag): - repo.delete_tag(tag) + if options.commit: edit = True if editor_cmd else False commit_changelog(repo, ch_file, author, committer, edit) - create_packaging_tag(repo, tag, 'HEAD', spec.version, options) + if options.tag: + if options.retag and repo.has_tag(tag): + repo.delete_tag(tag) + create_packaging_tag(repo, tag, 'HEAD', spec.version, options) except (GbpError, GitRepositoryError, ChangelogError, NoSpecError) as err: if len(err.__str__()): diff --git a/tests/component/rpm/test_rpm_ch.py b/tests/component/rpm/test_rpm_ch.py index 968cfd4..b8c3bca 100644 --- a/tests/component/rpm/test_rpm_ch.py +++ b/tests/component/rpm/test_rpm_ch.py @@ -265,6 +265,28 @@ class TestRpmCh(RpmRepoTestBase): header = self.read_file('packaging/gbp-test-native.changes')[0] ok_(re.match(r'.+ foobar$', header)) + def test_option_commit(self): + """Test the --commit cmdline option""" + repo = self.init_test_repo('gbp-test') + + # Check unclean repo + with open('untracked-file', 'w') as fobj: + fobj.write('this file is not tracked\n') + with open('foo.txt', 'a') as fobj: + fobj.write('new stuff\n') + + # Unstaged file (foo.txt) -> failure + eq_(mock_ch(['--commit', '--since=HEAD^']), 1) + self._check_log(-1, 'gbp:error: Please commit or stage your changes') + + # Add file, update and commit, untracked file should be ignored + repo.add_files('foo.txt') + sha = repo.rev_parse('HEAD') + eq_(mock_ch(['--commit', '--since=HEAD^']), 0) + eq_(sha, repo.rev_parse('HEAD^')) + eq_(repo.get_commit_info('HEAD')['files'], + {'M': ['foo.txt', 'gbp-test.spec']}) + def test_tagging(self): """Test commiting/tagging""" repo = self.init_test_repo('gbp-test-native') -- 2.7.4