Allow customizing git commit message

This commit is contained in:
Lubomír Sedlář 2016-05-26 15:00:39 +02:00
parent e8d4404094
commit a86501c1b5
3 changed files with 58 additions and 3 deletions

View file

@ -19,9 +19,15 @@ import re
import rpm import rpm
import shutil import shutil
import subprocess import subprocess
import sys
import tempfile import tempfile
import textwrap import textwrap
try:
from shlex import quote
except ImportError:
from pipes import quote
from string import Template from string import Template
from time import strftime from time import strftime
@ -478,9 +484,22 @@ class VersionTagger(ConfigObject):
run_command("git add %s" % os.path.join(self.full_project_dir, run_command("git add %s" % os.path.join(self.full_project_dir,
self.spec_file_name)) self.spec_file_name))
run_command('git commit -m "Automatic commit of package ' + fmt = ('Automatic commit of package '
'[%s] %s [%s]."' % (self.project_name, self.release_type(), '[%(name)s] %(release_type)s [%(version)s].')
new_version_w_suffix)) 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]." % \ tag_msg = "Tagging package [%s] version [%s] in directory [%s]." % \
(self.project_name, new_version_w_suffix, (self.project_name, new_version_w_suffix,

View file

@ -19,6 +19,7 @@ from tito.release import Releaser
from tito.compat import getoutput from tito.compat import getoutput
from functional.fixture import TitoGitTestFixture, tito from functional.fixture import TitoGitTestFixture, tito
from tito.compat import RawConfigParser from tito.compat import RawConfigParser
from unit import Capture
PKG_NAME = "titotestpkg" PKG_NAME = "titotestpkg"
@ -100,6 +101,36 @@ class SingleProjectTests(TitoGitTestFixture):
new_head = getoutput('git show-ref -s refs/heads/master') new_head = getoutput('git show-ref -s refs/heads/master')
self.assertEqual(original_head, new_head) 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): def test_latest_tgz(self):
tito("build --tgz -o %s" % self.repo_dir) tito("build --tgz -o %s" % self.repo_dir)

View file

@ -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 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) 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 KOJI and COPR
------------- -------------