diff options
-rw-r--r-- | docs/manpages/gbp-rpm-ch.sgml | 25 | ||||
-rwxr-xr-x | gbp/scripts/rpm_ch.py | 19 | ||||
-rw-r--r-- | 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 9f6ae999..37a42726 100644 --- a/docs/manpages/gbp-rpm-ch.sgml +++ b/docs/manpages/gbp-rpm-ch.sgml @@ -41,6 +41,7 @@ <arg><option>--git-log=</option><replaceable>GIT-LOG-OPTIONS</replaceable></arg> <arg><option>--spawn-editor=<replaceable>[always|release|no]</replaceable></option></arg> <arg><option>--editor-cmd=</option><replaceable>EDITOR</replaceable></arg> + <arg><option>--commit</option></arg> <arg><option>--tag</option></arg> <arg><option>--retag</option></arg> <arg><option>--[no-]sign-tags</option></arg> @@ -273,16 +274,28 @@ </listitem> </varlistentry> <varlistentry> + <term><option>--commit</option> + </term> + <listitem> + <para> + 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. + </para> + </listitem> + </varlistentry> + <varlistentry> <term><option>--tag</option> </term> <listitem> <para> - 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 - <option>--changelog-revision</option> string). + Commit the changes and create a packaging (release) tag. Similarly to + <option>--commit</option>, 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 <option>--changelog-revision</option> + string). </para> </listitem> </varlistentry> diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py index 09586d00..b509bd39 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 968cfd4a..b8c3bcaf 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') |