Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Pull as part of finalize_version() #408

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
7 changes: 5 additions & 2 deletions R/api-commit-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#' Commits changes to `NEWS.md` and `DESCRIPTION`, amending a previous commit
#' created by \pkg{fledge} if necessary.
#'
#' @param pull whether to fetch the remote (if it exists).
#'
#'
#' @example man/examples/commit-version.R
#'
#' @export
commit_version <- function() {
amending <- commit_version_impl()
commit_version <- function(pull = TRUE) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually the default should be FALSE I suppose

amending <- commit_version_impl(pull = pull)

#' @return Invisibly: `TRUE` if a previous commit for that version has been
#' amended, `FALSE` if not.
Expand Down
5 changes: 3 additions & 2 deletions R/api-finalize-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#' Calls the following functions:
#'
#' @param push If `TRUE`, push the created tag.
#' @inheritParams commit_version
#' @example man/examples/finalize-version.R
#' @return None
#' @export
finalize_version <- function(push = FALSE) {
with_repo(finalize_version_impl(push, suggest_finalize = FALSE))
finalize_version <- function(push = FALSE, pull = push) {
with_repo(finalize_version_impl(push, suggest_finalize = FALSE, pull))
}
2 changes: 1 addition & 1 deletion R/commit-version.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit_version_impl <- function() {
commit_version_impl <- function(pull) {
check_only_staged(c("DESCRIPTION", news_path()))

if (is_last_commit_bump()) {
Expand Down
10 changes: 9 additions & 1 deletion R/finalize-version.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#' @rdname finalize_version
#' @usage NULL
finalize_version_impl <- function(push, suggest_finalize = TRUE) {
finalize_version_impl <- function(push, suggest_finalize = TRUE, pull) {
#' @description
#' 1. [commit_version()]
force <- commit_version()
#' 1. [tag_version()], setting `force = TRUE` if and only if `commit_version()`
#' amended a commit.
tag <- tag_version(force)
#' 1. git pull with rebase if `pull = TRUE`.
if (has_remote_branch(gert::git_branch()) && pull) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should pull = TRUE fail if there's a remote branch?

# is the local branch behind?
if (gert::git_ahead_behind()$behind > 0) {
# With pull = TRUE we would fetch always and always uncommit + commit if behind master
gert::git_pull(rebase = TRUE)
}
}
#' 1. Force-pushes the created tag to the `"origin"` remote, if `push = TRUE`.
if (push) {
push_tag(tag, force = TRUE)
Expand Down
5 changes: 4 additions & 1 deletion man/commit_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/finalize_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 7 additions & 41 deletions tests/testthat/_snaps/bump_version.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
# bump_version() works -- dev

Code
bump_version()
Message
> Digesting messages from 3 commits.
v Found 1 NEWS-worthy entry.

-- Updating NEWS --

> Adding new entries to 'NEWS.md'.

-- Updating Version --

v Package version bumped to 0.0.0.9001.
> Added header to 'NEWS.md'.
> Committing changes.

-- Tagging Version --

> Creating tag v0.0.0.9001 with tag message derived from 'NEWS.md'.
! Call `fledge::finalize_version(push = TRUE)`.

---

x No change since last version.
i Use `no_change_behavior = "bump"` to force a version bump, or `no_change_behavior = "noop"` to do nothing.

Expand All @@ -33,28 +10,17 @@
Message
i No change since last version.

---

x No change since last version.
i Use `no_change_behavior = "bump"` to force a version bump, or `no_change_behavior = "noop"` to do nothing.

---

Code
bump_version(no_change_behavior = "bump")
bump_version(no_change_behavior = "noop")
Message
> Digesting messages from 1 commits.
i Same as previous version.

-- Updating NEWS --

> Adding new entries to 'NEWS.md'.

-- Updating Version --

v Package version bumped to 0.0.0.9002.
> Added header to 'NEWS.md'.
> Committing changes.

-- Tagging Version --

> Creating tag v0.0.0.9002 with tag message derived from 'NEWS.md'.
! Call `fledge::finalize_version(push = TRUE)`.
i No change since last version.

# bump_version() works -- not dev

Expand Down