diff --git a/share/tito_completion.sh b/share/tito_completion.sh index f426025..031d949 100644 --- a/share/tito_completion.sh +++ b/share/tito_completion.sh @@ -61,6 +61,7 @@ __tito_report_opts=' __tito_tag_opts=' --accept-auto-changelog --auto-changelog-message= + --changelog --debug --help --keep-version diff --git a/src/tito/cli.py b/src/tito/cli.py index 0ce4e03..546fdb8 100644 --- a/src/tito/cli.py +++ b/src/tito/cli.py @@ -634,6 +634,10 @@ class TagModule(BaseCliModule): help=("Use MESSAGE as the default changelog message for " "new packages")) + self.parser.add_option("--changelog", + dest="changelog", action="append", + help=("Supply a custom changelog message to be used for this tag")) + self.parser.add_option("--undo", "-u", dest="undo", action="store_true", help="Undo the most recent (un-pushed) tag.") diff --git a/src/tito/tagger/main.py b/src/tito/tagger/main.py index 79c648c..0cee7b5 100644 --- a/src/tito/tagger/main.py +++ b/src/tito/tagger/main.py @@ -72,6 +72,7 @@ class VersionTagger(ConfigObject): self._no_auto_changelog = False self._accept_auto_changelog = False self._new_changelog_msg = "new package built with tito" + self._changelog = None self.offline = offline def run(self, options): @@ -92,6 +93,8 @@ class VersionTagger(ConfigObject): self._new_changelog_msg = options.auto_changelog_msg if options.use_version: self._use_version = options.use_version + if options.changelog: + self._changelog = options.changelog self.check_tag_precondition() @@ -225,13 +228,6 @@ class VersionTagger(ConfigObject): old_version = get_latest_tagged_version(self.project_name) - # don't die if this is a new package with no history - if old_version is not None: - last_tag = "%s-%s" % (self.project_name, old_version) - output = self._generate_default_changelog(last_tag) - else: - output = self._new_changelog_msg - fd, name = tempfile.mkstemp() write(fd, "# Create your changelog entry below:\n") if self.git_email is None or (('HIDE_EMAIL' in self.user_config) and @@ -243,10 +239,24 @@ class VersionTagger(ConfigObject): write(fd, header) - for cmd_out in output.split("\n"): - write(fd, "- ") - write(fd, "\n ".join(textwrap.wrap(cmd_out, 77))) - write(fd, "\n") + # don't die if this is a new package with no history + if self._changelog is not None: + for entry in self._changelog: + if not entry.startswith('-'): + entry = '- ' + entry + write(fd, entry) + write(fd, "\n") + else: + if old_version is not None: + last_tag = "%s-%s" % (self.project_name, old_version) + output = self._generate_default_changelog(last_tag) + else: + output = self._new_changelog_msg + + for cmd_out in output.split("\n"): + write(fd, "- ") + write(fd, "\n ".join(textwrap.wrap(cmd_out, 77))) + write(fd, "\n") write(fd, "\n") diff --git a/test/functional/singleproject_tests.py b/test/functional/singleproject_tests.py index da89fac..a34752d 100644 --- a/test/functional/singleproject_tests.py +++ b/test/functional/singleproject_tests.py @@ -61,6 +61,28 @@ class SingleProjectTests(TitoGitTestFixture): tito("tag --accept-auto-changelog --debug --use-version 9.0.0") check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True) + def test_tag_with_changelog(self): + tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog='-Test'") + check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True) + + changelog = getoutput("cat *.spec") + self.assertTrue('-Test' in changelog) + + def test_tag_with_changelog_format(self): + tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog=Test") + check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True) + + changelog = getoutput("cat *.spec") + self.assertTrue('- Test' in changelog) + + def test_tag_with_changelog_multiple(self): + tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog=Test --changelog=Fake") + check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True) + + changelog = getoutput("cat *.spec") + self.assertTrue('- Test' in changelog) + self.assertTrue('- Fake' in changelog) + def test_undo_tag(self): os.chdir(self.repo_dir) original_head = getoutput('git show-ref -s refs/heads/master') diff --git a/tito.8.asciidoc b/tito.8.asciidoc index b050c69..a4e8339 100644 --- a/tito.8.asciidoc +++ b/tito.8.asciidoc @@ -101,6 +101,11 @@ Automatically accept the generated changelog. Use 'MESSAGE' as the default changelog message for new packages +--changelog='MESSAGE':: +Use 'MESSAGE' as the changelog when tagging, this can be specified +everytime a package is tagged. Useful when needing to generate +custom changelogs. This will override the auto generated changelog. + -u, --undo:: Undo the most recent (un-pushed) tag.