diff --git a/src/tito/tagger/main.py b/src/tito/tagger/main.py index 0cee7b5..c2a1ada 100644 --- a/src/tito/tagger/main.py +++ b/src/tito/tagger/main.py @@ -19,9 +19,15 @@ import re import rpm import shutil import subprocess +import sys import tempfile import textwrap +try: + from shlex import quote +except ImportError: + from pipes import quote + from string import Template from time import strftime @@ -478,9 +484,22 @@ class VersionTagger(ConfigObject): run_command("git add %s" % os.path.join(self.full_project_dir, self.spec_file_name)) - run_command('git commit -m "Automatic commit of package ' + - '[%s] %s [%s]."' % (self.project_name, self.release_type(), - new_version_w_suffix)) + fmt = ('Automatic commit of package ' + '[%(name)s] %(release_type)s [%(version)s].') + if self.config.has_option(BUILDCONFIG_SECTION, "tag_commit_message_format"): + fmt = self.config.get(BUILDCONFIG_SECTION, "tag_commit_message_format") + try: + msg = fmt % { + 'name': self.project_name, + 'release_type': self.release_type(), + 'version': new_version_w_suffix, + } + except KeyError: + exc = sys.exc_info()[1] + raise TitoException('Unknown placeholder %s in tag_commit_message_format' + % exc) + + run_command('git commit -m %s' % quote(msg)) tag_msg = "Tagging package [%s] version [%s] in directory [%s]." % \ (self.project_name, new_version_w_suffix, diff --git a/test/functional/singleproject_tests.py b/test/functional/singleproject_tests.py index a34752d..dd7ff85 100644 --- a/test/functional/singleproject_tests.py +++ b/test/functional/singleproject_tests.py @@ -19,6 +19,7 @@ from tito.release import Releaser from tito.compat import getoutput from functional.fixture import TitoGitTestFixture, tito from tito.compat import RawConfigParser +from unit import Capture PKG_NAME = "titotestpkg" @@ -100,6 +101,36 @@ class SingleProjectTests(TitoGitTestFixture): new_head = getoutput('git show-ref -s refs/heads/master') self.assertEqual(original_head, new_head) + def test_tag_with_custom_message(self): + os.chdir(self.repo_dir) + with open(os.path.join(self.repo_dir, '.tito', 'tito.props'), 'a') as f: + f.write('tag_commit_message_format = No info plz\n') + + tito("tag --accept-auto-changelog") + + last_msg = getoutput('git log -n 1 --pretty=format:%s') + self.assertEqual('No info plz', last_msg.strip()) + + def test_tag_with_custom_message_bad_placeholder(self): + os.chdir(self.repo_dir) + with open(os.path.join(self.repo_dir, '.tito', 'tito.props'), 'a') as f: + f.write('tag_commit_message_format = %(ultimate_answer)s\n') + + with Capture(silent=True) as capture: + self.assertRaises(SystemExit, tito, "tag --accept-auto-changelog") + self.assertIn("Unknown placeholder 'ultimate_answer' in tag_commit_message_format", + capture.err) + + def test_tag_with_custom_message_containing_quotes(self): + os.chdir(self.repo_dir) + with open(os.path.join(self.repo_dir, '.tito', 'tito.props'), 'a') as f: + f.write('tag_commit_message_format = Hack"%(name)s\\\n') + + tito("tag --accept-auto-changelog") + + last_msg = getoutput('git log -n 1 --pretty=format:%s') + self.assertEqual('Hack"titotestpkg\\', last_msg.strip()) + def test_latest_tgz(self): tito("build --tgz -o %s" % self.repo_dir) diff --git a/tito.props.5.asciidoc b/tito.props.5.asciidoc index 8832290..8229023 100644 --- a/tito.props.5.asciidoc +++ b/tito.props.5.asciidoc @@ -75,6 +75,11 @@ for this repo. Can be useful for situations where one git repository is inheriting from another, but tags are created in both. The suffix will be an indicator as to which repo the tag originated in. (i.e. tag_suffix = -mysuffix) +tag_commit_message_format:: +This option is used control the text of git commit message that is used when +new tag is generated. You can use "%(name)s", "%(release_type)s" and +"%(version)s" placeholders. + KOJI and COPR -------------