BumpVersion

Struct BumpVersion 

Source
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: VCS

Interface to the version control system (e.g., Git).

§config: FinalizedConfig

Finalized bumpversion configuration.

§logger: L

Logger for outputting messages and diffs.

§tag_and_revision: TagAndRevision

Metadata about the current tag and repository revision.

§file_map: FileMap

Mapping of files to their associated version change instructions.

§components: VersionComponentConfigs

Component 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,

Source

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

pub async fn run_pre_commit_hooks( &self, current_version: Option<&Version>, new_version: Option<&Version>, new_version_serialized: &str, ) -> Result<(), Error>

Run the pre-commit hooks

§Errors

When one of the user-provided pre-commit hooks exits with a non-zero exit code.

Source

pub async fn run_post_commit_hooks( &self, current_version: Option<&Version>, new_version: Option<&Version>, new_version_serialized: &str, ) -> Result<(), Error>

Run the post-commit hooks

§Errors

When one of the user-provided post-commit hooks exits with a non-zero exit code.

Source§

impl<VCS, L> BumpVersion<VCS, L>
where VCS: VersionControlSystem, L: Log,

Source

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.
Source

pub async fn update_config_file<K, V>( &self, config_file: &ConfigFile, ctx: &HashMap<K, V>, ) -> Result<Option<Modification>, BumpError<VCS>>
where K: Borrow<str> + Hash + Eq + Debug, V: AsRef<str> + Debug,

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.cfg and setup.cfg (INI)
  • .bumpversion.toml and pyproject.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.

Source

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:

  1. Collect files modified according to configured_files and any additional_files.
  2. Stage these files along with the configuration file if present.
  3. Commit with the configured commit message and arguments.
  4. 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.

Trait Implementations§

Source§

impl<VCS: Debug, L: Debug> Debug for BumpVersion<VCS, L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<VCS, L> Freeze for BumpVersion<VCS, L>
where VCS: Freeze, L: Freeze,

§

impl<VCS, L> RefUnwindSafe for BumpVersion<VCS, L>

§

impl<VCS, L> Send for BumpVersion<VCS, L>
where VCS: Send, L: Send,

§

impl<VCS, L> Sync for BumpVersion<VCS, L>
where VCS: Sync, L: Sync,

§

impl<VCS, L> Unpin for BumpVersion<VCS, L>
where VCS: Unpin, L: Unpin,

§

impl<VCS, L> UnwindSafe for BumpVersion<VCS, L>
where VCS: UnwindSafe, L: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more