pub struct BumpVersion<VCS, L> {
pub repo: VCS,
pub config: FinalizedConfig,
pub logger: L,
pub tag_and_revision: TagAndRevision,
pub file_map: FileMap,
pub components: VersionComponentConfigs,
pub config_file: Option<ConfigFile>,
}Expand description
Manager for performing version bumps in a repository.
Holds the VCS interface, configuration, and file mappings needed to update version numbers, run hooks, and commit/tag changes.
Fields§
§repo: VCSInterface to the version control system (e.g., Git).
config: FinalizedConfigFinalized bumpversion configuration.
logger: LLogger for outputting messages and diffs.
tag_and_revision: TagAndRevisionMetadata about the current tag and repository revision.
file_map: FileMapMapping of files to their associated version change instructions.
components: VersionComponentConfigsComponent definitions for parsing and serializing versions.
config_file: Option<ConfigFile>Path to the configuration file in use, if any.
Implementations§
Source§impl<VCS, L> BumpVersion<VCS, L>where
VCS: VersionControlSystem,
L: Log,
impl<VCS, L> BumpVersion<VCS, L>where
VCS: VersionControlSystem,
L: Log,
Sourcepub async fn run_setup_hooks(
&self,
current_version: Option<&Version>,
) -> Result<(), Error>
pub async fn run_setup_hooks( &self, current_version: Option<&Version>, ) -> Result<(), Error>
Run the setup hooks
§Errors
When one of the user-provided setup hooks exits with a non-zero exit code.
Source§impl<VCS, L> BumpVersion<VCS, L>where
VCS: VersionControlSystem,
L: Log,
impl<VCS, L> BumpVersion<VCS, L>where
VCS: VersionControlSystem,
L: Log,
Sourcepub async fn bump(&self, bump: Bump<'_>) -> Result<(), BumpError<VCS>>
pub async fn bump(&self, bump: Bump<'_>) -> Result<(), BumpError<VCS>>
Bump the desired version component to the next value or set the version to new_version.
§Errors
- When the no current version is present.
- When the current or next version are empty.
- When one of the user-provided setup, pre, or post-commit hooks fails.
- When the current version component cannot be bumped.
- When the next version cannot be serialized.
- When a version in a file cannot be replaced.
Sourcepub async fn update_config_file<K, V>(
&self,
config_file: &ConfigFile,
ctx: &HashMap<K, V>,
) -> Result<Option<Modification>, BumpError<VCS>>
pub async fn update_config_file<K, V>( &self, config_file: &ConfigFile, ctx: &HashMap<K, V>, ) -> Result<Option<Modification>, BumpError<VCS>>
Update the version string in the bumpversion configuration file.
Detects the file format (INI or TOML), applies version replacement using the provided template context, and writes the file if modified (unless dry-run is enabled). Supports:
.bumpversion.cfgandsetup.cfg(INI).bumpversion.tomlandpyproject.toml(TOML)
§Arguments
config_file- The configuration file variant indicating path and format.ctx- Mapping of template variables for version substitution.
§Returns
Ok(Some(modification))when the file was updated and a diff is available.Ok(None)when no change was needed or the config file is outside the repository.
§Errors
Returns BumpError::ReplaceVersion if the version replacement fails due to
I/O, serialization, or template errors.
Sourcepub async fn commit_changes(
&self,
configured_files: &IndexMap<PathBuf, Vec<FileChange>>,
additional_files: &[impl AsRef<Path>],
current_version_serialized: String,
next_version_serialized: String,
ctx: &HashMap<String, String>,
) -> Result<(), BumpError<VCS>>
pub async fn commit_changes( &self, configured_files: &IndexMap<PathBuf, Vec<FileChange>>, additional_files: &[impl AsRef<Path>], current_version_serialized: String, next_version_serialized: String, ctx: &HashMap<String, String>, ) -> Result<(), BumpError<VCS>>
Stage and commit versioned files, and optionally create a VCS tag.
This will:
- Collect files modified according to
configured_filesand anyadditional_files. - Stage these files along with the configuration file if present.
- Commit with the configured commit message and arguments.
- If tagging is enabled in config, create a new tag with the configured name and message.
§Arguments
configured_files- Map of file paths to their version change instructions.additional_files- Extra file paths to include in the commit (e.g., config file).current_version_serialized- Previous version string before bump.next_version_serialized- New version string after bump.ctx- Context map used to format commit and tag templates.
§Errors
Returns a BumpError<VCS> if staging, committing, or tagging fails,
or if message/tag formatting encounters an error.