From 271429bd98d0bd28d181d0a930e778de926fec86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 18 Aug 2024 22:54:15 +0200 Subject: [PATCH] feat: `bump_version(check_default_branch = TRUE)` --- R/api-bump-version.R | 19 ++++++++++++++----- R/bump-version.R | 8 ++++++-- man/bump_version.Rd | 12 ++++++++++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/R/api-bump-version.R b/R/api-bump-version.R index e2778c742..6e9494cbb 100644 --- a/R/api-bump-version.R +++ b/R/api-bump-version.R @@ -4,10 +4,13 @@ #' Calls the following functions: #' #' @inheritParams update_version +#' @inheritParams rlang::args_dots_empty #' @param no_change_behavior What to do if there was no change since the last -#' version: `"bump"` for bump the version; -#' `"noop"` for do nothing; -#' `"fail"` for erroring. +#' version: `"bump"` for bump the version; +#' `"noop"` for do nothing; +#' `"fail"` for erroring. +#' @param check_default_branch Whether to check that the current branch is the +#' default branch. #' @return #' `TRUE` if `NEWS.md` and `DESCRIPTION` have been updated, #' `FALSE` otherwise. @@ -25,7 +28,12 @@ #' @example man/examples/bump-version.R bump_version <- function( which = c("dev", "patch", "pre-minor", "minor", "pre-major", "major"), - no_change_behavior = c("bump", "noop", "fail")) { + ..., + no_change_behavior = c("bump", "noop", "fail"), + check_default_branch = TRUE +) { + check_dots_empty() + which <- arg_match(which) no_change_behavior <- arg_match(no_change_behavior) @@ -43,7 +51,8 @@ bump_version <- function( new_fledgeling <- bump_version_impl( fledgeling, which = which, - no_change_behavior = no_change_behavior + no_change_behavior = no_change_behavior, + check_default_branch = check_default_branch ) invisible(!identical(new_fledgeling, fledgeling)) diff --git a/R/bump-version.R b/R/bump-version.R index 3cf7d42a0..10b8056f0 100644 --- a/R/bump-version.R +++ b/R/bump-version.R @@ -3,11 +3,15 @@ bump_version_impl <- function(fledgeling, which, no_change_behavior, + check_default_branch = TRUE, edit = TRUE, no_change_message = NULL) { #' @description - #' 1. Verify that the current branch is the main branch. - check_main_branch("bump_version()") + #' 1. Verify that the current branch is the main branch + #' if `check_default_branch = TRUE` (the default). + if (check_default_branch) { + check_main_branch("bump_version()") + } #' 1. Check if there were changes since the last version. if (no_change()) { if (no_change_behavior == "fail") { diff --git a/man/bump_version.Rd b/man/bump_version.Rd index 05dbb4bed..0cf897fd2 100644 --- a/man/bump_version.Rd +++ b/man/bump_version.Rd @@ -7,7 +7,9 @@ \usage{ bump_version( which = c("dev", "patch", "pre-minor", "minor", "pre-major", "major"), - no_change_behavior = c("bump", "noop", "fail") + ..., + no_change_behavior = c("bump", "noop", "fail"), + check_default_branch = TRUE ) } \arguments{ @@ -24,10 +26,15 @@ values are \item \code{"major"} (x.0.0). }} +\item{...}{These dots are for future extensions and must be empty.} + \item{no_change_behavior}{What to do if there was no change since the last version: \code{"bump"} for bump the version; \code{"noop"} for do nothing; \code{"fail"} for erroring.} + +\item{check_default_branch}{Whether to check that the current branch is the +default branch.} } \value{ \code{TRUE} if \code{NEWS.md} and \code{DESCRIPTION} have been updated, @@ -38,7 +45,8 @@ Do not rely on this behavior. Calls the following functions: \enumerate{ -\item Verify that the current branch is the main branch. +\item Verify that the current branch is the main branch +if \code{check_default_branch = TRUE} (the default). \item Check if there were changes since the last version. \item \code{\link[=update_news]{update_news()}}, using the \code{which} argument \item Depending on the \code{which} argument: