rpm-ch: implement --commit option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 5 Jun 2014 13:37:25 +0000 (16:37 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:47:20 +0000 (14:47 +0200)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
docs/manpages/gbp-rpm-ch.sgml
gbp/scripts/rpm_ch.py
tests/component/rpm/test_rpm_ch.py

index 9f6ae999631db29e640e0f7b053bc2d6422fbd49..37a427269ecc61443b2913a14de8e46c477eb6a6 100644 (file)
@@ -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>
           </para>
         </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>
index 09586d008de1c5948af0d1a9b79ff0f352e46829..b509bd3919072926cf37478dd4b6edff04d7df8b 100755 (executable)
@@ -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__()):
index 968cfd4ae2f4640734dfb6fb78f1e4626a4a4217..b8c3bcaf63c058700b0507d7e9dce3f542a520d2 100644 (file)
@@ -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')