R/commit.R

Defines functions commit

Documented in commit

#' @title
#' Commit
#' @rdname commit
#' @export
#' @importFrom magrittr %>%
commit <-
  function(commit_msg,
           path = getwd(),
           verbose = TRUE) {
    command <-
      c(
        starting_command(path = path),
        paste0("git commit -m '", commit_msg, "'")
      ) %>%
      paste(collapse = "\n")

    commit_response <-
      suppressWarnings(
        system(
          command = command,
          intern = TRUE
        )
      )

    if (verbose) {
      cli::cat_line()
      cli::cat_rule(secretary::yellowTxt("Commit Response"))

      if ("no changes added to commit" %in% commit_response) {
        secretary::typewrite_italic(secretary::redTxt("\tNo changes added to the commit."))
      }

      cat(paste0("\t\t", commit_response), sep = "\n")

      cli::cat_line()
    }

    invisible(commit_response)
  }
meerapatelmd/glitter documentation built on Sept. 9, 2021, 6:21 p.m.