Adding --use-version to allow Tito to force a version to use.

This commit is contained in:
Alex Wood 2011-10-21 16:23:01 -04:00
parent fd4af9ef85
commit 3a621a9cc2
3 changed files with 46 additions and 3 deletions

View file

@ -500,6 +500,8 @@ class TagModule(BaseCliModule):
action="store_true", action="store_true",
help=("Use spec file version/release exactly as " help=("Use spec file version/release exactly as "
"specified in spec file to tag package.")) "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", self.parser.add_option("--no-auto-changelog", action="store_true",
default=False, default=False,
@ -532,7 +534,9 @@ class TagModule(BaseCliModule):
None, None) None, None)
tagger_class = 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_class = get_class_by_name(self.pkg_config.get("buildconfig",
"tagger")) "tagger"))
else: else:
@ -550,7 +554,9 @@ class TagModule(BaseCliModule):
except TitoException, e: except TitoException, e:
error_out(e.message) 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): class InitModule(BaseCliModule):
""" CLI Module for initializing a project for use with tito. """ """ CLI Module for initializing a project for use with tito. """

View file

@ -89,6 +89,8 @@ class VersionTagger(object):
self._accept_auto_changelog=True self._accept_auto_changelog=True
if options.auto_changelog_msg: if options.auto_changelog_msg:
self._new_changelog_msg = 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: # Only two paths through the tagger module right now:
if options.undo: if options.undo:
@ -303,7 +305,7 @@ class VersionTagger(object):
relative = current_dir[len(git_root) + 1:] + "/" relative = current_dir[len(git_root) + 1:] + "/"
return relative 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. Bump up the package version in the spec file.
@ -337,6 +339,20 @@ class VersionTagger(object):
, increase_zstream(match.group(2)) , increase_zstream(match.group(2))
, "\n" , "\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: else:
match = re.match(version_regex, line) match = re.match(version_regex, line)
if match: if match:
@ -508,3 +524,20 @@ class ReleaseTagger(VersionTagger):
def release_type(self): def release_type(self):
""" return short string "minor release" """ """ return short string "minor release" """
return "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)

View file

@ -53,6 +53,10 @@ class SingleProjectTests(TitoGitTestFixture):
tito("tag --accept-auto-changelog --debug") tito("tag --accept-auto-changelog --debug")
check_tag_exists("%s-0.0.2-1" % PKG_NAME, offline=True) 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): def test_undo_tag(self):
commit = self.repo.heads.master.commit commit = self.repo.heads.master.commit
tito("tag --accept-auto-changelog --debug") tito("tag --accept-auto-changelog --debug")