diff --git a/src/tito/cli.py b/src/tito/cli.py index 162f432..4f59f7b 100644 --- a/src/tito/cli.py +++ b/src/tito/cli.py @@ -500,6 +500,8 @@ class TagModule(BaseCliModule): action="store_true", help=("Use spec file version/release exactly as " "specified in spec file to tag package.")) + self.parser.add_option("--use-version", dest="use_version", + help=("Update the spec file with the specified version.")) self.parser.add_option("--no-auto-changelog", action="store_true", default=False, @@ -532,7 +534,9 @@ class TagModule(BaseCliModule): None, None) tagger_class = None - if self.pkg_config.has_option("buildconfig", "tagger"): + if self.options.use_version: + tagger_class = get_class_by_name("tito.tagger.ForceVersionTagger") + elif self.pkg_config.has_option("buildconfig", "tagger"): tagger_class = get_class_by_name(self.pkg_config.get("buildconfig", "tagger")) else: @@ -550,7 +554,9 @@ class TagModule(BaseCliModule): except TitoException, e: error_out(e.message) - + def _validate_options(self): + if self.options.keep_version and self.options.use_version: + error_out("Cannot combine --keep-version and --use-version") class InitModule(BaseCliModule): """ CLI Module for initializing a project for use with tito. """ diff --git a/src/tito/tagger.py b/src/tito/tagger.py index 4078e88..603aa91 100644 --- a/src/tito/tagger.py +++ b/src/tito/tagger.py @@ -89,6 +89,8 @@ class VersionTagger(object): self._accept_auto_changelog=True if options.auto_changelog_msg: self._new_changelog_msg = options.auto_changelog_msg + if options.use_version: + self._use_version = options.use_version # Only two paths through the tagger module right now: if options.undo: @@ -303,7 +305,7 @@ class VersionTagger(object): relative = current_dir[len(git_root) + 1:] + "/" return relative - def _bump_version(self, release=False, zstream=False): + def _bump_version(self, release=False, zstream=False, force=False): """ Bump up the package version in the spec file. @@ -337,6 +339,20 @@ class VersionTagger(object): , increase_zstream(match.group(2)) , "\n" )) + elif force: + match = re.match(version_regex, line) + if match: + line = "".join((match.group(1) + , self._use_version + , "\n" + )) + + match = re.match(release_regex, line) + if match: + line = "".join((match.group(1) + , reset_release(match.group(2)) + , "\n" + )) else: match = re.match(version_regex, line) if match: @@ -508,3 +524,20 @@ class ReleaseTagger(VersionTagger): def release_type(self): """ return short string "minor release" """ return "minor release" + +class ForceVersionTagger(VersionTagger): + """ + Tagger which forcibly updates the spec file to a version provided on the + command line by the --use-version option. + """ + + def _tag_release(self): + """ + Tag a new release of the package. + """ + self._make_changelog() + new_version = self._bump_version(force=True) + self._check_tag_does_not_exist(self._get_new_tag(new_version)) + self._update_changelog(new_version) + self._update_setup_py(new_version) + self._update_package_metadata(new_version) diff --git a/test/functional/singleproject_tests.py b/test/functional/singleproject_tests.py index 96c832e..533a351 100644 --- a/test/functional/singleproject_tests.py +++ b/test/functional/singleproject_tests.py @@ -53,6 +53,10 @@ class SingleProjectTests(TitoGitTestFixture): tito("tag --accept-auto-changelog --debug") check_tag_exists("%s-0.0.2-1" % PKG_NAME, offline=True) + def test_tag_with_version(self): + 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_undo_tag(self): commit = self.repo.heads.master.commit tito("tag --accept-auto-changelog --debug")